TwirreLink
 All Classes Functions Pages
TwirreLink.h
1 /*
2  * Twirre: architecture for autonomous UAVs using interchangeable commodity components
3  *
4  * Copyright© 2017 Centre of expertise in Computer Vision & Data Science, NHL Stenden University of applied sciences
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7  *
8  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11  */
12 
13 #ifndef TWIRRELINK_H_
14 #define TWIRRELINK_H_
15 
16 #include <map>
17 #include <set>
18 #include <initializer_list>
19 #include <thread>
20 
21 #include "Core/Actuator.h"
22 #include "Core/Sensor.h"
23 #include "Logger/TwirreLogger.h"
24 #include "DeviceProvider.h"
25 
26 namespace twirre
27 {
31  class TwirreLink
32  {
33  friend class DeviceProvider;
34  public:
38  TwirreLink();
39 
40  ~TwirreLink();
41 
46  explicit TwirreLink(DeviceProvider& prov);
47 
52  TwirreLink(const std::vector<DeviceProvider *> & provs);
53 
57  TwirreLink(const TwirreLink & other);
58 
62  TwirreLink(TwirreLink && other);
63 
67  TwirreLink& operator = (const TwirreLink & other);
68 
73 
74 
83  void addProvider(DeviceProvider& prov, bool update = true);
84 
92  void removeProvider(DeviceProvider& prov);
93 
99  const std::map<std::string, Actuator*> & getActuators();
100 
107  const std::map<std::string, Sensor*> & getSensors();
108 
116  bool haveSensor(const std::string & sensorName) const;
117 
125  bool haveActuator(const std::string & actuatorName) const;
126 
136  Sensor& getSensor(const std::string & sensorName);
137 
147  Actuator& getActuator(const std::string & actuatorName);
148 
154  void startLogging(const std::string & loggingPath);
155 
161  bool stopLogging(void);
162 
169  void writeToLog(std::string sensorName, const std::vector<std::pair<std::string, std::string>> & values);
170 
176  void setLoggingMaxArraySize(size_t max);
177 
178  private:
179  void logDevices(void);
180  void notifyChange(void);
181  void removeLink(DeviceProvider * which); //called by DeviceProvider's destructor
182 
183  std::set<DeviceProvider *> _providers;
184  std::map<std::string, Actuator*> _actuatorList;
185  std::map<std::string, Sensor*> _sensorList;
186 
187  mutable std::recursive_mutex _provMutex; //protects access / modification of providers
188  mutable std::recursive_mutex _tlMutex; //protects access / modification of sensorlist and acutatorlist
189 
190  TwirreLogger * _logger = nullptr;
191  };
192 
193 } /* namespace twirre */
194 
195 #endif /* TWIRRELINK_H_ */
Definition: TwirreLogger.h:31
Definition: Sensor.h:22
A DeviceProvider is a collection of Actuators and Sensors which can be connected to a TwirreLink inst...
Definition: DeviceProvider.h:33
Actuator is the base class for all 'actuator'-type devices.
Definition: Actuator.h:41