MotionLib  1.0.0
SamBuCa motion library
SmcController.hpp
1 /*
2 ** Copyright (C) 2022 CERN
3 **
4 ** This software is provided 'as-is', without any express or implied
5 ** warranty. In no event will the authors be held liable for any damages
6 ** arising from the use of this software.
7 **
8 ** Permission is granted to anyone to use this software for any purpose,
9 ** including commercial applications, and to alter it and redistribute it
10 ** freely, subject to the following restrictions:
11 **
12 ** 1. The origin of this software must not be misrepresented; you must not
13 ** claim that you wrote the original software. If you use this software
14 ** in a product, an acknowledgment in the product documentation would be
15 ** appreciated but is not required.
16 ** 2. Altered source versions must be plainly marked as such, and must not be
17 ** misrepresented as being the original software.
18 ** 3. This notice may not be removed or altered from any source distribution.
19 **
20 ** Created on: 2022-07-27T13:22:52
21 ** Author: Sylvain Fargier <sylvain.fargier@cern.ch>
22 */
23 
24 #ifndef SMCCONTROLLER_HPP__
25 #define SMCCONTROLLER_HPP__
26 
27 #include <memory>
28 
29 #include <oatpp/core/macro/codegen.hpp>
30 #include <oatpp/core/macro/component.hpp>
31 #include <oatpp/web/server/api/ApiController.hpp>
32 
33 #include "MotionController.hpp"
34 
35 #include OATPP_CODEGEN_BEGIN(ApiController)
36 
37 template<typename T>
38 T getQueryParameter(
39  const std::shared_ptr<oatpp::web::protocol::http::incoming::Request> &request,
40  const char *name,
41  const T &defaultValue)
42 {
43  const oatpp::String param = request->getQueryParameter(name);
44  if (param)
45  {
46  bool success = false;
47  typedef
48  typename oatpp::data::mapping::type::ObjectWrapperByUnderlyingType<
49  T>::ObjectWrapper W;
50  W ret = oatpp::web::server::api::ApiController::TypeInterpretation<
51  decltype(ret)>::fromString(W::Class::CLASS_ID.name, param, success);
52  if (success)
53  return ret.getValue(defaultValue);
54  }
55  return defaultValue;
56 }
57 
58 class SmcController : public oatpp::web::server::api::ApiController
59 {
60 public:
61  typedef std::shared_ptr<SmcController> Shared;
63 
64  explicit SmcController(OATPP_COMPONENT(std::shared_ptr<ObjectMapper>,
65  objectMapper)) :
66  oatpp::web::server::api::ApiController(objectMapper)
67  {}
68 
69  void connect(const std::shared_ptr<smc::internal::PlatformFactory> &p,
70  const std::shared_ptr<smc::internal::DeviceStore> &d)
71  {
72  platformFactory = p;
73  deviceStore = d;
74  }
75 
76  std::weak_ptr<smc::internal::PlatformFactory> platformFactory;
77  std::weak_ptr<smc::internal::DeviceStore> deviceStore;
78 };
79 
80 #include OATPP_CODEGEN_END(ApiController)
81 
82 #endif