EEROS  1.0.0.0
API for the EEROS Real-Time Robotics Framework
HAL.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_HAL_HAL_HPP_
2 #define ORG_EEROS_HAL_HAL_HPP_
3 
4 #include <string>
5 #include <map>
6 #include <unordered_set>
7 #include <eeros/hal/Input.hpp>
8 #include <eeros/hal/Output.hpp>
11 #include <eeros/hal/JsonParser.hpp>
12 #include <eeros/core/Fault.hpp>
13 
14 
15 namespace eeros {
16  namespace hal {
17 
18  class HAL {
19  public:
20  OutputInterface* getOutput(std::string name, bool exclusive = true);
21  Output<bool>* getLogicOutput(std::string name, bool exclusive = true);
22  ScalableOutput<double>* getScalableOutput(std::string name, bool exclusive = true);
23  InputInterface* getInput(std::string name, bool exclusive = true);
24  Input<bool>* getLogicInput(std::string name, bool exclusive = true);
25  ScalableInput<double>* getScalableInput(std::string name, bool exclusive = true);
26  void releaseInput(std::string name);
27  void releaseOutput(std::string name);
28 
29  bool addInput(InputInterface* systemInput);
30  bool addOutput(OutputInterface* systemOutput);
31 
32  bool readConfigFromFile(std::string file);
33  bool readConfigFromFile(int* argc, char** argv);
34 
35  static HAL& instance();
36 
37  template<typename ... ArgTypesOut>
38  void callOutputFeature(OutputInterface *obj, std::string featureName, ArgTypesOut... args){
39 
40  void (*featureFunction)(OutputInterface*, ArgTypesOut...) = reinterpret_cast<void(*)(OutputInterface*, ArgTypesOut...)>(getOutputFeature(obj, featureName));
41  if(featureFunction == nullptr){
42  throw Fault("could not find method in dynamic library: " + featureName);
43  }
44  featureFunction(obj, args...);
45  }
46 
47  template<typename ... ArgTypesIn>
48  void callInputFeature(InputInterface *obj, std::string featureName, ArgTypesIn... args){
49 
50  void (*featureFunction)(InputInterface*, ArgTypesIn...) = reinterpret_cast<void(*)(InputInterface*, ArgTypesIn...)>(getInputFeature(obj, featureName));
51  if(featureFunction == nullptr){
52  throw Fault("could not find method in dynamic library: " + featureName);
53  }
54  featureFunction(obj, args...);
55  }
56 
57  private:
58  HAL();
59  HAL(const HAL&);
60  HAL& operator=(const HAL&);
61 
62  bool loadModule(std::string moduleName);
63 
64  void* getOutputFeature(std::string name, std::string featureName);
65  void* getOutputFeature(OutputInterface * obj, std::string featureName);
66  void* getInputFeature(std::string name, std::string featureName);
67  void* getInputFeature(InputInterface * obj, std::string featureName);
68 
69  std::unordered_set<OutputInterface*> exclusiveReservedOutputs;
70  std::unordered_set<OutputInterface*> nonExclusiveOutputs;
71  std::unordered_set<InputInterface*> exclusiveReservedInputs;
72  std::unordered_set<InputInterface*> nonExclusiveInputs;
73 
74  std::map<std::string, InputInterface*> inputs;
75  std::map<std::string, OutputInterface*> outputs;
76 
77  std::map<std::string, void*> hwLibraries;
78  JsonParser parser;
79 
80  logger::Logger log;
81 
82  };
83 
84  };
85 };
86 
87 #endif /* ORG_EEROS_HAL_HAL_HPP_ */
Definition: JsonParser.hpp:9
OutputInterface * getOutput(std::string name, bool exclusive=true)
Definition: HAL.cpp:143
InputInterface * getInput(std::string name, bool exclusive=true)
Definition: HAL.cpp:194
Definition: Logger.hpp:15
Definition: HAL.hpp:18
Definition: Output.hpp:10
ScalableOutput< double > * getScalableOutput(std::string name, bool exclusive=true)
Definition: HAL.cpp:176
Input< bool > * getLogicInput(std::string name, bool exclusive=true)
Definition: HAL.cpp:209
bool addOutput(OutputInterface *systemOutput)
Definition: HAL.cpp:96
Definition: Config.hpp:14
Output< bool > * getLogicOutput(std::string name, bool exclusive=true)
Definition: HAL.cpp:158
ScalableInput< double > * getScalableInput(std::string name, bool exclusive=true)
Definition: HAL.cpp:227
void callInputFeature(InputInterface *obj, std::string featureName, ArgTypesIn...args)
Definition: HAL.hpp:48
Definition: Fault.hpp:9
static HAL & instance()
Definition: HAL.cpp:13
void callOutputFeature(OutputInterface *obj, std::string featureName, ArgTypesOut...args)
Definition: HAL.hpp:38
Definition: ScalableInput.hpp:11
bool readConfigFromFile(std::string file)
Definition: HAL.cpp:18
Definition: ScalableOutput.hpp:11
bool addInput(InputInterface *systemInput)
Definition: HAL.cpp:86
Definition: Input.hpp:9
void releaseInput(std::string name)
Definition: HAL.cpp:107
void releaseOutput(std::string name)
Definition: HAL.cpp:125