Lely core libraries  2.2.5
time.hpp
Go to the documentation of this file.
1 
23 #ifndef LELY_CO_TIME_HPP_
24 #define LELY_CO_TIME_HPP_
25 
26 #ifndef __cplusplus
27 #error "include <lely/co/time.h> for the C interface"
28 #endif
29 
30 #include <lely/can/net.hpp>
31 #include <lely/co/time.h>
32 
33 namespace lely {
34 
36 template <>
38  typedef __co_time 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_time_alloc();
47  }
48  static void
49  free(void* ptr) noexcept {
50  __co_time_free(ptr);
51  }
52 
53  static pointer
54  init(pointer p, CANNet* net, CODev* dev) noexcept {
55  return __co_time_init(p, net, dev);
56  }
57 
58  static void
59  fini(pointer p) noexcept {
60  __co_time_fini(p);
61  }
62 };
63 
65 class COTime : public incomplete_c_type<__co_time> {
67 
68  public:
69  COTime(CANNet* net, CODev* dev) : c_base(net, dev) {}
70 
71  CANNet*
72  getNet() const noexcept {
73  return co_time_get_net(this);
74  }
75  CODev*
76  getDev() const noexcept {
77  return co_time_get_dev(this);
78  }
79 
80  void
81  getInd(co_time_ind_t** pind, void** pdata) const noexcept {
82  co_time_get_ind(this, pind, pdata);
83  }
84 
85  void
86  setInd(co_time_ind_t* ind, void* data) noexcept {
87  co_time_set_ind(this, ind, data);
88  }
89 
90  template <class F>
91  void
92  setInd(F* f) noexcept {
93  setInd(&c_obj_call<co_time_ind_t*, F>::function, static_cast<void*>(f));
94  }
95 
96  template <class C, typename c_mem_fn<co_time_ind_t*, C>::type M>
97  void
98  setInd(C* obj) noexcept {
100  static_cast<void*>(obj));
101  }
102 
103  void
104  start(const timespec* start = 0, const timespec* interval = 0) noexcept {
105  co_time_start(this, start, interval);
106  }
107 
108  void
109  stop() noexcept {
110  co_time_stop(this);
111  }
112 
113  protected:
114  ~COTime() = default;
115 };
116 
117 } // namespace lely
118 
119 #endif // !LELY_CO_TIME_HPP_
lely::incomplete_c_type
The base class for a C++ interface to an incomplete C type.
Definition: c_type.hpp:249
net.hpp
__co_time
A CANopen TIME producer/consumer service.
Definition: time.c:41
co_time_set_ind
void co_time_set_ind(co_time_t *time, co_time_ind_t *ind, void *data)
Sets the indication function invoked when a CANopen time stamp is received.
Definition: time.c:287
lely::c_obj_call
Definition: c_call.hpp:62
co_time_stop
void co_time_stop(co_time_t *time)
Stops a CANopen TIME producer.
Definition: time.c:306
time.h
lely::COTime
An opaque CANopen TIME producer/consumer service type.
Definition: time.hpp:65
lely::CANNet
An opaque CAN network interface type.
Definition: net.hpp:85
co_time_get_dev
co_dev_t * co_time_get_dev(const co_time_t *time)
Returns a pointer to the CANopen device of a TIME producer/consumer service.
Definition: time.c:268
lely::c_type_traits
A class template supplying a uniform interface to certain attributes of C types.
Definition: c_type.hpp:120
co_time_get_ind
void co_time_get_ind(const co_time_t *time, co_time_ind_t **pind, void **pdata)
Retrieves the indication function invoked when a CANopen time stamp is received.
Definition: time.c:276
co_time_ind_t
void co_time_ind_t(co_time_t *time, const struct timespec *tp, void *data)
The type of a CANopen TIME indication function, invoked when a time stamp is received.
Definition: time.h:52
co_time_get_net
can_net_t * co_time_get_net(const co_time_t *time)
Returns a pointer to the CAN network of a TIME producer/consumer service.
Definition: time.c:260
lely::c_mem_call
Definition: c_call.hpp:67
co_time_start
void co_time_start(co_time_t *time, const struct timespec *start, const struct timespec *interval)
Starts a CANopen TIME producer.
Definition: time.c:296
lely::CODev
An opaque CANopen device type.
Definition: dev.hpp:77