sensord: clean up the source code 63/60863/1
authorkibak.yoon <kibak.yoon@samsung.com>
Wed, 2 Mar 2016 14:35:51 +0000 (23:35 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Wed, 2 Mar 2016 14:35:51 +0000 (23:35 +0900)
- syntax / coding style
- clean up including header files
- remove compiler warning
- remove useless lines/white space
- correct typing-errors
- sync with private source

Change-Id: I4abce149946aa4cf3a81296a88cb6288a71c1ced
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
51 files changed:
src/client/client.cpp
src/client/client_common.cpp
src/client/client_common.h
src/client/command_channel.cpp
src/client/command_channel.h
src/client/reg_event_info.h
src/client/sensor_client_info.cpp
src/client/sensor_event_listener.cpp
src/client/sensor_event_listener.h
src/client/sensor_handle_info.h
src/client/sensor_internal.h [moved from src/shared/sensor_internal.h with 99% similarity]
src/client/sensor_internal_deprecated.h [moved from src/shared/sensor_internal_deprecated.h with 99% similarity]
src/hal/sensor_hal.h
src/sensor/auto_rotation/auto_rotation_sensor.cpp
src/sensor/auto_rotation/auto_rotation_sensor.h
src/sensor/rotation_vector/gaming_rv/gaming_rv_sensor.cpp
src/sensor/rotation_vector/gaming_rv/gaming_rv_sensor.h
src/server/client_sensor_record.h
src/server/command_worker.cpp
src/server/command_worker.h
src/server/device_config.h
src/server/physical_sensor.cpp
src/server/sensor_base.cpp
src/server/sensor_base.h
src/server/sensor_event_dispatcher.cpp
src/server/sensor_event_dispatcher.h
src/server/sensor_event_poller.cpp
src/server/sensor_event_queue.cpp
src/server/sensor_event_queue.h
src/server/sensor_info_list.cpp [moved from src/server/plugin_info_list.cpp with 66% similarity]
src/server/sensor_info_list.h [moved from src/server/plugin_info_list.h with 57% similarity]
src/server/sensor_loader.cpp
src/server/sensor_loader.h
src/server/sensor_usage.cpp
src/server/server.cpp
src/server/server.h
src/server/virtual_sensor.cpp
src/server/virtual_sensor.h
src/shared/command_common.h
src/shared/cpacket.h
src/shared/csocket.cpp
src/shared/csocket.h
src/shared/poller.cpp
src/shared/sensor_common.h
src/shared/sensor_info.cpp
src/shared/sensor_info.h
src/shared/sensor_log.cpp
src/shared/sensor_log.h
src/shared/sensor_types.h
src/test/src/check-sensor.c
src/test/src/sensor-test.c

index 6e1a416..96a3e95 100644 (file)
  *
  */
 
+#include <sensor_common.h>
 #include <sensor_internal_deprecated.h>
 #include <sensor_internal.h>
 #include <sensor_event_listener.h>
+#include <sensor_client_info.h>
 #include <client_common.h>
 #include <vconf.h>
 #include <cmutex.h>
@@ -37,9 +39,6 @@ using std::vector;
 
 #define DEFAULT_INTERVAL POLL_10HZ_MS
 
-static const int OP_SUCCESS = 0;
-static const int OP_ERROR =  -1;
-
 static cmutex lock;
 
 static int g_power_save_state = 0;
@@ -161,7 +160,7 @@ void restore_session(void)
 {
        AUTOLOCK(lock);
 
-       _I("Trying to restore session for %s", get_client_name());
+       _I("Trying to restore sensor client session for %s", get_client_name());
 
        command_channel *cmd_channel;
        int client_id;
@@ -221,7 +220,7 @@ void restore_session(void)
                ++it_sensor;
        }
 
-       _I("Succeeded to restore session for %s", get_client_name());
+       _I("Succeeded to restore sensor client session for %s", get_client_name());
 
        return;
 
@@ -486,11 +485,12 @@ API bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event
        sensor_info* info = sensor_to_sensor_info(sensor);
 
        retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !event_types || !count,
-               false, "Invalid param: sensor (%p), event_types(%p), count(%)", sensor, event_types, count);
+               false, "Invalid param: sensor (%p), event_types(%p), count(%p)", sensor, event_types, count);
 
        unsigned int event_type;
        event_type = info->get_supported_event();
-       *event_types = (unsigned int *) malloc(sizeof(unsigned int));
+       *event_types = (unsigned int *)malloc(sizeof(unsigned int));
+
        retvm_if(!*event_types, false, "Failed to allocate memory");
 
        (*event_types)[0] = event_type;
@@ -504,7 +504,7 @@ API bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_typ
        sensor_info* info = sensor_to_sensor_info(sensor);
 
        retvm_if (!sensor_info_manager::get_instance().is_valid(info) || !event_type || !supported,
-               false, "Invalid param: sensor (%p), event_type(%p), supported(%)", sensor, event_type, supported);
+               false, "Invalid param: sensor (%p), event_type(%p), supported(%p)", sensor, event_type, supported);
 
        *supported = info->is_supported_event(event_type);
 
@@ -548,7 +548,11 @@ API int sensord_connect(sensor_t sensor)
 
        if (!sensor_registered) {
                cmd_channel = new(std::nothrow) command_channel();
-               retvm_if (!cmd_channel, OP_ERROR, "Failed to allocate memory");
+               if (!cmd_channel) {
+                       _E("Failed to allocated memory");
+                       sensor_client_info::get_instance().delete_handle(handle);
+                       return OP_ERROR;
+               }
 
                if (!cmd_channel->create_channel()) {
                        _E("%s failed to create command channel for %s", get_client_name(), get_sensor_name(sensor_id));
@@ -881,6 +885,9 @@ static bool change_event_batch(int handle, unsigned int event_type, unsigned int
                return false;
        }
 
+       if (interval == 0)
+               interval = DEFAULT_INTERVAL;
+
        _I("%s changes batch of event %s[0x%x] for %s[%d] to (%d, %d)", get_client_name(), get_event_name(event_type),
                        event_type, get_sensor_name(sensor_id), handle, interval, latency);
 
@@ -888,9 +895,6 @@ static bool change_event_batch(int handle, unsigned int event_type, unsigned int
 
        sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb_type, prev_cb, prev_user_data);
 
-       if (interval == 0)
-               interval = DEFAULT_INTERVAL;
-
        if (!sensor_client_info::get_instance().set_event_batch(handle, event_type, interval, latency))
                return false;
 
@@ -1068,12 +1072,12 @@ API bool sensord_set_attribute_str(int handle, int attribute, const char *value,
        AUTOLOCK(lock);
 
        if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
-               _E("client %s failed to get handle information", get_client_name());
+               _E("Client %s failed to get handle information", get_client_name());
                return false;
        }
 
        if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
-               _E("client %s failed to get command channel for %s",
+               _E("Client %s failed to get command channel for %s",
                        get_client_name(), get_sensor_name(sensor_id));
                return false;
        }
@@ -1101,6 +1105,11 @@ API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len)
        return sensord_set_attribute_str(handle, 0, data, data_len);
 }
 
+API bool sensord_send_command(int handle, const char *command, int command_len)
+{
+       return sensord_set_attribute_str(handle, 0, command, command_len);
+}
+
 API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data)
 {
        sensor_id_t sensor_id;
index 19831a2..519880b 100644 (file)
  * limitations under the License.
  *
  */
+#include <time.h>
 #include <client_common.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <unordered_map>
-using std::unordered_map;
-
-#define FILL_LOG_ELEMENT(ID, TYPE, CNT, PRINT_PER_CNT) {ID, TYPE, {#TYPE, CNT, PRINT_PER_CNT} }
-
-log_element g_log_elements[] = {
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, UNKNOWN_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, ACCELEROMETER_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GEOMAGNETIC_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, LIGHT_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, PROXIMITY_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GYROSCOPE_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, PRESSURE_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, CONTEXT_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, AUTO_ROTATION_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GRAVITY_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, LINEAR_ACCEL_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, ORIENTATION_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, TEMPERATURE_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, ROTATION_VECTOR_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GEOMAGNETIC_RV_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GAMING_RV_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, FUSION_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, TILT_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GYROSCOPE_UNCAL_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, ULTRAVIOLET_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, BIO_LED_RED_SENSOR, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_SENSOR_TYPE, GESTURE_WRIST_UP_SENSOR, 0, 1),
-
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, PROXIMITY_CHANGE_STATE_EVENT, 0,1),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, LIGHT_CHANGE_LEVEL_EVENT, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, PROXIMITY_STATE_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, PROXIMITY_DISTANCE_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, AUTO_ROTATION_CHANGE_STATE_EVENT, 0, 1),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, ACCELEROMETER_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, GYROSCOPE_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, GEOMAGNETIC_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, PRESSURE_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, LIGHT_LEVEL_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, LIGHT_LUX_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, GRAVITY_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, LINEAR_ACCEL_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, ORIENTATION_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, PRESSURE_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, TEMPERATURE_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, ROTATION_VECTOR_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, GEOMAGNETIC_RV_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, GAMING_RV_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, FUSION_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, TILT_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, GYROSCOPE_UNCAL_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, ULTRAVIOLET_RAW_DATA_EVENT, 0, 10),
-       FILL_LOG_ELEMENT(LOG_ID_EVENT, BIO_LED_RED_RAW_DATA_EVENT, 0, 10),
+#include <map>
+
+typedef std::map<sensor_type_t, log_attr> sensor_type_map;
+static sensor_type_map g_log_maps = {
+       {UNKNOWN_SENSOR, {"UNKNOWN", "UNKNOWN_EVENT"}},
+       {ACCELEROMETER_SENSOR, {"ACCELEROMETER", "ACCELEROMETER_RAW_DATA_EVENT"}},
+       {GRAVITY_SENSOR, {"GRAVITY", "GRAVITY_RAW_DATA_EVENT"}},
+       {LINEAR_ACCEL_SENSOR, {"LINEAR_ACCEL", "LINEAR_ACCEL_RAW_DATA_EVENT"}},
+       {GEOMAGNETIC_SENSOR, {"GEOMAGNETIC SENSOR", "GEOMAGNETIC SENSOR_RAW_DATA_EVENT"}},
+       {ROTATION_VECTOR_SENSOR, {"ROTATION VECTOR", "ROTATION VECTOR_RAW_DATA_EVENT"}},
+       {ORIENTATION_SENSOR, {"ORIENTATION", "ORIENTATION_RAW_DATA_EVENT"}},
+       {GYROSCOPE_SENSOR, {"GYROSCOPE", "GYROSCOPE_RAW_DATA_EVENT"}},
+       {LIGHT_SENSOR, {"LIGHT", "LIGHT_RAW_DATA_EVENT"}},
+       {PROXIMITY_SENSOR, {"PROXIMITY", "PROXIMITY_RAW_DATA_EVENT"}},
+       {PRESSURE_SENSOR, {"PRESSURE", "PRESSURE_RAW_DATA_EVENT"}},
+       {ULTRAVIOLET_SENSOR, {"ULTRAVIOLET", "ULTRAVIOLET_RAW_DATA_EVENT"}},
+       {TEMPERATURE_SENSOR, {"TEMPERATURE", "TEMPERATURE_RAW_DATA_EVENT"}},
+       {HUMIDITY_SENSOR, {"HUMIDITY", "HUMIDITY_RAW_DATA_EVENT"}},
+       {BIO_HRM_SENSOR, {"BIO_HRM", "BIO_HRM_RAW_DATA_EVENT"}},
+       {BIO_LED_GREEN_SENSOR, {"BIO_LED_GREEN", "BIO_LED_GREEN_RAW_DATA_EVENT"}},
+       {BIO_LED_IR_SENSOR, {"BIO_LED_IR", "BIO_LED_IR_RAW_DATA_EVENT"}},
+       {BIO_LED_RED_SENSOR, {"BIO_LED_RED", "BIO_LED_RED_RAW_DATA_EVENT"}},
+       {GYROSCOPE_UNCAL_SENSOR, {"GYROSCOPE_UNCAL", "GYROSCOPE_UNCAL_RAW_DATA_EVENT"}},
+       {GEOMAGNETIC_UNCAL_SENSOR, {"GEOMAGNETIC_UNCAL", "GEOMAGNETIC_UNCAL_RAW_DATA_EVENT"}},
+       {GYROSCOPE_RV_SENSOR, {"GYROSCOPE_RV", "GYROSCOPE_RV_RAW_DATA_EVENT"}},
+       {GEOMAGNETIC_RV_SENSOR, {"GEOMAGNETIC_RV", "GEOMAGNETIC_RV_RAW_DATA_EVENT"}},
+       {CONTEXT_SENSOR, {"CONTEXT", "CONTEXT_RAW_DATA_EVENT"}},
 };
 
