[Sensor] Refactoring of code
authorPiotr Kosko <p.kosko@samsung.com>
Mon, 16 Feb 2015 12:49:01 +0000 (13:49 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Tue, 17 Feb 2015 13:19:38 +0000 (22:19 +0900)
[Feature] Changed JS listener structure and C++ SensorData class added.

[Verification] Code compiles.
  All features work fine.

Change-Id: I0d11e3f2f9def07e928473c9c6ccee95393c7bfd
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/sensor/sensor_api.js
src/sensor/sensor_service.cc
src/sensor/sensor_service.h

index b179bddc6a15e1aa8391ebccb4bde0c0582cb380..7becb735557f82c05b6a28613d39cfc3501ab6a6 100644 (file)
@@ -30,29 +30,110 @@ var MagneticSensorAccuracy = {
     VERYGOOD : 'ACCURACY_VERYGOOD'
 };
 
-var _supportedSensors = [];
-var _startedSensors = {
-    LIGHT : false,
-    MAGNETIC : false,
-    PRESSURE : false,
-    PROXIMITY : false,
-    ULTRAVIOLET : false
+// helper class for sensor listeners
+var SensorListener = function (type, constructor) {
+    this.sensorType = type;
+    this.isStarted = false;
+    this.callback = undefined;
+    this.constructor = constructor;
+};
+
+SensorListener.prototype.tryCall = function (object) {
+    if (this.callback) {
+        this.callback(new this.constructor(object));
+    }
+};
+
+SensorListener.prototype.start = function (successCallback, errorCallback) {
+    if (!this.isStarted) {
+        // sensor not started
+        var thisObject = this;
+        native_.call('Sensor_start', {'sensorType' : thisObject.sensorType},
+                function(result) {
+                    if (native_.isFailure(result)) {
+                        if(!T_.isNullOrUndefined(errorCallback)) {
+                            errorCallback(native_.getErrorObject(result));
+                        }
+                    } else {
+                        thisObject.isStarted = true;
+                        successCallback();
+                    }
+                }
+        );
+    } else {
+        // sensor is already started - just call success callback
+        setTimeout(function(){successCallback()}, 0);
+    }
+};
+
+SensorListener.prototype.stop = function () {
+    if (this.isStarted) {
+        var result = native_.callSync('Sensor_stop', {'sensorType' : this.sensorType});
+        if (native_.isFailure(result)) {
+            throw native_.getErrorObject(result);
+        }
+        this.isStarted = false;
+    }
+};
+
+SensorListener.prototype.setListener = function (successCallback) {
+    if (!this.callback) {
+        //call platform only if there was no listener registered
+        var result = native_.callSync('Sensor_setChangeListener', {'sensorType' : this.sensorType});
+        if (native_.isFailure(result)) {
+            throw native_.getErrorObject(result);
+        }
+    }
+    this.callback = successCallback;
+};
+
+SensorListener.prototype.unsetListener = function () {
+    if (this.callback) {
+        //unregister in platform only if there is callback registered
+        this.callback = undefined;
+        var result = native_.callSync('Sensor_unsetChangeListener', {'sensorType' : this.sensorType});
+        if (native_.isFailure(result)) {
+            throw native_.getErrorObject(result);
+        }
+    }
 };
-var _isChecked = false;
 
+SensorListener.prototype.getData = function (successCallback, errorCallback) {
+    var thisObj = this;
+    if (!thisObj.isStarted) {
+        setTimeout(function() {
+            if (!T_.isNullOrUndefined(errorCallback)) {
+                errorCallback(new tizen.WebAPIException(
+                        tizen.WebAPIException.SERVICE_NOT_AVAILABLE_ERR,
+                        'Service is not available.'));
+            }
+        }, 0);
+    } else {
+        native_.call('Sensor_getData', { type : thisObj.sensorType },
+                function(result) {
+            if (native_.isFailure(result)) {
+                if(!T_.isNullOrUndefined(errorCallback)) {
+                    errorCallback(native_.getErrorObject(result));
+                }
+            } else {
+                successCallback(new thisObj.constructor(result));
+            }
+        });
+    }
+};
+
+var _supportedSensors = [];
+var _isChecked = false;
 var _sensorListeners = {
-    'LIGHT'       : { callback : undefined, constructor : undefined },
-    'MAGNETIC'    : { callback : undefined, constructor : undefined },
-    'PRESSURE'    : { callback : undefined, constructor : undefined },
-    'PROXIMITY'   : { callback : undefined, constructor : undefined },
-    'ULTRAVIOLET' : { callback : undefined, constructor : undefined }
-}
+    'LIGHT'       : {},
+    'MAGNETIC'    : {},
+    'PRESSURE'    : {},
+    'PROXIMITY'   : {},
+    'ULTRAVIOLET' : {}
+};
 
 var _listener = function(object) {
-    if (_sensorListeners[object.sensorType].callback) {
-        _sensorListeners[object.sensorType].callback(
-                new _sensorListeners[object.sensorType].constructor(object));
-    }
+    _sensorListeners[object.sensorType].tryCall(object);
 };
 
 var SENSOR_CHANGED_LISTENER = 'SensorChangedListener';
@@ -130,35 +211,11 @@ Sensor.prototype.start = function() {
        }
     ]);
 
