Lely core libraries  2.2.5
sync.hpp
Go to the documentation of this file.
1 
23 #ifndef LELY_CO_SYNC_HPP_
24 #define LELY_CO_SYNC_HPP_
25 
26 #ifndef __cplusplus
27 #error "include <lely/co/sync.h> for the C interface"
28 #endif
29 
30 #include <lely/can/net.hpp>
31 #include <lely/co/sync.h>
32 
33 namespace lely {
34 
36 template <>
38  typedef __co_sync value_type;
39  typedef value_type& reference;
40  typedef const value_type& const_reference;
41  typedef value_type* pointer;
42  typedef const value_type* const_pointer;
43 
44  static void*
45  alloc() noexcept {
46  return __co_sync_alloc();
47  }
48  static void
49  free(void* ptr) noexcept {
50  __co_sync_free(ptr);
51  }
52 
53  static pointer
54  init(pointer p, CANNet* net, CODev* dev) noexcept {
55  return __co_sync_init(p, net, dev);
56  }
57 
58  static void
59  fini(pointer p) noexcept {
60  __co_sync_fini(p);
61  }
62 };
63 
65 class COSync : public incomplete_c_type<__co_sync> {
67 
68  public:
69  COSync(CANNet* net, CODev* dev) : c_base(net, dev) {}
70 
71  CANNet*
72  getNet() const noexcept {
73  return co_sync_get_net(this);
74  }
75  CODev*
76  getDev() const noexcept {
77  return co_sync_get_dev(this);
78  }
79 
80  void
81  getInd(co_sync_ind_t** pind, void** pdata) const noexcept {
82  co_sync_get_ind(this, pind, pdata);
83  }
84 
85  void
86  setInd(co_sync_ind_t* ind, void* data) noexcept {
87  co_sync_set_ind(this, ind, data);
88  }
89 
90  template <class F>
91  void
92  setInd(F* f) noexcept {
93  setInd(&c_obj_call<co_sync_ind_t*, F>::function, static_cast<void*>(f));
94  }
95 
96  template <class C, typename c_mem_fn<co_sync_ind_t*, C>::type M>
97  void
98  setInd(C* obj) noexcept {
100  static_cast<void*>(obj));
101  }
102 
103  void
104  getErr(co_sync_err_t** perr, void** pdata) const noexcept {
105  co_sync_get_err(this, perr, pdata);
106  }
107 
108  void
109  setErr(co_sync_err_t* err, void* data) noexcept {
110  co_sync_set_err(this, err, data);
111  }
112 
113  template <class F>
114  void
115  setErr(F* f) noexcept {
116  setErr(&c_obj_call<co_sync_err_t*, F>::function, static_cast<void*>(f));
117  }
118 
119  template <class C, typename c_mem_fn<co_sync_err_t*, C>::type M>
120  void
121  setErr(C* obj) noexcept {
123  static_cast<void*>(obj));
124  }
125 
126  protected:
127  ~COSync() = default;
128 };
129 
130 } // namespace lely
131 
132 #endif // !LELY_CO_SYNC_HPP_
lely::incomplete_c_type
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:249
co_sync_set_err
void co_sync_set_err(co_sync_t *sync, co_sync_err_t *err, void *data)
Sets the error handling function of a SYNC consumer service.
Definition: sync.c:314
co_sync_ind_t
void co_sync_ind_t(co_sync_t *sync, co_unsigned8_t cnt, void *data)
The type of a CANopen SYNC indication function, invoked after a SYNC message is received or transmitt...
Definition: sync.h:49
net.hpp
sync.h
lely::c_obj_call
Definition: c_call.hpp:62
co_sync_get_err
void co_sync_get_err(const co_sync_t *sync, co_sync_err_t **perr, void **pdata)
Retrieves the error handling function of a SYNC consumer service.
Definition: sync.c:303
lely::COSync
An opaque CANopen SYNC producer/consumer service type.
Definition: sync.hpp:65
lely::CANNet
An opaque CAN network interface type.
Definition: net.hpp:85
lely::c_type_traits
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:120
co_sync_get_ind
void co_sync_get_ind(const co_sync_t *sync, co_sync_ind_t **pind, void **pdata)
Retrieves the indication function invoked after a CANopen SYNC message is received or transmitted.
Definition: sync.c:283
co_sync_err_t
void co_sync_err_t(co_sync_t *sync, co_unsigned16_t eec, co_unsigned8_t er, void *data)
The type of a CANopen SYNC error handling function, invoked when the SYNC data length does not match.
Definition: sync.h:60
co_sync_get_dev
co_dev_t * co_sync_get_dev(const co_sync_t *sync)
Returns a pointer to the CANopen device of a SYNC producer/consumer service.
Definition: sync.c:275
co_sync_get_net
can_net_t * co_sync_get_net(const co_sync_t *sync)
Returns a pointer to the CAN network of a SYNC producer/consumer service.
Definition: sync.c:267
lely::c_mem_call
Definition: c_call.hpp:67
__co_sync
A CANopen SYNC producer/consumer service.
Definition: sync.c:40
lely::CODev
An opaque CANopen device type.
Definition: dev.hpp:77
co_sync_set_ind
void co_sync_set_ind(co_sync_t *sync, co_sync_ind_t *ind, void *data)
Sets the indication function invoked after a CANopen SYNC message is received or transmitted.
Definition: sync.c:294