-typedef unordered_map<unsigned int, log_attr* > log_map;
-static log_map g_log_maps[LOG_ID_END];
-
-static void init_log_maps(void);
-
-class initiator {
-public:
-       initiator()
-       {
-               init_log_maps();
-       }
-};
-
-static initiator g_initiator;
-
-void init_log_maps(void)
+const char* get_sensor_name(sensor_id_t sensor_id)
 {
-       int cnt;
+       const char* p_unknown = "UNKNOWN";
+       sensor_type_t sensor_type = (sensor_type_t) (sensor_id >> SENSOR_TYPE_SHIFT);
 
-       cnt = sizeof(g_log_elements) / sizeof(g_log_elements[0]);
+       auto iter = g_log_maps.find(sensor_type);
 
-       for (int i = 0; i < cnt; ++i) {
-               g_log_maps[g_log_elements[i].id][g_log_elements[i].type] = &g_log_elements[i].log_attr;
+       if (iter == g_log_maps.end()) {
+               _I("Unknown type value: 0x%x", sensor_type);
+               return p_unknown;
        }
 
+       return iter->second.sensor_name;
 }
 
-const char* get_log_element_name(log_id id, unsigned int type)
+const char* get_event_name(unsigned int event_type)
 {
        const char* p_unknown = "UNKNOWN";
+       sensor_type_t sensor_type = (sensor_type_t) (event_type >> EVENT_TYPE_SHIFT);
 
-       auto iter = g_log_maps[id].find(type);
+       auto iter = g_log_maps.find(sensor_type);
 
-       if (iter == g_log_maps[id].end()) {
-               _I("Unknown type value: 0x%x", type);
+       if (iter == g_log_maps.end()) {
+               _I("Unknown type value: 0x%x", sensor_type);
                return p_unknown;
        }
 
-       return iter->second->name;
-}
-
-const char* get_sensor_name(sensor_id_t sensor_id)
-{
-       sensor_type_t sensor_type = (sensor_type_t) (sensor_id >> SENSOR_TYPE_SHIFT);
-
-       return get_log_element_name(LOG_ID_SENSOR_TYPE, sensor_type);
-}
-
-const char* get_event_name(unsigned int event_type)
-{
-       return get_log_element_name(LOG_ID_EVENT, event_type);
-}
-
-
-const char* get_data_name(unsigned int data_id)
-{
-       return get_log_element_name(LOG_ID_DATA, data_id);
+       return iter->second.event_name;
 }
 
 bool is_one_shot_event(unsigned int event_type)
@@ -200,27 +146,8 @@ unsigned long long get_timestamp(void)
 
 void print_event_occurrence_log(sensor_handle_info &sensor_handle_info, const reg_event_info *event_info)
 {
-       log_attr *log_attr;
-
-       auto iter = g_log_maps[LOG_ID_EVENT].find(event_info->type);
-
-       if (iter == g_log_maps[LOG_ID_EVENT].end())
-               return;
-
-       log_attr = iter->second;
-
-       log_attr->cnt++;
-
-       if ((log_attr->cnt != 1) && ((log_attr->cnt % log_attr->print_per_cnt) != 0)) {
-               return;
-       }
-
-       _I("%s receives %s with %s[%d][state: %d, option: %d count: %d]", get_client_name(), log_attr->name,
-                       get_sensor_name(sensor_handle_info.m_sensor_id), sensor_handle_info.m_handle, sensor_handle_info.m_sensor_state,
-                       sensor_handle_info.m_sensor_option, log_attr->cnt);
-
-       _I("0x%x(cb_event_type = %s, &user_data, client_data = 0x%x)\n", event_info->m_cb,
-                       log_attr->name, event_info->m_user_data);
+       _D("%s receives %s[%d]", get_client_name(),
+                       get_sensor_name(sensor_handle_info.m_sensor_id), sensor_handle_info.m_handle);
 }
 
 /*
index 532cb8d..85606db 100644 (file)
 
 #define CLIENT_NAME_SIZE NAME_MAX+10
 
-enum log_id {
-       LOG_ID_START = 0,
-       LOG_ID_SENSOR_TYPE = 0,
-       LOG_ID_EVENT,
-       LOG_ID_DATA,
-       LOG_ID_PROPERTY,
-       LOG_ID_END,
-};
-
 struct log_attr {
-       const char *name;
-       unsigned long cnt;
-       const unsigned int print_per_cnt;
-};
-
-struct log_element {
-       log_id id;
-       int type;
-       struct log_attr log_attr;
+       char *sensor_name;
+       char *event_name;
 };
 
-
-typedef struct {
-       int handle;
-       unsigned int event_type;
-       sensor_event_data_t ev_data;
-       int sensor_state;
-       int sensor_option;
-       sensor_type_t sensor;
-       reg_event_info event_info;
-} log_info;
-
 bool is_one_shot_event(unsigned int event_type);
 bool is_ontime_event(unsigned int event_type);
 bool is_panning_event(unsigned int event_type);
@@ -69,10 +42,8 @@ bool is_single_state_event(unsigned int event_type);
 unsigned int get_calibration_event_type(unsigned int event_type);
 unsigned long long get_timestamp(void);
 
-const char* get_log_element_name(log_id id, unsigned int type);
 const char* get_sensor_name(sensor_id_t sensor_id);
 const char* get_event_name(unsigned int event_type);
-const char* get_data_name(unsigned int data_id);
 void print_event_occurrence_log(sensor_handle_info &sensor_handle_info, const reg_event_info *event_info);
 
 class sensor_info;
index a034e0b..4e978a8 100644 (file)
@@ -58,7 +58,7 @@ bool command_channel::command_handler(cpacket *packet, void **return_payload)
 
        if (m_command_socket.recv(&header, sizeof(header)) <= 0) {
                m_command_socket.close();
-               _E("Failed to receive header for reply packet in client %s", get_client_name());
+               _E("Failed to receive header for command reply packet in client %s", get_client_name());
                return false;
        }
 
@@ -67,7 +67,7 @@ bool command_channel::command_handler(cpacket *packet, void **return_payload)
 
        if (m_command_socket.recv(buffer, header.size) <= 0) {
                m_command_socket.close();
-               _E("Failed to receive reply packet in client %s", get_client_name());
+               _E("Failed to receive command reply packet in client %s", get_client_name());
                delete[] buffer;
                return false;
        }
@@ -611,15 +611,15 @@ bool command_channel::cmd_get_data(unsigned int type, sensor_data_t* sensor_data
        cmd_get_data->type = type;
 
        if (!command_handler(packet, (void **)&cmd_get_data_done)) {
-               _E("Client %s failed to send/receive command with client_id [%d], data_id[%s]",
-                       get_client_name(), m_client_id, get_data_name(type));
+               _E("Client %s failed to send/receive command with client_id [%d]",
+                       get_client_name(), m_client_id);
                delete packet;
                return false;
        }
 
        if (cmd_get_data_done->state < 0 ) {
-               _E("Client %s got error[%d] from server with client_id [%d], data_id[%s]",
-                       get_client_name(), cmd_get_data_done->state, m_client_id, get_data_name(type));
+               _E("Client %s got error[%d] from server with client_id [%d]",
+                       get_client_name(), cmd_get_data_done->state, m_client_id);
                sensor_data->accuracy = SENSOR_ACCURACY_UNDEFINED;
                sensor_data->timestamp = 0;
                sensor_data->value_count = 0;
@@ -663,14 +663,14 @@ bool command_channel::cmd_set_attribute_int(int attribute, int value)
                get_client_name(), m_client_id, get_sensor_name(m_sensor_id), attribute, value);
 
        if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d], property[0x%x], value[%d]",
+               _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d], attribute[0x%x], value[%d]",
                        get_client_name(), get_sensor_name(m_sensor_id), m_client_id, attribute, value);
                delete packet;
                return false;
        }
 
        if (cmd_done->value < 0) {
-               _E("Client %s got error[%d] from server for sensor[%s] with property[0x%x], value[%d]",
+               _E("Client %s got error[%d] from server for sensor[%s] with attribute[0x%x], value[%d]",
                        get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), attribute, value);
 
                delete[] (char *)cmd_done;
@@ -700,8 +700,8 @@ bool command_channel::cmd_set_attribute_str(int attribute, const char* value, in
        cmd_set_attribute_str->value_len = value_len;
        memcpy(cmd_set_attribute_str->value, value, value_len);
 
-       _I("%s send cmd_set_attribute_str(client_id=%d, value_len = %d, buffer = 0x%x)",
-               get_client_name(), m_client_id, value_len, value);
+       _I("%s send cmd_set_attribute_str(client_id=%d, attribute = 0x%x, value_len = %d, value = 0x%x)",
+               get_client_name(), m_client_id, attribute, value_len, value);
 
        if (!command_handler(packet, (void **)&cmd_done)) {
                _E("%s failed to send/receive command with client_id [%d]",
@@ -721,8 +721,5 @@ bool command_channel::cmd_set_attribute_str(int attribute, const char* value, in
 
        delete[] (char *)cmd_done;
        delete packet;
-
        return true;
-
-
 }
index 63d5ceb..faa3837 100644 (file)
@@ -27,7 +27,6 @@
 
 class command_channel {
 public:
-
        command_channel();
        ~command_channel();
 
@@ -48,9 +47,9 @@ public:
        bool cmd_unregister_events(event_type_vector &event_vec);
        bool cmd_set_batch(unsigned int interval, unsigned int latency);
        bool cmd_unset_batch(void);
-       bool cmd_get_data(unsigned int type, sensor_data_tvalues);
+       bool cmd_get_data(unsigned int type, sensor_data_t *values);
        bool cmd_set_attribute_int(int attribute, int value);
-       bool cmd_set_attribute_str(int attribute, const char* buffer, int data_len);
+       bool cmd_set_attribute_str(int attribute, const char *value, int value_len);
 private:
        csocket m_command_socket;
        int m_client_id;
@@ -58,4 +57,4 @@ private:
        bool command_handler(cpacket *packet, void **return_payload);
 };
 
-#endif /* COMMAND_CHANNEL_H_ */
+#endif /* _COMMAND_CHANNEL_H_ */
index cf2fd76..fa8994c 100644 (file)
@@ -40,17 +40,16 @@ public:
        void *m_cb;
        void *m_user_data;
        unsigned long long m_previous_event_time;
-       bool    m_fired;
+       bool m_fired;
        GMainContext *m_maincontext;
 
-       reg_event_info():m_id(0), m_handle(-1),
-                       type(0), m_interval(POLL_1HZ_MS),
-                       m_latency(0),
-                       m_cb_type(SENSOR_EVENT_CB), m_cb(NULL), m_user_data(NULL),
-                       m_previous_event_time(0), m_fired(false), m_maincontext(NULL){}
+       reg_event_info()
+       : m_id(0), m_handle(-1),
+       type(0), m_interval(POLL_1HZ_MS), m_latency(0),
+       m_cb_type(SENSOR_EVENT_CB), m_cb(NULL), m_user_data(NULL),
+       m_previous_event_time(0), m_fired(false), m_maincontext(NULL) {}
 
-       ~reg_event_info(){}
+       ~reg_event_info() {}
 };
 
-
 #endif /* _REG_EVENT_INFO_H_ */
index 3ffc120..684cd52 100644 (file)
@@ -24,9 +24,6 @@
 #include <thread>
 #include <chrono>
 
-#define MS_TO_US 1000
-#define MIN_DELIVERY_DIFF_FACTOR 0.75f
-
 using std::thread;
 using std::pair;
 
@@ -417,7 +414,6 @@ bool sensor_client_info::close_command_channel(sensor_id_t sensor_id)
        return true;
 }
 
