Lely core libraries  2.3.4
gw.hpp
Go to the documentation of this file.
1 
22 #ifndef LELY_CO_GW_HPP_
23 #define LELY_CO_GW_HPP_
24 
25 #if !defined(__cplusplus) || LELY_NO_CXX
26 #error "include <lely/co/gw.h> for the C interface"
27 #endif
28 
29 #include <lely/util/c_type.hpp>
30 
31 namespace lely {
32 class COGW;
33 }
36 
37 #include <lely/co/gw.h>
38 
39 namespace lely {
40 
42 template <>
44  typedef __co_gw value_type;
45  typedef value_type& reference;
46  typedef const value_type& const_reference;
47  typedef value_type* pointer;
48  typedef const value_type* const_pointer;
49 
50  static void*
51  alloc() noexcept {
52  return __co_gw_alloc();
53  }
54  static void
55  free(void* ptr) noexcept {
56  __co_gw_free(ptr);
57  }
58 
59  static pointer
60  init(pointer p) noexcept {
61  return __co_gw_init(p);
62  }
63  static void
64  fini(pointer p) noexcept {
65  __co_gw_fini(p);
66  }
67 };
68 
70 class COGW : public incomplete_c_type<__co_gw> {
72 
73  public:
74  COGW() : c_base() {}
75 
76  int
77  initNet(co_unsigned16_t id, CONMT* nmt) noexcept {
78  return co_gw_init_net(this, id, nmt);
79  }
80 
81  int
82  finiNet(co_unsigned16_t id) noexcept {
83  return co_gw_fini_net(this, id);
84  }
85 
86  int
87  recv(const co_gw_req* req) noexcept {
88  return co_gw_recv(this, req);
89  }
90 
91  void
92  getSendFunc(co_gw_send_func_t** pfunc, void** pdata) const noexcept {
93  co_gw_get_send_func(this, pfunc, pdata);
94  }
95 
96  void
97  setSendFunc(co_gw_send_func_t* func, void* data) noexcept {
98  co_gw_set_send_func(this, func, data);
99  }
100 
101  template <class F>
102  void
103  setSendFunc(F* f) noexcept {
105  static_cast<void*>(f));
106  }
107 
108  template <class C, typename c_mem_fn<co_gw_send_func_t*, C>::type M>
109  void
110  setSendFunc(C* obj) noexcept {
112  static_cast<void*>(obj));
113  }
114 
115  void
116  getRateFunc(co_gw_rate_func_t** pfunc, void** pdata) const noexcept {
117  co_gw_get_rate_func(this, pfunc, pdata);
118  }
119 
120  void
121  setRateFunc(co_gw_rate_func_t* func, void* data) noexcept {
122  co_gw_set_rate_func(this, func, data);
123  }
124 
125  template <class F>
126  void
127  setRateFunc(F* f) noexcept {
129  static_cast<void*>(f));
130  }
131 
132  template <class C, typename c_mem_fn<co_gw_rate_func_t*, C>::type M>
133  void
134  setRateFunc(C* obj) noexcept {
136  static_cast<void*>(obj));
137  }
138 
139  protected:
140  ~COGW() = default;
141 };
142 
143 } // namespace lely
144 
145 #endif // !LELY_CO_GW_HPP_
lely::incomplete_c_type
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:249
co_gw_rate_func_t
void co_gw_rate_func_t(co_unsigned16_t net, co_unsigned16_t rate, void *data)
The type of a CANopen gateway 'set bit timing' function, invoked when a baudrate switch is needed aft...
Definition: gw.h:986
co_gw_req
The common parameters of a CANopen gateway request.
Definition: gw.h:271
co_gw_set_rate_func
void co_gw_set_rate_func(co_gw_t *gw, co_gw_rate_func_t *func, void *data)
Sets the callback function invoked when a baudrate switch is needed after an 'Initialize gateway' com...
Definition: gw.c:945
lely::c_obj_call
Definition: c_call.hpp:62
co_gw_send_func_t
int co_gw_send_func_t(const struct co_gw_srv *srv, void *data)
The type of a CANopen gateway send callback function, invoked by a gateway when an indication or conf...
Definition: gw.h:976
__co_gw
A CANopen gateway.
Definition: gw.c:313
lely::CONMT
An opaque CANopen NMT master/slave service type.
Definition: nmt.hpp:71
co_gw_init_net
int co_gw_init_net(co_gw_t *gw, co_unsigned16_t id, co_nmt_t *nmt)
Registers a CANopen network with a gateway.
Definition: gw.c:583
c_type.hpp
co_gw_recv
int co_gw_recv(co_gw_t *gw, const struct co_gw_req *req)
Receives and processes a request with a CANopen gateway.
Definition: gw.c:614
co_gw_t
lely::COGW co_gw_t
An opaque CANopen gateway type.
Definition: gw.hpp:35
co_gw_fini_net
int co_gw_fini_net(co_gw_t *gw, co_unsigned16_t id)
Unregisters a CANopen network with a gateway.
Definition: gw.c:598
lely::c_type_traits
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:120
co_gw_set_send_func
void co_gw_set_send_func(co_gw_t *gw, co_gw_send_func_t *func, void *data)
Sets the callback function used to send indications and confirmations from a CANopen gateway.
Definition: gw.c:925
co_gw_get_send_func
void co_gw_get_send_func(const co_gw_t *gw, co_gw_send_func_t **pfunc, void **pdata)
Retrieves the callback function used to send indications and confirmations from a CANopen gateway.
Definition: gw.c:914
lely::c_mem_call
Definition: c_call.hpp:67
gw.h
lely::COGW
An opaque CANopen gateway type.
Definition: gw.hpp:70
co_gw_get_rate_func
void co_gw_get_rate_func(const co_gw_t *gw, co_gw_rate_func_t **pfunc, void **pdata)
Retrieves the callback function invoked when a baudrate switch is needed after an 'Initialize gateway...
Definition: gw.c:934