-    if (!_startedSensors[this.sensorType]) {
-        // sensor not started
-        var type = this.sensorType;
-        native_.call('Sensor_start', {'sensorType' : type},
-            function(result) {
-                if (native_.isFailure(result)) {
-                    if(!T_.isNullOrUndefined(args.errorCallback)) {
-                        args.errorCallback(native_.getErrorObject(result));
-                    }
-                } else {
-                    _startedSensors[type] = true;
-                    args.successCallback();
-                }
-            }
-        );
-    } else {
-        // sensor is already started - just call success callback
-        setTimeout(function(){args.successCallback()}, 0);
-    }
+    _sensorListeners[this.sensorType].start(args.successCallback, args.errorCallback);
 };
 
 Sensor.prototype.stop = function() {
-    if (_startedSensors[this.sensorType]) {
-        var result = native_.callSync('Sensor_stop', {'sensorType' : this.sensorType});
-        if (native_.isFailure(result)) {
-            throw native_.getErrorObject(result);
-        }
-        _startedSensors[this.sensorType] = false;
-    }
+    _sensorListeners[this.sensorType].stop();
 };
 
 Sensor.prototype.setChangeListener = function() {
@@ -169,25 +226,11 @@ Sensor.prototype.setChangeListener = function() {
        }
     ]);
 
-    if (!_sensorListeners[this.sensorType].callback) {
-        //call platform only if there was no listener registered
-        var result = native_.callSync('Sensor_setChangeListener', {'sensorType' : this.sensorType});
-        if (native_.isFailure(result)) {
-            throw native_.getErrorObject(result);
-        }
-    }
-    _sensorListeners[this.sensorType].callback = args.successCallback;
+    _sensorListeners[this.sensorType].setListener(args.successCallback);
 };
 
 Sensor.prototype.unsetChangeListener = function() {
-    if (_sensorListeners[this.sensorType].callback) {
-        //unregister in platform only if there is callback registered
-        _sensorListeners[this.sensorType].callback = undefined;
-        var result = native_.callSync('Sensor_unsetChangeListener', {'sensorType' : this.sensorType});
-        if (native_.isFailure(result)) {
-            throw native_.getErrorObject(result);
-        }
-    }
+    _sensorListeners[this.sensorType].unsetListener();
 };
 
 //// LightSensor
@@ -213,26 +256,7 @@ LightSensor.prototype.getLightSensorData = function() {
        }
     ]);
 
-    if (!_startedSensors[this.sensorType]) {
-        setTimeout(function() {
-            if (!T_.isNullOrUndefined(args.errorCallback)) {
-                args.errorCallback(new tizen.WebAPIException(
-                        tizen.WebAPIException.SERVICE_NOT_AVAILABLE_ERR,
-                        'Service is not available.'));
-            }
-        }, 0);
-    } else {
-        native_.call('Sensor_getData', { type : this.sensorType },
-                function(result) {
-            if (native_.isFailure(result)) {
-                if(!T_.isNullOrUndefined(args.errorCallback)) {
-                    args.errorCallback(native_.getErrorObject(result));
-                }
-            } else {
-                args.successCallback(new SensorLightData(result));
-            }
-        });
-    }
+    _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
 };
 
 //// MagneticSensor
@@ -258,26 +282,7 @@ MagneticSensor.prototype.getMagneticSensorData = function() {
        }
     ]);
 
