Kallisto Linux API
Library for interacting with Kallisto devices
sensor_factory.hpp
Go to the documentation of this file.
1 
42 #ifndef SENSOR_FACTORY_HPP
43 #define SENSOR_FACTORY_HPP
44 
45 #include <vector>
46 #include <map>
47 #include <memory>
48 
49 #include "../../../util/log/easylogging++.h"
50 
51 #include "../../../util/error/kallisto_error.hpp"
52 #include "../../../util/executor/executor.hpp"
53 #include "../../../bluetooth/device/bluetooth_dispatcher.hpp"
54 #include "../synchronization/time_synchronizer.hpp"
55 #include "sensor_provider.hpp"
56 #include "sensor.hpp"
57 
58 namespace kallisto {
59 namespace hardware {
60 
61 class SensorFactory {
62 private:
64  std::vector<std::unique_ptr<SensorProvider>> m_providers; //Holds the providers
65 
66 public:
70  SensorFactory(){
71  m_providers = std::vector<std::unique_ptr<SensorProvider>>();
72  }
73 
78  m_providers.clear();
79  }
80 
86  error::KallistoDetailedResult registerProvider(std::unique_ptr<SensorProvider> provider){
87  for(auto it = m_providers.begin(); it != m_providers.end(); it++){
88  if(*it == provider){
89  return error::KallistoDetailedResult::build(error::ERROR_INVALID_PARAM, "Already registered");
90  }
91  }
92  m_providers.push_back(std::move(provider));
93  return error::KallistoDetailedResult::build(error::SUCCESS);
94  }
95 
101  error::KallistoDetailedResult unregisterProvider(std::unique_ptr<SensorProvider> provider){
102  for(auto it = m_providers.begin(); it != m_providers.end(); it++){
103  if(*it == provider){
104  m_providers.erase(it);
105  return error::KallistoDetailedResult::build(error::SUCCESS);
106  }
107  }
108 
109  return error::KallistoDetailedResult::build(error::ERROR_INVALID_PARAM, "Not registered");
110  }
111 
123  std::vector<std::unique_ptr<SensorImpl> > build(Kallisto& kallisto, const std::map<std::string, std::vector<uint8_t>>& service_data,
124  const std::map<uint16_t, std::vector<uint8_t> >& manufacturer_data, util::Executor& event_dispatcher,
125  bluetooth::BluetoothDispatcher& bluetooth_dispatcher, TimeSynchronizer& sensor_synchonizer){
126  std::vector<std::unique_ptr<SensorImpl> > sensor_list = std::vector<std::unique_ptr<SensorImpl> >();
127 
128  for(auto it1 = m_providers.begin(); it1 != m_providers.end(); it1++){
129  std::vector<std::unique_ptr<SensorImpl> > list = (*it1)->provide(kallisto, service_data, manufacturer_data, event_dispatcher, bluetooth_dispatcher, sensor_synchonizer);
130 
131  for(auto it2 = list.begin(); it2 != list.end(); it2++){
132  sensor_list.push_back(std::move(*it2));
133  }
134  }
135 
136  return sensor_list;
137  }
138 };
139 
140 } /* namespace hardware */
141 } /* namespace kallisto */
142 
143 #endif // SENSOR_FACTORY_HPP
static KallistoDetailedResult build(const KallistoResult result)
error::KallistoDetailedResult unregisterProvider(std::unique_ptr< SensorProvider > provider)
Definition: sensor_factory.hpp:100
Definition: time_synchronizer.hpp:56
Definition: bluetooth_adapter.hpp:52
Class that encapsulates a result.
Definition: kallisto_error.hpp:81
Definition: bluetooth_dispatcher.hpp:57
Definition: kallisto.hpp:52
Definition: executor.hpp:71
Definition: sensor_factory.hpp:60
SensorFactory()
Definition: sensor_factory.hpp:69
~SensorFactory()
Definition: sensor_factory.hpp:76
error::KallistoDetailedResult registerProvider(std::unique_ptr< SensorProvider > provider)
Definition: sensor_factory.hpp:85
std::vector< std::unique_ptr< SensorImpl > > build(Kallisto &kallisto, const std::map< std::string, std::vector< uint8_t >> &service_data, const std::map< uint16_t, std::vector< uint8_t > > &manufacturer_data, util::Executor &event_dispatcher, bluetooth::BluetoothDispatcher &bluetooth_dispatcher, TimeSynchronizer &sensor_synchonizer)
Definition: sensor_factory.hpp:122