Motorcortex Core  version: 2.7.6
cm_grouprawpub.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2019 VECTIONEER.
4  */
5 
6 #ifndef MOTORCORTEX_CORE_CM_GROUPRAWPUB_H
7 #define MOTORCORTEX_CORE_CM_GROUPRAWPUB_H
8 
9 #include "cm_basepub.h"
10 #include "cm_groupmanager.h"
11 #include "motorcortex.pb.h"
12 
13 #include <nng/nng.h>
14 #include <nng/supplemental/tls/tls.h>
15 
16 namespace mcx::comm {
17 
18 class BaseRequestReply;
19 
20 struct GroupContainer;
21 
22 auto constexpr GP_ID_HEADER_SIZE_BYTES = 4;
23 
25 public:
26  explicit GroupRawPublisher(const BaseRequestReply& group_manager);
27 
28  GroupRawPublisher(const GroupRawPublisher& orig) = delete;
29 
30  ~GroupRawPublisher() override;
31 
32  bool connect(const ConnectionData& conn_data) override;
33 
34  void iterate() override;
35 
36  void publish(GroupContainer& group);
37 
38  void close() override;
39 
40 private:
41  static void pipeEvent(nng_pipe pipe, nng_pipe_ev pipe_ev, void* ptr);
42 
43  // needed for older g++ in yocto
44  static void pipeEvent(nng_pipe pipe, int pipe_ev, void* ptr);
45 
46  virtual size_t encodeGroupParameterMsgWithId(GroupContainer& group, uint8_t* reply) = 0;
47 
48  nng_socket sock_{};
49  union {
50  nng_listener listener;
51  nng_dialer dialer;
52  } endpoint_;
53  bool is_listener_{};
54  nng_tls_config* tls_cfg_{nullptr};
55  //
56  long group_update_counter_;
57  // const ref. to the group manager
58  const GroupManager& group_manager_;
59  // a copy on change, obtained from the group manager
60  GroupMap groups_;
61 
62  struct {
63  void* buffer;
64  uint32_t size;
65  } output_;
66 };
67 
68 } // namespace mcx::comm
69 
70 #endif // MOTORCORTEX_CORE_CM_GROUPRAWPUB_H
mcx::comm::GroupManager
Definition: cm_groupmanager.h:55
mcx::comm::BaseRequestReply
Definition: cm_basereqrep.h:18
mcx::comm::ConnectionData
Definition: cm_conndata.h:18
mcx::comm::BasePublisher
Definition: cm_basepub.h:14
mcx::comm::GroupRawPublisher
Definition: cm_grouprawpub.h:24
mcx::comm::GroupContainer
Definition: cm_groupmanager.h:45