sensord: sync/clean up sensord source code 17/62217/2
authorkibak.yoon <kibak.yoon@samsung.com>
Tue, 15 Mar 2016 02:33:20 +0000 (11:33 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Tue, 15 Mar 2016 02:56:46 +0000 (11:56 +0900)
Change-Id: I3fa2c377700e828443ec747e226f89c6249d541f
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
13 files changed:
src/client/CMakeLists.txt
src/client/client.cpp
src/client/client_common.h
src/client/sensor_event_listener.cpp
src/client/sensor_event_listener.h
src/client/sensor_handle_info.cpp
src/server/command_worker.cpp
src/server/physical_sensor.h
src/server/sensor_event_dispatcher.cpp
src/server/sensor_event_poller.cpp
src/server/sensor_loader.cpp
src/server/sensor_usage.cpp
src/shared/command_common.h

index 0ad7db0..2f32b9c 100644 (file)
@@ -1,7 +1,7 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 PROJECT(sensor CXX)
 
-SET(DEPENDENTS "vconf glib-2.0 dlog")
+SET(DEPENDENTS "vconf glib-2.0 gio-2.0 dlog")
 SET(VERSION ${FULLVER})
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(EXEC_PREFIX "${CMAKE_INSTALL_PREFIX}/bin")
index 4366792..0a3024e 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include <sensor_common.h>
+#include <sensor_internal_deprecated.h>
 #include <sensor_internal.h>
 #include <sensor_event_listener.h>
 #include <sensor_client_info.h>
@@ -543,7 +544,7 @@ API int sensord_connect(sensor_t sensor)
        atexit(good_bye);
 
        handle = sensor_client_info::get_instance().create_handle(sensor_id);
-       if (handle == MAX_HANDLE_REACHED) {
+       if (handle == MAX_HANDLE) {
                _E("Maximum number of handles reached, sensor: %s in client %s", get_sensor_name(sensor_id), get_client_name());
                return OP_ERROR;
        }
@@ -1108,11 +1109,10 @@ API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* senso
                return false;
        }
 
-       if(!cmd_channel->cmd_get_data(data_id, sensor_data)) {
+       if (!cmd_channel->cmd_get_data(data_id, sensor_data)) {
                _E("cmd_get_data(%d, %d, 0x%x) failed for %s", client_id, data_id, sensor_data, get_client_name());
                return false;
        }
 
        return true;
-
 }
index 8b5ec8e..ff6eb2c 100644 (file)
@@ -27,6 +27,7 @@
 #include <sensor_log.h>
 
 #define BASE_GATHERING_INTERVAL        100
+
 #define CLIENT_NAME_SIZE NAME_MAX+10
 
 struct log_attr {
index 778392d..c71b9cd 100644 (file)
@@ -47,14 +47,6 @@ sensor_event_listener::~sensor_event_listener()
        stop_event_listener();
 }
 
-sensor_event_listener::sensor_event_listener(const sensor_event_listener& listener)
-: m_poller(listener.m_poller)
-, m_thread_state(listener.m_thread_state)
-, m_hup_observer(listener.m_hup_observer)
-, m_client_info(listener.m_client_info)
-{
-}
-
 sensor_event_listener& sensor_event_listener::get_instance(void)
 {
        static sensor_event_listener inst;
@@ -409,7 +401,7 @@ void sensor_event_listener::listen_events(void)
 bool sensor_event_listener::create_event_channel(void)
 {
        int client_id;
-       event_channel_ready_t event_channel_ready;
+       channel_ready_t event_channel_ready;
 
        if (!m_event_socket.create(SOCK_SEQPACKET))
                return false;
@@ -437,7 +429,7 @@ bool sensor_event_listener::create_event_channel(void)
                return false;
        }
 
-       if ((event_channel_ready.magic != EVENT_CHANNEL_MAGIC) || (event_channel_ready.client_id != client_id)) {
+       if ((event_channel_ready.magic != CHANNEL_MAGIC_NUM) || (event_channel_ready.client_id != client_id)) {
                _E("Event_channel_ready packet is wrong, magic = 0x%x, client id = %d",
                        event_channel_ready.magic, event_channel_ready.client_id);
                return false;
index 4af7092..fa7b77e 100644 (file)
@@ -102,7 +102,6 @@ private:
        sensor_event_listener();
        ~sensor_event_listener();
 
-       sensor_event_listener(const sensor_event_listener&);
        sensor_event_listener& operator=(const sensor_event_listener&);
 
        bool create_event_channel(void);
index 9ea4d0d..796107f 100644 (file)
@@ -149,7 +149,7 @@ void sensor_handle_info::get_batch(unsigned int &interval, unsigned int &latency
 {
        if (m_reg_event_infos.empty()) {
                _D("No events are registered for client %s", get_client_name());
-               interval = POLL_MAX_HZ_MS;
+               interval = POLL_1HZ_MS;
                latency = 0;
                return;
        }
index b99ba0f..c8804d7 100644 (file)
@@ -772,7 +772,7 @@ bool command_worker::cmd_set_attribute_int(void *payload)
        cmd = (cmd_set_attribute_int_t*)payload;
 
        if (!is_permission_allowed()) {
-               _E("Permission denied to set command for client [%d], for sensor [0x%llx] with attribute [%d]",
+               _E("Permission denied to set attribute for client [%d], for sensor [0x%llx] with attribute [%d]",
                        m_client_id, m_sensor_id, cmd->attribute);
                ret_value = OP_ERROR;
                goto out;
@@ -797,7 +797,7 @@ bool command_worker::cmd_set_attribute_str(void *payload)
        cmd = (cmd_set_attribute_str_t*)payload;
 
        if (!is_permission_allowed()) {
-               _E("Permission denied to send sensorhub_data for client [%d], for sensor [0x%llx]",
+               _E("Permission denied to set attribute for client [%d], for sensor [0x%llx]",
                        m_client_id, m_sensor_id);
                ret_value = OP_ERROR;
                goto out;
index 7bad87d..a2e8763 100644 (file)
@@ -43,20 +43,22 @@ public:
        virtual bool read_fd(std::vector<uint32_t> &ids);
        virtual int get_data(sensor_data_t **data, int *length);
        virtual bool flush(void);
-private:
-       static cmutex m_mutex;
 
+protected:
        const sensor_info_t *m_info;
        sensor_device *m_sensor_device;
        uint32_t hal_id;
 
-       virtual bool set_interval(unsigned long interval);
-       virtual bool set_batch_latency(unsigned long latency);
-       virtual int set_attribute(int32_t attribute, int32_t value);
-       virtual int set_attribute(int32_t attribute, char *value, int value_len);
        virtual bool on_start(void);
        virtual bool on_stop(void);
+       virtual int set_attribute(int32_t attribute, int32_t value);
+       virtual int set_attribute(int32_t attribute, char *value, int value_len);
+       virtual bool set_interval(unsigned long interval);
+       virtual bool set_batch_latency(unsigned long latency);
        virtual bool get_sensor_info(sensor_info &info);
+
+private:
+       static cmutex m_mutex;
 };
 
 #endif /* _PHYSICAL_SENSOR_H_ */
index b03a5e4..977a657 100644 (file)
@@ -53,7 +53,7 @@ bool sensor_event_dispatcher::run(void)
 void sensor_event_dispatcher::accept_event_channel(csocket client_socket)
 {
        int client_id;
-       event_channel_ready_t event_channel_ready;
+       channel_ready_t event_channel_ready;
        client_info_manager& client_info_manager = get_client_info_manager();
 
        client_socket.set_connection_mode();
@@ -71,7 +71,7 @@ void sensor_event_dispatcher::accept_event_channel(csocket client_socket)
                return;
        }
 
-       event_channel_ready.magic = EVENT_CHANNEL_MAGIC;
+       event_channel_ready.magic = CHANNEL_MAGIC_NUM;
        event_channel_ready.client_id = client_id;
 
        _I("Event channel is accepted for %s on socket[%d]",
index 0063871..af7d8cd 100644 (file)
@@ -131,8 +131,11 @@ bool sensor_event_poller::process_event(int fd, const std::vector<uint32_t> &ids
 
                while (remains > 0) {
                        event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
-
                        remains = sensor->get_data(&data, &data_length);
+                       if (remains < 0) {
+                               _E("Failed to get sensor data");
+                               break;
+                       }
 
                        event->sensor_id = sensor->get_id();
                        event->event_type = sensor->get_event_type();
index 5626214..a050df7 100644 (file)
@@ -141,9 +141,9 @@ void sensor_loader::create_physical_sensors(sensor_type_t type)
        physical_sensor *sensor;
        sensor_device *device;
 
-       sensor_device_map_t::iterator it = m_devices.begin();
+       sensor_device_map_t::iterator it;
 
-       for (sensor_device_map_t::iterator it = m_devices.begin(); it != m_devices.end(); ++it) {
+       for (it = m_devices.begin(); it != m_devices.end(); ++it) {
                info = it->first;
                device = it->second;
                if (m_devices[info] == NULL)
index 4b6c881..83ead8d 100644 (file)
@@ -23,7 +23,7 @@
 #include <sensor_log.h>
 
 sensor_usage::sensor_usage()
-: m_interval(POLL_MAX_HZ_MS)
+: m_interval(POLL_1HZ_MS)
 , m_latency(0)
 , m_option(SENSOR_OPTION_DEFAULT)
 , m_start(false)
index 0e2a5ac..48dd750 100644 (file)
@@ -126,12 +126,12 @@ typedef struct  {
        char value[0];
 } cmd_set_attribute_str_t;
 
-#define EVENT_CHANNEL_MAGIC 0xCAFECAFE
+#define CHANNEL_MAGIC_NUM 0xCAFECAFE
 
 typedef struct {
        unsigned int magic;
        int client_id;
-} event_channel_ready_t;
+} channel_ready_t;
 
 typedef void *(*cmd_func_t)(void *data, void *cb_data);