yarp-devices
SyncPeriodicThread.hpp
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __SYNC_PERIODIC_THREAD_HPP__
4 #define __SYNC_PERIODIC_THREAD_HPP__
5 
6 #include <string>
7 #include <vector>
8 
9 #include <yarp/os/Bottle.h>
10 #include <yarp/os/PeriodicThread.h>
11 #include <yarp/os/Port.h>
12 #include <yarp/os/PortWriterBuffer.h>
13 
14 #include "FutureTask.hpp"
15 #include "SingleBusBroker.hpp"
16 #include "StateObserver.hpp"
17 
18 namespace roboticslab
19 {
20 
28 class SyncPeriodicThread final : public yarp::os::PeriodicThread
29 {
30 public:
32  SyncPeriodicThread(std::vector<SingleBusBroker *> & brokers, FutureTaskFactory * taskFactory);
33 
35  ~SyncPeriodicThread() override;
36 
38  bool openPort(const std::string & name);
39 
42  { this->syncObserver = syncObserver; }
43 
45  void run() override;
46 
47 private:
48  std::vector<SingleBusBroker *> & brokers;
49  FutureTaskFactory * taskFactory;
50  TypedStateObserver<double> * syncObserver;
51  yarp::os::Port syncPort;
52  yarp::os::PortWriterBuffer<yarp::os::Bottle> syncWriter;
53 };
54 
55 } // namespace roboticslab
56 
57 #endif // __SYNC_PERIODIC_THREAD_HPP__
Base class for an abstract factory of FutureTask.
Definition: FutureTask.hpp:56
Periodic SYNC signal emitter.
Definition: SyncPeriodicThread.hpp:29
SyncPeriodicThread(std::vector< SingleBusBroker * > &brokers, FutureTaskFactory *taskFactory)
Constructor, manages the lifetime of taskFactory.
Definition: SyncPeriodicThread.cpp:13
void run() override
Periodic task.
Definition: SyncPeriodicThread.cpp:44
void setObserver(TypedStateObserver< double > *syncObserver)
Set synchronization observer.
Definition: SyncPeriodicThread.hpp:41
bool openPort(const std::string &name)
Open synchronization port.
Definition: SyncPeriodicThread.cpp:35
~SyncPeriodicThread() override
Destructor.
Definition: SyncPeriodicThread.cpp:22
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6