-    if (!_startedSensors[this.sensorType]) {
-        setTimeout(function() {
-            if (!T_.isNullOrUndefined(args.errorCallback)) {
-                args.errorCallback(new tizen.WebAPIException(
-                        tizen.WebAPIException.SERVICE_NOT_AVAILABLE_ERR,
-                        'Service is not available.'));
-            }
-        }, 0);
-    } else {
-        native_.call('Sensor_getData', { type : this.sensorType },
-                function(result) {
-            if (native_.isFailure(result)) {
-                if(!T_.isNullOrUndefined(args.errorCallback)) {
-                    args.errorCallback(native_.getErrorObject(result));
-                }
-            } else {
-                args.successCallback(new SensorMagneticData(result));
-            }
-        });
-    }
+    _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
 };
 
 //// PressureSensor
@@ -303,26 +308,7 @@ PressureSensor.prototype.getPressureSensorData = function() {
        }
     ]);
 
-    if (!_startedSensors[this.sensorType]) {
-        setTimeout(function() {
-            if (!T_.isNullOrUndefined(args.errorCallback)) {
-                args.errorCallback(new tizen.WebAPIException(
-                        tizen.WebAPIException.SERVICE_NOT_AVAILABLE_ERR,
-                        'Service is not available.'));
-            }
-        }, 0);
-    } else {
-        native_.call('Sensor_getData', { type : this.sensorType },
-                function(result) {
-            if (native_.isFailure(result)) {
-                if(!T_.isNullOrUndefined(args.errorCallback)) {
-                    args.errorCallback(native_.getErrorObject(result));
-                }
-            } else {
-                args.successCallback(new SensorPressureData(result));
-            }
-        });
-    }
+    _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
 };
 
 //// ProximitySensor
@@ -348,26 +334,7 @@ ProximitySensor.prototype.getProximitySensorData = function() {
        }
     ]);
 
-    if (!_startedSensors[this.sensorType]) {
-        setTimeout(function() {
-            if (!T_.isNullOrUndefined(args.errorCallback)) {
-                args.errorCallback(new tizen.WebAPIException(
-                        tizen.WebAPIException.SERVICE_NOT_AVAILABLE_ERR,
-                        'Service is not available.'));
-            }
-        }, 0);
-    } else {
-        native_.call('Sensor_getData', { type : this.sensorType },
-                function(result) {
-            if (native_.isFailure(result)) {
-                if(!T_.isNullOrUndefined(args.errorCallback)) {
-                    args.errorCallback(native_.getErrorObject(result));
-                }
-            } else {
-                args.successCallback(new SensorProximityData(result));
-            }
-        });
-    }
+    _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
 };
 
 //// UltravioletSensor
@@ -393,26 +360,7 @@ UltravioletSensor.prototype.getUltravioletSensorData = function() {
        }
     ]);
 
-    if (!_startedSensors[this.sensorType]) {
-        setTimeout(function() {
-            if (!T_.isNullOrUndefined(args.errorCallback)) {
-                args.errorCallback(new tizen.WebAPIException(
-                        tizen.WebAPIException.SERVICE_NOT_AVAILABLE_ERR,
-                        'Service is not available.'));
-            }
-        }, 0);
-    } else {
-        native_.call('Sensor_getData', { type : this.sensorType },
-                function(result) {
-            if (native_.isFailure(result)) {
-                if(!T_.isNullOrUndefined(args.errorCallback)) {
-                    args.errorCallback(native_.getErrorObject(result));
-                }
-            } else {
-                args.successCallback(new SensorUltravioletData(result));
-            }
-        });
-    }
+    _sensorListeners[this.sensorType].getData(args.successCallback, args.errorCallback);
 };
 
 ////////////////////// Sensor Data classes/////////////////////////////////////////////////////
@@ -432,7 +380,8 @@ SensorLightData.prototype = new SensorData();
 
 SensorLightData.prototype.constructor = SensorData;
 
