summaryrefslogtreecommitdiff
path: root/peripheral/sensors/edison_arduino
diff options
context:
space:
mode:
authorConstantin Musca <constantin.musca@intel.com>2015-11-19 18:28:49 +0200
committerBruce Beare <bruce.j.beare@intel.com>2015-12-04 10:47:02 -0800
commit0a9924187ea64e64698d53d86663a625141f8693 (patch)
tree153c2a4e9956849ba90c96107272b16b5c21288f /peripheral/sensors/edison_arduino
parentcdc30c6fbc24dd1b880eab4a4d52a155727938ea (diff)
downloadintel-0a9924187ea64e64698d53d86663a625141f8693.tar.gz
SensorDescriptionFactory: make the state static
SensorDescriptionFactory needs to be accessed from different classes and it's waste of space to allocate from each class an object or pass references between classes. Statically expose the sensor description methods. BUG=25892368 Tracked-On: https://jira01.devtools.intel.com/browse/BP-128 Change-Id: I993036045d48f874f22e27f7069fe3c74b738b96 Reviewed-on: https://android.intel.com/438391 Reviewed-by: Serban, Mihai <mihai.serban@intel.com> Signed-off-by: Beare, Bruce J <bruce.j.beare@intel.com> Signed-off-by: Constantin Musca <constantin.musca@intel.com>
Diffstat (limited to 'peripheral/sensors/edison_arduino')
-rw-r--r--peripheral/sensors/edison_arduino/SensorDescriptionFactory.cpp46
-rw-r--r--peripheral/sensors/edison_arduino/SensorDescriptionFactory.hpp25
-rw-r--r--peripheral/sensors/edison_arduino/SensorsHAL.cpp6
-rw-r--r--peripheral/sensors/edison_arduino/SensorsHAL.hpp9
4 files changed, 43 insertions, 43 deletions
diff --git a/peripheral/sensors/edison_arduino/SensorDescriptionFactory.cpp b/peripheral/sensors/edison_arduino/SensorDescriptionFactory.cpp
index ebee43c..a7385a1 100644
--- a/peripheral/sensors/edison_arduino/SensorDescriptionFactory.cpp
+++ b/peripheral/sensors/edison_arduino/SensorDescriptionFactory.cpp
@@ -18,24 +18,8 @@
#include "SensorDescriptionFactory.hpp"
#include "sensors/Sensors.hpp"
-SensorDescriptionFactory::SensorDescriptionFactory() {
- for (int i = 0; i < Sensor::Type::kNumTypes; i++) {
- descriptions[i] = *SensorDescriptionFactory::getDescription(
- static_cast<Sensor::Type>(i));
- }
-}
-
-struct sensor_t const * SensorDescriptionFactory::getDescriptions() {
- return descriptions;
-}
-
-bool SensorDescriptionFactory::areFlagsSet(int handle, uint32_t flags) {
- if ((handle < 0) || (handle >= Sensor::Type::kNumTypes)) {
- return false;
- }
-
- return (descriptions[handle].flags & flags) == flags;
-}
+bool SensorDescriptionFactory::initialized = false;
+struct sensor_t SensorDescriptionFactory::descriptions[Sensor::Type::kNumTypes];
struct sensor_t const *
SensorDescriptionFactory::getDescription(Sensor::Type type) {
@@ -58,3 +42,29 @@ SensorDescriptionFactory::getDescription(Sensor::Type type) {
}
return nullptr;
}
+
+struct sensor_t const * SensorDescriptionFactory::getDescriptions() {
+ init();
+
+ return descriptions;
+}
+
+bool SensorDescriptionFactory::areFlagsSet(int handle, uint32_t flags) {
+ if ((handle < 0) || (handle >= Sensor::Type::kNumTypes)) {
+ return false;
+ }
+
+ init();
+
+ return (descriptions[handle].flags & flags) == flags;
+}
+
+void SensorDescriptionFactory::init() {
+ if (!SensorDescriptionFactory::initialized) {
+ for (int i = 0; i < Sensor::Type::kNumTypes; i++) {
+ descriptions[i] = *SensorDescriptionFactory::getDescription(
+ static_cast<Sensor::Type>(i));
+ }
+ SensorDescriptionFactory::initialized = true;
+ }
+}
diff --git a/peripheral/sensors/edison_arduino/SensorDescriptionFactory.hpp b/peripheral/sensors/edison_arduino/SensorDescriptionFactory.hpp
index 3d77c8a..18807e5 100644
--- a/peripheral/sensors/edison_arduino/SensorDescriptionFactory.hpp
+++ b/peripheral/sensors/edison_arduino/SensorDescriptionFactory.hpp
@@ -29,34 +29,35 @@ class SensorDescriptionFactory {
public:
/**
- * SensorDescriptionFactory constructor
- */
- SensorDescriptionFactory();
+ * Retrieve a sensor description of a certain type
+ * @param type sensor type
+ * @return pointer to a description data structure
+ */
+ static struct sensor_t const * getDescription(Sensor::Type type);
/**
- * get all available sensor descriptions
+ * Get all available sensor descriptions
* @return array of sensor description data structures
*/
- struct sensor_t const * getDescriptions();
+ static struct sensor_t const * getDescriptions();
/**
- * check if a sensor description has certain flags set
+ * Check if a sensor description has certain flags set
* @param handle sensor type identifier
* @param flags flags to check
* @return true if flags are set, false otherwise
*/
- bool areFlagsSet(int handle, uint32_t flags);
+ static bool areFlagsSet(int handle, uint32_t flags);
private:
/*
- * Retrieve a sensor description of a certain type
- * @param type sensor type
- * @return pointer to a description data structure
+ * Initialize static members
*/
- static struct sensor_t const * getDescription(Sensor::Type type);
+ static void init();
- struct sensor_t descriptions[Sensor::Type::kNumTypes];
+ static struct sensor_t descriptions[Sensor::Type::kNumTypes];
+ static bool initialized;
};
#endif // SENSOR_DESCRIPTION_FACTORY_HPP
diff --git a/peripheral/sensors/edison_arduino/SensorsHAL.cpp b/peripheral/sensors/edison_arduino/SensorsHAL.cpp
index 74ca3d8..1863f1c 100644
--- a/peripheral/sensors/edison_arduino/SensorsHAL.cpp
+++ b/peripheral/sensors/edison_arduino/SensorsHAL.cpp
@@ -26,8 +26,6 @@
int gPollFd;
-SensorDescriptionFactory SensorContext::sensorDescriptionFactory;
-
SensorContext::SensorContext(const hw_module_t* module) {
memset(&device, 0, sizeof(device));
@@ -152,7 +150,7 @@ int SensorContext::flush(int handle) {
}
/* flush doesn't apply to one-shot sensors */
- if (SensorContext::sensorDescriptionFactory.areFlagsSet(
+ if (SensorDescriptionFactory::areFlagsSet(
handle, SENSOR_FLAG_ONE_SHOT_MODE))
return -EINVAL;
@@ -225,7 +223,7 @@ static struct hw_module_methods_t sensors_module_methods = {
static int get_sensors_list(struct sensors_module_t* module,
struct sensor_t const** list) {
if (!list) return 0;
- *list = SensorContext::getSensorDescriptions();
+ *list = SensorDescriptionFactory::getDescriptions();
return Sensor::Type::kNumTypes;
}
diff --git a/peripheral/sensors/edison_arduino/SensorsHAL.hpp b/peripheral/sensors/edison_arduino/SensorsHAL.hpp
index 08b43d3..d238c58 100644
--- a/peripheral/sensors/edison_arduino/SensorsHAL.hpp
+++ b/peripheral/sensors/edison_arduino/SensorsHAL.hpp
@@ -42,14 +42,6 @@ class SensorContext {
*/
~SensorContext();
- /**
- * Get all supported sensor descriptions
- * @return array of sensor descriptions
- */
- static struct sensor_t const * getSensorDescriptions() {
- return SensorContext::sensorDescriptionFactory.getDescriptions();
- }
-
private:
int activate(int handle, int enabled);
int setDelay(int handle, int64_t ns);
@@ -71,7 +63,6 @@ class SensorContext {
static int FlushWrapper(sensors_poll_device_1_t* dev, int handle);
Sensor * sensors[Sensor::Type::kNumTypes];
- static SensorDescriptionFactory sensorDescriptionFactory;
};
#endif // SENSORS_HAL_HPP