Motorcortex Core  version: 2.7.6
cm_rpcmotorcortex.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2016 VECTIONEER.
4  */
5 
6 #ifndef CM_MOTORCORTEX_H
7 #define CM_MOTORCORTEX_H
8 
9 #include "cm_conndata.h"
10 #include "cm_rpcprocessor.h"
11 #include "motorcortex.pb.h"
12 #include "motorcortex_hash.h"
13 #include "pb.h"
14 
15 #include <string>
16 #include <vector>
17 
18 namespace mcx {
19 
20 namespace parameter_server {
21 class Parameter;
22 }
23 
24 namespace comm {
25 
26 class GroupManager;
27 class ParameterTree;
28 struct RequestParamList;
29 struct RequestParam;
30 
31 class RPCMotorcortex : public RPCProcessor {
32  static constexpr auto MAX_NUM_OF_REQ_ITR = 100;
33  static constexpr struct timespec SHORT_WAIT_TIME_MSEC { .tv_sec = 0, .tv_nsec = 1000000 };
34  static constexpr auto PARAMETER_SERIALIZATION_TIMEOUT_MSEC = 2000;
35  static constexpr auto PARAMETER_SERIALIZATION_N_TRIALS = 2;
36 
37 public:
38  RPCMotorcortex(GroupManager* group_manager, ParameterTree* parameter_tree);
39 
40  ~RPCMotorcortex() override = default;
41 
42  [[nodiscard]] MsgHashSet getHashList() const override;
43 
44  constexpr static int getHashSize() { return motorcortex::getHashSize(); }
45 
46  void setConfigPath(const std::string& path);
47 
48 private:
49  bool processRequest(const RequestMsg& request, ReplyMsg& reply) override;
50 
51  static bool decodeCreateGroupMsg(const RequestMsg& msg, motorcortex_CreateGroupMsg& create_grp_msg);
52 
53  inline size_t guessGroupParameterSize(const motorcortex_GroupParameterInfo& group_param_info) const;
54 
55  bool encodeGroupStatusMsg(size_t total_size, motorcortex_GroupStatusMsg& group_status, ReplyMsg& output_msg);
56 
57  static bool decodeRemoveGroupMsg(const RequestMsg& msg, motorcortex_RemoveGroupMsg& remove_grp_msg);
58 
59  static bool encodeStatusMsg(const motorcortex_StatusMsg& status_msg, ReplyMsg& output_msg);
60 
61  static bool decodeGetParameterMsg(const RequestMsg& msg, motorcortex_GetParameterMsg& get_param_msg);
62 
63  static bool decodeGetParameterListMsgHook(pb_istream_s* stream, const pb_field_t* field, void** arg);
64 
65  static bool decodeGetParameterListMsg(const RequestMsg& request,
66  std::vector<motorcortex_GetParameterMsg>& get_param_list);
67 
68  static bool decodeSetParameterMsgHook(pb_istream_s* stream, const pb_field_t* field, void** arg);
69 
70  bool decodeSetParameterMsg(const RequestMsg& msg);
71 
72  static bool decodeOverwriteParameterMsgHook(pb_istream_s* stream, const pb_field_t* field, void** arg);
73 
74  bool decodeOverwriteParameterMsg(const RequestMsg& msg);
75 
76  bool decodeReleaseParameterMsg(const RequestMsg& msg);
77 
78  static bool decodeSetParameterListMsgHook(pb_istream_s* stream, const pb_field_t* field, void** arg);
79 
80  bool decodeSetParameterListMsg(const RequestMsg& msg);
81 
82  static size_t guessParamSize(size_t param_size, size_t path_length);
83 
84  static bool encodeEmptyParameterMsgHook(pb_ostream_s* stream, const pb_field_t* field, void* const* arg);
85 
86  static bool encodeParameterMsgHook(pb_ostream_s* stream, const pb_field_t* field, void* const* arg);
87 
88  bool encodeEmptyParameterMsg(RequestParam& req_param, motorcortex_StatusCode status, ReplyMsg& output_msg);
89 
90  bool encodeParameterMsg(RequestParam& req_param, ReplyMsg& output_msg);
91 
92  static bool encodeParameterListMsgHook(pb_ostream_s* stream, const pb_field_t* field, void* const* arg);
93 
94  bool encodeParameterListMsg(RequestParamList& req_params, ReplyMsg& output_msg);
95 
96  static bool encodeParameterTreeHashMsg(const motorcortex_ParameterTreeHashMsg& hash_msg, ReplyMsg& output_msg);
97 
98  parameter_server::Parameter* getRoot();
99 
100  GroupManager* group_manager_;
101 
102  ParameterTree* parameter_tree_;
103 
104  std::string config_path_;
105 };
106 
107 } // namespace comm
108 
109 } // namespace mcx
110 
111 #endif /* CM_MOTORCORTEX_H */
mcx::comm::GroupManager
Definition: cm_groupmanager.h:55
mcx::parameter_server::Parameter
Definition: ps_parameter.h:45
_motorcortex_GetParameterMsg
Definition: motorcortex.pb.h:196
mcx::comm::ReplyMsg
Definition: cm_rpctypes.h:33
mcx::comm::RequestParamList
Definition: cm_rpcmotorcortex.cpp:25
_motorcortex_GroupStatusMsg
Definition: motorcortex.pb.h:345
_motorcortex_CreateGroupMsg
Definition: motorcortex.pb.h:174
mcx::comm::RPCProcessor
Definition: cm_rpcprocessor.h:13
mcx::comm::RPCMotorcortex
Definition: cm_rpcmotorcortex.h:31
_motorcortex_StatusMsg
Definition: motorcortex.pb.h:332
_motorcortex_ParameterTreeHashMsg
Definition: motorcortex.pb.h:270
mcx::comm::ParameterTree
Definition: cm_paramtree.h:30
mcx::comm::RequestParam
Definition: cm_rpcmotorcortex.cpp:19
_motorcortex_GroupParameterInfo
Definition: motorcortex.pb.h:217
_motorcortex_RemoveGroupMsg
Definition: motorcortex.pb.h:291
mcx::comm::RequestMsg
Definition: cm_rpctypes.h:24