-_sensorListeners[SensorType.LIGHT].constructor = SensorLightData;
+_sensorListeners[SensorType.LIGHT] = new SensorListener(SensorType.LIGHT,
+        SensorLightData);
 
 //// SensorMagneticData
 var SensorMagneticData = function(data) {
@@ -449,7 +398,8 @@ SensorMagneticData.prototype = new SensorData();
 
 SensorMagneticData.prototype.constructor = SensorData;
 
-_sensorListeners[SensorType.MAGNETIC].constructor = SensorMagneticData;
+_sensorListeners[SensorType.MAGNETIC] = new SensorListener(SensorType.MAGNETIC,
+        SensorMagneticData);
 
 //// SensorPressureData
 var SensorPressureData = function(data) {
@@ -463,7 +413,8 @@ SensorPressureData.prototype = new SensorData();
 
 SensorPressureData.prototype.constructor = SensorData;
 
-_sensorListeners[SensorType.PRESSURE].constructor = SensorPressureData;
+_sensorListeners[SensorType.PRESSURE] = new SensorListener(SensorType.PRESSURE,
+        SensorPressureData);
 
 //// SensorProximityData
 var SensorProximityData = function(data) {
@@ -477,7 +428,8 @@ SensorProximityData.prototype = new SensorData();
 
 SensorProximityData.prototype.constructor = SensorData;
 
-_sensorListeners[SensorType.PROXIMITY].constructor = SensorProximityData;
+_sensorListeners[SensorType.PROXIMITY] = new SensorListener(SensorType.PROXIMITY,
+        SensorProximityData);
 
 //// SensorUltravioletData
 var SensorUltravioletData = function(data) {
@@ -492,7 +444,8 @@ SensorUltravioletData.prototype = new SensorData();
 
 SensorUltravioletData.prototype.constructor = SensorData;
 
-_sensorListeners[SensorType.ULTRAVIOLET].constructor = SensorUltravioletData;
+_sensorListeners[SensorType.ULTRAVIOLET] = new SensorListener(SensorType.ULTRAVIOLET,
+        SensorUltravioletData);
 
 // Exports
 exports = new SensorService();
index 93238f841b4dd4af9b13777b5c9e9eaf064a87dc..3266ab08f129e77df74dcd2021675d102504739a 100644 (file)
@@ -71,26 +71,48 @@ static const std::string kListenerId = "listenerId";
 static const std::string kSensorChangedListener = "SensorChangedListener";
 }
 
-SensorService::SensorService() {
+SensorService::SensorData::SensorData(sensor_type_e type) :
+  handle_(nullptr),
+  listener_(nullptr),
+  type_enum_(type) {
 
 }
 
-SensorService::~SensorService() {
-  if (light_sensor_.listener) {
-    sensor_destroy_listener(light_sensor_.listener);
-  }
-  if (magnetic_sensor_.listener) {
-    sensor_destroy_listener(magnetic_sensor_.listener);
-  }
-  if (pressure_sensor_.listener) {
-    sensor_destroy_listener(pressure_sensor_.listener);
+SensorService::SensorData::~SensorData() {
+  if (listener_) {
+    sensor_destroy_listener(listener_);
   }
-  if (proximity_sensor_.listener) {
-    sensor_destroy_listener(proximity_sensor_.listener);
-  }
-  if (ultraviolet_sensor_.listener) {
-    sensor_destroy_listener(ultraviolet_sensor_.listener);
+}
+
+common::PlatformResult SensorService::SensorData::CheckInitialization() {
+  if (!handle_) {
+    LoggerD("initialization of handle and listener");
+    int ret = sensor_get_default_sensor(type_enum_, &handle_);
+    if (SENSOR_ERROR_NONE != ret) {
+      LoggerE("ret : %d", ret);
+      return PlatformResult(ErrorCode::UNKNOWN_ERR, "sensor_get_default_sensor");
+    }
+
+    ret = sensor_create_listener(handle_, &listener_);
+    if (SENSOR_ERROR_NONE != ret) {
+      LoggerE("ret : %d", ret);
+      return PlatformResult(ErrorCode::UNKNOWN_ERR, "sensor_create_listener");
+    }
   }
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+SensorService::SensorService() :
+    light_sensor_(SENSOR_LIGHT),
+    magnetic_sensor_(SENSOR_MAGNETIC),
+    pressure_sensor_(SENSOR_PRESSURE),
+    proximity_sensor_(SENSOR_PROXIMITY),
+    ultraviolet_sensor_(SENSOR_ULTRAVIOLET) {
+
+}
+
+SensorService::~SensorService() {
+
 }
 
 SensorService* SensorService::GetInstance() {
@@ -169,14 +191,7 @@ void SensorService::SensorStart(const picojson::value& args, picojson::object& o
   sensor_type_e type_enum = string_to_type_map[type_str];
 
   auto start = [this, type_enum, type_str](const std::shared_ptr<picojson::value>& result) {
-    PlatformResult res = CheckSensorInitialization(type_enum);
-    if (res.IsError()) {
-      LoggerE("Sensor initialization for sensor %s failed", type_str.c_str());
-      ReportError(res, &(result->get<picojson::object>()));
-      return;
-    }
     SensorData* sensor_data = GetSensorStruct(type_enum);
-
     if (!sensor_data) {
       LoggerD("Sensor data is null");
       ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Sensor data is null"),
@@ -184,8 +199,15 @@ void SensorService::SensorStart(const picojson::value& args, picojson::object& o
       return;
     }
 
-    int ret = sensor_listener_start(sensor_data->listener);
-    if (ret != SENSOR_ERROR_NONE) {
+    PlatformResult res = sensor_data->CheckInitialization();
+    if (res.IsError()) {
+      LoggerE("Sensor initialization for sensor %s failed", type_str.c_str());
+      ReportError(res, &(result->get<picojson::object>()));
+      return;
+    }
+
+    int ret = sensor_listener_start(sensor_data->listener_);
+    if (SENSOR_ERROR_NONE != ret) {
       LoggerE("ret : %d", ret);
       ReportError(GetSensorPlatformResult(ret, "sensor_listener_start"),
                   &(result->get<picojson::object>()));
@@ -214,20 +236,27 @@ void SensorService::SensorStop(const picojson::value& args, picojson::object& ou
 
   sensor_type_e type_enum = string_to_type_map[type_str];
 
-  PlatformResult res = CheckSensorInitialization(type_enum);
   SensorData* sensor_data = GetSensorStruct(type_enum);
-
   if (!sensor_data) {
     LoggerD("Sensor data is null");
     ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Sensor data is null"), &out);
     return;
   }
 
-  int ret = sensor_listener_stop(sensor_data->listener);
-  if (ret != SENSOR_ERROR_NONE) {
-    LOGE("ret : %d", ret);
+  PlatformResult res = sensor_data->CheckInitialization();
+  if (res.IsError()) {
+    LoggerE("Sensor initialization for sensor %s failed", type_str.c_str());
+    ReportError(res, &out);
+    return;
+  }
+
+  int ret = sensor_listener_stop(sensor_data->listener_);
+  if (SENSOR_ERROR_NONE != ret) {
+    LoggerE("ret : %d", ret);
     ReportError(GetSensorPlatformResult(ret, "sensor_listener_stop"), &out);
+    return;
   }
+  ReportSuccess(out);
 }
 
 void SensorService::SensorSetChangeListener(const picojson::value& args, picojson::object& out) {
@@ -238,21 +267,28 @@ void SensorService::SensorSetChangeListener(const picojson::value& args, picojso
 
   sensor_type_e type_enum = string_to_type_map[type_str];
 
-  PlatformResult res = CheckSensorInitialization(type_enum);
   SensorData* sensor_data = GetSensorStruct(type_enum);
-
   if (!sensor_data) {
     LoggerD("Sensor data is null");
     ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Sensor data is null"), &out);
     return;
   }
 
+  PlatformResult res = sensor_data->CheckInitialization();
+  if (res.IsError()) {
+    LoggerE("Sensor initialization for sensor %s failed", type_str.c_str());
+    ReportError(res, &out);
+    return;
+  }
+
   int ret = sensor_listener_set_event_cb(
-      sensor_data->listener, 100, GetCallbackFunction(type_enum), this);
-  if (ret != SENSOR_ERROR_NONE) {
-    LOGE("ret : %d", ret);
+      sensor_data->listener_, 100, GetCallbackFunction(type_enum), this);
+  if (SENSOR_ERROR_NONE != ret) {
+    LoggerE("ret : %d", ret);
     ReportError(GetSensorPlatformResult(ret, "sensor_listener_set_event_cb"), &out);
+    return;
   }
+  ReportSuccess(out);
 }
 
 void SensorService::SensorUnsetChangeListener(const picojson::value& args, picojson::object& out) {
@@ -263,59 +299,27 @@ void SensorService::SensorUnsetChangeListener(const picojson::value& args, picoj
 
   sensor_type_e type_enum = string_to_type_map[type_str];
 
-  PlatformResult res = CheckSensorInitialization(type_enum);
   SensorData* sensor_data = GetSensorStruct(type_enum);
-
   if (!sensor_data) {
     LoggerD("Sensor data is null");
     ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Sensor data is null"), &out);
     return;
   }
 
-  int ret = sensor_listener_unset_event_cb(sensor_data->listener);
-  if (ret != SENSOR_ERROR_NONE) {
-    LOGE("ret : %d", ret);
-    ReportError(GetSensorPlatformResult(ret, "sensor_listener_unset_event_cb"), &out);
-  }
-}
-
-PlatformResult SensorService::CheckSensorInitialization(sensor_type_e type_enum) {
-  LoggerD("Entered");
-  std::lock_guard<std::mutex> lock(init_mutex);
-
-  SensorData* sensor_data = NULL;
-  switch(type_enum) {
-    case SENSOR_LIGHT :
-      sensor_data = &light_sensor_;
-      break;
-    case SENSOR_MAGNETIC :
-      sensor_data = &magnetic_sensor_;
-      break;
-    case SENSOR_PRESSURE :
-      sensor_data = &pressure_sensor_;
-      break;
-    case SENSOR_PROXIMITY :
-      sensor_data = &proximity_sensor_;
-      break;
-    case SENSOR_ULTRAVIOLET :
-      sensor_data = &ultraviolet_sensor_;
-      break;
+  PlatformResult res = sensor_data->CheckInitialization();
+  if (res.IsError()) {
+    LoggerE("Sensor initialization for sensor %s failed", type_str.c_str());
+    ReportError(res, &out);
+    return;
   }
-  if (!(sensor_data->handle)) {
-    LoggerD("initialization of handle and listener");
-    int ret = sensor_get_default_sensor(type_enum, &(sensor_data->handle));
-    if (ret != SENSOR_ERROR_NONE) {
-      LoggerE("ret : %d", ret);
-      return PlatformResult(ErrorCode::UNKNOWN_ERR, "sensor_get_default_sensor");
-    }
 
-    ret = sensor_create_listener(sensor_data->handle, &(sensor_data->listener));
-    if (ret != SENSOR_ERROR_NONE) {
-      LoggerE("ret : %d", ret);
-      return PlatformResult(ErrorCode::UNKNOWN_ERR, "sensor_create_listener");
-    }
+  int ret = sensor_listener_unset_event_cb(sensor_data->listener_);
+  if (SENSOR_ERROR_NONE != ret) {
+    LoggerE("ret : %d", ret);
+    ReportError(GetSensorPlatformResult(ret, "sensor_listener_unset_event_cb"), &out);
+    return;
   }
-  return PlatformResult(ErrorCode::NO_ERROR);
+  ReportSuccess(out);
 }
 
 SensorService::SensorData* SensorService::GetSensorStruct(sensor_type_e type_enum) {
@@ -472,7 +476,7 @@ void SensorService::GetSensorData(const picojson::value& args, picojson::object&
   auto get_data = [this, sensor_type](const std::shared_ptr<picojson::value>& result) {
     sensor_event_s sensor_event;
     SensorData* sensor = this->GetSensorStruct(sensor_type);
-    int ret = sensor_listener_read_data(sensor->listener, &sensor_event);
+    int ret = sensor_listener_read_data(sensor->listener_, &sensor_event);
 
     if (SENSOR_ERROR_NONE != ret) {
       ReportError(GetSensorPlatformResult(ret, type_to_string_map[sensor_type]),
index a33d3ab22bcfcb751848e6bea0db6b00565ca737..1b206e6b76cfdcabe12743f393a7583e550b2166 100644 (file)
@@ -16,10 +16,16 @@ namespace sensor {
 typedef void (*CallbackPtr)(sensor_h sensor, sensor_event_s *event, void *user_data);
 
 class SensorService {
-  typedef struct {
-    sensor_h handle;
-    sensor_listener_h listener;
-  } SensorData;
+  class SensorData {
+   public:
+    SensorData(sensor_type_e type_enum);
+    ~SensorData();
+
+    common::PlatformResult CheckInitialization();
+    sensor_h handle_;
+    sensor_listener_h listener_;
+    sensor_type_e type_enum_;
+  };
 
  public:
   static SensorService* GetInstance();
@@ -36,7 +42,6 @@ class SensorService {
   std::string GetSensorErrorMessage(const int error_code);
   common::PlatformResult GetSensorPlatformResult(const int error_code, const std::string &hint);
 
-  common::PlatformResult CheckSensorInitialization(sensor_type_e type_enum);
   SensorData* GetSensorStruct(sensor_type_e type_enum);
   CallbackPtr GetCallbackFunction(sensor_type_e type_enum);