-
 bool sensor_client_info::has_client_id(void)
 {
        return (m_client_id != CLIENT_ID_INVALID);
@@ -641,7 +637,6 @@ bool sensor_client_info::is_sensor_registered(sensor_id_t sensor)
        return false;
 }
 
-
 bool sensor_client_info::is_sensor_active(sensor_id_t sensor)
 {
        AUTOLOCK(m_handle_info_lock);
index 568d8cb..7ea6c95 100644 (file)
 #include <chrono>
 #include <vector>
 
-#define MS_TO_US 1000
-#define MIN_DELIVERY_DIFF_FACTOR 0.75f
+#include <sensor_types.h>
 
-/* TODO: this macro should be adjusted */
+/* TODO: this macro should be adjusted(4224 = 4096(data) + 128(header)) */
 #define EVENT_BUFFER_SIZE 4224
 
 using std::thread;
@@ -353,8 +352,6 @@ ssize_t sensor_event_listener::sensor_event_poll(void* buffer, int buffer_len, s
        return len;
 }
 
-
-
 void sensor_event_listener::listen_events(void)
 {
        struct epoll_event event;
index aaa29a6..4af7092 100644 (file)
@@ -97,6 +97,8 @@ private:
 
        hup_observer_t m_hup_observer;
 
+       sensor_client_info &m_client_info;
+
        sensor_event_listener();
        ~sensor_event_listener();
 
@@ -106,7 +108,7 @@ private:
        bool create_event_channel(void);
        void close_event_channel(void);
 
-       ssize_t sensor_event_poll(voidbuffer, int buffer_len, struct epoll_event &event);
+       ssize_t sensor_event_poll(void *buffer, int buffer_len, struct epoll_event &event);
 
        void listen_events(void);
        client_callback_info* handle_calibration_cb(sensor_handle_info &handle_info, unsigned event_type, unsigned long long time, int accuracy);
@@ -122,7 +124,5 @@ private:
        static gboolean callback_dispatcher(gpointer data);
 
        void set_thread_state(thread_state state);
-
-       sensor_client_info &m_client_info;
 };
 #endif /* _SENSOR_EVENT_LISTENER_H_ */
index c72fb00..f56da67 100644 (file)
 #ifndef _SENSOR_HANDLE_INFO_H_
 #define _SENSOR_HANDLE_INFO_H_
 
+#include <sensor_internal.h>
 #include <reg_event_info.h>
 #include <sensor_log.h>
 #include <string.h>
 #include <unordered_map>
 #include <glib.h>
-#include <sensor_internal.h>
 
 typedef std::unordered_map<unsigned int,reg_event_info> event_info_map;
 
similarity index 99%
rename from src/shared/sensor_internal.h
rename to src/client/sensor_internal.h
index c1a102b..b16e086 100644 (file)
 
 /*header for common sensor type*/
 #include <sensor_common.h>
-
-/*header for each sensor type*/
 #include <sensor_types.h>
-
+#include <sensor_deprecated.h>
 #include <sensor_internal_deprecated.h>
 
 #ifdef __cplusplus
@@ -355,6 +353,7 @@ bool sensord_set_attribute_str(int handle, int attribute, const char *value, int
  * @return true on success, otherwise false.
  */
 bool sensord_send_sensorhub_data(int handle, const char *data, int data_len);
+bool sensord_send_command(int handle, const char *command, int command_len);
 
 /**
  * @brief get sensor data from a connected sensor
similarity index 99%
rename from src/shared/sensor_internal_deprecated.h
rename to src/client/sensor_internal_deprecated.h
index 5116303..469b8da 100644 (file)
 
 /*header for common sensor type*/
 #include <sensor_common.h>
-
-/*header for each sensor type*/
 #include <sensor_types.h>
-
 #include <sensor_deprecated.h>
 
-
 #ifdef __cplusplus
 extern "C"
 {
index 9ae5c62..8d89f75 100644 (file)
@@ -69,16 +69,6 @@ typedef enum {
        SENSOR_DEVICE_GYROSCOPE_RV,
        SENSOR_DEVICE_GEOMAGNETIC_RV,
 
-       SENSOR_DEVICE_ACTIVITY_STATIONARY = 0x100,
-       SENSOR_DEVICE_ACTIVITY_WALK,
-       SENSOR_DEVICE_ACTIVITY_RUN,
-       SENSOR_DEVICE_ACTIVITY_IN_VEHICLE,
-       SENSOR_DEVICE_ACTIVITY_ON_BICYCLE,
-
-       SENSOR_DEVICE_GESTURE_MOVEMENT = 0x200,
-       SENSOR_DEVICE_GESTURE_WRIST_UP,
-       SENSOR_DEVICE_GESTURE_WRIST_DOWN,
-
        SENSOR_DEVICE_HUMAN_PEDOMETER = 0x300,
        SENSOR_DEVICE_HUMAN_SLEEP_MONITOR,
 
@@ -96,11 +86,21 @@ typedef enum {
        SENSOR_DEVICE_HRM_RAW,
        SENSOR_DEVICE_TILT,
        SENSOR_DEVICE_ROTATION_VECTOR_RAW,
+
+       SENSOR_DEVICE_ACTIVITY_STATIONARY = 0x1100,
+       SENSOR_DEVICE_ACTIVITY_WALK,
+       SENSOR_DEVICE_ACTIVITY_RUN,
+       SENSOR_DEVICE_ACTIVITY_IN_VEHICLE,
+       SENSOR_DEVICE_ACTIVITY_ON_BICYCLE,
+
+       SENSOR_DEVICE_GESTURE_MOVEMENT = 0x1200,
+       SENSOR_DEVICE_GESTURE_WRIST_UP,
+       SENSOR_DEVICE_GESTURE_WRIST_DOWN,
 } sensor_device_type;
 
 /*
  * A platform sensor handler is generated based on this handle
- * ID can be assigned from HAL developer. so it has to be unique in HAL.
+ * This id can be assigned from HAL developer. so it has to be unique in 1 sensor_device.
  */
 typedef struct sensor_info_t {
        uint32_t id;
@@ -175,15 +175,29 @@ public:
        virtual bool enable(uint32_t id) = 0;
        virtual bool disable(uint32_t id) = 0;
 
-       virtual bool set_interval(uint32_t id, unsigned long val) = 0;
-       virtual bool set_batch_latency(uint32_t id, unsigned long val) = 0;
-       virtual bool set_attribute_int(uint32_t id, int32_t attribute, int32_t value) = 0;
-       virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, int value_len) = 0;
-
        virtual int read_fd(uint32_t **ids) = 0;
        virtual int get_data(uint32_t id, sensor_data_t **data, int *length) = 0;
 
-       virtual bool flush(uint32_t id) = 0;
+       virtual bool set_interval(uint32_t id, unsigned long val)
+       {
+               return false;
+       }
+       virtual bool set_batch_latency(uint32_t id, unsigned long val)
+       {
+               return false;
+       }
+       virtual bool set_attribute_int(uint32_t id, int32_t attribute, int32_t value)
+       {
+               return false;
+       }
+       virtual bool set_attribute_str(uint32_t id, int32_t attribute, char *value, int value_len)
+       {
+               return false;
+       }
+       virtual bool flush(uint32_t id)
+       {
+               return false;
+       }
 };
 #endif /* __cplusplus */
 
index b1f7dba..3afd961 100644 (file)
@@ -174,6 +174,11 @@ void auto_rotation_sensor::synthesize(const sensor_event_t& event)
        int remains;
 
        rotation_event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
+       if (!rotation_event) {
+               _E("Failed to allocate memory");
+               return;
+       }
+
        remains = get_data(&rotation_data, &data_length);
 
        if (remains < 0)
index 9b40c7c..ef69a6d 100644 (file)
@@ -21,7 +21,7 @@
 #define _AUTO_ROTATION_SENSOR_H_
 
 #include <virtual_sensor.h>
-#include <sensor_internal.h>
+#include <sensor_types.h>
 #include <auto_rotation_alg.h>
 
 class auto_rotation_sensor : public virtual_sensor {
@@ -67,4 +67,4 @@ private:
        auto_rotation_alg *get_alg();
 };
 
-#endif
+#endif /* _AUTO_ROTATION_SENSOR_H_ */
index 5a7adc2..3fd0268 100644 (file)
@@ -34,7 +34,7 @@
 using std::string;
 using std::vector;
 
-#define SENSOR_NAME "GAMING_RV_SENSOR"
+#define SENSOR_NAME "GYROSCOPE_RV_SENSOR"
 #define SENSOR_TYPE_GAMING_RV "GAMING_ROTATION_VECTOR"
 
 #define ACCELEROMETER_ENABLED 0x01
@@ -144,7 +144,7 @@ bool gaming_rv_sensor::init()
 
 void gaming_rv_sensor::get_types(vector<sensor_type_t> &types)
 {
-       types.push_back(GAMING_RV_SENSOR);
+       types.push_back(GYROSCOPE_RV_SENSOR);
 }
 
 bool gaming_rv_sensor::on_start(void)
index 3307263..ec89b21 100644 (file)
@@ -17,8 +17,8 @@
  *
  */
 
-#ifndef _GAMING_RV_SENSOR_H_
-#define _GAMING_RV_SENSOR_H_
+#ifndef _GYROSCOPE_RV_SENSOR_H_
+#define _GYROSCOPE_RV_SENSOR_H_
 
 #include <sensor_internal.h>
 #include <virtual_sensor.h>
@@ -70,4 +70,4 @@ private:
        bool on_stop(void);
 };
 
-#endif /*_GAMING_RV_SENSOR_H_*/
+#endif /*_GYROSCOPE_RV_SENSOR_H_*/
index ac3f3db..9386507 100644 (file)
@@ -20,7 +20,8 @@
 #ifndef _CLIENT_SENSOR_RECORD_H_
 #define _CLIENT_SENSOR_RECORD_H_
 
-#include <sensor_internal.h>
+#include <sensor_common.h>
+#include <sensor_types.h>
 #include <sensor_usage.h>
 #include <csocket.h>
 #include <unordered_map>
index 8e6931d..4970e2a 100644 (file)
  *
  */
 
+#include <sensor_common.h>
 #include <command_common.h>
 #include <sensor_loader.h>
 #include <sensor_info.h>
-#include <sensor_types.h>
 #include <thread>
 #include <string>
 #include <vector>
@@ -221,7 +221,6 @@ bool command_worker::stopped(void *ctx)
        _I("%s is stopped", info.c_str());
 
        if ((inst->m_module) && (inst->m_client_id != CLIENT_ID_INVALID)) {
-
                if (get_client_info_manager().is_started(inst->m_client_id, inst->m_sensor_id)) {
                        _W("Does not receive cmd_stop before connection broken for [%s]!!", inst->m_module->get_name());
                        inst->m_module->delete_interval(inst->m_client_id, false);
index f455cb6..abe89e6 100644 (file)
 #ifndef _COMMAND_WORKER_H_
 #define _COMMAND_WORKER_H_
 
+#include <sensor_common.h>
 #include <command_common.h>
 #include <worker_thread.h>
 #include <client_info_manager.h>
 #include <sensor_event_dispatcher.h>
 #include <sensor_base.h>
 #include <map>
-#include <cpacket.h>
 
 typedef std::multimap<int, raw_data_t> sensor_raw_data_map;
 void insert_priority_list(unsigned int);
@@ -35,9 +35,6 @@ class command_worker {
 private:
        typedef bool (command_worker::*cmd_handler_t)(void *payload);
 
-       static const int OP_ERROR = -1;
-       static const int OP_SUCCESS = 0;
-
        int m_client_id;
        int m_permission;
        csocket m_socket;
index 3b85f2f..5c73509 100644 (file)
 #include <sensor_log.h>
 
 class device_config {
-protected:
-       virtual bool load_config(const std::string& config_path) = 0;
-
-       std::string m_device_id;
 public:
        device_config();
        virtual ~device_config();
 
        bool get_device_id(void);
 
+protected:
+       virtual bool load_config(const std::string& config_path) = 0;
+
+       std::string m_device_id;
 };
 
 #endif /* _DEVICE_CONFIG_H_ */
index f631265..83efec8 100644 (file)
  *
  */
 
+#include <sensor_common.h>
 #include <physical_sensor.h>
 #include <sensor_event_queue.h>
 
 #define UNKNOWN_NAME "UNKNOWN_SENSOR"
 
-#define OP_SUCCESS 0
-#define OP_ERROR -1
-
 cmutex physical_sensor::m_mutex;
 
 physical_sensor::physical_sensor()
@@ -74,7 +72,7 @@ int physical_sensor::get_poll_fd()
        AUTOLOCK(m_mutex);
 
        if (!m_sensor_device)
-               return -1;
+               return OP_ERROR;
 
        return m_sensor_device->get_poll_fd();
 }
@@ -101,14 +99,14 @@ int physical_sensor::get_data(sensor_data_t **data, int *length)
        AUTOLOCK(m_mutex);
 
        if (!m_sensor_device)
-               return -1;
+               return OP_ERROR;
 
        int remains = 0;
        remains = m_sensor_device->get_data(m_info->id, data, length);
 
        if (*length < 0) {
                _E("Failed to get sensor event");
-               return -1;
+               return OP_ERROR;
        }
 
        return remains;
@@ -153,7 +151,7 @@ int physical_sensor::set_attribute(int32_t attribute, int32_t value)
        AUTOLOCK(m_mutex);
 
        if (!m_sensor_device)
-               return false;
+               return OP_ERROR;
 
        if (!m_sensor_device->set_attribute_int(m_info->id, attribute, value))
                return OP_ERROR;
@@ -166,7 +164,7 @@ int physical_sensor::set_attribute(int32_t attribute, char *value, int value_len
        AUTOLOCK(m_mutex);
 
        if (!m_sensor_device)
-               return false;
+               return OP_ERROR;
 
        if (!m_sensor_device->set_attribute_str(m_info->id, attribute, value, value_len))
                return OP_ERROR;
@@ -210,7 +208,7 @@ bool physical_sensor::get_sensor_info(sensor_info &info)
        info.set_max_range(m_info->max_range);
        info.set_resolution(m_info->resolution);
        info.set_min_interval(m_info->min_interval);
-       info.set_fifo_count(0); // FIXME
+       info.set_fifo_count(0);
        info.set_max_batch_count(m_info->max_batch_count);
        info.set_supported_event(get_event_type());
        info.set_wakeup_supported(m_info->wakeup_supported);
index 4aaacf6..4fefeff 100644 (file)
  */
 
 #include <stdint.h>
-#include <algorithm>
-#include <utility>
-#include <functional>
 #include <sensor_hal.h>
 #include <sensor_event_queue.h>
 #include <sensor_base.h>
+#include <sensor_common.h>
+
+#include <algorithm>
+#include <utility>
+#include <functional>
 
 using std::make_pair;
 using std::vector;
 
 sensor_base::sensor_base()
-: m_unique_id(-1)
+: m_id(SENSOR_ID_INVALID)
 , m_permission(SENSOR_PERMISSION_STANDARD)
 , m_started(false)
 , m_client(0)
@@ -42,15 +44,15 @@ sensor_base::~sensor_base()
 
 void sensor_base::set_id(sensor_id_t id)
 {
-       m_unique_id = id;
+       m_id = id;
 }
 
 sensor_id_t sensor_base::get_id(void)
 {
-       if (m_unique_id == -1)
+       if (m_id == SENSOR_ID_INVALID)
                return UNKNOWN_SENSOR;
 
-       return m_unique_id;
+       return m_id;
 }
 
 sensor_type_t sensor_base::get_type(void)
@@ -80,7 +82,7 @@ bool sensor_base::is_virtual()
 
 int sensor_base::get_data(sensor_data_t **data, int *length)
 {
-       return -1;
+       return OP_ERROR;
 }
 
 bool sensor_base::flush(void)
@@ -90,12 +92,12 @@ bool sensor_base::flush(void)
 
 int sensor_base::set_attribute(int32_t cmd, int32_t value)
 {
-       return -1;
+       return OP_ERROR;
 }
 
 int sensor_base::set_attribute(int32_t attribute, char *value, int value_size)
 {
-       return -1;
+       return OP_ERROR;
 }
 
 bool sensor_base::start()
@@ -149,14 +151,14 @@ bool sensor_base::add_interval(int client_id, unsigned int interval, bool is_pro
 {
        unsigned int prev_min, cur_min;
 
-       AUTOLOCK(m_plugin_info_list_mutex);
+       AUTOLOCK(m_sensor_info_list_mutex);
 
-       prev_min = m_plugin_info_list.get_min_interval();
+       prev_min = m_sensor_info_list.get_min_interval();
 
-       if (!m_plugin_info_list.add_interval(client_id, interval, is_processor))
+       if (!m_sensor_info_list.add_interval(client_id, interval, is_processor))
                return false;
 
-       cur_min = m_plugin_info_list.get_min_interval();
+       cur_min = m_sensor_info_list.get_min_interval();
 
        if (cur_min != prev_min) {
                _I("Min interval for sensor[0x%llx] is changed from %dms to %dms"
@@ -173,14 +175,14 @@ bool sensor_base::add_interval(int client_id, unsigned int interval, bool is_pro
 bool sensor_base::delete_interval(int client_id, bool is_processor)
 {
        unsigned int prev_min, cur_min;
-       AUTOLOCK(m_plugin_info_list_mutex);
+       AUTOLOCK(m_sensor_info_list_mutex);
 
-       prev_min = m_plugin_info_list.get_min_interval();
+       prev_min = m_sensor_info_list.get_min_interval();
 
-       if (!m_plugin_info_list.delete_interval(client_id, is_processor))
+       if (!m_sensor_info_list.delete_interval(client_id, is_processor))
                return false;
 
-       cur_min = m_plugin_info_list.get_min_interval();
+       cur_min = m_sensor_info_list.get_min_interval();
 
        if (!cur_min) {
                _I("No interval for sensor[0x%llx] by%sclient[%d] deleting interval, "
@@ -203,23 +205,23 @@ bool sensor_base::delete_interval(int client_id, bool is_processor)
 
 unsigned int sensor_base::get_interval(int client_id, bool is_processor)
 {
-       AUTOLOCK(m_plugin_info_list_mutex);
+       AUTOLOCK(m_sensor_info_list_mutex);
 
-       return m_plugin_info_list.get_interval(client_id, is_processor);
+       return m_sensor_info_list.get_interval(client_id, is_processor);
 }
 
 bool sensor_base::add_batch(int client_id, unsigned int latency)
 {
        unsigned int prev_max, cur_max;
 
-       AUTOLOCK(m_plugin_info_list_mutex);
+       AUTOLOCK(m_sensor_info_list_mutex);
 
-       prev_max = m_plugin_info_list.get_max_batch();
+       prev_max = m_sensor_info_list.get_max_batch();
 
-       if (!m_plugin_info_list.add_batch(client_id, latency))
+       if (!m_sensor_info_list.add_batch(client_id, latency))
                return false;
 
-       cur_max = m_plugin_info_list.get_max_batch();
+       cur_max = m_sensor_info_list.get_max_batch();
 
        if (cur_max != prev_max) {
                _I("Max latency for sensor[0x%llx] is changed from %dms to %dms by client[%d] adding latency",
@@ -233,14 +235,14 @@ bool sensor_base::add_batch(int client_id, unsigned int latency)
 bool sensor_base::delete_batch(int client_id)
 {
        unsigned int prev_max, cur_max;
-       AUTOLOCK(m_plugin_info_list_mutex);
+       AUTOLOCK(m_sensor_info_list_mutex);
 
-       prev_max = m_plugin_info_list.get_max_batch();
+       prev_max = m_sensor_info_list.get_max_batch();
 
-       if (!m_plugin_info_list.delete_batch(client_id))
+       if (!m_sensor_info_list.delete_batch(client_id))
                return false;
 
-       cur_max = m_plugin_info_list.get_max_batch();
+       cur_max = m_sensor_info_list.get_max_batch();
 
        if (!cur_max) {
                _I("No latency for sensor[0x%llx] by client[%d] deleting latency, so set to default 0 ms",
@@ -259,23 +261,23 @@ bool sensor_base::delete_batch(int client_id)
 
 unsigned int sensor_base::get_batch(int client_id)
 {
-       AUTOLOCK(m_plugin_info_list_mutex);
+       AUTOLOCK(m_sensor_info_list_mutex);
 
-       return m_plugin_info_list.get_batch(client_id);
+       return m_sensor_info_list.get_batch(client_id);
 }
 
 bool sensor_base::add_wakeup(int client_id, int wakeup)
 {
        int prev_wakeup, cur_wakeup;
 
-       AUTOLOCK(m_plugin_info_list_mutex);
+       AUTOLOCK(m_sensor_info_list_mutex);
 
-       prev_wakeup = m_plugin_info_list.is_wakeup_on();
+       prev_wakeup = m_sensor_info_list.is_wakeup_on();
 
-       if (!m_plugin_info_list.add_wakeup(client_id, wakeup))
+       if (!m_sensor_info_list.add_wakeup(client_id, wakeup))
                return false;
 
-       cur_wakeup = m_plugin_info_list.is_wakeup_on();
+       cur_wakeup = m_sensor_info_list.is_wakeup_on();
 
        if ((cur_wakeup == SENSOR_WAKEUP_ON) && (prev_wakeup < SENSOR_WAKEUP_ON)) {
                _I("Wakeup for sensor[0x%llx] is changed from %d to %d by client[%d] adding wakeup",
@@ -289,14 +291,14 @@ bool sensor_base::add_wakeup(int client_id, int wakeup)
 bool sensor_base::delete_wakeup(int client_id)
 {
        int prev_wakeup, cur_wakeup;
-       AUTOLOCK(m_plugin_info_list_mutex);
+       AUTOLOCK(m_sensor_info_list_mutex);
 
-       prev_wakeup = m_plugin_info_list.is_wakeup_on();
+       prev_wakeup = m_sensor_info_list.is_wakeup_on();
 
-       if (!m_plugin_info_list.delete_wakeup(client_id))
+       if (!m_sensor_info_list.delete_wakeup(client_id))
                return false;
 
-       cur_wakeup = m_plugin_info_list.is_wakeup_on();
+       cur_wakeup = m_sensor_info_list.is_wakeup_on();
 
        if ((cur_wakeup < SENSOR_WAKEUP_ON) && (prev_wakeup == SENSOR_WAKEUP_ON)) {
                _I("Wakeup for sensor[0x%llx] is changed from %d to %d by client[%d] deleting wakeup",
@@ -309,9 +311,9 @@ bool sensor_base::delete_wakeup(int client_id)
 
 int sensor_base::get_wakeup(int client_id)
 {
-       AUTOLOCK(m_plugin_info_list_mutex);
+       AUTOLOCK(m_sensor_info_list_mutex);
 
-       return m_plugin_info_list.is_wakeup_on();
+       return m_sensor_info_list.is_wakeup_on();
 }
 
 bool sensor_base::is_wakeup_supported(void)
@@ -381,4 +383,3 @@ unsigned long long sensor_base::get_timestamp(timeval *t)
 
        return ((unsigned long long)(t->tv_sec)*1000000LL +t->tv_usec);
 }
-
index 072c3f2..0260119 100644 (file)
@@ -20,9 +20,8 @@
 #ifndef _SENSOR_BASE_H_
 #define _SENSOR_BASE_H_
 
-#include <vector>
 #include <sensor_types.h>
-#include <plugin_info_list.h>
+#include <sensor_info_list.h>
 #include <cmutex.h>
 
 #include <sensor_log.h>
@@ -30,6 +29,7 @@
 #include <worker_thread.h>
 #include <sensor_info.h>
 #include <sensor_hal.h>
+#include <vector>
 
 class sensor_base {
 public:
@@ -44,9 +44,9 @@ public:
        virtual sensor_type_t get_type();
        virtual unsigned int get_event_type(void);
        virtual const char* get_name(void);
+       virtual bool is_virtual(void);
 
        virtual bool get_sensor_info(sensor_info &info);
-       virtual bool is_virtual(void);
 
        /* set/get data */
        virtual int get_data(sensor_data_t **data, int *length);
@@ -61,16 +61,16 @@ public:
        bool is_started(void);
 
        /* interval / batch / wakeup */
-       bool add_interval(int client_id, unsigned int interval, bool is_processor);
-       bool delete_interval(int client_id, bool is_processor);
+       virtual bool add_interval(int client_id, unsigned int interval, bool is_processor);
+       virtual bool delete_interval(int client_id, bool is_processor);
        unsigned int get_interval(int client_id, bool is_processor);
 
-       bool add_batch(int client_id, unsigned int latency);
-       bool delete_batch(int client_id);
+       virtual bool add_batch(int client_id, unsigned int latency);
+       virtual bool delete_batch(int client_id);
        unsigned int get_batch(int client_id);
 
-       bool add_wakeup(int client_id, int wakeup);
-       bool delete_wakeup(int client_id);
+       virtual bool add_wakeup(int client_id, int wakeup);
+       virtual bool delete_wakeup(int client_id);
        int get_wakeup(int client_id);
        bool is_wakeup_supported(void);
 
@@ -83,11 +83,11 @@ protected:
        void set_permission(int permission);
 
 private:
-       sensor_id_t m_unique_id;
+       sensor_id_t m_id;
        int m_permission;
 
-       plugin_info_list m_plugin_info_list;
-       cmutex m_plugin_info_list_mutex;
+       sensor_info_list m_sensor_info_list;
+       cmutex m_sensor_info_list_mutex;
 
        bool m_started;
        unsigned int m_client;
index 564ab70..a673ae4 100644 (file)
@@ -17,6 +17,7 @@
  *
  */
 
+#include <sensor_common.h>
 #include <command_common.h>
 #include <sensor_event_dispatcher.h>
 #include <sensor_log.h>
@@ -29,7 +30,6 @@ using std::pair;
 #define MAX_PENDING_CONNECTION 32
 
 sensor_event_dispatcher::sensor_event_dispatcher()
-: m_lcd_on(false)
 {
 }
 
@@ -282,8 +282,7 @@ void sensor_event_dispatcher::request_last_event(int client_id, sensor_id_t sens
        }
 }
 
-
-bool sensor_event_dispatcher::add_active_virtual_sensor(virtual_sensor * sensor)
+bool sensor_event_dispatcher::add_active_virtual_sensor(virtual_sensor *sensor)
 {
        AUTOLOCK(m_active_virtual_sensors_mutex);
 
@@ -297,7 +296,7 @@ bool sensor_event_dispatcher::add_active_virtual_sensor(virtual_sensor * sensor)
        return true;
 }
 
-bool sensor_event_dispatcher::delete_active_virtual_sensor(virtual_sensor * sensor)
+bool sensor_event_dispatcher::delete_active_virtual_sensor(virtual_sensor *sensor)
 {
        AUTOLOCK(m_active_virtual_sensors_mutex);
 
index b597816..befb9ea 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef _SENSOR_EVENT_DISPATCHER_H_
 #define _SENSOR_EVENT_DISPATCHER_H_
 
+#include <sensor_common.h>
 #include <sensor_event_queue.h>
 #include <client_info_manager.h>
 #include <csocket.h>
 #include <list>
 #include <vector>
 
-
 typedef std::unordered_map<unsigned int, sensor_event_t> event_type_last_event_map;
 typedef std::list<virtual_sensor *> virtual_sensors;
 
 class sensor_event_dispatcher {
 private:
-       bool m_lcd_on;
        csocket m_accept_socket;
        cmutex m_mutex;
        cmutex m_last_events_mutex;
index 97fd19a..274c11e 100644 (file)
@@ -24,8 +24,6 @@
 #include <sensor_loader.h>
 #include <algorithm>
 
-#define EPOLL_MAX_FD 32
-
 sensor_event_poller::sensor_event_poller()
 {
        init_sensor_map();
index 9378c8d..26b4d97 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #include <sensor_event_queue.h>
-#include "sensor_log.h"
+#include <sensor_log.h>
 
 sensor_event_queue& sensor_event_queue::get_instance()
 {
index df33035..1564d7d 100644 (file)
@@ -82,9 +82,9 @@ private:
        typedef std::lock_guard<std::mutex> lock;
        typedef std::unique_lock<std::mutex> ulock;
 
-       sensor_event_queue() {};
-       ~sensor_event_queue() {};
-       sensor_event_queue(const sensor_event_queue &) {};
+       sensor_event_queue() {}
+       ~sensor_event_queue() {}
+       sensor_event_queue(const sensor_event_queue &) {}
        sensor_event_queue& operator=(const sensor_event_queue &);
        void push_internal(void *event);
 public:
similarity index 66%
rename from src/server/plugin_info_list.cpp
rename to src/server/sensor_info_list.cpp
index db36f04..21e6f62 100644 (file)
  *
  */
 
-#include <plugin_info_list.h>
+#include <sensor_info_list.h>
 #include <algorithm>
 
-
-cinterval_info::cinterval_info(int client_id, bool is_processor, unsigned int interval)
+interval_info::interval_info(int client_id, bool is_processor, unsigned int interval)
 {
        this->client_id = client_id;
        this->is_processor = is_processor;
        this->interval = interval;
 }
 
-cbatch_info::cbatch_info(int client_id, unsigned int latency)
+batch_info::batch_info(int client_id, unsigned int latency)
 {
        this->client_id = client_id;
        this->latency = latency;
 }
 
-cwakeup_info::cwakeup_info(int client_id, int wakeup)
+wakeup_info::wakeup_info(int client_id, int wakeup)
 {
        this->client_id = client_id;
        this->wakeup = wakeup;
 }
 
-bool plugin_info_list::comp_interval_info(cinterval_info a, cinterval_info b)
+bool sensor_info_list::comp_interval_info(interval_info a, interval_info b)
 {
        return a.interval < b.interval;
 }
 
-bool plugin_info_list::comp_batch_info(cbatch_info a, cbatch_info b)
+bool sensor_info_list::comp_batch_info(batch_info a, batch_info b)
 {
        return a.latency < b.latency;
 }
 
-cinterval_info_iterator plugin_info_list::find_if_interval_info(int client_id, bool is_processor)
+interval_info_iterator sensor_info_list::find_if_interval_info(int client_id, bool is_processor)
 {
        auto iter = m_interval_info_list.begin();
 
@@ -64,7 +63,7 @@ cinterval_info_iterator plugin_info_list::find_if_interval_info(int client_id, b
        return iter;
 }
 
-cbatch_info_iterator plugin_info_list::find_if_batch_info(int client_id)
+batch_info_iterator sensor_info_list::find_if_batch_info(int client_id)
 {
        auto iter = m_batch_info_list.begin();
 
@@ -78,7 +77,7 @@ cbatch_info_iterator plugin_info_list::find_if_batch_info(int client_id)
        return iter;
 }
 
-cwakeup_info_iterator plugin_info_list::find_if_wakeup_info(int client_id)
+wakeup_info_iterator sensor_info_list::find_if_wakeup_info(int client_id)
 {
        auto iter = m_wakeup_info_list.begin();
 
@@ -92,19 +91,19 @@ cwakeup_info_iterator plugin_info_list::find_if_wakeup_info(int client_id)
        return iter;
 }
 
-bool plugin_info_list::add_interval(int client_id, unsigned int interval, bool is_processor)
+bool sensor_info_list::add_interval(int client_id, unsigned int interval, bool is_processor)
 {
        auto iter = find_if_interval_info(client_id, is_processor);
 
        if (iter != m_interval_info_list.end())
-               *iter = cinterval_info(client_id, is_processor, interval);
+               *iter = interval_info(client_id, is_processor, interval);
        else
-               m_interval_info_list.push_back(cinterval_info(client_id, is_processor, interval));
+               m_interval_info_list.push_back(interval_info(client_id, is_processor, interval));
 
        return true;
 }
 
-bool plugin_info_list::delete_interval(int client_id, bool is_processor)
+bool sensor_info_list::delete_interval(int client_id, bool is_processor)
 {
        auto iter = find_if_interval_info(client_id, is_processor);
 
@@ -116,7 +115,7 @@ bool plugin_info_list::delete_interval(int client_id, bool is_processor)
        return true;
 }
 
-unsigned int plugin_info_list::get_interval(int client_id, bool is_processor)
+unsigned int sensor_info_list::get_interval(int client_id, bool is_processor)
 {
        auto iter = find_if_interval_info(client_id, is_processor);
 
@@ -126,7 +125,7 @@ unsigned int plugin_info_list::get_interval(int client_id, bool is_processor)
        return iter->interval;
 }
 
-unsigned int plugin_info_list::get_min_interval(void)
+unsigned int sensor_info_list::get_min_interval(void)
 {
        if (m_interval_info_list.empty())
                return 0;
@@ -136,19 +135,19 @@ unsigned int plugin_info_list::get_min_interval(void)
        return iter->interval;
 }
 
-bool plugin_info_list::add_batch(int client_id, unsigned int latency)
+bool sensor_info_list::add_batch(int client_id, unsigned int latency)
 {
        auto iter = find_if_batch_info(client_id);
 
        if (iter != m_batch_info_list.end())
-               *iter = cbatch_info(client_id, latency);
+               *iter = batch_info(client_id, latency);
        else
-               m_batch_info_list.push_back(cbatch_info(client_id, latency));
+               m_batch_info_list.push_back(batch_info(client_id, latency));
 
        return true;
 }
 
-bool plugin_info_list::delete_batch(int client_id)
+bool sensor_info_list::delete_batch(int client_id)
 {
        auto iter = find_if_batch_info(client_id);
 
@@ -160,7 +159,7 @@ bool plugin_info_list::delete_batch(int client_id)
        return true;
 }
 
-unsigned int plugin_info_list::get_batch(int client_id)
+unsigned int sensor_info_list::get_batch(int client_id)
 {
        auto iter = find_if_batch_info(client_id);
 
@@ -170,7 +169,7 @@ unsigned int plugin_info_list::get_batch(int client_id)
        return iter->latency;
 }
 
-unsigned int plugin_info_list::get_max_batch(void)
+unsigned int sensor_info_list::get_max_batch(void)
 {
        if (m_batch_info_list.empty())
                return 0;
@@ -180,19 +179,19 @@ unsigned int plugin_info_list::get_max_batch(void)
        return iter->latency;
 }
 
-bool plugin_info_list::add_wakeup(int client_id, int wakeup)
+bool sensor_info_list::add_wakeup(int client_id, int wakeup)
 {
        auto iter = find_if_wakeup_info(client_id);
 
        if (iter != m_wakeup_info_list.end())
-               *iter = cwakeup_info(client_id, wakeup);
+               *iter = wakeup_info(client_id, wakeup);
        else
-               m_wakeup_info_list.push_back(cwakeup_info(client_id, wakeup));
+               m_wakeup_info_list.push_back(wakeup_info(client_id, wakeup));
 
        return true;
 }
 
-bool plugin_info_list::delete_wakeup(int client_id)
+bool sensor_info_list::delete_wakeup(int client_id)
 {
        auto iter = find_if_wakeup_info(client_id);
 
@@ -204,7 +203,7 @@ bool plugin_info_list::delete_wakeup(int client_id)
        return true;
 }
 
-int plugin_info_list::get_wakeup(int client_id)
+int sensor_info_list::get_wakeup(int client_id)
 {
        auto iter = find_if_wakeup_info(client_id);
 
@@ -214,7 +213,7 @@ int plugin_info_list::get_wakeup(int client_id)
        return iter->wakeup;
 }
 
-int plugin_info_list::is_wakeup_on(void)
+int sensor_info_list::is_wakeup_on(void)
 {
        if (m_wakeup_info_list.empty())
                return -1;
similarity index 57%
rename from src/server/plugin_info_list.h
rename to src/server/sensor_info_list.h
index e8b034e..fc253aa 100644 (file)
  *
  */
 
-#ifndef _PLUGIN_INFO_LIST_H_
-#define _PLUGIN_INFO_LIST_H_
+#ifndef _SENSOR_INFO_LIST_H_
+#define _SENSOR_INFO_LIST_H_
 
 #include <list>
 
-class cinterval_info {
+class interval_info {
 public:
-       cinterval_info(int client_id, bool is_processor, unsigned int interval);
+       interval_info(int client_id, bool is_processor, unsigned int interval);
        int client_id;
        bool is_processor;
        unsigned int interval;
 };
 
-typedef std::list<cinterval_info>::iterator cinterval_info_iterator;
+typedef std::list<interval_info>::iterator interval_info_iterator;
 
-class cbatch_info {
+class batch_info {
 public:
-       cbatch_info(int client_id, unsigned int latency);
+       batch_info(int client_id, unsigned int latency);
        int client_id;
        unsigned int latency;
 };
 
-typedef std::list<cbatch_info>::iterator cbatch_info_iterator;
+typedef std::list<batch_info>::iterator batch_info_iterator;
 
-class cwakeup_info {
+class wakeup_info {
 public:
-       cwakeup_info(int client_id, int wakeup);
+       wakeup_info(int client_id, int wakeup);
        int client_id;
        int wakeup;
 };
 
-typedef std::list<cwakeup_info>::iterator cwakeup_info_iterator;
-
-class plugin_info_list {
-private:
-       static bool comp_interval_info(cinterval_info a, cinterval_info b);
-       cinterval_info_iterator find_if_interval_info(int client_id, bool is_processor);
-
-       static bool comp_batch_info(cbatch_info a, cbatch_info b);
-       cbatch_info_iterator find_if_batch_info(int client_id);
-
-       cwakeup_info_iterator find_if_wakeup_info(int client_id);
-
-       std::list<cinterval_info> m_interval_info_list;
-       std::list<cbatch_info> m_batch_info_list;
-       std::list<cwakeup_info> m_wakeup_info_list;
+typedef std::list<wakeup_info>::iterator wakeup_info_iterator;
 
+class sensor_info_list {
 public:
        bool add_interval(int client_id, unsigned int interval, bool is_processor);
        bool delete_interval(int client_id, bool is_processor);
@@ -79,5 +66,18 @@ public:
        bool delete_wakeup(int client_id);
        int get_wakeup(int client_id);
        int is_wakeup_on(void);
+
+private:
+       static bool comp_interval_info(interval_info a, interval_info b);
+       interval_info_iterator find_if_interval_info(int client_id, bool is_processor);
+
+       static bool comp_batch_info(batch_info a, batch_info b);
+       batch_info_iterator find_if_batch_info(int client_id);
+
+       wakeup_info_iterator find_if_wakeup_info(int client_id);
+
+       std::list<interval_info> m_interval_info_list;
+       std::list<batch_info> m_batch_info_list;
+       std::list<wakeup_info> m_wakeup_info_list;
 };
-#endif /* _PLUGIN_INFO_LIST_H_ */
+#endif /* _SENSOR_INFO_LIST_H_ */
index 74448da..d8636f1 100644 (file)
  *
  */
 
+#include <dlfcn.h>
+#include <dirent.h>
+#include <sensor_common.h>
 #include <sensor_loader.h>
-#include <libxml/xmlmemory.h>
-#include <libxml/parser.h>
 #include <sensor_hal.h>
 #include <sensor_base.h>
-#include <physical_sensor.h>
-#include <dlfcn.h>
-#include <dirent.h>
 #include <sensor_log.h>
+#include <physical_sensor.h>
+#include <virtual_sensor.h>
 #include <unordered_set>
 #include <algorithm>
 
@@ -37,9 +37,7 @@
 using std::vector;
 using std::string;
 
-#define DEVICE_PLUGINS_DIR_PATH "/usr/lib/sensor"
-#define SENSOR_TYPE_SHIFT 32
-#define SENSOR_INDEX_MASK 0xFFFFFFFF
+#define DEVICE_HAL_DIR_PATH "/usr/lib/sensor"
 
 sensor_loader::sensor_loader()
 {
@@ -53,10 +51,10 @@ sensor_loader& sensor_loader::get_instance()
 
 bool sensor_loader::load(void)
 {
-       std::vector<string> device_plugin_paths;
-       std::vector<string> unique_device_plugin_paths;
+       std::vector<string> device_hal_paths;
+       std::vector<string> unique_device_hal_paths;
 
-       get_paths_from_dir(string(DEVICE_PLUGINS_DIR_PATH), device_plugin_paths);
+       get_paths_from_dir(string(DEVICE_HAL_DIR_PATH), device_hal_paths);
 
        std::unordered_set<string> s;
        auto unique = [&s](vector<string> &paths, const string &path) {
@@ -64,13 +62,13 @@ bool sensor_loader::load(void)
                        paths.push_back(path);
        };
 
-       for_each(device_plugin_paths.begin(), device_plugin_paths.end(),
+       for_each(device_hal_paths.begin(), device_hal_paths.end(),
                [&](const string &path) {
-                       unique(unique_device_plugin_paths, path);
+                       unique(unique_device_hal_paths, path);
                }
        );
 
-       for_each(unique_device_plugin_paths.begin(), unique_device_plugin_paths.end(),
+       for_each(unique_device_hal_paths.begin(), unique_device_hal_paths.end(),
                [&](const string &path) {
                        void *handle;
                        load_sensor_devices(path, handle);
@@ -86,7 +84,7 @@ bool sensor_loader::load(void)
 bool sensor_loader::load_sensor_devices(const string &path, void* &handle)
 {
        sensor_device_t *_devices = NULL;
-       sensor_device *device;
+       sensor_device *device = NULL;
        const sensor_info_t *infos;
 
        _I("load device: [%s]", path.c_str());
@@ -156,7 +154,7 @@ void sensor_loader::create_physical_sensors(sensor_type_t type)
                                continue;
                }
 
-               sensor = reinterpret_cast<physical_sensor *>(create_sensor<_sensor>());
+               sensor = dynamic_cast<physical_sensor *>(create_sensor<_sensor>());
 
                if (!sensor) {
                        _E("Memory allocation failed[%s]", info->name);
@@ -177,7 +175,6 @@ void sensor_loader::create_physical_sensors(sensor_type_t type)
 
                m_devices[info] = NULL;
        }
-       return;
 }
 
 template <typename _sensor>
@@ -187,7 +184,7 @@ void sensor_loader::create_virtual_sensors(const char *name)
        sensor_type_t type;
        virtual_sensor *instance;
 
-       instance = reinterpret_cast<virtual_sensor *>(create_sensor<_sensor>());
+       instance = dynamic_cast<virtual_sensor *>(create_sensor<_sensor>());
        if (!instance) {
                _E("Memory allocation failed[%s]", name);
                return;
@@ -249,7 +246,7 @@ void sensor_loader::show_sensor_info(void)
        _I("===============================================\n");
 }
 
-bool sensor_loader::get_paths_from_dir(const string &dir_path, vector<string> &plugin_paths)
+bool sensor_loader::get_paths_from_dir(const string &dir_path, vector<string> &hal_paths)
 {
        DIR *dir = NULL;
        struct dirent *dir_entry = NULL;
@@ -263,13 +260,13 @@ bool sensor_loader::get_paths_from_dir(const string &dir_path, vector<string> &p
 
        string name;
 
-       while ((dir_entry = readdir(dir))) {
+       while (dir_entry = readdir(dir)) {
                name = string(dir_entry->d_name);
 
                if (name == "." || name == "..")
                        continue;
 
-               plugin_paths.push_back(dir_path + "/" + name);
+               hal_paths.push_back(dir_path + "/" + name);
        }
 
        closedir(dir);
@@ -278,12 +275,12 @@ bool sensor_loader::get_paths_from_dir(const string &dir_path, vector<string> &p
 
 sensor_base* sensor_loader::get_sensor(sensor_type_t type)
 {
-       auto it_plugins = m_sensors.find(type);
+       auto it = m_sensors.find(type);
 
-       if (it_plugins == m_sensors.end())
+       if (it == m_sensors.end())
                return NULL;
 
-       return it_plugins->second.get();
+       return it->second.get();
 }
 
 sensor_base* sensor_loader::get_sensor(sensor_id_t id)
@@ -336,12 +333,13 @@ vector<sensor_base *> sensor_loader::get_virtual_sensors(void)
        vector<sensor_base *> virtual_list;
        sensor_base* sensor;
 
-       for (auto sensor_it = m_sensors.begin(); sensor_it != m_sensors.end(); ++sensor_it) {
-               sensor = sensor_it->second.get();
+       for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) {
+               sensor = it->second.get();
 
-               if (sensor && sensor->is_virtual() == true) {
-                       virtual_list.push_back(sensor);
-               }
+               if (!sensor || !sensor->is_virtual())
+                       continue;
+
+               virtual_list.push_back(sensor);
        }
 
        return virtual_list;
index 19997d7..763ea9a 100644 (file)
@@ -17,8 +17,8 @@
  *
  */
 
-#ifndef _SENSOR_PLUGIN_LOADER_H_
-#define _SENSOR_PLUGIN_LOADER_H_
+#ifndef _SENSOR_LOADER_H_
+#define _SENSOR_LOADER_H_
 
 #include <sensor_common.h>
 #include <sensor_types.h>
@@ -32,8 +32,6 @@
 #include <map>
 #include <set>
 #include <memory>
-#include <physical_sensor.h>
-#include <virtual_sensor.h>
 
 class sensor_base;
 
@@ -52,7 +50,7 @@ private:
        template <typename _sensor> sensor_base* create_sensor(void);
 
        void show_sensor_info(void);
-       bool get_paths_from_dir(const std::string &dir_path, std::vector<std::string> &plugin_paths);
+       bool get_paths_from_dir(const std::string &dir_path, std::vector<std::string> &hal_paths);
 
        sensor_map_t m_sensors;
        sensor_device_map_t m_devices;
@@ -67,4 +65,4 @@ public:
        std::vector<sensor_base *> get_sensors(sensor_type_t type);
        std::vector<sensor_base *> get_virtual_sensors(void);
 };
-#endif /* _SENSOR_PLUGIN_LOADER_H_ */
+#endif /* _SENSOR_LOADER_H_ */
index 6041913..8f4e758 100644 (file)
@@ -17,7 +17,8 @@
  *
  */
 
-#include <sensor_internal.h>
+#include <sensor_common.h>
+#include <sensor_types.h>
 #include <sensor_usage.h>
 #include <sensor_log.h>
 
index 52671ce..213a43c 100644 (file)
@@ -57,7 +57,7 @@ int server::get_systemd_socket(const char *name)
        }
 
        if (sd_listen_fds(fd_env) < 0) {
-               ERR("Failed to listen fds from systemd");
+               _E("Failed to listen fds from systemd");
                return -1;
        }
 
index 8c69a7a..3f32b3f 100644 (file)
 #include <csocket.h>
 
 class server {
+public:
+       void run(void);
+       void stop(void);
+       static server& get_instance();
+
 private:
        GMainLoop *m_mainloop;
        csocket m_command_channel_accept_socket;
@@ -42,10 +47,6 @@ private:
        void accept_event_channel(void);
 
        int get_systemd_socket(const char *name);
-public:
-       void run(void);
-       void stop(void);
-       static server& get_instance();
 };
 
 #endif /* _SERVER_H_ */
index fd03a49..6701642 100644 (file)
@@ -22,7 +22,6 @@
 
 
 virtual_sensor::virtual_sensor()
-: m_hardware_fusion(false)
 {
 
 }
index 270285b..a0adbcc 100644 (file)
@@ -50,8 +50,6 @@ protected:
        bool deactivate(void);
 
 private:
-       bool m_hardware_fusion;
-
        virtual bool set_interval(unsigned long interval) = 0;
        virtual bool set_batch_latency(unsigned long latency) = 0;
        virtual bool set_wakeup(int wakeup) = 0;
index 141c24c..a75415c 100644 (file)
 #ifndef _COMMAND_COMMON_H_
 #define _COMMAND_COMMON_H_
 
+#include <cpacket.h>
 #include <sensor_common.h>
 
-#define COMMAND_CHANNEL_PATH                   "/tmp/sensord_command_socket"
-#define EVENT_CHANNEL_PATH                             "/tmp/sensord_event_socket"
+#define COMMAND_CHANNEL_PATH           "/tmp/sensord_command_socket"
+#define EVENT_CHANNEL_PATH                     "/tmp/sensord_event_socket"
 
 #define MAX_HANDLE                     256
 #define MAX_HANDLE_REACHED     -2
 
 enum packet_type_t {
+       CMD_DONE = -1,
        CMD_NONE = 0,
        CMD_GET_ID,
        CMD_GET_SENSOR_LIST,
        CMD_HELLO,
        CMD_BYEBYE,
-       CMD_DONE,
        CMD_START,
        CMD_STOP,
        CMD_REG,
index 6cf6317..64845e8 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef _CPACKET_H_
 #define _CPACKET_H_
 
+#include <stddef.h>
+
 typedef struct packet_header {
        int cmd;
        size_t size;
index cf65aac..513c4b1 100644 (file)
@@ -17,6 +17,7 @@
  *
  */
 
+#include <sensor_log.h>
 #include <csocket.h>
 #include <attr/xattr.h>
 #include <sys/stat.h>
index b538fe1..474c38d 100644 (file)
@@ -26,7 +26,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <fcntl.h>
-#include "sensor_log.h"
+#include <sensor_log.h>
 
 class csocket {
 public:
index b0180fe..6676632 100644 (file)
 #define EPOLL_MAX 32
 
 poller::poller()
+: m_epfd(-1)
 {
        init_poll_fd();
 }
 
 poller::poller(int fd)
+: m_epfd(-1)
 {
        init_poll_fd();
        add_fd(fd);
@@ -100,7 +102,7 @@ bool poller::poll(struct epoll_event &event)
                        m_event_queue.pop();
 
                        if (event.events & EPOLLERR) {
-                               _D("Poll error!");
+                               _E("Poll error!");
                                return false;
                        }
 
index de74ebb..7ba2a89 100644 (file)
 #ifndef __SENSOR_COMMON_H__
 #define __SENSOR_COMMON_H__
 
+#include <stddef.h>
+#include <stdint.h>
 #include <sensor_hal.h>
 #include <sensor_types.h>
-#include <stdint.h>
 
-#define CLIENT_ID_INVALID   -1
+#define OP_ERROR -1
+#define OP_SUCCESS 0
+
+#define CLIENT_ID_INVALID -1
+#define SENSOR_ID_INVALID -1
+
+#define SENSOR_TYPE_SHIFT 32
+#define SENSOR_INDEX_MASK 0xFFFFFFFF
 
 #ifndef NAME_MAX
 #define NAME_MAX 256
@@ -125,6 +133,6 @@ typedef struct sensor_event_t {
 #include <vector>
 
 typedef std::vector<unsigned int> event_type_vector;
-#endif
+#endif /* __cplusplus */
 
 #endif /* __SENSOR_COMMON_H__ */
index 394ee92..eae3bde 100644 (file)
@@ -81,7 +81,7 @@ int sensor_info::get_max_batch_count(void)
        return m_max_batch_count;
 }
 
-unsigned int sensor_info::get_supported_event()
+unsigned int sensor_info::get_supported_event(void)
 {
        return m_supported_event;
 }
@@ -221,8 +221,7 @@ void sensor_info::show(void)
        _I("Min_interval = %d", m_min_interval);
        _I("Fifo_count = %d", m_fifo_count);
        _I("Max_batch_count = %d", m_max_batch_count);
-       _I("supported_event = 0x%x", m_supported_event);
-
+       _I("Supported_event = 0x%x", m_supported_event);
        _I("Wakeup_supported = %d", m_wakeup_supported);
 }
 
@@ -249,7 +248,7 @@ void sensor_info::put(raw_data_t &data, int value)
 {
        char buffer[sizeof(value)];
 
-       int *temp = (int *) buffer;
+       int *temp = (int *)buffer;
        *temp = value;
 
        copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data));
@@ -259,7 +258,7 @@ void sensor_info::put(raw_data_t &data, unsigned int value)
 {
        char buffer[sizeof(value)];
 
-       unsigned int *temp = (unsigned int *) buffer;
+       unsigned int *temp = (unsigned int *)buffer;
        *temp = value;
 
        copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data));
index 6a7ab8b..e2e9e57 100644 (file)
@@ -42,7 +42,7 @@ public:
        int get_min_interval(void);
        int get_fifo_count(void);
        int get_max_batch_count(void);
-       unsigned int get_supported_event();
+       unsigned int get_supported_event(void);
        bool is_supported_event(unsigned int event);
        bool is_wakeup_supported(void);
 
index d28ae63..0026801 100644 (file)
 #include <sys/stat.h>
 #include <unistd.h>
 #include <string.h>
+#include <sensor_log.h>
 #include <dlog.h>
+#include <stddef.h>
 #include <sensor_common.h>
-#include "sensor_log.h"
+#include <sensor_types.h>
 
 #define PATH_MAX 256
 
index 9df8791..be30df0 100644 (file)
  *
  */
 
-#ifndef _SENSOR_LOGS_H_
-#define _SENSOR_LOGS_H_
+#ifndef _SENSOR_LOG_H_
+#define _SENSOR_LOG_H_
 
-#include <dlog.h>
+#include <dlog/dlog.h>
 #include <sys/types.h>
 
 #define EVENT_TYPE_SHIFT 16
@@ -33,6 +33,8 @@
 #endif
 #define LOG_TAG        "SENSOR"
 
+#define LOG_DUMP(fp, fmt, arg...) do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while(0)
+
 #ifdef _DEBUG
 #define DBG SLOGD
 #else
@@ -123,4 +125,4 @@ bool get_proc_name(pid_t pid, char *process_name);
 }
 #endif
 
-#endif /* _SENSOR_LOGS_H_ */
+#endif /* _SENSOR_LOG_H_ */
index 57b20eb..dfa5461 100644 (file)
@@ -41,25 +41,19 @@ typedef enum {
        ULTRAVIOLET_SENSOR,
        TEMPERATURE_SENSOR,
        HUMIDITY_SENSOR,
-       BIO_HRM_SENSOR,
-       BIO_LED_GREEN_SENSOR,
-       BIO_LED_IR_SENSOR,
-       BIO_LED_RED_SENSOR,
+       HRM_SENSOR,
+       BIO_HRM_SENSOR = HRM_SENSOR,
+       HRM_LED_GREEN_SENSOR,
+       BIO_LED_GREEN_SENSOR = HRM_LED_GREEN_SENSOR,
+       HRM_LED_IR_SENSOR,
+       BIO_LED_IR_SENSOR = HRM_LED_IR_SENSOR,
+       HRM_LED_RED_SENSOR,
+       BIO_LED_RED_SENSOR = HRM_LED_RED_SENSOR,
        GYROSCOPE_UNCAL_SENSOR,
-       UNCAL_GEOMAGNETIC_SENSOR,
-       GAMING_RV_SENSOR,
+       GEOMAGNETIC_UNCAL_SENSOR,
+       GYROSCOPE_RV_SENSOR,
        GEOMAGNETIC_RV_SENSOR,
 
-       ACTIVITY_STATIONARY_SENSOR = 0x1100,
-       ACTIVITY_WALK_SENSOR,
-       ACTIVITY_RUN_SENSOR,
-       ACTIVITY_IN_VEHICLE_SENSOR,
-       ACTIVITY_ON_BICYCLE_SENSOR,
-
-       GESTURE_MOVEMENT_SENSOR = 0x1200,
-       GESTURE_WRIST_UP_SENSOR,
-       GESTURE_WRIST_DOWN_SENSOR,
-
        HUMAN_PEDOMETER_SENSOR = 0x300,
        HUMAN_SLEEP_MONITOR_SENSOR,
 
@@ -74,9 +68,20 @@ typedef enum {
        THERMOMETER_SENSOR,
        PEDOMETER_SENSOR,
        FLAT_SENSOR,
-       BIO_SENSOR,
+       HRM_RAW_SENSOR,
+       BIO_SENSOR = HRM_RAW_SENSOR,
        TILT_SENSOR,
        RV_RAW_SENSOR,
+
+       ACTIVITY_STATIONARY_SENSOR = 0x1100,
+       ACTIVITY_WALK_SENSOR,
+       ACTIVITY_RUN_SENSOR,
+       ACTIVITY_IN_VEHICLE_SENSOR,
+       ACTIVITY_ON_BICYCLE_SENSOR,
+
+       GESTURE_MOVEMENT_SENSOR = 0x1200,
+       GESTURE_WRIST_UP_SENSOR,
+       GESTURE_WRIST_DOWN_SENSOR,
 } sensor_type_t;
 
 // Sensor Event Types
@@ -112,7 +117,7 @@ enum event_types_t {
 
        BIO_LED_RED_RAW_DATA_EVENT      = (BIO_LED_RED_SENSOR << 16) | 0x0001,
 
-       GAMING_RV_RAW_DATA_EVENT        = (GAMING_RV_SENSOR << 16) | 0x0001,
+       GAMING_RV_RAW_DATA_EVENT        = (GYROSCOPE_RV_SENSOR << 16) | 0x0001,
 
        GEOMAGNETIC_RV_RAW_DATA_EVENT   = (GEOMAGNETIC_RV_SENSOR << 16) | 0x0001,
 
@@ -262,4 +267,6 @@ enum motion_property_id {
 }
 #endif
 
+#include <sensor_deprecated.h>
+
 #endif /* _SENSOR_TYPES_H_ */
index 0475880..d9cd3ba 100644 (file)
@@ -80,7 +80,7 @@ void printpollinglogs(sensor_type_t type,sensor_data_t data)
        case(GEOMAGNETIC_RV_SENSOR):
                printf("Geomagnetic Rv [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3]);
                break;
-       case(GAMING_RV_SENSOR):
+       case(GYROSCOPE_RV_SENSOR):
                printf("Gaming Rv [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n\n", data.timestamp, data.values[0], data.values[1], data.values[2], data.values[3]);
                break;
        case(GYROSCOPE_UNCAL_SENSOR):
@@ -158,7 +158,7 @@ int get_event(sensor_type_t sensor_type, char str[])
                if (strcmp(str, "RAW_DATA_EVENT") == 0)
                        return GEOMAGNETIC_RV_RAW_DATA_EVENT;
                break;
-       case GAMING_RV_SENSOR:
+       case GYROSCOPE_RV_SENSOR:
                if (strcmp(str, "RAW_DATA_EVENT") == 0)
                        return GAMING_RV_RAW_DATA_EVENT;
                break;
@@ -226,7 +226,7 @@ void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, voi
        case GEOMAGNETIC_RV_SENSOR:
                printf("Geomagnetic RV [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3]);
                break;
-       case GAMING_RV_SENSOR:
+       case GYROSCOPE_RV_SENSOR:
                printf("Gaming RV [%lld] [%6.6f] [%6.6f] [%6.6f] [%6.6f]\n", data->timestamp, data->values[0], data->values[1], data->values[2], data->values[3]);
                break;
        case GYROSCOPE_UNCAL_SENSOR:
index 82d27fa..9f5310f 100644 (file)
@@ -125,7 +125,7 @@ int main(int argc, char **argv)
                 event = GEOMAGNETIC_RV_RAW_DATA_EVENT;
        }
        else if (strcmp(argv[1], "gaming_rv") == 0) {
-                sensor_type = GAMING_RV_SENSOR;
+                sensor_type = GYROSCOPE_RV_SENSOR;
                 event = GAMING_RV_RAW_DATA_EVENT;
        }
        else if (strcmp(argv[1], "light") == 0) {