Fix coverity issue
[platform/core/system/sensord.git] / src / sensorctl / sensor_adapter.cpp
index 13bc4e5..2af7398 100644 (file)
@@ -27,6 +27,8 @@
 
 #define SENSOR_EVENT(type) ((type) << 16 | 0x1)
 
+bool sensor_adapter::is_batch_mode = false;
+
 bool sensor_adapter::is_supported(sensor_type_t type)
 {
        sensor_t sensor;
@@ -53,39 +55,54 @@ bool sensor_adapter::get_handle(sensor_info info, int &handle)
 {
        int err;
        int count;
-       sensor_t *sensors;
+       sensor_t *sensors = NULL;
 
        err = sensord_get_sensors(info.type, &sensors, &count);
        ASSERT_EQ(err, 0);
 
        handle = sensord_connect(sensors[info.index]);
+       ASSERT_FREE((handle < 0), sensors);
        ASSERT_GE(handle, 0);
 
+       free(sensors);
+       sensors = NULL;
+
        return true;
 }
 
 bool sensor_adapter::start(sensor_info info, int &handle)
 {
-       sensor_t *sensors;
+       sensor_t *sensors = NULL;
        int count;
        int err;
        bool ret;
 
        err = sensord_get_sensors(info.type, &sensors, &count);
        ASSERT_EQ(err, 0);
+
+       ASSERT_FREE((info.index >= count), sensors);
        ASSERT_LT(info.index, count);
+
+       ASSERT_FREE((info.index < 0), sensors);
        ASSERT_GE(info.index, 0);
 
        handle = sensord_connect(sensors[info.index]);
+       ASSERT_FREE((handle < 0), sensors);
        ASSERT_GE(handle, 0);
 
-       ret = sensord_register_event(handle, SENSOR_EVENT(info.type), info.interval, info.batch_latency, info.cb, NULL);
+       if (is_batch_mode) {
+               ret = sensord_register_events(handle, SENSOR_EVENT(info.type), info.batch_latency, info.events_cb, NULL);
+       } else {
+               ret = sensord_register_event(handle, SENSOR_EVENT(info.type), info.interval, info.batch_latency, info.cb, NULL);
+       }
        ASSERT_TRUE(ret);
 
        ret = sensord_start(handle, info.powersave);
+       ASSERT_FREE((ret != true), sensors);
        ASSERT_TRUE(ret);
 
        free(sensors);
+       sensors = NULL;
 
        return true;
 }
@@ -97,7 +114,11 @@ bool sensor_adapter::stop(sensor_info info, int handle)
        ret = sensord_stop(handle);
        EXPECT_TRUE(ret);
 
-       ret = sensord_unregister_event(handle, SENSOR_EVENT(info.type));
+       if (is_batch_mode) {
+               ret = sensord_unregister_events(handle, SENSOR_EVENT(info.type));
+       } else {
+               ret = sensord_unregister_event(handle, SENSOR_EVENT(info.type));
+       }
        EXPECT_TRUE(ret);
 
        ret = sensord_disconnect(handle);