TwirreLink
 All Classes Functions Pages
Sensor.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 SENSOR_H_
14 #define SENSOR_H_
15 
16 #include <vector>
17 
18 #include "Device.h"
19 
20 namespace twirre
21 {
22  class Sensor: public Device
23  {
24  public:
25  Sensor(const std::string name, const std::string description);
26  virtual ~Sensor();
27 
28  /*
29  * This class must never be passed by value
30  */
31  //disable empty constructor
32  Sensor() = delete;
33  //disable copy
34  Sensor(const Sensor&) = delete;
35  //disable move
36  Sensor(Sensor&&) = delete;
37  //disable assignment
38  Sensor& operator=(const Sensor&) = delete;
39  //disable move assignment
40  Sensor& operator=(Sensor&&) = delete;
41 
42  virtual std::map<std::string, Value*> SenseAll();
43 
44  virtual std::vector<std::string> getAvailableValues();
45  virtual bool haveValue(std::string name);
46  virtual bool haveValues(std::vector<std::string>);
47 
48  virtual Value & peekValue(std::string name);
49  virtual std::map<std::string, Value*> peekValues(const std::vector<std::string> &names);
50 
51 
52  virtual std::map<std::string, Value*> Sense_impl(const std::vector<std::string> &names);
53 
54  virtual void onSense(const std::vector<std::string> &names); //will be called by the Sense functions before sense_impl is called
55  Value & Sense(const std::string &name);
56  std::map<std::string, Value*> Sense(const std::vector<std::string> &names);
57 
58  Value & operator[](const std::string &name);
59  std::map<std::string, Value*> operator[](const std::vector<std::string> &names);
60 
61  virtual std::string ToString() override;
62 
63  void clearLoggerCallback();
64  void setLoggerCallback(std::function<void(Sensor *, std::map<std::string, Value*>&)> cbfn);
65  protected:
66  std::function<void(Sensor *, std::map<std::string, Value*>&)> _loggerCallback;
67  std::map<std::string, Value*> _valueList;
68  void registerValue(Value* val);
69  void registerValues(std::vector<Value *> vals);
70  };
71 
72 } /* namespace twirre */
73 
74 #endif /* SENSOR_H_ */
Definition: Sensor.h:22
Definition: Value.h:140
Definition: Device.h:24