sensord: refactoring: remove regacy code 21/114021/2
authorkibak.yoon <kibak.yoon@samsung.com>
Thu, 9 Feb 2017 11:18:20 +0000 (20:18 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Tue, 28 Feb 2017 05:31:49 +0000 (14:31 +0900)
Change-Id: I4ed2735fd80ab5c9345a03d87ce312c00502c3e2
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
83 files changed:
include/enum_factory.h [deleted file]
include/sensor_types.h
src/client/client.cpp
src/client/client_common.cpp [deleted file]
src/client/client_common.h [deleted file]
src/client/command_channel.cpp [deleted file]
src/client/command_channel.h [deleted file]
src/client/dbus_listener.cpp [deleted file]
src/client/dbus_listener.h [deleted file]
src/client/external_client.cpp [deleted file]
src/client/external_data_channel.cpp [deleted file]
src/client/external_data_channel.h [deleted file]
src/client/external_sensor_manager.cpp [deleted file]
src/client/external_sensor_manager.h [deleted file]
src/client/reg_event_info.h [deleted file]
src/client/sensor_callback_deliverer.cpp [deleted file]
src/client/sensor_callback_deliverer.h [deleted file]
src/client/sensor_client_info.cpp [deleted file]
src/client/sensor_client_info.h [deleted file]
src/client/sensor_event_listener.cpp [deleted file]
src/client/sensor_event_listener.h [deleted file]
src/client/sensor_handle_info.cpp [deleted file]
src/client/sensor_handle_info.h [deleted file]
src/client/sensor_info_manager.cpp [deleted file]
src/client/sensor_info_manager.h [deleted file]
src/sensor/CMakeLists.txt
src/server/client_info_manager.cpp [deleted file]
src/server/client_info_manager.h [deleted file]
src/server/client_sensor_record.cpp [deleted file]
src/server/client_sensor_record.h [deleted file]
src/server/command_queue.cpp [deleted file]
src/server/command_queue.h [deleted file]
src/server/command_worker.cpp [deleted file]
src/server/command_worker.h [deleted file]
src/server/external_client_manager.cpp [deleted file]
src/server/external_client_manager.h [deleted file]
src/server/external_sensor.cpp [deleted file]
src/server/external_sensor.h [deleted file]
src/server/external_sensor_record.cpp [deleted file]
src/server/external_sensor_record.h [deleted file]
src/server/external_sensor_service.cpp [deleted file]
src/server/external_sensor_service.h [deleted file]
src/server/external_sensor_worker.cpp [deleted file]
src/server/external_sensor_worker.h [deleted file]
src/server/main.cpp
src/server/permission_checker.cpp
src/server/permission_checker.h
src/server/physical_sensor.cpp
src/server/physical_sensor.h
src/server/sensor_base.cpp [deleted file]
src/server/sensor_base.h [deleted file]
src/server/sensor_event_dispatcher.cpp [deleted file]
src/server/sensor_event_dispatcher.h [deleted file]
src/server/sensor_event_poller.cpp [deleted file]
src/server/sensor_event_poller.h [deleted file]
src/server/sensor_event_queue.cpp [deleted file]
src/server/sensor_event_queue.h [deleted file]
src/server/sensor_fusion.cpp [deleted file]
src/server/sensor_fusion.h [deleted file]
src/server/sensor_info_list.cpp [deleted file]
src/server/sensor_info_list.h [deleted file]
src/server/sensor_loader.cpp
src/server/sensor_loader.h
src/server/sensor_usage.cpp [deleted file]
src/server/sensor_usage.h [deleted file]
src/server/server.cpp
src/server/server.h
src/server/virtual_sensor.cpp
src/server/virtual_sensor.h
src/server/worker_thread.cpp [deleted file]
src/server/worker_thread.h [deleted file]
src/shared/cbase_lock.cpp [deleted file]
src/shared/cbase_lock.h [deleted file]
src/shared/cmutex.cpp [deleted file]
src/shared/cmutex.h [deleted file]
src/shared/command_common.h
src/shared/cpacket.cpp [deleted file]
src/shared/cpacket.h [deleted file]
src/shared/csocket.cpp [deleted file]
src/shared/csocket.h [deleted file]
src/shared/poller.cpp [deleted file]
src/shared/poller.h [deleted file]
src/shared/sensor_types.cpp [deleted file]

diff --git a/include/enum_factory.h b/include/enum_factory.h
deleted file mode 100644 (file)
index e67d71b..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _ENUM_FACTORY_H_
-#define _ENUM_FACTORY_H_
-
-#define ENUM_SENSOR(name) name,
-#define ENUM_SENSOR_VALUE(name, assign) name = (assign),
-
-#define ENUM_CASE(name) case (name): return #name;
-#define ENUM_CASE_VALUE(name, assign) ENUM_CASE(name)
-
-#define DECLARE_SENSOR_ENUM(ENUM_TYPE, ENUM_DEF) \
-       typedef enum ENUM_TYPE { \
-               ENUM_DEF(ENUM_SENSOR, ENUM_SENSOR_VALUE) \
-       } ENUM_TYPE;
-
-#define DECLARE_SENSOR_ENUM_UTIL_NS(ENUM_TYPE) \
-       namespace util_##ENUM_TYPE { \
-               const char *get_string(ENUM_TYPE type); \
-       };
-
-#define DECLARE_SENSOR_ENUM_UTIL(ENUM_TYPE, ENUM_DEF) \
-       const char *util_##ENUM_TYPE::get_string(ENUM_TYPE type) { \
-               switch (type) { \
-               ENUM_DEF(ENUM_CASE, ENUM_CASE_VALUE) \
-               } \
-               return "UNKNOWN"; \
-       }
-
-#endif /* _ENUM_FACTORY_H_ */
index ac1f13a..5b752af 100644 (file)
  *
  */
 
-#ifndef _SENSOR_TYPES_H_
-#define _SENSOR_TYPES_H_
-
-#include <enum_factory.h>
+#ifndef __SENSOR_TYPES_H__
+#define __SENSOR_TYPES_H__
 
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
-#define SENSOR_TYPE(DEF_SENSOR, DEF_SENSOR_VALUE) \
-       DEF_SENSOR_VALUE(UNKNOWN_SENSOR, -2) \
-       DEF_SENSOR_VALUE(ALL_SENSOR, -1) \
-       DEF_SENSOR_VALUE(ACCELEROMETER_SENSOR, 0) \
-       DEF_SENSOR(GRAVITY_SENSOR) \
-       DEF_SENSOR(LINEAR_ACCEL_SENSOR) \
-       DEF_SENSOR(GEOMAGNETIC_SENSOR) \
-       DEF_SENSOR(ROTATION_VECTOR_SENSOR) \
-       DEF_SENSOR(ORIENTATION_SENSOR) \
-       DEF_SENSOR(GYROSCOPE_SENSOR) \
-       DEF_SENSOR(LIGHT_SENSOR) \
-       DEF_SENSOR(PROXIMITY_SENSOR) \
-       DEF_SENSOR(PRESSURE_SENSOR) \
-       DEF_SENSOR(ULTRAVIOLET_SENSOR) \
-       DEF_SENSOR(TEMPERATURE_SENSOR) \
-       DEF_SENSOR(HUMIDITY_SENSOR) \
-       DEF_SENSOR(HRM_SENSOR) \
-       DEF_SENSOR(HRM_LED_GREEN_SENSOR) \
-       DEF_SENSOR(HRM_LED_IR_SENSOR) \
-       DEF_SENSOR(HRM_LED_RED_SENSOR) \
-       DEF_SENSOR(GYROSCOPE_UNCAL_SENSOR) \
-       DEF_SENSOR(GEOMAGNETIC_UNCAL_SENSOR) \
-       DEF_SENSOR(GYROSCOPE_RV_SENSOR) \
-       DEF_SENSOR(GEOMAGNETIC_RV_SENSOR) \
-       \
-       DEF_SENSOR_VALUE(HUMAN_PEDOMETER_SENSOR, 0x300) \
-       DEF_SENSOR(HUMAN_SLEEP_MONITOR_SENSOR) \
-       DEF_SENSOR(HUMAN_SLEEP_DETECTOR_SENSOR) \
-       DEF_SENSOR(HUMAN_STRESS_MONITOR_SENSOR) \
-       \
-       DEF_SENSOR_VALUE(EXERCISE_WALKING_SENSOR, 0x400) \
-       DEF_SENSOR(EXERCISE_RUNNING_SENSOR) \
-       DEF_SENSOR(EXERCISE_HIKING_SENSOR) \
-       DEF_SENSOR(EXERCISE_CYCLING_SENSOR) \
-       DEF_SENSOR(EXERCISE_ELLIPTICAL_SENSOR) \
-       DEF_SENSOR(EXERCISE_INDOOR_CYCLING_SENSOR) \
-       DEF_SENSOR(EXERCISE_ROWING_SENSOR) \
-       DEF_SENSOR(EXERCISE_STEPPER_SENSOR) \
-       \
-       DEF_SENSOR_VALUE(EXTERNAL_EXERCISE_SENSOR, 0x800) \
-       \
-       DEF_SENSOR_VALUE(FUSION_SENSOR, 0x900) \
-       DEF_SENSOR(AUTO_ROTATION_SENSOR) \
-       DEF_SENSOR(AUTO_BRIGHTNESS_SENSOR) \
-       \
-       DEF_SENSOR_VALUE(GESTURE_MOVEMENT_SENSOR, 0x1200) \
-       DEF_SENSOR(GESTURE_WRIST_UP_SENSOR) \
-       DEF_SENSOR(GESTURE_WRIST_DOWN_SENSOR) \
-       DEF_SENSOR(GESTURE_MOVEMENT_STATE_SENSOR) \
-       DEF_SENSOR(GESTURE_FACE_DOWN_SENSOR) \
-       \
-       DEF_SENSOR_VALUE(ACTIVITY_TRACKER_SENSOR, 0x1A00) \
-       DEF_SENSOR(ACTIVITY_LEVEL_MONITOR_SENSOR) \
-       DEF_SENSOR(GPS_BATCH_SENSOR) \
-       \
-       DEF_SENSOR_VALUE(HRM_CTRL_SENSOR, 0x1A80) \
-       \
-       DEF_SENSOR_VALUE(WEAR_STATUS_SENSOR, 0x2000) \
-       DEF_SENSOR(WEAR_ON_MONITOR_SENSOR) \
-       DEF_SENSOR(NO_MOVE_DETECTOR_SENSOR) \
-       DEF_SENSOR(RESTING_HR_SENSOR) \
-       DEF_SENSOR(STEP_LEVEL_MONITOR_SENSOR) \
-       DEF_SENSOR(EXERCISE_STANDALONE_SENSOR) \
-       DEF_SENSOR(EXERCISE_HR_SENSOR) \
-       DEF_SENSOR(WORKOUT_SENSOR) \
-       DEF_SENSOR(CYCLE_MONITOR_SENSOR) \
-       DEF_SENSOR(STAIR_TRACKER_SENSOR) \
-       DEF_SENSOR(PRESSURE_INDICATOR_SENSOR) \
-       DEF_SENSOR(PRESSURE_ALERT_SENSOR) \
-       DEF_SENSOR(HR_CALORIE_SENSOR) \
-       \
-       DEF_SENSOR_VALUE(CONTEXT_SENSOR, 0x7000) \
-       DEF_SENSOR(MOTION_SENSOR) \
-       DEF_SENSOR(PIR_SENSOR) \
-       DEF_SENSOR(PIR_LONG_SENSOR) \
-       DEF_SENSOR(DUST_SENSOR) \
-       DEF_SENSOR(THERMOMETER_SENSOR) \
-       DEF_SENSOR(PEDOMETER_SENSOR) \
-       DEF_SENSOR(FLAT_SENSOR) \
-       DEF_SENSOR(HRM_RAW_SENSOR) \
-       DEF_SENSOR(TILT_SENSOR) \
-       DEF_SENSOR(RV_RAW_SENSOR) \
-       DEF_SENSOR(GSR_SENSOR) \
-       DEF_SENSOR(SIMSENSE_SENSOR) \
-       DEF_SENSOR(PPG_SENSOR) \
-
-#define BIO_HRM_SENSOR              HRM_SENSOR
-#define BIO_LED_GREEN_SENSOR        HRM_LED_GREEN_SENSOR
-#define BIO_LED_IR_SENSOR           HRM_LED_IR_SENSOR
-#define BIO_LED_RED_SENSOR          HRM_LED_RED_SENSOR
-#define BIO_SENSOR                  HRM_RAW_SENSOR
-#define SLEEP_DETECTOR_SENSOR       HUMAN_SLEEP_DETECTOR_SENSOR
-#define STRESS_MONITOR_SENSOR       HUMAN_STRESS_MONITOR_SENSOR
-#define AUTOSESSION_EXERCISE_SENSOR WORKOUT_SENSOR
-#define EXERCISE_COACH_SENSOR       EXERCISE_STANDALONE_SENSOR
-#define EXERCISE_SENSOR             EXTERNAL_EXERCISE_SENSOR
-
-DECLARE_SENSOR_ENUM(sensor_type_t, SENSOR_TYPE)
+typedef enum sensor_type_t {
+       UNKNOWN_SENSOR = -2,
+       ALL_SENSOR = -1,
+       ACCELEROMETER_SENSOR = 0,
+       GRAVITY_SENSOR,
+       LINEAR_ACCEL_SENSOR,
+       GEOMAGNETIC_SENSOR,
+       ROTATION_VECTOR_SENSOR,
+       ORIENTATION_SENSOR,
+       GYROSCOPE_SENSOR,
+       LIGHT_SENSOR,
+       PROXIMITY_SENSOR,
+       PRESSURE_SENSOR,
+       ULTRAVIOLET_SENSOR,
+       TEMPERATURE_SENSOR,
+       HUMIDITY_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,
+       GEOMAGNETIC_UNCAL_SENSOR,
+       GYROSCOPE_RV_SENSOR,
+       GEOMAGNETIC_RV_SENSOR,
+
+       HUMAN_PEDOMETER_SENSOR = 0x300,
+       HUMAN_SLEEP_MONITOR_SENSOR,
+       HUMAN_SLEEP_DETECTOR_SENSOR,
+       SLEEP_DETECTOR_SENSOR = HUMAN_SLEEP_DETECTOR_SENSOR,
+       HUMAN_STRESS_MONITOR_SENSOR,
+       STRESS_MONITOR_SENSOR = HUMAN_STRESS_MONITOR_SENSOR,
+
+       EXERCISE_WALKING_SENSOR = 0x400,
+       EXERCISE_RUNNING_SENSOR,
+       EXERCISE_HIKING_SENSOR,
+       EXERCISE_CYCLING_SENSOR,
+       EXERCISE_ELLIPTICAL_SENSOR,
+       EXERCISE_INDOOR_CYCLING_SENSOR,
+       EXERCISE_ROWING_SENSOR,
+       EXERCISE_STEPPER_SENSOR,
+
+       EXTERNAL_EXERCISE_SENSOR = 0x800,
+       EXERCISE_SENSOR = EXTERNAL_EXERCISE_SENSOR,
+
+       FUSION_SENSOR = 0x900,
+       AUTO_ROTATION_SENSOR,
+       AUTO_BRIGHTNESS_SENSOR,
+
+       GESTURE_MOVEMENT_SENSOR = 0x1200,
+       GESTURE_WRIST_UP_SENSOR,
+       GESTURE_WRIST_DOWN_SENSOR,
+       GESTURE_MOVEMENT_STATE_SENSOR,
+       GESTURE_FACE_DOWN_SENSOR,
+
+       ACTIVITY_TRACKER_SENSOR = 0x1A00,
+       ACTIVITY_LEVEL_MONITOR_SENSOR,
+       GPS_BATCH_SENSOR,
+
+       HRM_CTRL_SENSOR = 0x1A80,
+
+       WEAR_STATUS_SENSOR = 0x2000,
+       WEAR_ON_MONITOR_SENSOR,
+       NO_MOVE_DETECTOR_SENSOR,
+       RESTING_HR_SENSOR,
+       STEP_LEVEL_MONITOR_SENSOR,
+       EXERCISE_STANDALONE_SENSOR,
+       EXERCISE_COACH_SENSOR = EXERCISE_STANDALONE_SENSOR,
+       EXERCISE_HR_SENSOR,
+       WORKOUT_SENSOR,
+       AUTOSESSION_EXERCISE_SENSOR = WORKOUT_SENSOR,
+       CYCLE_MONITOR_SENSOR,
+       STAIR_TRACKER_SENSOR,
+       PRESSURE_INDICATOR_SENSOR,
+       PRESSURE_ALERT_SENSOR,
+       HR_CALORIE_SENSOR,
+
+       CONTEXT_SENSOR = 0x7000,
+       MOTION_SENSOR,
+       PIR_SENSOR,
+       PIR_LONG_SENSOR,
+       DUST_SENSOR,
+       THERMOMETER_SENSOR,
+       PEDOMETER_SENSOR,
+       FLAT_SENSOR,
+       HRM_RAW_SENSOR,
+       BIO_SENSOR = HRM_RAW_SENSOR,
+       TILT_SENSOR,
+       RV_RAW_SENSOR,
+       GSR_SENSOR,
+       SIMSENSE_SENSOR,
+       PPG_SENSOR,
+
+       CUSTOM_SENSOR = 0X9000,
+} sensor_type_t;
 
 enum proxi_change_state {
        PROXIMITY_STATE_NEAR = 0,
@@ -143,10 +141,6 @@ enum auto_rotation_state {
 }
 #endif
 
-#ifdef __cplusplus
-DECLARE_SENSOR_ENUM_UTIL_NS(sensor_type_t)
-#endif
-
 #include <sensor_deprecated.h>
 
-#endif /* _SENSOR_TYPES_H_ */
+#endif /* __SENSOR_TYPES_H__ */
index 7fd43f5..0864b14 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>
+#include "sensor_internal.h"
+#include <stdlib.h>
 #include <sensor_log.h>
-#include <sensor_info.h>
-#include <sensor_info_manager.h>
-#include <vector>
-#include <algorithm>
-#include "dbus_listener.h"
 
-using std::vector;
-
-#ifndef API
-#define API __attribute__((visibility("default")))
-#endif
-
-#ifndef VCONFKEY_SETAPPL_PSMODE
-#define VCONFKEY_SETAPPL_PSMODE "db/setting/psmode"
-#endif
-
-#define DEFAULT_INTERVAL POLL_10HZ_MS
-
-#define CONVERT_OPTION_PAUSE_POLICY(option) ((option) ^ 0b11)
-
-static cmutex lock;
-
-static int g_power_save_state = SENSORD_PAUSE_NONE;
-
-static int get_power_save_state(void);
-static void power_save_state_cb(keynode_t *node, void *data);
-static void clean_up(void);
-static bool change_sensor_rep(sensor_id_t sensor_id, sensor_rep &prev_rep, sensor_rep &cur_rep);
-static void restore_session(void);
-static bool register_event(int handle, unsigned int event_type, unsigned int interval, int max_batch_latency, void* cb, void *user_data);
-
-class initiator {
-public:
-       initiator()
-       {
-               sensor_event_listener::get_instance().set_hup_observer(restore_session);
-       }
-};
-
-void good_bye(void)
-{
-       _I("Good bye! %s\n", get_client_name());
-       clean_up();
-}
-
-static initiator g_initiator;
-
-static int g_power_save_state_cb_cnt = 0;
-
-static void set_power_save_state_cb(void)
-{
-       if (g_power_save_state_cb_cnt < 0)
-               _E("g_power_save_state_cb_cnt(%d) is wrong", g_power_save_state_cb_cnt);
-
-       ++g_power_save_state_cb_cnt;
-
-       if (g_power_save_state_cb_cnt == 1) {
-               _D("Power save callback is registered");
-               g_power_save_state = get_power_save_state();
-               _D("power_save_state = [%d]", g_power_save_state);
-               vconf_notify_key_changed(VCONFKEY_PM_STATE, power_save_state_cb, NULL);
-               vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, power_save_state_cb, NULL);
-       }
-}
-
-static void unset_power_save_state_cb(void)
-{
-       --g_power_save_state_cb_cnt;
-
-       if (g_power_save_state_cb_cnt < 0)
-               _E("g_power_save_state_cb_cnt(%d) is wrong", g_power_save_state_cb_cnt);
-
-       if (g_power_save_state_cb_cnt == 0) {
-               _D("Power save callback is unregistered");
-               vconf_ignore_key_changed(VCONFKEY_PM_STATE, power_save_state_cb);
-               vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, power_save_state_cb);
-       }
-}
-
-void clean_up(void)
-{
-       handle_vector handles;
-
-       sensor_client_info::get_instance().get_all_handles(handles);
-
-       auto it_handle = handles.begin();
-
-       while (it_handle != handles.end()) {
-               sensord_disconnect(*it_handle);
-               ++it_handle;
-       }
-
-       sensor_event_listener::get_instance().clear();
-}
-
-static int get_power_save_state(void)
-{
-       int ret;
-       int state = 0;
-       int pm_state, ps_state;
-
-       ret = vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
-
-       if (!ret && pm_state == VCONFKEY_PM_STATE_LCDOFF)
-               state |= SENSORD_PAUSE_ON_DISPLAY_OFF;
-
-       ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ps_state);
-
-       if (!ret && ps_state != SETTING_PSMODE_NORMAL)
-               state |= SENSORD_PAUSE_ON_POWERSAVE_MODE;
-
-       return state;
-}
-
-static void power_save_state_cb(keynode_t *node, void *data)
-{
-       int cur_power_save_state;
-       sensor_id_vector sensors;
-       sensor_rep prev_rep, cur_rep;
-
-       AUTOLOCK(lock);
-
-       cur_power_save_state = get_power_save_state();
-
-       if (cur_power_save_state == g_power_save_state) {
-               _D("g_power_save_state NOT changed : [%d]", cur_power_save_state);
-               return;
-       }
-
-       g_power_save_state = cur_power_save_state;
-       _D("power_save_state: %d noti to %s", g_power_save_state, get_client_name());
-
-       sensor_client_info::get_instance().get_listening_sensors(sensors);
-
-       auto it_sensor = sensors.begin();
-
-       while (it_sensor != sensors.end()) {
-               sensor_client_info::get_instance().get_sensor_rep(*it_sensor, prev_rep);
-               sensor_client_info::get_instance().set_pause_policy(*it_sensor, cur_power_save_state);
-               sensor_client_info::get_instance().get_sensor_rep(*it_sensor, cur_rep);
-               change_sensor_rep(*it_sensor, prev_rep, cur_rep);
-
-               ++it_sensor;
-       }
-}
-
-bool restore_attributes(int client_id, sensor_id_t sensor, command_channel *cmd_channel)
-{
-       sensor_handle_info_map handle_infos;
-
-       sensor_client_info::get_instance().get_sensor_handle_info(sensor, handle_infos);
-
-       for (auto it_handles = handle_infos.begin(); it_handles != handle_infos.end(); ++it_handles) {
-               sensor_handle_info info = it_handles->second;
-
-               for (auto it = info.attributes_int.begin(); it != info.attributes_int.end(); ++it) {
-                       int attribute = it->first;
-                       int value = it->second;
-                       if (!cmd_channel->cmd_set_attribute_int(attribute, value)) {
-                               _E("Failed to send cmd_set_attribute_int(%d, %d) for %s",
-                                   client_id, value, get_client_name());
-                               return false;
-                       }
-               }
-
-               for (auto it = info.attributes_str.begin(); it != info.attributes_str.end(); ++it) {
-                       int attribute = it->first;
-                       const char *value = it->second->get();
-                       int len = it->second->size();
-                       if (!cmd_channel->cmd_set_attribute_str(attribute, value, len)) {
-                               _E("Failed to send cmd_set_attribute_str(%d, %d, %s) for %s",
-                                   client_id, len, value, get_client_name());
-                               return false;
-                       }
-               }
-       }
-
-       return true;
-}
-
-void restore_session(void)
-{
-       AUTOLOCK(lock);
-
-       _I("Trying to restore sensor client session for %s", get_client_name());
-
-       command_channel *cmd_channel;
-       int client_id;
-
-       sensor_client_info::get_instance().close_command_channel();
-       sensor_client_info::get_instance().set_client_id(CLIENT_ID_INVALID);
-
-       sensor_id_vector sensors;
-
-       sensor_client_info::get_instance().get_listening_sensors(sensors);
-
-       bool first_connection = true;
-
-       auto it_sensor = sensors.begin();
-
-       while (it_sensor != sensors.end()) {
-               cmd_channel = new(std::nothrow) command_channel();
-               retm_if(!cmd_channel, "Failed to allocate memory");
-
-               if (!cmd_channel->create_channel()) {
-                       _E("%s failed to create command channel for %s", get_client_name(), get_sensor_name(*it_sensor));
-                       delete cmd_channel;
-                       goto FAILED;
-               }
-
-               sensor_client_info::get_instance().add_command_channel(*it_sensor, cmd_channel);
-
-               if (first_connection) {
-                       first_connection = false;
-                       if (!cmd_channel->cmd_get_id(client_id)) {
-                               _E("Failed to get client id");
-                               goto FAILED;
-                       }
-
-                       sensor_client_info::get_instance().set_client_id(client_id);
-                       sensor_event_listener::get_instance().start_event_listener();
-               }
-
-               cmd_channel->set_client_id(client_id);
-
-               if (!cmd_channel->cmd_hello(*it_sensor)) {
-                       _E("Sending cmd_hello(%s, %d) failed for %s", get_sensor_name(*it_sensor), client_id, get_client_name());
-                       goto FAILED;
-               }
-
-               sensor_rep prev_rep, cur_rep;
-               prev_rep.active = false;
-               prev_rep.pause_policy = SENSORD_PAUSE_ALL;
-               prev_rep.interval = 0;
-
-               sensor_client_info::get_instance().get_sensor_rep(*it_sensor, cur_rep);
-               if (!change_sensor_rep(*it_sensor, prev_rep, cur_rep)) {
-                       _E("Failed to change rep(%s) for %s", get_sensor_name(*it_sensor), get_client_name());
-                       goto FAILED;
-               }
-
-               if (!restore_attributes(client_id, *it_sensor, cmd_channel)) {
-                       _E("Failed to restore attributes(%s) for %s", get_sensor_name(*it_sensor), get_client_name());
-                       goto FAILED;
-               }
-               ++it_sensor;
-       }
-
-       _I("Succeeded to restore sensor client session for %s", get_client_name());
-
-       return;
-
-FAILED:
-       sensor_event_listener::get_instance().clear();
-       _E("Failed to restore session for %s", get_client_name());
-}
-
-static bool get_events_diff(event_type_vector &a_vec, event_type_vector &b_vec, event_type_vector &add_vec, event_type_vector &del_vec)
-{
-       sort(a_vec.begin(), a_vec.end());
-       sort(b_vec.begin(), b_vec.end());
-
-       set_difference(a_vec.begin(), a_vec.end(), b_vec.begin(), b_vec.end(), back_inserter(del_vec));
-       set_difference(b_vec.begin(), b_vec.end(), a_vec.begin(), a_vec.end(), back_inserter(add_vec));
-
-       return !(add_vec.empty() && del_vec.empty());
-}
-
-static bool change_sensor_rep(sensor_id_t sensor_id, sensor_rep &prev_rep, sensor_rep &cur_rep)
-{
-       int client_id;
-       command_channel *cmd_channel;
-       event_type_vector add_event_types, del_event_types;
-
-       if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
-               _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
-               return false;
-       }
-
-       client_id = sensor_client_info::get_instance().get_client_id();
-       retvm_if((client_id < 0), false, "Invalid client id : %d, %s, %s", client_id, get_sensor_name(sensor_id), get_client_name());
-
-       get_events_diff(prev_rep.event_types, cur_rep.event_types, add_event_types, del_event_types);
-
-       if (cur_rep.active) {
-               if (prev_rep.pause_policy != cur_rep.pause_policy) {
-                       if (!cmd_channel->cmd_set_pause_policy(cur_rep.pause_policy)) {
-                               _E("Sending cmd_set_pause_policy(%d, %s, %d) failed for %s", client_id, get_sensor_name(sensor_id), cur_rep.pause_policy, get_client_name());
-                               return false;
-                       }
-               }
-
-               if ( (prev_rep.interval != cur_rep.interval) || (prev_rep.latency != cur_rep.latency)) {
-                       if (!cmd_channel->cmd_set_batch(cur_rep.interval, cur_rep.latency)) {
-                               _E("Sending cmd_set_batch(%d, %s, %d, %d) failed for %s", client_id, get_sensor_name(sensor_id), cur_rep.interval, cur_rep.latency, get_client_name());
-                               return false;
-                       }
-               }
-
-               if (!add_event_types.empty()) {
-                       if (!cmd_channel->cmd_register_events(add_event_types)) {
-                               _E("Sending cmd_register_events(%d, add_event_types) failed for %s", client_id, get_client_name());
-                               return false;
-                       }
-               }
-       }
-
-       if (prev_rep.active && !del_event_types.empty()) {
-               if (!cmd_channel->cmd_unregister_events(del_event_types)) {
-                       _E("Sending cmd_unregister_events(%d, del_event_types) failed for %s", client_id, get_client_name());
-                       return false;
-               }
-       }
-
-       if (prev_rep.active != cur_rep.active) {
-               if (cur_rep.active) {
-                       if (!cmd_channel->cmd_start()) {
-                               _E("Sending cmd_start(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
-                               return false;
-                       }
-               } else {
-                       if (!cmd_channel->cmd_unset_batch()) {
-                               _E("Sending cmd_unset_interval(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
-                               return false;
-                       }
-
-                       if (!cmd_channel->cmd_stop()) {
-                               _E("Sending cmd_stop(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
-                               return false;
-                       }
-               }
-       }
-
-       return true;
-}
-
-static bool get_sensor_list(void)
-{
-       static cmutex l;
-       static bool init = false;
-
-       AUTOLOCK(l);
-
-       if (!init) {
-               command_channel cmd_channel;
-
-               if (!cmd_channel.create_channel()) {
-                       _E("%s failed to create command channel", get_client_name());
-                       return false;
-               }
-
-               if (!cmd_channel.cmd_get_sensor_list())
-                       return false;
-
-               init = true;
-       }
-
-       return true;
-}
+/*
+ * TO-DO-LIST:
+ * 1. restore session
+ * 1.1 close socket
+ * 1.2 listener : start, interval, batch latency, attributes
+ * 2. power save option / lcd vconf : move to server
+ * 3. clean up data
+ * 4. thread-safe : ipc_client
+ * 5. client-id
+ * 6. cmd_hello
+ * 7. stop : unset interval, batch
+ * 8. get sensor list
+ */
 
-API int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count)
+API int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *count)
 {
-       retvm_if(!get_sensor_list(), -EPERM, "Fail to get sensor list from server");
-
-       vector<sensor_info *> sensor_infos = sensor_info_manager::get_instance().get_infos(type);
-
-       if (sensor_infos.empty()) {
-               *sensor_count = 0;
-               return -ENODATA;
-       }
-
-       if (type != ALL_SENSOR) {
-               if (sensor_infos[0]->get_id() == (sensor_id_t)(-EACCES))
-                       return -EACCES;
-       }
-
-       *list = (sensor_t *) malloc(sizeof(sensor_info *) * sensor_infos.size());
-       retvm_if(!*list, false, "Failed to allocate memory");
-
-       for (unsigned int i = 0; i < sensor_infos.size(); ++i)
-               *(*list + i) = sensor_info_to_sensor(sensor_infos[i]);
-
-       *sensor_count = sensor_infos.size();
+       /*
+        * 1. get sensor list()
+        * 2. if sensor list is empty, return -ENODATA
+        * 3. if id is -EACCESS, return -EACCESS (except ALL_SENSOR)
+        * 4. list : memory allocation
+        * 5. return list, count
+        */
 
        return OP_SUCCESS;
 }
 
 API int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor)
 {
-       retvm_if(!get_sensor_list(), -EPERM, "Fail to get sensor list from server");
-
-       const sensor_info *info;
-
-       info = sensor_info_manager::get_instance().get_info(type);
-       if (info == NULL) {
-               *sensor = NULL;
-               return -ENODATA;
-       }
-
-       if ((const_cast<sensor_info *>(info))->get_id() == (sensor_id_t)(-EACCES))
-               return -EACCES;
-
-       *sensor = sensor_info_to_sensor(info);
+       /*
+        * 1. get sensor list()
+        * 2. if there is no sensor, return -ENODATA
+        * 3. if id is -EACCESS, return -EACCESS
+        * 4. if SENSOR_ALL, ???
+        * 5. return sensor
+        */
 
        return OP_SUCCESS;
 }
 
-API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count)
-{
-       return (sensord_get_sensors(type, list, sensor_count) == OP_SUCCESS);
-}
-
-API sensor_t sensord_get_sensor(sensor_type_t type)
-{
-       sensor_t sensor;
-       sensord_get_default_sensor(type, &sensor);
-
-       return sensor;
-}
-
 API bool sensord_get_type(sensor_t sensor, sensor_type_t *type)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
-
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !type,
-               NULL, "Invalid param: sensor (%p), type(%p)", sensor, type);
-
-       *type = info->get_type();
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        */
 
        return true;
 }
 
 API const char* sensord_get_name(sensor_t sensor)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
-
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info),
-               NULL, "Invalid param: sensor (%p)", sensor);
+       /*
+        * 1. if there is no sensor, return NULL
+        */
 
-       return info->get_name();
+       return NULL;
 }
 
 API const char* sensord_get_vendor(sensor_t sensor)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
+       /*
+        * 1. if there is no sensor, return NULL
+        */
 
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info),
-               NULL, "Invalid param: sensor (%p)", sensor);
-
-       return info->get_vendor();
+       return NULL;
 }
 
 API bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
-
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !privilege,
-               false, "Invalid param: sensor (%p), privilege(%p)", sensor, privilege);
-
-       *privilege = info->get_privilege();
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        */
 
        return true;
 }
 
 API bool sensord_get_min_range(sensor_t sensor, float *min_range)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
-
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !min_range,
-               false, "Invalid param: sensor (%p), min_range(%p)", sensor, min_range);
-
-       *min_range = info->get_min_range();
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        */
 
        return true;
 }
 
 API bool sensord_get_max_range(sensor_t sensor, float *max_range)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
-
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !max_range,
-               false, "Invalid param: sensor (%p), max_range(%p)", sensor, max_range);
-
-       *max_range = info->get_max_range();
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        */
 
        return true;
 }
 
 API bool sensord_get_resolution(sensor_t sensor, float *resolution)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
-
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !resolution,
-               false, "Invalid param: sensor (%p), resolution(%p)", sensor, resolution);
-
-       *resolution = info->get_resolution();
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        */
 
        return true;
 }
 
 API bool sensord_get_min_interval(sensor_t sensor, int *min_interval)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
-
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !min_interval,
-               false, "Invalid param: sensor (%p), min_interval(%p)", sensor, min_interval);
-
-       *min_interval = info->get_min_interval();
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        */
 
        return true;
 }
 
 API bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
-
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !fifo_count,
-               false, "Invalid param: sensor (%p), fifo_count(%p)", sensor, fifo_count);
-
-       *fifo_count = info->get_fifo_count();
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        */
 
        return true;
 }
 
 API bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
-
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !max_batch_count,
-               false, "Invalid param: sensor (%p), max_batch_count(%p)", sensor, max_batch_count);
-
-       *max_batch_count = info->get_max_batch_count();
-
-       return true;
-}
-
-API bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count)
-{
-       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(%p)", sensor, event_types, count);
-
-       unsigned int event_type;
-       event_type = info->get_supported_event();
-       *event_types = (unsigned int *)malloc(sizeof(unsigned int));
-
-       retvm_if(!*event_types, false, "Failed to allocate memory");
-
-       (*event_types)[0] = event_type;
-       *count = 1;
-
-       return true;
-}
-
-API bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported)
-{
-       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(%p)", sensor, event_type, supported);
-
-       *supported = info->is_supported_event(event_type);
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        */
 
        return true;
 }
 
 API bool sensord_is_wakeup_supported(sensor_t sensor)
 {
-       sensor_info* info = sensor_to_sensor_info(sensor);
-
-       retvm_if(!sensor_info_manager::get_instance().is_valid(info),
-               false, "Invalid param: sensor (%p)", sensor);
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        */
 
-       return info->is_wakeup_supported();
+       return true;
 }
 
 API int sensord_connect(sensor_t sensor)
 {
-       command_channel *cmd_channel = NULL;
-       int handle;
-       int client_id;
-       bool sensor_registered;
-       bool first_connection = false;
-
-       sensor_info* info = sensor_to_sensor_info(sensor);
-       retv_if(!sensor_info_manager::get_instance().is_valid(info), OP_ERROR);
-
-       sensor_id_t sensor_id = info->get_id();
-
-       AUTOLOCK(lock);
-
-       sensor_registered = sensor_client_info::get_instance().is_sensor_registered(sensor_id);
-
-       // lazy loading after creating static variables
-       atexit(good_bye);
-
-       handle = sensor_client_info::get_instance().create_handle(sensor_id);
-       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;
-       }
-
-       if (!sensor_registered) {
-               cmd_channel = new(std::nothrow) command_channel();
-               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));
-                       sensor_client_info::get_instance().delete_handle(handle);
-                       delete cmd_channel;
-                       return OP_ERROR;
-               }
-
-               sensor_client_info::get_instance().add_command_channel(sensor_id, cmd_channel);
-       }
-
-       if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
-               _E("%s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
-               sensor_client_info::get_instance().delete_handle(handle);
-               return OP_ERROR;
-       }
-
-       if (!sensor_client_info::get_instance().has_client_id()) {
-               first_connection = true;
-               if (!cmd_channel->cmd_get_id(client_id)) {
-                       _E("Sending cmd_get_id() failed for %s", get_sensor_name(sensor_id));
-                       sensor_client_info::get_instance().close_command_channel(sensor_id);
-                       sensor_client_info::get_instance().delete_handle(handle);
-                       return OP_ERROR;
-               }
-
-               sensor_client_info::get_instance().set_client_id(client_id);
-               _I("%s gets client_id [%d]", get_client_name(), client_id);
-               sensor_event_listener::get_instance().start_event_listener();
-               _I("%s starts listening events with client_id [%d]", get_client_name(), client_id);
-       }
-
-       client_id = sensor_client_info::get_instance().get_client_id();
-       cmd_channel->set_client_id(client_id);
-
-       _I("%s[%d] connects with %s[%d]", get_client_name(), client_id, get_sensor_name(sensor_id), handle);
-
-       sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_STOPPED, SENSORD_PAUSE_ALL);
-
-       if (!sensor_registered) {
-               if (!cmd_channel->cmd_hello(sensor_id)) {
-                       _E("Sending cmd_hello(%s, %d) failed for %s", get_sensor_name(sensor_id), client_id, get_client_name());
-                       sensor_client_info::get_instance().close_command_channel(sensor_id);
-                       sensor_client_info::get_instance().delete_handle(handle);
-                       if (first_connection) {
-                               sensor_client_info::get_instance().set_client_id(CLIENT_ID_INVALID);
-                               sensor_event_listener::get_instance().stop_event_listener();
-                       }
-                       return OP_ERROR;
-               }
-       }
-
-       set_power_save_state_cb();
-       dbus_listener::init();
-       return handle;
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return -EPERM
+        * 3. sensor is already registered(sensor), it doesn't need to connect server
+        * 4. create integer handle for only this client
+        * 5. if it is first connection(client), get client id from server
+        * 6. if it is first connection(client), start sensor event listener
+        * 7. sensor initialization : stop, pause_all
+        * 8. if it is first connection(client), send cmd hello
+        * 9. if cmd hello is failed and it is first connection(client) stop listener, remove id
+        */
+
+       return 0;
 }
 
 API bool sensord_disconnect(int handle)
 {
-       command_channel *cmd_channel;
-       sensor_id_t sensor_id;
-       int client_id;
-       int sensor_state;
-
-       AUTOLOCK(lock);
-
-       if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state)||
-               !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
-               _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", get_client_name(), get_sensor_name(sensor_id));
-               return false;
-       }
-
-       client_id = sensor_client_info::get_instance().get_client_id();
-       retvm_if((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
-
-       _I("%s disconnects with %s[%d]", get_client_name(), get_sensor_name(sensor_id), handle);
-
-       if (sensor_client_info::get_instance().get_passive_mode(handle)) {
-               _W("%s[%d] for %s is on passive mode while disconnecting.",
-                       get_sensor_name(sensor_id), handle, get_client_name());
-
-               command_channel *cmd_channel;
-               event_type_vector event_types;
-               sensor_client_info::get_instance().get_active_event_types(sensor_id, event_types);
-
-               for (auto it = event_types.begin(); it != event_types.end(); ++it)
-                       sensord_unregister_event(handle, *it);
-
-               if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
-                       _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
-                       return false;
-               }
-
-               if (!cmd_channel->cmd_unset_batch()) {
-                       _E("Sending cmd_unset_interval(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
-                       return false;
-               }
-       }
-
-       if (sensor_state != SENSOR_STATE_STOPPED) {
-               _W("%s[%d] for %s is not stopped before disconnecting.",
-                       get_sensor_name(sensor_id), handle, get_client_name());
-               sensord_stop(handle);
-       }
-
-       if (!sensor_client_info::get_instance().delete_handle(handle))
-               return false;
-
-       if (!sensor_client_info::get_instance().is_active())
-               sensor_client_info::get_instance().set_client_id(CLIENT_ID_INVALID);
-
-       if (!sensor_client_info::get_instance().is_sensor_registered(sensor_id)) {
-               if (!cmd_channel->cmd_byebye()) {
-                       _E("Sending cmd_byebye(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
-                       return false;
-               }
-               sensor_client_info::get_instance().close_command_channel(sensor_id);
-       }
-
-       if (!sensor_client_info::get_instance().is_active()) {
-               _I("Stop listening events for client %s with client id [%d]", get_client_name(), sensor_client_info::get_instance().get_client_id());
-               sensor_event_listener::get_instance().stop_event_listener();
-       }
-
-       unset_power_save_state_cb();
+       /*
+        * 1. check parameter(check handle???)
+        * 2. check state of this handle
+        * 3. if it is on passive mode, unregister event and unset interval/latency
+        * 4. if it is not stop, stop it
+        * 5. if there is no active sensor(client), reset id & byebye and stop listener
+        */
 
        return true;
 }
 
-static bool register_event(int handle, unsigned int event_type, unsigned int interval, int max_batch_latency, void* cb, void *user_data)
+API bool sensord_register_event(int handle, unsigned int event_type,
+               unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data)
 {
-       sensor_id_t sensor_id;
-       sensor_rep prev_rep, cur_rep;
-       bool ret;
-
-       retvm_if(!cb, false, "callback is NULL");
+       /*
+        * 1. check parameter
+        * 2. if interval is 0, default interval
+        * ** if cb is null, how to handle it?
+        * ** event type is deprecated
+        */
 
-       AUTOLOCK(lock);
-
-       if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
-               _W("client %s failed to get handle information", get_client_name());
-               return false;
-       }
-
-       if (interval == 0)
-               interval = DEFAULT_INTERVAL;
-
-       _I("%s registers event %s[%#x] for sensor %s[%d] with interval: %d, latency: %d,  cb: %#x, user_data: %#x",
-               get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id),
-               handle, interval, max_batch_latency, cb, user_data);
-
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
-       sensor_client_info::get_instance().register_event(handle, event_type, interval, max_batch_latency, cb, user_data);
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
-       ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
-
-       if (!ret)
-               sensor_client_info::get_instance().unregister_event(handle, event_type);
-
-       return ret;
-}
-
-API bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data)
-{
-       return register_event(handle, event_type, interval, max_batch_latency, (void *)cb, user_data);
+       return true;
 }
 
 API bool sensord_unregister_event(int handle, unsigned int event_type)
 {
-       sensor_id_t sensor_id;
-       sensor_rep prev_rep, cur_rep;
-       bool ret;
-       unsigned int prev_interval, prev_latency;
-       void *prev_cb;
-       void *prev_user_data;
-
-       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());
-               return false;
-       }
-
-       _I("%s unregisters event %s[%#x] for sensor %s[%d]", get_client_name(), get_event_name(event_type),
-               event_type, get_sensor_name(sensor_id), handle);
-
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
-       sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data);
-
-       if (!sensor_client_info::get_instance().unregister_event(handle, event_type)) {
-               _E("%s try to unregister non registered event %s[%#x] for sensor %s[%d]",
-                       get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id), handle);
-               return false;
-       }
-
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
-       ret =  change_sensor_rep(sensor_id, prev_rep, cur_rep);
-
-       if (sensor_client_info::get_instance().get_passive_mode(handle))
-               sensor_client_info::get_instance().set_passive_mode(handle, false);
-
-       if (!ret)
-               sensor_client_info::get_instance().register_event(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data);
+       /*
+        * 1. check parameter
+        * 2. check previous interval, latency, cb, user_data
+        * 3. if passive mode is true, set false
+        * 4. if ret is false, register event
+        */
 
-       return ret;
+       return true;
 }
 
 API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data)
 {
-       sensor_id_t sensor_id;
-
-       retvm_if(!cb, false, "callback is NULL");
-
-       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());
-               return false;
-       }
-
-       _I("%s registers accuracy_changed_cb for sensor %s[%d] with cb: %#x, user_data: %#x",
-               get_client_name(), get_sensor_name(sensor_id), handle, cb, user_data);
-
-       sensor_client_info::get_instance().register_accuracy_cb(handle, cb , user_data);
+       /*
+        * 1. check parameter
+        */
 
        return true;
 }
 
 API bool sensord_unregister_accuracy_cb(int handle)
 {
-       sensor_id_t sensor_id;
-
-       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());
-               return false;
-       }
-
-       _I("%s unregisters accuracy_changed_cb for sensor %s[%d]",
-               get_client_name(), get_sensor_name(sensor_id), handle);
-
-       sensor_client_info::get_instance().unregister_accuracy_cb(handle);
+       /*
+        * 1. check parameter
+        */
 
        return true;
 }
 
 API bool sensord_start(int handle, int option)
 {
-       sensor_id_t sensor_id;
-       sensor_rep prev_rep, cur_rep;
-       bool ret;
-       int prev_state, prev_pause;
-       int pause;
-
-       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());
-               return false;
-       }
-
-       retvm_if((option < 0) || (option >= SENSOR_OPTION_END), false, "Invalid option value : %d, handle: %d, %s, %s",
-               option, handle, get_sensor_name(sensor_id), get_client_name());
-
-       _I("%s starts %s[%d], with option: %d, power save state: %d", get_client_name(), get_sensor_name(sensor_id),
-               handle, option, g_power_save_state);
-
-       pause = CONVERT_OPTION_PAUSE_POLICY(option);
-
-       if (g_power_save_state && (g_power_save_state & pause)) {
-               sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_PAUSED, pause);
-               return true;
-       }
-
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
-       sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_pause);
-       sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_STARTED, pause);
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
-
-       ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
-
-       if (!ret)
-               sensor_client_info::get_instance().set_sensor_params(handle, prev_state, prev_pause);
+       /*
+        * 1. check parameter
+        * 2. pause = CONVERT_OPTION_PAUSE_POLICY(option)
+        * 3. start listener
+        */
 
-       return ret;
+       return true;
 }
 
 API bool sensord_stop(int handle)
 {
-       sensor_id_t sensor_id;
-       int sensor_state;
-       bool ret;
-       int prev_state, prev_pause;
-
-       sensor_rep prev_rep, cur_rep;
-
-       AUTOLOCK(lock);
-
-       if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state)||
-               !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
-               _E("client %s failed to get handle information", get_client_name());
-               return false;
-       }
-
-       retvm_if((sensor_state == SENSOR_STATE_STOPPED), true, "%s already stopped with %s[%d]",
-               get_client_name(), get_sensor_name(sensor_id), handle);
-
-       _I("%s stops sensor %s[%d]", get_client_name(), get_sensor_name(sensor_id), handle);
-
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
-       sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_pause);
-       sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_STOPPED);
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
-
-       ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
-
-       if (!ret)
-               sensor_client_info::get_instance().set_sensor_params(handle, prev_state, prev_pause);
+       /*
+        * 1. check parameter
+        * 2. check sensor state, id
+        * 2.1. if sensor is already stopped, return true
+        * 3. stop listener
+        */
 
-       return ret;
-}
-
-static bool change_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency)
-{
-       sensor_id_t sensor_id;
-       sensor_rep prev_rep, cur_rep;
-       bool ret;
-       unsigned int prev_interval, prev_latency;
-       void *prev_cb;
-       void *prev_user_data;
-
-       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());
-               return false;
-       }
-
-       if (interval == 0)
-               interval = DEFAULT_INTERVAL;
-
-       _I("%s changes batch of event %s[%#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);
-
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
-
-       sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data);
-
-       if (!sensor_client_info::get_instance().set_event_batch(handle, event_type, interval, latency))
-               return false;
-
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
-
-       ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
-
-       if (!ret)
-               sensor_client_info::get_instance().set_event_batch(handle, event_type, prev_interval, prev_latency);
-
-       return ret;
+       return true;
 }
 
 API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval)
 {
-       unsigned int prev_interval, prev_latency;
-       void *prev_cb;
-       void *prev_user_data;
-
-       AUTOLOCK(lock);
+       /*
+        * 1. check parameter
+        * 2. if interval is 0, default interval
+        * 3. if previous interval is lower than interval, return true
+        * 4. change interval
+        */
 
-       if (!sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data)) {
-               _E("Failed to get event info with handle = %d, event_type = %#x", handle, event_type);
-               return false;
-       }
-
-       _I("handle = %d, event_type = %#x, interval = %d, prev_latency = %d", handle, event_type, interval, prev_latency);
-       return change_event_batch(handle, event_type, interval, prev_latency);
+       return true;
 }
 
 API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency)
 {
-       unsigned int prev_interval, prev_latency;
-       void *prev_cb;
-       void *prev_user_data;
+       /*
+        * 1. check parameter
+        * 2. if previous interval is lower than interval, return true
+        * 3. change batch latency
+        */
 
-       AUTOLOCK(lock);
-
-       if (!sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data)) {
-               _E("Failed to get event info with handle = %d, event_type = %#x", handle, event_type);
-               return false;
-       }
-
-       return change_event_batch(handle, event_type, prev_interval, max_batch_latency);
+       return true;
 }
 
-static int change_pause_policy(int handle, int pause)
+API bool sensord_set_option(int handle, int option)
 {
-       sensor_id_t sensor_id;
-       sensor_rep prev_rep, cur_rep;
-       int sensor_state;
-       bool ret;
-       int prev_state, prev_pause;
-
-       AUTOLOCK(lock);
-
-       retvm_if((pause < 0) || (pause >= SENSORD_PAUSE_END), -EINVAL,
-               "Invalid pause value : %d, handle: %d, %s, %s",
-               pause, handle, get_sensor_name(sensor_id), get_client_name());
-
-       if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state)||
-               !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
-               _E("client %s failed to get handle information", get_client_name());
-               return -EPERM;
-       }
-
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
-       sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_pause);
-
-       if (g_power_save_state) {
-               if ((pause & g_power_save_state) && (sensor_state == SENSOR_STATE_STARTED))
-                       sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_PAUSED);
-               else if (!(pause & g_power_save_state) && (sensor_state == SENSOR_STATE_PAUSED))
-                       sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_STARTED);
-       }
-       sensor_client_info::get_instance().set_sensor_pause_policy(handle, pause);
-
-       sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
-       ret =  change_sensor_rep(sensor_id, prev_rep, cur_rep);
-
-       if (!ret)
-               sensor_client_info::get_instance().set_sensor_pause_policy(handle, prev_pause);
-
-       return (ret ? OP_SUCCESS : OP_ERROR);
+       /*
+        * change option, always-on/power save option/lcd off/default
+        */
+
+       return true;
 }
 
-static int change_axis_orientation(int handle, int axis_orientation)
+API int sensord_set_attribute_int(int handle, int attribute, int value)
 {
-       sensor_event_listener::get_instance().set_sensor_axis(axis_orientation);
+       /*
+        * 1. if ATTRIBUTE_PAUSE_POLICY
+        * 2. if ATTRIBUTE_AXIS_ORIENTATION
+        * 3. else attribute
+        */
+
        return OP_SUCCESS;
 }
 
-static int change_attribute_int(int handle, int attribute, int value)
+API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len)
 {
-       sensor_id_t sensor_id;
-       command_channel *cmd_channel;
-       int client_id;
+       /*
+        * 1. check parameter
+        * 2. if client id is invalid, return -EPERM
+        * 3. if there is other problems, return -EPERM
+        */
 
-       AUTOLOCK(lock);
+       return OP_SUCCESS;
+}
 
-       if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
-               _E("client %s failed to get handle information", get_client_name());
-               return -EINVAL;
-       }
+API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data)
+{
+       /*
+        * 1. check parameter
+        * 2. check sensor state(is it really needed?)
+        * 3. get data
+        */
 
-       if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
-               _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
-               return -EPERM;
-       }
+       return true;
+}
 
-       client_id = sensor_client_info::get_instance().get_client_id();
-       retvm_if((client_id < 0), -EPERM,
-                       "Invalid client id : %d, handle: %d, %s, %s",
-                       client_id, handle, get_sensor_name(sensor_id), get_client_name());
+API bool sensord_flush(int handle)
+{
+       /*
+        * 1. check parameter
+        * 2. check sensor state(is it really needed?)
+        * 3. flush sensor
+        */
 
-       if (!cmd_channel->cmd_set_attribute_int(attribute, value)) {
-               _E("Sending cmd_set_attribute_int(%d, %d) failed for %s",
-                       client_id, value, get_client_name());
-               return -EPERM;
-       }
+       return true;
+}
 
-       sensor_client_info::get_instance().set_attribute(handle, attribute, value);
+API bool sensord_set_passive_mode(int handle, bool passive)
+{
+       /* set passive mode*/
 
-       return OP_SUCCESS;
+       return true;
 }
 
-API bool sensord_set_option(int handle, int option)
+API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data)
 {
-       return (change_pause_policy(handle, CONVERT_OPTION_PAUSE_POLICY(option)) == OP_SUCCESS);
+       /*
+        * 1. check parameter
+        * 2. create handle in this client
+        * 3. first connection(client)
+        * 4. cmd_connect for external sensor with key
+        */
+       retvm_if(!key, -EPERM, "Invalid key");
+       return 0;
 }
 
-API int sensord_set_attribute_int(int handle, int attribute, int value)
+API bool sensord_external_disconnect(int handle)
 {
-       switch (attribute) {
-       case SENSORD_ATTRIBUTE_PAUSE_POLICY:
-               return change_pause_policy(handle, value);
-       case SENSORD_ATTRIBUTE_AXIS_ORIENTATION:
-               return change_axis_orientation(handle, value);
-       default:
-               break;
-       }
-
-       return change_attribute_int(handle, attribute, value);
+       /*
+        * 1. check parameter
+        * 2. create handle in this client
+        * 3. first connection(client)
+        * 4. cmd_connect for external sensor with key
+        * 5. disconnect this handle
+        * 6. if there is no active sensor, remove client id and stop listener
+        */
+       return true;
 }
 
-API int sensord_set_attribute_str(int handle, int attribute, const char *value, int len)
+API bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt)
 {
-       sensor_id_t sensor_id;
-       command_channel *cmd_channel;
-       int client_id;
-
-       AUTOLOCK(lock);
+       /*
+        * 1. check parameter
+        * 1.1 (data_cnt <= 0) || (data_cnt > POST_DATA_LEN_MAX)), return false
+        * 2. cmd_post
+        */
 
-       if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
-               _E("Client %s failed to get handle information", get_client_name());
-               return -EINVAL;
-       }
-
-       if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
-               _E("Client %s failed to get command channel for %s",
-                       get_client_name(), get_sensor_name(sensor_id));
-               return -EPERM;
-       }
-
-       retvm_if((len < 0) || (value == NULL), -EINVAL,
-                       "Invalid value_len: %d, value: %#x, handle: %d, %s, %s",
-                       len, value, handle, get_sensor_name(sensor_id), get_client_name());
-
-       client_id = sensor_client_info::get_instance().get_client_id();
-       retvm_if((client_id < 0), -EPERM,
-                       "Invalid client id : %d, handle: %d, %s, %s",
-                       client_id, handle, get_sensor_name(sensor_id), get_client_name());
-
-       if (!cmd_channel->cmd_set_attribute_str(attribute, value, len)) {
-               _E("Sending cmd_set_attribute_str(%d, %d, %#x) failed for %s",
-                       client_id, len, value, get_client_name());
-               return -EPERM;
-       }
-
-       sensor_client_info::get_instance().set_attribute(handle, attribute, value, len);
-
-       return OP_SUCCESS;
+       return true;
 }
 
-API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len)
+/* deperecated */
+API sensor_t sensord_get_sensor(sensor_type_t type)
 {
-       return (sensord_set_attribute_str(handle, 0, data, data_len) == OP_SUCCESS);
+       return NULL;
 }
 
-API bool sensord_send_command(int handle, const char *command, int command_len)
+/* deprecated */
+API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count)
 {
-       return (sensord_set_attribute_str(handle, 0, command, command_len) == OP_SUCCESS);
+       return (sensord_get_sensors(type, list, sensor_count) == OP_SUCCESS);
 }
 
-API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data)
+/* deprecated */
+API bool sensord_register_hub_event(int handle, unsigned int event_type,
+               unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data)
 {
-       sensor_id_t sensor_id;
-       command_channel *cmd_channel;
-       int sensor_state;
-       int client_id;
-
-       retvm_if((!sensor_data), false, "sensor_data is NULL");
-
-       AUTOLOCK(lock);
-
-       if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state)||
-               !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
-               _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", get_client_name(), get_sensor_name(sensor_id));
-               return false;
-       }
-
-       client_id = sensor_client_info::get_instance().get_client_id();
-       retvm_if((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
-
-       if (sensor_state != SENSOR_STATE_STARTED) {
-               _E("Sensor %s is not started for client %s with handle: %d, sensor_state: %d", get_sensor_name(sensor_id), get_client_name(), handle, sensor_state);
-               return false;
-       }
-
-       if (!cmd_channel->cmd_get_data(data_id, sensor_data)) {
-               _E("cmd_get_data(%d, %d, %#x) failed for %s", client_id, data_id, sensor_data, get_client_name());
-               return false;
-       }
+       return false;
+}
 
+/* deprecated */
+API bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count)
+{
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        * 3. memory allocation
+        */
        return true;
 }
 
-API bool sensord_flush(int handle)
+/* deprecated(BUT it is used in C-API....) */
+API bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported)
 {
-       sensor_id_t sensor_id;
-       command_channel *cmd_channel;
-       int sensor_state;
-       int client_id;
-
-       AUTOLOCK(lock);
-
-       if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state) ||
-               !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
-               _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", get_client_name(), get_sensor_name(sensor_id));
-               return false;
-       }
-
-       client_id = sensor_client_info::get_instance().get_client_id();
-       retvm_if((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
-
-       if (sensor_state != SENSOR_STATE_STARTED) {
-               _E("Sensor %s is not started for client %s with handle: %d, sensor_state: %d", get_sensor_name(sensor_id), get_client_name(), handle, sensor_state);
-               return false;
-       }
-
-       if (!cmd_channel->cmd_flush()) {
-               _E("cmd_flush() failed for %s", get_client_name());
-               return false;
-       }
-
+       /*
+        * 1. check parameter
+        * 2. if there is no sensor, return false
+        */
        return true;
 }
 
-API bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data)
+/* deprecated */
+API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len)
 {
-       return false;
+       return (sensord_set_attribute_str(handle, 0, data, data_len) == OP_SUCCESS);
 }
 
-API bool sensord_set_passive_mode(int handle, bool passive)
+/* deprecated */
+API bool sensord_send_command(int handle, const char *command, int command_len)
 {
-       if (!sensor_client_info::get_instance().set_passive_mode(handle, passive)) {
-               _E("Failed to set passive mode %d", passive);
-               return false;
-       }
-
-       return true;
+       return (sensord_set_attribute_str(handle, 0, command, command_len) == OP_SUCCESS);
 }
+
diff --git a/src/client/client_common.cpp b/src/client/client_common.cpp
deleted file mode 100644 (file)
index 96ce4ff..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <time.h>
-#include <sensor_common.h>
-#include <client_common.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sensor_types.h>
-#include <string>
-#include <map>
-
-#define LOG_PER_COUNT_EVERY_EVENT 1
-#define LOG_PER_COUNT_MAX 25
-
-static std::map<sensor_id_t, unsigned int> sensor_log_count;
-
-const char* get_sensor_name(sensor_id_t id)
-{
-       sensor_type_t type = (sensor_type_t) (id >> SENSOR_TYPE_SHIFT);
-
-       return util_sensor_type_t::get_string(type);
-}
-
-const char* get_event_name(unsigned int event_type)
-{
-       sensor_type_t type = (sensor_type_t) (event_type >> SENSOR_EVENT_SHIFT);
-
-       return util_sensor_type_t::get_string(type);
-}
-
-unsigned int get_calibration_event_type(unsigned int event_type)
-{
-       sensor_type_t type = (sensor_type_t)(event_type >> SENSOR_EVENT_SHIFT);
-
-       switch (type) {
-       case GEOMAGNETIC_SENSOR:
-       case ROTATION_VECTOR_SENSOR:
-       case RV_RAW_SENSOR:
-       case ORIENTATION_SENSOR:
-               return CALIBRATION_EVENT(type);
-       default:
-               return 0;
-       }
-}
-
-unsigned int get_log_per_count(sensor_id_t id)
-{
-       sensor_type_t type = (sensor_type_t)(id >> SENSOR_TYPE_SHIFT);
-
-       switch (type) {
-       /* on_changed_event type sensors */
-       case PROXIMITY_SENSOR:
-       case GESTURE_WRIST_UP_SENSOR:
-       case GESTURE_WRIST_DOWN_SENSOR:
-       case GESTURE_MOVEMENT_SENSOR:
-       case WEAR_STATUS_SENSOR:
-       case PRESSURE_SENSOR:
-               return LOG_PER_COUNT_EVERY_EVENT;
-       default:
-               break;
-       }
-       return LOG_PER_COUNT_MAX;
-}
-
-void print_event_occurrence_log(sensor_handle_info &info)
-{
-       unsigned int count;
-       unsigned int log_per_count;
-
-       auto it_count = sensor_log_count.find(info.m_sensor_id);
-       if (it_count == sensor_log_count.end())
-               sensor_log_count[info.m_sensor_id] = 0;
-
-       count = ++sensor_log_count[info.m_sensor_id];
-       log_per_count = get_log_per_count(info.m_sensor_id);
-
-       if ((count != 1) && (count % log_per_count != 0))
-               return;
-
-       _D("%s receives %s[%d][state: %d, pause policy: %d, count: %d]", get_client_name(),
-                       get_sensor_name(info.m_sensor_id), info.m_handle,
-                       info.m_sensor_state, info.m_pause_policy, count);
-}
-
-/*
- *     To prevent user mistakenly freeing sensor_info using sensor_t
- */
-static const int SENSOR_TO_SENSOR_INFO = 4;
-static const int SENSOR_INFO_TO_SENSOR = -SENSOR_TO_SENSOR_INFO;
-
-sensor_info *sensor_to_sensor_info(sensor_t sensor)
-{
-       if (!sensor)
-               return NULL;
-
-       sensor_info* info = (sensor_info *)((char *)sensor + SENSOR_TO_SENSOR_INFO);
-
-       return info;
-}
-
-sensor_t sensor_info_to_sensor(const sensor_info *info)
-{
-       if (!info)
-               return NULL;
-
-       sensor_t sensor = (sensor_t)((char *)info + SENSOR_INFO_TO_SENSOR);
-
-       return sensor;
-}
diff --git a/src/client/client_common.h b/src/client/client_common.h
deleted file mode 100644 (file)
index 5671987..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _CLIENT_COMMON_H_
-#define _CLIENT_COMMON_H_
-
-#include <sensor_internal.h>
-#include <sensor_handle_info.h>
-#include <reg_event_info.h>
-#include <sensor_log.h>
-
-#include <memory>
-
-#define BASE_GATHERING_INTERVAL        100
-#define THREAD_TERMINATION -1
-
-typedef struct {
-       unsigned long long event_id;
-       int handle;
-       sensor_t sensor;
-       unsigned int event_type;
-       sensor_cb_t cb;
-       std::shared_ptr<void> sensor_data;
-       void *user_data;
-       sensor_accuracy_changed_cb_t accuracy_cb;
-       unsigned long long timestamp;
-       int accuracy;
-       void *accuracy_user_data;
-} client_callback_info;
-
-const char *get_sensor_name(sensor_id_t sensor_id);
-const char *get_event_name(unsigned int event_type);
-
-unsigned int get_calibration_event_type(unsigned int event_type);
-unsigned int get_log_per_count(sensor_id_t id);
-
-void print_event_occurrence_log(sensor_handle_info &sensor_handle_info);
-
-class sensor_info;
-sensor_info *sensor_to_sensor_info(sensor_t sensor);
-sensor_t sensor_info_to_sensor(const sensor_info *info);
-
-#endif /* _CLIENT_COMMON_H_ */
diff --git a/src/client/command_channel.cpp b/src/client/command_channel.cpp
deleted file mode 100644 (file)
index 683c017..0000000
+++ /dev/null
@@ -1,713 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdlib.h>
-#include <command_channel.h>
-#include <client_common.h>
-#include <command_common.h>
-#include <sensor_info.h>
-#include <sensor_info_manager.h>
-
-command_channel::command_channel()
-: m_client_id(CLIENT_ID_INVALID)
-, m_sensor_id(UNKNOWN_SENSOR)
-{
-}
-
-command_channel::~command_channel()
-{
-       if (m_command_socket.is_valid())
-               m_command_socket.close();
-}
-
-bool command_channel::command_handler(cpacket *packet, void **return_payload)
-{
-       if (!m_command_socket.is_valid()) {
-               _E("Command socket(%d) is not valid for client %s", m_command_socket.get_socket_fd(), get_client_name());
-               return false;
-       }
-
-       if (packet->size() == 0) {
-               _E("Packet is not valid for client %s", get_client_name());
-               return false;
-       }
-
-       if (m_command_socket.send(packet->packet(), packet->size()) <= 0) {
-               m_command_socket.close();
-               _E("Failed to send command in client %s", get_client_name());
-               return false;
-       }
-
-       packet_header header;
-
-       if (m_command_socket.recv(&header, sizeof(header)) <= 0) {
-               m_command_socket.close();
-               _E("Failed to receive header for command reply packet in client %s", get_client_name());
-               return false;
-       }
-
-       char *buffer = new(std::nothrow) char[header.size];
-       retvm_if(!buffer, false, "Failed to allocate memory");
-
-       if (m_command_socket.recv(buffer, header.size) <= 0) {
-               m_command_socket.close();
-               _E("Failed to receive command reply packet in client %s", get_client_name());
-               delete[] buffer;
-               return false;
-       }
-
-       *return_payload = buffer;
-
-       return true;
-}
-
-bool command_channel::create_channel(void)
-{
-       const int cllient_type = CLIENT_TYPE_SENSOR_CLIENT;
-       if (!m_command_socket.create(SOCK_STREAM))
-               return false;
-
-       if (!m_command_socket.connect(COMMAND_CHANNEL_PATH)) {
-               _E("Failed to connect command channel for client %s, command socket fd[%d]", get_client_name(), m_command_socket.get_socket_fd());
-               return false;
-       }
-
-       m_command_socket.set_connection_mode();
-
-       if (m_command_socket.send(&cllient_type, sizeof(cllient_type)) <= 0) {
-               _E("Failed to send client type in client %s, command socket fd[%d]", get_client_name(), m_command_socket.get_socket_fd());
-               return false;
-       }
-
-       return true;
-}
-
-void command_channel::set_client_id(int client_id)
-{
-       m_client_id = client_id;
-}
-
-bool command_channel::cmd_get_id(int &client_id)
-{
-       cpacket *packet;
-       cmd_get_id_t *cmd_get_id;
-       cmd_get_id_done_t *cmd_get_id_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_get_id_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_GET_ID);
-
-       cmd_get_id = (cmd_get_id_t *)packet->data();
-
-       get_proc_name(getpid(), cmd_get_id->name);
-
-       _I("%s send cmd_get_id()", get_client_name());
-
-       if (!command_handler(packet, (void **)&cmd_get_id_done)) {
-               _E("Client %s failed to send/receive command", get_client_name());
-               delete packet;
-               return false;
-       }
-
-       if (cmd_get_id_done->client_id < 0) {
-               _E("Client %s failed to get client_id[%d] from server",
-                       get_client_name(), cmd_get_id_done->client_id);
-               delete[] (char *)cmd_get_id_done;
-               delete packet;
-               return false;
-       }
-
-       client_id = cmd_get_id_done->client_id;
-
-       delete[] (char *)cmd_get_id_done;
-       delete packet;
-
-       return true;
-}
-
-bool command_channel::cmd_get_sensor_list(void)
-{
-       cpacket packet;
-       cmd_get_sensor_list_done_t *cmd_get_sensor_list_done;
-
-       packet.set_payload_size(sizeof(cmd_get_sensor_list_t));
-       packet.set_cmd(CMD_GET_SENSOR_LIST);
-
-       _I("%s send cmd_get_sensor_list", get_client_name());
-
-       if (!command_handler(&packet, (void **)&cmd_get_sensor_list_done)) {
-               _E("Client %s failed to send/receive command", get_client_name());
-               return false;
-       }
-
-       int sensor_cnt;
-       const size_t *size_field;
-       const char *raw_data_field;
-
-       sensor_cnt = cmd_get_sensor_list_done->sensor_cnt;
-       size_field = (const size_t *)cmd_get_sensor_list_done->data;
-       raw_data_field = (const char *)size_field + (sizeof(size_t) * sensor_cnt);
-
-       sensor_info *info;
-
-       int idx = 0;
-       for (int i = 0; i < sensor_cnt; ++i) {
-               info = new(std::nothrow) sensor_info;
-
-               if (!info) {
-                       _E("Failed to allocate memory");
-                       delete[] (char *)cmd_get_sensor_list_done;
-                       return false;
-               }
-
-               info->set_raw_data(raw_data_field + idx, size_field[i]);
-               sensor_info_manager::get_instance().add_info(info);
-               idx += size_field[i];
-       }
-
-       delete[] (char *)cmd_get_sensor_list_done;
-       return true;
-}
-
-bool command_channel::cmd_hello(sensor_id_t sensor)
-{
-       cpacket *packet;
-       cmd_hello_t *cmd_hello;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_hello_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_HELLO);
-
-       cmd_hello = (cmd_hello_t*)packet->data();
-       cmd_hello->client_id = m_client_id;
-       cmd_hello->sensor = sensor;
-
-       _I("%s send cmd_hello(client_id=%d, %s)",
-               get_client_name(), m_client_id, get_sensor_name(sensor));
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("Client %s failed to send/receive command for sensor[%s]",
-                       get_client_name(), get_sensor_name(sensor));
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _W("client %s got value[%d] from server with sensor [%s]",
-                       get_client_name(), cmd_done->value, get_sensor_name(sensor));
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       m_sensor_id = sensor;
-
-       return true;
-}
-
-bool command_channel::cmd_byebye(void)
-{
-       cpacket *packet;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_byebye_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_BYEBYE);
-
-       _I("%s send cmd_byebye(client_id=%d, %s)",
-               get_client_name(), m_client_id, get_sensor_name(m_sensor_id));
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d]",
-                       get_client_name(), get_sensor_name(m_sensor_id), m_client_id);
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("Client %s got error[%d] from server for sensor[%s] with client_id [%d]",
-                       get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id);
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       if (m_command_socket.is_valid())
-               m_command_socket.close();
-
-       m_client_id = CLIENT_ID_INVALID;
-       m_sensor_id = UNKNOWN_SENSOR;
-
-       return true;
-}
-
-bool command_channel::cmd_start(void)
-{
-       cpacket *packet;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_start_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_START);
-
-       _I("%s send cmd_start(client_id=%d, %s)",
-               get_client_name(), m_client_id, get_sensor_name(m_sensor_id));
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d]",
-                       get_client_name(), get_sensor_name(m_sensor_id), m_client_id);
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("Client %s got error[%d] from server for sensor[%s] with client_id [%d]",
-                       get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id);
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       return true;
-}
-
-bool command_channel::cmd_stop(void)
-{
-       cpacket *packet;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_stop_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_STOP);
-
-       _I("%s send cmd_stop(client_id=%d, %s)",
-               get_client_name(), m_client_id, get_sensor_name(m_sensor_id));
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d]",
-                       get_client_name(), get_sensor_name(m_sensor_id), m_client_id);
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("Client %s got error[%d] from server for sensor[%s] with client_id [%d]",
-                       get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id);
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       return true;
-}
-
-bool command_channel::cmd_set_pause_policy(int pause_policy)
-{
-       cpacket *packet;
-       cmd_set_pause_policy_t *cmd_set_pause_policy;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_set_pause_policy_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_SET_PAUSE_POLICY);
-
-       cmd_set_pause_policy = (cmd_set_pause_policy_t*)packet->data();
-       cmd_set_pause_policy->pause_policy = pause_policy;
-
-       _I("%s send cmd_set_pause_policy(client_id=%d, %s, pause_policy=%d)",
-               get_client_name(), m_client_id, get_sensor_name(m_sensor_id), pause_policy);
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d], pause_policy[%d]",
-                       get_client_name(), get_sensor_name(m_sensor_id), m_client_id, pause_policy);
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("Client %s got error[%d] from server for sensor[%s] with client_id [%d], pause_policy[%d]",
-                       get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id, pause_policy);
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       return true;
-}
-
-bool command_channel::cmd_register_event(unsigned int event_type)
-{
-       cpacket *packet;
-       cmd_reg_t *cmd_reg;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_reg_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_REG);
-
-       cmd_reg = (cmd_reg_t*)packet->data();
-       cmd_reg->event_type = event_type;
-
-       _I("%s send cmd_register_event(client_id=%d, %s)",
-               get_client_name(), m_client_id, get_event_name(event_type));
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("Client %s failed to send/receive command with client_id [%d], event_type[%s]",
-                       get_client_name(), m_client_id, get_event_name(event_type));
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("Client %s got error[%d] from server with client_id [%d], event_type[%s]",
-                       get_client_name(), cmd_done->value, m_client_id, get_event_name(event_type));
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       return true;
-}
-
-bool command_channel::cmd_register_events(event_type_vector &event_vec)
-{
-       auto it_event = event_vec.begin();
-
-       while (it_event != event_vec.end()) {
-               if (!cmd_register_event(*it_event))
-                       return false;
-
-               ++it_event;
-       }
-
-       return true;
-}
-
-bool command_channel::cmd_unregister_event(unsigned int event_type)
-{
-       cpacket *packet;
-       cmd_unreg_t *cmd_unreg;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_unreg_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_UNREG);
-
-       cmd_unreg = (cmd_unreg_t*)packet->data();
-       cmd_unreg->event_type = event_type;
-
-       _I("%s send cmd_unregister_event(client_id=%d, %s)",
-               get_client_name(), m_client_id, get_event_name(event_type));
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("Client %s failed to send/receive command with client_id [%d], event_type[%s]",
-                       get_client_name(), m_client_id, get_event_name(event_type));
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("Client %s got error[%d] from server with client_id [%d], event_type[%s]",
-                       get_client_name(), cmd_done->value, m_client_id, get_event_name(event_type));
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       return true;
-}
-
-bool command_channel::cmd_unregister_events(event_type_vector &event_vec)
-{
-       auto it_event = event_vec.begin();
-
-       while (it_event != event_vec.end()) {
-               if (!cmd_unregister_event(*it_event))
-                       return false;
-
-               ++it_event;
-       }
-
-       return true;
-}
-
-bool command_channel::cmd_set_batch(unsigned int interval, unsigned int latency)
-{
-       cpacket *packet;
-       cmd_set_batch_t *cmd_set_batch;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_set_batch_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_SET_BATCH);
-
-       cmd_set_batch = (cmd_set_batch_t*)packet->data();
-       cmd_set_batch->interval = interval;
-       cmd_set_batch->latency = latency;
-
-       _I("%s send cmd_set_batch(client_id=%d, %s, interval=%d, latency = %d)",
-               get_client_name(), m_client_id, get_sensor_name(m_sensor_id), interval, latency);
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("%s failed to send/receive command for sensor[%s] with client_id [%d], interval[%d], latency[%d]",
-                       get_client_name(), get_sensor_name(m_sensor_id), m_client_id, interval, latency);
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("%s got error[%d] from server for sensor[%s] with client_id [%d], interval[%d], latency[%d]",
-                       get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id, interval, latency);
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       return true;
-}
-
-bool command_channel::cmd_unset_batch(void)
-{
-       cpacket *packet;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_unset_batch_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_UNSET_BATCH);
-
-       _I("%s send cmd_unset_batch(client_id=%d, %s)",
-               get_client_name(), m_client_id, get_sensor_name(m_sensor_id));
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("Client %s failed to send/receive command for sensor[%s] with client_id [%d]",
-                       get_client_name(), get_sensor_name(m_sensor_id), m_client_id);
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("Client %s got error[%d] from server for sensor[%s] with client_id [%d]",
-                       get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id);
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       return true;
-}
-
-bool command_channel::cmd_get_data(unsigned int type, sensor_data_t* sensor_data)
-{
-       cpacket *packet;
-       cmd_get_data_t *cmd_get_data;
-       cmd_get_data_done_t *cmd_get_data_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_get_data_done_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_GET_DATA);
-
-       cmd_get_data = (cmd_get_data_t*)packet->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]",
-                       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]",
-                       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;
-               delete[] (char *)cmd_get_data_done;
-               delete packet;
-               return false;
-       }
-
-       memcpy(sensor_data, &cmd_get_data_done->base_data, sizeof(sensor_data_t));
-
-       delete[] (char *)cmd_get_data_done;
-       delete packet;
-
-       return true;
-}
-
-bool command_channel::cmd_set_attribute_int(int attribute, int value)
-{
-       cpacket *packet;
-       cmd_set_attribute_int_t *cmd_set_attribute_int;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_set_attribute_int_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_SET_ATTRIBUTE_INT);
-
-       cmd_set_attribute_int = (cmd_set_attribute_int_t*)packet->data();
-       cmd_set_attribute_int->attribute = attribute;
-       cmd_set_attribute_int->value = value;
-
-       _I("%s send cmd_set_attribute_int(client_id=%d, %s, %#x, %d)",
-               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], attribute[%#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 attribute[%#x], value[%d]",
-                       get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), attribute, value);
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       return true;
-}
-
-bool command_channel::cmd_set_attribute_str(int attribute, const char* value, int len)
-{
-       cpacket *packet;
-       cmd_set_attribute_str_t *cmd_set_attribute_str;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_set_attribute_str_t) + len);
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_SET_ATTRIBUTE_STR);
-
-       cmd_set_attribute_str = (cmd_set_attribute_str_t*)packet->data();
-       cmd_set_attribute_str->attribute = attribute;
-       cmd_set_attribute_str->len = len;
-       memcpy(cmd_set_attribute_str->value, value, len);
-
-       _I("%s send cmd_set_attribute_str(client_id=%d, attribute = %#x, value_len = %d, value = %#x)",
-               get_client_name(), m_client_id, attribute, len, value);
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("%s failed to send/receive command with client_id [%d]",
-                       get_client_name(), m_client_id);
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("%s got error[%d] from server with client_id [%d]",
-                       get_client_name(), cmd_done->value, m_client_id);
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-       return true;
-}
-
-bool command_channel::cmd_flush(void)
-{
-       cpacket *packet;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_flush_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_FLUSH);
-
-       _I("%s send cmd_flush(client_id=%d)", get_client_name(), m_client_id);
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("%s failed to send flush with client_id [%d]",
-                       get_client_name(), m_client_id);
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("%s got error[%d] from server with client_id [%d]",
-                       get_client_name(), cmd_done->value, m_client_id);
-
-               delete [] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete [] (char *)cmd_done;
-       delete packet;
-       return true;
-}
diff --git a/src/client/command_channel.h b/src/client/command_channel.h
deleted file mode 100644 (file)
index 0a9cbc4..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _COMMAND_CHANNEL_H_
-#define _COMMAND_CHANNEL_H_
-
-#include <command_common.h>
-#include <sensor_internal.h>
-#include <cpacket.h>
-#include <csocket.h>
-
-class command_channel {
-public:
-       command_channel();
-       ~command_channel();
-
-       bool create_channel(void);
-       void set_client_id(int client_id);
-
-       bool cmd_get_id(int &client_id);
-       bool cmd_get_sensor_list(void);
-       bool cmd_hello(sensor_id_t sensor);
-       bool cmd_byebye(void);
-       bool cmd_start(void);
-       bool cmd_stop(void);
-       bool cmd_set_pause_policy(int pause_policy);
-       bool cmd_register_event(unsigned int event_type);
-       bool cmd_register_events(event_type_vector &event_vec);
-       bool cmd_unregister_event(unsigned int event_type);
-       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_t *values);
-       bool cmd_set_attribute_int(int attribute, int value);
-       bool cmd_set_attribute_str(int attribute, const char *value, int len);
-       bool cmd_flush(void);
-
-private:
-       csocket m_command_socket;
-       int m_client_id;
-       sensor_id_t m_sensor_id;
-       bool command_handler(cpacket *packet, void **return_payload);
-};
-
-#endif /* _COMMAND_CHANNEL_H_ */
diff --git a/src/client/dbus_listener.cpp b/src/client/dbus_listener.cpp
deleted file mode 100644 (file)
index 7f96ef1..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_log.h>
-#include "sensor_event_listener.h"
-#include "dbus_listener.h"
-
-#define HANDLE_GERROR(Err) \
-       do { \
-               if ((Err)) { \
-                       _E("GError: %s", Err->message); \
-                       g_error_free(Err); \
-                       Err = NULL; \
-               } \
-       } while (0)
-
-#define ROTATION_DBUS_DEST             "org.tizen.system.coord"
-#define ROTATION_DBUS_OBJ_PATH "/Org/Tizen/System/Coord/Rotation"
-#define ROTATION_DBUS_IFACE            "org.tizen.system.coord.rotation"
-#define ROTATION_DBUS_SIGNAL   "Changed"
-#define ROTATION_DBUS_METHOD   "Degree"
-
-static void rotation_signal_cb(GDBusConnection *conn, const gchar *sender,
-               const gchar *obj_path, const gchar *iface, const gchar *signal_name,
-               GVariant *param, gpointer user_data)
-{
-       gint state;
-       g_variant_get(param, "(i)", &state);
-       sensor_event_listener::get_instance().set_display_rotation(state);
-}
-
-static void rotation_read_cb(GObject *source_object, GAsyncResult *res, gpointer user_data)
-{
-       GError *error = NULL;
-       GDBusConnection *conn = G_DBUS_CONNECTION(source_object);
-       GVariant *result = g_dbus_connection_call_finish(conn, res, &error);
-       HANDLE_GERROR(error);
-       ret_if(result == NULL);
-
-       gint state;
-       g_variant_get(result, "(i)", &state);
-       g_variant_unref(result);
-       sensor_event_listener::get_instance().set_display_rotation(state);
-}
-
-dbus_listener::dbus_listener()
-: m_connection(NULL)
-{
-#ifndef GLIB_VERSION_2_36
-       g_type_init();
-#endif
-}
-
-dbus_listener::~dbus_listener()
-{
-       disconnect();
-}
-
-void dbus_listener::init(void)
-{
-       static dbus_listener listener;
-       static bool done = false;
-       ret_if(done);
-       listener.connect();
-       done = true;
-}
-
-void dbus_listener::connect(void)
-{
-       GError *gerr = NULL;
-
-       gchar *addr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &gerr);
-       HANDLE_GERROR(gerr);
-       retm_if(addr == NULL, "Getting address failed");
-
-       g_dbus_connection_new_for_address(addr,
-                       (GDBusConnectionFlags)(G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
-                       NULL, NULL, on_connection_ready, this);
-       g_free(addr);
-}
-
-void dbus_listener::on_connection_ready(GObject *source_object, GAsyncResult *res, gpointer user_data)
-{
-       GError *gerr = NULL;
-       dbus_listener *listener = static_cast<dbus_listener*>(user_data);
-
-       GDBusConnection *conn = g_dbus_connection_new_finish(res, &gerr);
-       HANDLE_GERROR(gerr);
-
-       retm_if(conn == NULL, "Connection failed");
-       _D("Dbus connection established: %s", g_dbus_connection_get_unique_name(conn));
-
-       listener->m_connection = conn;
-       listener->get_current_state();
-       listener->subscribe();
-}
-
-void dbus_listener::disconnect(void)
-{
-       ret_if(!m_connection);
-       g_dbus_connection_close_sync(m_connection, NULL, NULL);
-       g_object_unref(m_connection);
-}
-
-void dbus_listener::subscribe(void)
-{
-       /* Diplay rotation */
-       g_dbus_connection_signal_subscribe(m_connection,
-                       ROTATION_DBUS_DEST, ROTATION_DBUS_IFACE, ROTATION_DBUS_SIGNAL, ROTATION_DBUS_OBJ_PATH,
-                       NULL, G_DBUS_SIGNAL_FLAGS_NONE, (GDBusSignalCallback)rotation_signal_cb, NULL, NULL);
-}
-
-void dbus_listener::get_current_state(void)
-{
-       /* Display rotation */
-       g_dbus_connection_call(m_connection,
-                       ROTATION_DBUS_DEST, ROTATION_DBUS_OBJ_PATH, ROTATION_DBUS_IFACE, ROTATION_DBUS_METHOD,
-                       NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, (GAsyncReadyCallback)rotation_read_cb, NULL);
-}
diff --git a/src/client/dbus_listener.h b/src/client/dbus_listener.h
deleted file mode 100644 (file)
index 3d4a804..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _DBUS_LISTENER_H_
-#define _DBUS_LISTENER_H_
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <cmutex.h>
-
-class dbus_listener {
-public:
-       static void init(void);
-
-private:
-       GDBusConnection *m_connection;
-
-       dbus_listener();
-       ~dbus_listener();
-
-       void connect(void);
-       void disconnect(void);
-
-       void subscribe(void);
-       void get_current_state(void);
-
-       static void on_connection_ready(GObject *source_object, GAsyncResult *res, gpointer user_data);
-};
-
-#endif /* _DBUS_LISTENER_H_ */
diff --git a/src/client/external_client.cpp b/src/client/external_client.cpp
deleted file mode 100644 (file)
index 1a3e2da..0000000
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <sensor_common.h>
-#include <command_common.h>
-#include <sensor_internal.h>
-#include <external_sensor_manager.h>
-#include <external_data_channel.h>
-#include <cmutex.h>
-
-using std::vector;
-using std::string;
-
-static cmutex lock;
-
-static void clean_up(void);
-static void restore_session(void);
-
-class initiator {
-public:
-       initiator()
-       {
-               external_sensor_manager::get_instance().set_hup_observer(restore_session);
-       }
-};
-
-static initiator g_initiator;
-
-void clean_up(void)
-{
-       vector<int> handles;
-
-       external_sensor_manager::get_instance().get_all_handles(handles);
-
-       auto it_handle = handles.begin();
-
-       while (it_handle != handles.end()) {
-               sensord_external_disconnect(*it_handle);
-               ++it_handle;
-       }
-}
-
-void restore_session(void)
-{
-       AUTOLOCK(lock);
-
-       _I("Trying to restore external source session for %s", get_client_name());
-
-       external_data_channel *data_channel;
-       int client_id;
-
-       external_sensor_manager::get_instance().close_data_channel();
-       external_sensor_manager::get_instance().set_client_id(CLIENT_ID_INVALID);
-
-       vector<int> handles;
-
-       external_sensor_manager::get_instance().get_all_handles(handles);
-
-       bool first_connection = true;
-
-       auto it_handle = handles.begin();
-
-       while (it_handle != handles.end()) {
-               data_channel = new(std::nothrow) external_data_channel();
-               retm_if(!data_channel, "Failed to allocate memory");
-
-               if (!data_channel->create_channel()) {
-                       _E("%s failed to create data channel", get_client_name());
-                       delete data_channel;
-                       goto FAILED;
-               }
-
-               external_sensor_manager::get_instance().add_data_channel(*it_handle, data_channel);
-
-               if (first_connection) {
-                       first_connection = false;
-                       if (!data_channel->cmd_get_id(client_id)) {
-                               _E("Failed to get client id");
-                               goto FAILED;
-                       }
-
-                       external_sensor_manager::get_instance().set_client_id(client_id);
-                       external_sensor_manager::get_instance().start_command_listener();
-               }
-
-               data_channel->set_client_id(client_id);
-
-               sensor_id_t dummy;
-               if (!data_channel->cmd_connect(external_sensor_manager::get_instance().get_key(*it_handle), dummy)) {
-                       _E("Sending cmd_connect(%s) failed for %s", external_sensor_manager::get_instance().get_key(*it_handle).c_str(), get_client_name());
-                       goto FAILED;
-               }
-
-               ++it_handle;
-       }
-
-       _I("Succeeded to restore external source session for %s", get_client_name());
-
-       return;
-
-FAILED:
-       external_sensor_manager::get_instance().clear();
-       _E("Failed to restore external source session for %s", get_client_name());
-}
-
-API int sensord_external_connect(const char *key, sensor_external_command_cb_t cb, void *user_data)
-{
-       external_data_channel *channel = NULL;
-       int handle;
-       int client_id;
-       bool first_connection = false;
-
-       retvm_if(!key, OP_ERROR, "client %s passes null key", get_client_name());
-
-       AUTOLOCK(lock);
-
-       handle = external_sensor_manager::get_instance().create_handle();
-
-       // lazy loading after creating static variables
-       atexit(clean_up);
-
-       if (handle == MAX_HANDLE) {
-               _E("Maximum number of handles reached, key %s in client %s", key, get_client_name());
-               return OP_ERROR;
-       }
-
-       channel = new(std::nothrow) external_data_channel();
-       if (!channel) {
-               _E("Failed to allocated memory");
-               external_sensor_manager::get_instance().delete_handle(handle);
-               return OP_ERROR;
-       }
-
-       if (!channel->create_channel()) {
-               _E("%s failed to create data channel for %s", get_client_name(), key);
-               external_sensor_manager::get_instance().delete_handle(handle);
-               delete channel;
-               return OP_ERROR;
-       }
-
-       external_sensor_manager::get_instance().add_data_channel(handle, channel);
-
-       if (!external_sensor_manager::get_instance().has_client_id()) {
-               first_connection = true;
-               if (!channel->cmd_get_id(client_id)) {
-                       _E("Sending cmd_get_id() failed for %s", key);
-                       external_sensor_manager::get_instance().close_data_channel(handle);
-                       external_sensor_manager::get_instance().delete_handle(handle);
-                       return OP_ERROR;
-               }
-
-               external_sensor_manager::get_instance().set_client_id(client_id);
-               _I("%s gets client_id [%d]", get_client_name(), client_id);
-               external_sensor_manager::get_instance().start_command_listener();
-               _I("%s starts listening command with client_id [%d]", get_client_name(), client_id);
-       }
-
-       client_id = external_sensor_manager::get_instance().get_client_id();
-       channel->set_client_id(client_id);
-
-       sensor_id_t sensor;
-
-       if (!channel->cmd_connect(key, sensor)) {
-               _E("Failed to connect %s for %s", key, get_client_name());
-               external_sensor_manager::get_instance().close_data_channel(handle);
-               external_sensor_manager::get_instance().delete_handle(handle);
-
-               if (first_connection) {
-                       external_sensor_manager::get_instance().set_client_id(CLIENT_ID_INVALID);
-                       external_sensor_manager::get_instance().stop_command_listener();
-               }
-
-               return OP_ERROR;
-       }
-
-       _I("%s[%d] connects with %s[%d]", get_client_name(), client_id, key, handle);
-
-       external_sensor_manager::get_instance().set_handle(handle, sensor, string(key), (void *)cb, user_data);
-
-       return handle;
-}
-
-API bool sensord_external_disconnect(int handle)
-{
-       external_data_channel *channel;
-
-       AUTOLOCK(lock);
-
-       retvm_if(!external_sensor_manager::get_instance().is_valid(handle), false, "Handle %d is not valid for %s",
-               handle, get_client_name());
-
-       if (!external_sensor_manager::get_instance().get_data_channel(handle, &channel)) {
-               _E("client %s failed to get data channel", get_client_name());
-               return false;
-       }
-
-       _I("%s disconnects with %s[%d]", get_client_name(), external_sensor_manager::get_instance().get_key(handle).c_str(), handle);
-
-       if (!external_sensor_manager::get_instance().delete_handle(handle))
-               return false;
-
-       if (!channel->cmd_disconnect()) {
-               _E("Sending cmd_disconnect() failed for %s", get_client_name());
-               return false;
-       }
-
-       external_sensor_manager::get_instance().close_data_channel(handle);
-
-       if (!external_sensor_manager::get_instance().is_active()) {
-               _I("Stop listening command for client %s with client id [%d]", get_client_name(), external_sensor_manager::get_instance().get_client_id());
-               external_sensor_manager::get_instance().set_client_id(CLIENT_ID_INVALID);
-               external_sensor_manager::get_instance().stop_command_listener();
-       }
-
-       return true;
-}
-
-API bool sensord_external_post(int handle, unsigned long long timestamp, const float* data, int data_cnt)
-{
-       external_data_channel *channel;
-
-       retvm_if(((data_cnt <= 0) || (data_cnt > POST_DATA_LEN_MAX)), false,
-               "data_cnt(%d) is invalid for %s", data_cnt, get_client_name());
-
-       AUTOLOCK(lock);
-
-       retvm_if(!external_sensor_manager::get_instance().is_valid(handle), false, "Handle %d is not valid for %s",
-               handle, get_client_name());
-
-       if (!external_sensor_manager::get_instance().get_data_channel(handle, &channel)) {
-               _E("client %s failed to get data channel", get_client_name());
-               return false;
-       }
-
-       if (!channel->cmd_post(timestamp, data, data_cnt)) {
-               _E("Failed to post data:%#x, data_cnt:%d", data, data_cnt);
-               return false;
-       }
-
-       return true;
-}
diff --git a/src/client/external_data_channel.cpp b/src/client/external_data_channel.cpp
deleted file mode 100644 (file)
index 70a7325..0000000
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <command_common.h>
-#include <sensor_types.h>
-#include <external_data_channel.h>
-
-using std::string;
-
-external_data_channel::external_data_channel()
-: m_client_id(CLIENT_ID_INVALID)
-, m_sensor_id(UNKNOWN_SENSOR)
-{
-}
-
-external_data_channel::~external_data_channel()
-{
-       m_socket.close();
-}
-
-bool external_data_channel::command_handler(cpacket *packet, void **return_payload)
-{
-       packet_header header;
-       char *buffer = NULL;
-
-       if (!m_socket.is_valid()) {
-               _E("Socket(%d) is not valid for client %s", m_socket.get_socket_fd(), get_client_name());
-               return false;
-       }
-
-       if (!packet->size()) {
-               _E("Packet is not valid for client %s", get_client_name());
-               return false;
-       }
-
-       if (m_socket.send(packet->packet(), packet->size()) <= 0) {
-               m_socket.close();
-               _E("Failed to send command in client %s", get_client_name());
-               return false;
-       }
-
-       if (m_socket.recv(&header, sizeof(header)) <= 0) {
-               m_socket.close();
-               _E("Failed to receive header for command packet in client %s", get_client_name());
-               return false;
-       }
-
-       buffer = new(std::nothrow) char[header.size];
-       retvm_if(!buffer, false, "Failed to allocate memory");
-
-       if (m_socket.recv(buffer, header.size) <= 0) {
-               m_socket.close();
-               _E("Failed to receive command packet in client %s", get_client_name());
-               delete[] buffer;
-               return false;
-       }
-
-       *return_payload = buffer;
-
-       return true;
-}
-
-bool external_data_channel::create_channel(void)
-{
-       const int client_type = CLIENT_TYPE_EXTERNAL_SOURCE;
-
-       if (!m_socket.create(SOCK_STREAM)) {
-               _E("Failed to create external data channel for client %s", get_client_name());
-               return false;
-       }
-
-       if (!m_socket.connect(COMMAND_CHANNEL_PATH)) {
-               _E("Failed to connect external data channel for client %s, command socket fd[%d]", get_client_name(), m_socket.get_socket_fd());
-               return false;
-       }
-
-       m_socket.set_connection_mode();
-
-       if (m_socket.send(&client_type, sizeof(client_type)) <= 0) {
-               _E("Failed to send client type in client %s, command socket fd[%d]", get_client_name(), m_socket.get_socket_fd());
-               return false;
-       }
-
-       return true;
-}
-
-void external_data_channel::set_client_id(int client_id)
-{
-       m_client_id = client_id;
-}
-
-bool external_data_channel::cmd_get_id(int &client_id)
-{
-       cpacket *packet;
-       cmd_ext_get_id_t *cmd_ext_get_id;
-       cmd_ext_get_id_done_t *cmd_ext_get_id_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_ext_get_id_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_EXT_GET_ID);
-
-       cmd_ext_get_id = (cmd_ext_get_id_t *)packet->data();
-
-       get_proc_name(getpid(), cmd_ext_get_id->name);
-
-       _I("%s send cmd_get_id()", get_client_name());
-
-       if (!command_handler(packet, (void **)&cmd_ext_get_id_done)) {
-               _E("Client %s failed to send/receive command", get_client_name());
-               delete packet;
-               return false;
-       }
-
-       if (cmd_ext_get_id_done->client_id < 0) {
-               _E("Client %s failed to get client_id[%d] from server",
-                       get_client_name(), cmd_ext_get_id_done->client_id);
-               delete[] (char *)cmd_ext_get_id_done;
-               delete packet;
-               return false;
-       }
-
-       client_id = cmd_ext_get_id_done->client_id;
-
-       delete[] (char *)cmd_ext_get_id_done;
-       delete packet;
-
-       return true;
-}
-
-bool external_data_channel::cmd_connect(const string &key, sensor_id_t &sensor_id)
-{
-       cpacket *packet;
-       cmd_ext_connect_t *cmd_ext_connect;
-       cmd_ext_connect_done_t *cmd_ext_connect_done;
-
-       int key_size = key.size();
-
-       if ((key_size == 0) || (key_size >= NAME_MAX)) {
-               _I("Key(%s) is not valid", key.c_str());
-               return false;
-       }
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_ext_connect_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_EXT_CONNECT);
-
-       cmd_ext_connect = (cmd_ext_connect_t *)packet->data();
-       cmd_ext_connect->client_id = m_client_id;
-       strncpy(cmd_ext_connect->key, key.c_str(), NAME_MAX-1);
-
-       _I("%s send cmd_get_connect(key = %s, client_id = %d)", get_client_name(), key.c_str(), m_client_id);
-
-       if (!command_handler(packet, (void **)&cmd_ext_connect_done)) {
-               _E("Client %s failed to send/receive command", get_client_name());
-               delete packet;
-               return false;
-       }
-
-       if (cmd_ext_connect_done->sensor_id == UNKNOWN_SENSOR) {
-               _E("Client %s failed to connect to external sensor", get_client_name());
-               delete[] (char *)cmd_ext_connect_done;
-               delete packet;
-               return false;
-       }
-
-       m_sensor_id = sensor_id = cmd_ext_connect_done->sensor_id;
-
-       delete[] (char *)cmd_ext_connect_done;
-       delete packet;
-
-       return true;
-}
-
-bool external_data_channel::cmd_disconnect(void)
-{
-       cpacket *packet;
-       cmd_ext_done_t *cmd_ext_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_ext_disconnect_t));
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_EXT_DISCONNECT);
-
-       _I("%s send cmd_disconnect(client_id=%d)", get_client_name(), m_client_id);
-
-       if (!command_handler(packet, (void **)&cmd_ext_done)) {
-               _E("Client %s failed to send/receive command  with client_id [%d]",
-                       get_client_name(), m_client_id);
-               delete packet;
-               return false;
-       }
-
-       if (cmd_ext_done->value < 0) {
-               _E("Client %s got error[%d] from server with client_id [%d]",
-                       get_client_name(), cmd_ext_done->value, m_client_id);
-
-               delete[] (char *)cmd_ext_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_ext_done;
-       delete packet;
-
-       m_socket.close();
-       m_client_id = CLIENT_ID_INVALID;
-       return true;
-}
-
-bool external_data_channel::cmd_post(unsigned long long timestamp, const float *data, int data_cnt)
-{
-       cpacket *packet;
-       cmd_ext_post_t *cmd_ext_post;
-       cmd_done_t *cmd_done;
-
-       packet = new(std::nothrow) cpacket(sizeof(cmd_ext_post_t) + sizeof(float) * data_cnt);
-       retvm_if(!packet, false, "Failed to allocate memory");
-
-       packet->set_cmd(CMD_EXT_POST);
-
-       cmd_ext_post = (cmd_ext_post_t*)packet->data();
-       cmd_ext_post->timestamp = timestamp;
-       cmd_ext_post->data_cnt = data_cnt;
-       memcpy(cmd_ext_post->data, data, sizeof(float) * data_cnt);
-
-       _I("%s send cmd_post(client_id=%d, data = %#x, data_cnt = %d)",
-               get_client_name(), m_client_id, data, data_cnt);
-
-       if (!command_handler(packet, (void **)&cmd_done)) {
-               _E("%s failed to send/receive command with client_id [%d]",
-                       get_client_name(), m_client_id);
-               delete packet;
-               return false;
-       }
-
-       if (cmd_done->value < 0) {
-               _E("%s got error[%d] from server with client_id [%d]",
-                       get_client_name(), cmd_done->value, m_client_id);
-
-               delete[] (char *)cmd_done;
-               delete packet;
-               return false;
-       }
-
-       delete[] (char *)cmd_done;
-       delete packet;
-
-       return true;
-}
diff --git a/src/client/external_data_channel.h b/src/client/external_data_channel.h
deleted file mode 100644 (file)
index 19a2a41..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _EXTERNAL_DATA_CHANNEL_H_
-#define _EXTERNAL_DATA_CHANNEL_H_
-
-#include <string>
-#include <csocket.h>
-
-class cpacket;
-
-class external_data_channel {
-public:
-       external_data_channel();
-       ~external_data_channel();
-
-       bool create_channel(void);
-       void set_client_id(int client_id);
-       bool cmd_get_id(int &client_id);
-       bool cmd_connect(const std::string &key, sensor_id_t &sensor_id);
-       bool cmd_disconnect(void);
-       bool cmd_post(unsigned long long timestamp, const float *data, int data_cnt);
-private:
-       csocket m_socket;
-       int m_client_id;
-       sensor_id_t m_sensor_id;
-       bool command_handler(cpacket *packet, void **return_payload);
-};
-
-#endif /* _EXTERNAL_DATA_CHANNEL_H_ */
diff --git a/src/client/external_sensor_manager.cpp b/src/client/external_sensor_manager.cpp
deleted file mode 100644 (file)
index 9a0b3c4..0000000
+++ /dev/null
@@ -1,543 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <sensor_internal.h>
-#include <sensor_common.h>
-#include <command_common.h>
-#include <external_sensor_manager.h>
-#include <external_data_channel.h>
-#include <poller.h>
-#include <thread>
-
-using std::pair;
-using std::vector;
-using std::thread;
-using std::string;
-
-external_sensor_manager::external_sensor_manager()
-: m_client_id(CLIENT_ID_INVALID)
-, m_poller(NULL)
-, m_thread_state(THREAD_STATE_TERMINATE)
-, m_hup_observer(NULL)
-{
-}
-
-external_sensor_manager::~external_sensor_manager()
-{
-       stop_command_listener();
-}
-
-external_sensor_manager& external_sensor_manager::get_instance(void)
-{
-       static external_sensor_manager inst;
-       return inst;
-}
-
-int external_sensor_manager::create_handle(void)
-{
-       sensor_ext_handle_info handle_info;
-       int handle = 0;
-
-       AUTOLOCK(m_handle_info_lock);
-
-       while (m_sensor_handle_infos.count(handle) > 0)
-               handle++;
-
-       if (handle >= MAX_HANDLE) {
-               _E("Handles of client %s are full", get_client_name());
-               return MAX_HANDLE_REACHED;
-       }
-
-       handle_info.m_handle = handle;
-       handle_info.m_sensor = UNKNOWN_SENSOR;
-       handle_info.m_cb = NULL;
-       handle_info.m_user_data = NULL;
-
-       m_sensor_handle_infos.insert(pair<int, sensor_ext_handle_info>(handle, handle_info));
-
-       return handle;
-}
-
-bool external_sensor_manager::delete_handle(int handle)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _E("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       m_sensor_handle_map.erase(it_handle->second.m_sensor);
-       m_sensor_handle_infos.erase(it_handle);
-
-       return true;
-}
-
-bool external_sensor_manager::set_handle(int handle, sensor_id_t sensor, const string& key, void* cb, void* user_data)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _E("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       it_handle->second.m_sensor = sensor;
-       it_handle->second.m_key = key;
-       it_handle->second.m_cb = cb;
-       it_handle->second.m_user_data = user_data;
-
-       m_sensor_handle_map.insert(pair<sensor_id_t, int>(sensor, handle));
-
-       return true;
-}
-
-bool external_sensor_manager::get_sensor(int handle, sensor_id_t &sensor)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _E("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       sensor = it_handle->second.m_sensor;
-
-       return true;
-}
-
-int external_sensor_manager::get_handle(sensor_id_t sensor)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_map.find(sensor);
-
-       if (it_handle == m_sensor_handle_map.end()) {
-               _E("Handle is not found for client %s with sensor: %d", get_client_name(), sensor);
-               return -1;
-       }
-
-       return it_handle->second;
-}
-
-bool external_sensor_manager::get_handle_info(int handle, const sensor_ext_handle_info*& handle_info)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _E("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       handle_info = &(it_handle->second);
-       return true;
-}
-
-string external_sensor_manager::get_key(int handle)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               return string("INVALID_KEY");
-       }
-
-       return it_handle->second.m_key;
-}
-
-bool external_sensor_manager::has_client_id(void)
-{
-       return (m_client_id != CLIENT_ID_INVALID);
-}
-
-int external_sensor_manager::get_client_id(void)
-{
-       return m_client_id;
-}
-
-void external_sensor_manager::set_client_id(int client_id)
-{
-       m_client_id = client_id;
-}
-
-bool external_sensor_manager::add_data_channel(int handle, external_data_channel *channel)
-{
-       auto it_channel = m_data_channels.find(handle);
-
-       if (it_channel != m_data_channels.end()) {
-               _E("%s alreay has data_channel for %s", get_client_name(), get_key(handle).c_str());
-               return false;
-       }
-
-       m_data_channels.insert(pair<int, external_data_channel *>(handle, channel));
-       return true;
-}
-
-bool external_sensor_manager::get_data_channel(int handle, external_data_channel **channel)
-{
-       auto it_channel = m_data_channels.find(handle);
-
-       if (it_channel == m_data_channels.end()) {
-               _E("%s doesn't have data_channel for %s", get_client_name(), get_key(handle).c_str());
-               return false;
-       }
-
-       *channel = it_channel->second;
-
-       return true;
-}
-
-bool external_sensor_manager::close_data_channel(void)
-{
-       auto it_channel = m_data_channels.begin();
-
-       if (it_channel != m_data_channels.end()) {
-               delete it_channel->second;
-               ++it_channel;
-       }
-
-       m_data_channels.clear();
-
-       return true;
-}
-
-bool external_sensor_manager::close_data_channel(int handle)
-{
-       auto it_channel = m_data_channels.find(handle);
-
-       if (it_channel == m_data_channels.end()) {
-               _E("%s doesn't have data_channel for %s", get_client_name(), get_key(handle).c_str());
-               return false;
-       }
-
-       delete it_channel->second;
-
-       m_data_channels.erase(it_channel);
-
-       return true;
-}
-
-bool external_sensor_manager::is_valid(int handle)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end())
-               return false;
-
-       return true;
-}
-
-bool external_sensor_manager::is_active(void)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       return !m_sensor_handle_infos.empty();
-}
-
-void external_sensor_manager::get_all_handles(vector<int> &handles)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end()) {
-               handles.push_back(it_handle->first);
-               ++it_handle;
-       }
-}
-
-bool external_sensor_manager::create_command_channel(void)
-{
-       const int client_type = CLIENT_TYPE_EXTERNAL_SOURCE;
-       int client_id;
-       channel_ready_t channel_ready;
-
-       if (!m_command_socket.create(SOCK_SEQPACKET))
-               return false;
-
-       if (!m_command_socket.connect(EVENT_CHANNEL_PATH)) {
-               _E("Failed to connect command channel for client %s, command socket fd[%d]", get_client_name(), m_command_socket.get_socket_fd());
-               return false;
-       }
-
-       m_command_socket.set_connection_mode();
-
-       if (m_command_socket.send(&client_type, sizeof(client_type)) <= 0) {
-               _E("Failed to send client type in client %s, event socket fd[%d]", get_client_name(), m_command_socket.get_socket_fd());
-               return false;
-       }
-
-       client_id = get_client_id();
-
-       if (m_command_socket.send(&client_id, sizeof(client_id)) <= 0) {
-               _E("Failed to send client id for client %s on command socket[%d]", get_client_name(), m_command_socket.get_socket_fd());
-               return false;
-       }
-
-       if (m_command_socket.recv(&channel_ready, sizeof(channel_ready)) <= 0) {
-               _E("%s failed to recv command channel ready packet on command socket[%d] with client id [%d]",
-                       get_client_name(), m_command_socket.get_socket_fd(), client_id);
-               return false;
-       }
-
-       if ((channel_ready.magic != CHANNEL_MAGIC_NUM) || (channel_ready.client_id != client_id)) {
-               _E("Command channel ready packet is wrong, magic = %#x, client id = %d",
-                       channel_ready.magic, channel_ready.client_id);
-               return false;
-       }
-
-       _I("Command channel is established for client %s on socket[%d] with client id : %d",
-               get_client_name(), m_command_socket.get_socket_fd(), client_id);
-
-       return true;
-}
-
-void external_sensor_manager::close_command_channel(void)
-{
-       m_command_socket.close();
-}
-
-bool external_sensor_manager::start_command_listener(void)
-{
-       if (!create_command_channel()) {
-               _E("Command channel is not established for %s", get_client_name());
-               return false;
-       }
-
-       m_command_socket.set_transfer_mode();
-
-       m_poller = new(std::nothrow) poller(m_command_socket.get_socket_fd());
-       retvm_if(!m_poller, false, "Failed to allocate memory");
-
-       set_thread_state(THREAD_STATE_START);
-
-       thread listener(&external_sensor_manager::listen_command, this);
-       listener.detach();
-
-       return true;
-}
-
-void external_sensor_manager::stop_command_listener(void)
-{
-       const int THREAD_TERMINATING_TIMEOUT = 2;
-
-       ulock u(m_thread_mutex);
-
-       if (m_thread_state != THREAD_STATE_TERMINATE) {
-               m_thread_state = THREAD_STATE_STOP;
-
-               _D("%s is waiting listener thread[state: %d] to be terminated", get_client_name(), m_thread_state);
-               if (m_thread_cond.wait_for(u, std::chrono::seconds(THREAD_TERMINATING_TIMEOUT))
-                       == std::cv_status::timeout)
-                       _E("Fail to stop listener thread after waiting %d seconds", THREAD_TERMINATING_TIMEOUT);
-               else
-                       _D("Listener thread for %s is terminated", get_client_name());
-       }
-}
-
-void external_sensor_manager::set_thread_state(thread_state state)
-{
-       lock l(m_thread_mutex);
-       m_thread_state = state;
-}
-
-bool external_sensor_manager::get_cb_info(sensor_id_t sensor, char* data, int data_cnt, command_cb_info &cb_info)
-{
-       int handle;
-       const sensor_ext_handle_info *handle_info;
-
-       AUTOLOCK(m_handle_info_lock);
-
-       handle = get_handle(sensor);
-
-       if (handle < 0)
-               return false;
-
-       get_handle_info(handle, handle_info);
-
-       cb_info.handle = handle_info->m_handle;
-       cb_info.sensor = handle_info->m_sensor;
-       cb_info.cb = handle_info->m_cb;
-       cb_info.data = data;
-       cb_info.data_cnt = data_cnt;
-       cb_info.user_data = handle_info->m_user_data;
-
-       return true;
-}
-
-bool external_sensor_manager::sensor_command_poll(void* buffer, int buffer_len, struct epoll_event &event)
-{
-       ssize_t len;
-
-       len = m_command_socket.recv(buffer, buffer_len);
-
-       if (!len) {
-               if (!m_poller->poll(event))
-                       return false;
-               len = m_command_socket.recv(buffer, buffer_len);
-
-               if (len <= 0) {
-                       _I("%s failed to read after poll!", get_client_name());
-                       return false;
-               }
-       } else if (len < 0) {
-               _I("%s failed to recv command from command socket", get_client_name());
-               return false;
-       }
-
-       return true;
-}
-
-void external_sensor_manager::post_callback_to_main_loop(command_cb_info* cb_info)
-{
-       g_idle_add_full(G_PRIORITY_DEFAULT, callback_dispatcher, cb_info, NULL);
-}
-
-void external_sensor_manager::handle_command(sensor_id_t sensor, char* data, int data_cnt)
-{
-       command_cb_info *cb_info = NULL;
-
-       {       /* scope for the lock */
-               AUTOLOCK(m_handle_info_lock);
-
-               cb_info = new(std::nothrow) command_cb_info;
-               if (!cb_info) {
-                       _E("Failed to allocate memory");
-                       delete[] data;
-                       return;
-               }
-
-               if (!get_cb_info(sensor, data, data_cnt, *cb_info)) {
-                       delete[] data;
-                       delete cb_info;
-                       _E("Sensor %d is not connected, so command is discarded", sensor);
-                       return;
-               }
-       }
-
-       if (cb_info)
-               post_callback_to_main_loop(cb_info);
-}
-
-void external_sensor_manager::listen_command(void)
-{
-       external_command_header_t command_header;
-       struct epoll_event event;
-       event.events = EPOLLIN | EPOLLPRI;
-
-       do {
-               lock l(m_thread_mutex);
-               if (m_thread_state == THREAD_STATE_START) {
-                       if (!sensor_command_poll(&command_header, sizeof(command_header), event)) {
-                               _I("Failed to poll command header");
-                               break;
-                       }
-
-                       char *command = new(std::nothrow) char[command_header.command_len];
-                       if (!command) {
-                               _E("Failed to allocated memory");
-                               break;
-                       }
-
-                       if (!sensor_command_poll(command, command_header.command_len, event)) {
-                               _I("Failed to poll command data");
-                               delete []command;
-                               break;
-                       }
-
-                       handle_command(command_header.sensor_id, command, command_header.command_len);
-               } else {
-                       break;
-               }
-       } while (true);
-
-       if (m_poller != NULL) {
-               delete m_poller;
-               m_poller = NULL;
-       }
-
-       close_command_channel();
-
-       { /* the scope for the lock */
-               lock l(m_thread_mutex);
-               m_thread_state = THREAD_STATE_TERMINATE;
-               m_thread_cond.notify_one();
-       }
-
-       _I("Command listener thread is terminated.");
-
-       if (has_client_id() && (event.events & EPOLLHUP)) {
-               if (m_hup_observer)
-                       m_hup_observer();
-       }
-}
-
-bool external_sensor_manager::is_valid_callback(const command_cb_info *cb_info)
-{
-       sensor_id_t sensor;
-
-       if (!external_sensor_manager::get_instance().get_sensor(cb_info->handle, sensor))
-               return false;
-
-       return (cb_info->sensor == sensor);
-}
-
-gboolean external_sensor_manager::callback_dispatcher(gpointer data)
-{
-       const command_cb_info *cb_info = reinterpret_cast<const command_cb_info*>(data);
-
-       if (external_sensor_manager::get_instance().is_valid_callback(cb_info)) {
-               reinterpret_cast<sensor_external_command_cb_t>(cb_info->cb)(cb_info->handle, cb_info->data, cb_info->data_cnt, cb_info->user_data);
-       } else {
-               _W("Discard invalid callback cb(%#x)(%d, %#x, %d, %#x)",
-               cb_info->cb, cb_info->handle, cb_info->data, cb_info->data_cnt, cb_info->user_data);
-       }
-
-       delete[] cb_info->data;
-       delete cb_info;
-
-/*
-*      To be called only once, it returns false
-*/
-       return false;
-}
-
-void external_sensor_manager::clear(void)
-{
-       close_command_channel();
-       stop_command_listener();
-       close_data_channel();
-       m_sensor_handle_infos.clear();
-       set_client_id(CLIENT_ID_INVALID);
-}
-
-void external_sensor_manager::set_hup_observer(hup_observer_t observer)
-{
-       m_hup_observer = observer;
-}
diff --git a/src/client/external_sensor_manager.h b/src/client/external_sensor_manager.h
deleted file mode 100644 (file)
index 9259c2c..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef _EXTERNAL_SENSOR_MANAGER_H_
-#define _EXTERNAL_SENSOR_MANAGER_H_
-
-#include <glib.h>
-#include <sys/epoll.h>
-#include <sensor_common.h>
-#include <csocket.h>
-#include <cmutex.h>
-#include <string>
-#include <vector>
-#include <unordered_map>
-#include <mutex>
-#include <condition_variable>
-
-class external_data_channel;
-class poller;
-
-class sensor_ext_handle_info {
-public:
-       int m_handle;
-       sensor_id_t m_sensor;
-       std::string m_key;
-       void *m_cb;
-       void *m_user_data;
-};
-
-typedef struct {
-       int handle;
-       sensor_id_t sensor;
-       char *data;
-       int data_cnt;
-       void *cb;
-       void *user_data;
-} command_cb_info;
-
-class external_sensor_manager {
-public:
-       typedef void (*hup_observer_t)(void);
-
-       static external_sensor_manager& get_instance(void);
-       int create_handle(void);
-       bool delete_handle(int handle);
-
-       bool set_handle(int handle, sensor_id_t sensor, const std::string& key, void* cb, void* user_data);
-
-       bool get_sensor(int handle, sensor_id_t &sensor_id);
-       int get_handle(sensor_id_t sensor);
-       bool get_handle_info(int handle, const sensor_ext_handle_info*& handle_info);
-       std::string get_key(int handle);
-
-       bool has_client_id(void);
-       int get_client_id(void);
-       void set_client_id(int client_id);
-
-       bool add_data_channel(int handle, external_data_channel *channel);
-       bool get_data_channel(int handle, external_data_channel **channel);
-       bool close_data_channel(void);
-       bool close_data_channel(int handle);
-
-       bool is_valid(int handle);
-       bool is_active(void);
-
-       void get_all_handles(std::vector<int> &handles);
-
-       bool start_command_listener(void);
-       void stop_command_listener(void);
-       void clear(void);
-
-       void set_hup_observer(hup_observer_t observer);
-private:
-       enum thread_state {
-               THREAD_STATE_START,
-               THREAD_STATE_STOP,
-               THREAD_STATE_TERMINATE,
-       };
-
-       typedef std::lock_guard<std::mutex> lock;
-       typedef std::unique_lock<std::mutex> ulock;
-
-       external_sensor_manager();
-       ~external_sensor_manager();
-
-       external_sensor_manager(const external_sensor_manager&) {};
-       external_sensor_manager& operator=(const external_sensor_manager&);
-
-       bool create_command_channel(void);
-       void close_command_channel(void);
-       void set_thread_state(thread_state state);
-
-       bool sensor_command_poll(void* buffer, int buffer_len, struct epoll_event &event);
-
-       bool get_cb_info(sensor_id_t sensor, char* data, int data_cnt, command_cb_info &cb_info);
-       void post_callback_to_main_loop(command_cb_info* cb_info);
-       void handle_command(sensor_id_t sensor, char* data, int data_cnt);
-       void listen_command(void);
-
-       bool is_valid_callback(const command_cb_info *cb_info);
-       static gboolean callback_dispatcher(gpointer data);
-
-       int m_client_id;
-
-       csocket m_command_socket;
-       poller *m_poller;
-
-       cmutex m_handle_info_lock;
-
-       thread_state m_thread_state;
-       std::mutex m_thread_mutex;
-       std::condition_variable m_thread_cond;
-
-       hup_observer_t m_hup_observer;
-
-       std::unordered_map<int, sensor_ext_handle_info> m_sensor_handle_infos;
-       std::unordered_map<sensor_id_t, int> m_sensor_handle_map;
-       std::unordered_map<int, external_data_channel*> m_data_channels;
-};
-#endif /* _EXTERNAL_SENSOR_MANAGER_H_ */
diff --git a/src/client/reg_event_info.h b/src/client/reg_event_info.h
deleted file mode 100644 (file)
index 1f65f1d..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _REG_EVENT_INFO_H_
-#define _REG_EVENT_INFO_H_
-
-#include <sensor_common.h>
-
-class reg_event_info {
-public:
-       unsigned long long m_id;
-       int m_handle;
-       unsigned int type;
-       unsigned int m_interval;
-       unsigned int m_latency;
-       void *m_cb;
-       void *m_user_data;
-       unsigned long long m_previous_event_time;
-       bool m_fired;
-
-       reg_event_info()
-       : m_id(0), m_handle(-1),
-       type(0), m_interval(POLL_1HZ_MS), m_latency(0),
-       m_cb(NULL), m_user_data(NULL),
-       m_previous_event_time(0), m_fired(false) {}
-
-       ~reg_event_info() {}
-};
-
-#endif /* _REG_EVENT_INFO_H_ */
diff --git a/src/client/sensor_callback_deliverer.cpp b/src/client/sensor_callback_deliverer.cpp
deleted file mode 100644 (file)
index 9af3790..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_callback_deliverer.h>
-#include <sensor_event_listener.h>
-#include <sensor_client_info.h>
-
-sensor_callback_deliverer::sensor_callback_deliverer()
-: m_running(false)
-, m_callbacks(NULL)
-{
-}
-
-sensor_callback_deliverer::~sensor_callback_deliverer()
-{
-}
-
-bool sensor_callback_deliverer::start(void)
-{
-       if (is_running())
-               return true;
-
-       m_callbacks = g_async_queue_new();
-       retvm_if(!m_callbacks, false, "Failed to allocated memory");
-
-       m_deliverer = new(std::nothrow) std::thread(&sensor_callback_deliverer::run, this);
-
-       if (!m_deliverer) {
-               g_async_queue_unref(m_callbacks);
-               _E("Failed to allocated memory");
-               return false;
-       }
-
-       m_running = true;
-
-       _I("Succeeded to start");
-
-       return true;
-}
-
-bool sensor_callback_deliverer::stop(void)
-{
-       if (!is_running())
-               return true;
-
-       if (!terminate())
-               return false;
-
-       m_deliverer->join();
-       delete m_deliverer;
-
-       g_async_queue_unref(m_callbacks);
-
-       _I("Succeeded to stop");
-
-       return true;
-}
-
-bool sensor_callback_deliverer::is_running(void)
-{
-       return m_running.load();
-}
-
-bool sensor_callback_deliverer::push(client_callback_info *ci)
-{
-       if (!is_running())
-               return false;
-
-       retvm_if(!ci, false, "Invalid callback");
-
-       g_async_queue_push(m_callbacks, ci);
-
-       return true;
-}
-
-gboolean sensor_callback_deliverer::callback_dispatcher(gpointer data)
-{
-       bool ret;
-       client_callback_info *ci = (client_callback_info *)data;
-
-       ret = sensor_client_info::get_instance().is_event_active(ci->handle, ci->event_type, ci->event_id);
-
-       if (!ret) {
-               _W("Discard invalid callback cb(%#x)(%s, %#x, %#x) with id: %llu",
-                       ci->cb, get_event_name(ci->event_type), ci->sensor_data.get(),
-                       ci->user_data, ci->event_id);
-
-               delete ci;
-               return FALSE;
-       }
-
-       if (ci->accuracy_cb)
-               ci->accuracy_cb(ci->sensor, ci->timestamp, ci->accuracy, ci->accuracy_user_data);
-
-       if (ci->cb)
-               ci->cb(ci->sensor, ci->event_type, (sensor_data_t *)ci->sensor_data.get(), ci->user_data);
-
-       delete ci;
-
-       /* To be called only once, it returns false */
-       return FALSE;
-}
-
-void sensor_callback_deliverer::run(void)
-{
-       client_callback_info *ci;
-
-       while (is_running()) {
-               ci = static_cast<client_callback_info *>(g_async_queue_pop(m_callbacks));
-
-               if (ci->handle == THREAD_TERMINATION) {
-                       m_running = false;
-                       delete ci;
-                       return;
-               }
-
-               deliver_to_main_loop(ci);
-       }
-}
-
-bool sensor_callback_deliverer::terminate(void)
-{
-       client_callback_info *ci = new(std::nothrow) client_callback_info;
-       retvm_if(!ci, false, "Failed to allocated memory");
-
-       ci->handle = THREAD_TERMINATION;
-       g_async_queue_push(m_callbacks, ci);
-
-       return true;
-}
-
-void sensor_callback_deliverer::deliver_to_main_loop(client_callback_info *ci)
-{
-       /*
-        * Because callback function always returns FALSE,
-        * it is unnecessary to manage g_source id returned from g_idle_add().
-        */
-       g_idle_add(callback_dispatcher, ci);
-}
diff --git a/src/client/sensor_callback_deliverer.h b/src/client/sensor_callback_deliverer.h
deleted file mode 100644 (file)
index db2145d..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_CALLBACK_DELIVERER_H_
-#define _SENSOR_CALLBACK_DELIVERER_H_
-
-#include <glib.h>
-#include <client_common.h>
-
-#include <thread>
-#include <atomic>
-
-class sensor_callback_deliverer {
-public:
-       sensor_callback_deliverer();
-       ~sensor_callback_deliverer();
-
-       bool start(void);
-       bool stop(void);
-       bool is_running(void);
-
-       bool push(client_callback_info *ci);
-
-private:
-       static gboolean callback_dispatcher(gpointer data);
-
-       std::atomic_bool m_running;
-
-       GAsyncQueue *m_callbacks;
-       std::thread *m_deliverer;
-
-       void run(void);
-       bool terminate(void);
-
-       void deliver_to_main_loop(client_callback_info *ci);
-};
-
-#endif /* _SENSOR_CALLBACK_DELIVERER_H_ */
diff --git a/src/client/sensor_client_info.cpp b/src/client/sensor_client_info.cpp
deleted file mode 100644 (file)
index 2a755aa..0000000
+++ /dev/null
@@ -1,723 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_event_listener.h>
-#include <client_common.h>
-#include <sensor_info_manager.h>
-
-#include <thread>
-#include <chrono>
-
-using std::thread;
-using std::pair;
-
-sensor_client_info::sensor_client_info()
-: m_client_id(CLIENT_ID_INVALID)
-{
-}
-
-sensor_client_info::~sensor_client_info()
-{
-}
-
-sensor_client_info& sensor_client_info::get_instance(void)
-{
-       static sensor_client_info inst;
-       return inst;
-}
-
-int sensor_client_info::create_handle(sensor_id_t sensor)
-{
-       sensor_handle_info handle_info;
-       int handle = 0;
-
-       AUTOLOCK(m_handle_info_lock);
-
-       while (m_sensor_handle_infos.count(handle) > 0)
-               handle++;
-
-       if (handle == MAX_HANDLE) {
-               _W("Handles of client %s are full", get_client_name());
-               return MAX_HANDLE_REACHED;
-       }
-
-       handle_info.m_sensor_id = sensor;
-       handle_info.m_sensor_state = SENSOR_STATE_STOPPED;
-       handle_info.m_pause_policy = SENSORD_PAUSE_ALL;
-       handle_info.m_handle = handle;
-       handle_info.m_accuracy = -1;
-       handle_info.m_accuracy_cb = NULL;
-       handle_info.m_accuracy_user_data = NULL;
-
-       m_sensor_handle_infos.insert(pair<int, sensor_handle_info>(handle, handle_info));
-
-       return handle;
-}
-
-bool sensor_client_info::delete_handle(int handle)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       m_sensor_handle_infos.erase(it_handle);
-       return true;
-}
-
-bool sensor_client_info::is_active(void)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       return !m_sensor_handle_infos.empty();
-}
-
-bool sensor_client_info::register_event(int handle, unsigned int event_type,
-               unsigned int interval, unsigned int latency, void *cb, void* user_data)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       if (!it_handle->second.add_reg_event_info(event_type, interval, latency, cb, user_data))
-               return false;
-
-       return true;
-}
-
-bool sensor_client_info::unregister_event(int handle, unsigned int event_type)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       if (!it_handle->second.delete_reg_event_info(event_type))
-               return false;
-
-       return true;
-}
-
-bool sensor_client_info::register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       it_handle->second.m_accuracy = -1;
-       it_handle->second.m_accuracy_cb = cb;
-       it_handle->second.m_accuracy_user_data = user_data;
-
-       return true;
-}
-
-bool sensor_client_info::unregister_accuracy_cb(int handle)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       it_handle->second.m_accuracy = -1;
-       it_handle->second.m_accuracy_cb = NULL;
-       it_handle->second.m_accuracy_user_data = NULL;
-
-       return true;
-}
-
-bool sensor_client_info::set_sensor_params(int handle, int sensor_state, int pause_policy)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       it_handle->second.m_sensor_state = sensor_state;
-       it_handle->second.m_pause_policy = pause_policy;
-
-       return true;
-}
-
-bool sensor_client_info::get_sensor_params(int handle, int &sensor_state, int &pause_policy)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       sensor_state = it_handle->second.m_sensor_state;
-       pause_policy = it_handle->second.m_pause_policy;
-
-       return true;
-}
-
-bool sensor_client_info::set_sensor_state(int handle, int sensor_state)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       it_handle->second.m_sensor_state = sensor_state;
-
-       return true;
-}
-
-bool sensor_client_info::get_passive_mode(int handle)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       return it_handle->second.get_passive_mode();
-}
-
-bool sensor_client_info::set_passive_mode(int handle, bool passive)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       it_handle->second.set_passive_mode(passive);
-
-       return true;
-}
-
-bool sensor_client_info::set_sensor_pause_policy(int handle, int pause_policy)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       it_handle->second.m_pause_policy = pause_policy;
-
-       return true;
-}
-
-bool sensor_client_info::set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       if (!it_handle->second.change_reg_event_batch(event_type, interval, latency))
-               return false;
-
-       return true;
-}
-
-bool sensor_client_info::set_accuracy(int handle, int accuracy)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       it_handle->second.m_accuracy = accuracy;
-
-       return true;
-}
-
-bool sensor_client_info::set_bad_accuracy(int handle, int bad_accuracy)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       it_handle->second.m_bad_accuracy = bad_accuracy;
-
-       return true;
-}
-
-bool sensor_client_info::get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, void* &cb, void* &user_data)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       const reg_event_info *event_info;
-
-       event_info = it_handle->second.get_reg_event_info(event_type);
-
-       if (!event_info)
-               return NULL;
-
-       interval = event_info->m_interval;
-       cb = event_info->m_cb;
-       user_data = event_info->m_user_data;
-       latency = event_info->m_latency;
-
-       return true;
-}
-
-void sensor_client_info::get_listening_sensors(sensor_id_vector &sensors)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end()) {
-               sensors.push_back(it_handle->second.m_sensor_id);
-               ++it_handle;
-       }
-
-       sort(sensors.begin(), sensors.end());
-       unique(sensors.begin(), sensors.end());
-}
-
-void sensor_client_info::get_sensor_rep(sensor_id_t sensor, sensor_rep& rep) {
-       const unsigned int INVALID_BATCH_VALUE = std::numeric_limits<unsigned int>::max();
-
-       rep.active = is_sensor_active(sensor);
-       rep.pause_policy = get_active_pause_policy(sensor);
-       if (!get_active_batch(sensor, rep.interval, rep.latency)) {
-               rep.interval = INVALID_BATCH_VALUE;
-               rep.latency = INVALID_BATCH_VALUE;
-       }
-
-       get_active_event_types(sensor, rep.event_types);
-}
-
-bool sensor_client_info::add_command_channel(sensor_id_t sensor, command_channel *cmd_channel)
-{
-       auto it_channel = m_command_channels.find(sensor);
-
-       if (it_channel != m_command_channels.end()) {
-               _W("%s alreay has command_channel for %s", get_client_name(), get_sensor_name(sensor));
-               return false;
-       }
-
-       m_command_channels.insert(pair<sensor_id_t, command_channel *>(sensor, cmd_channel));
-
-       return true;
-}
-
-bool sensor_client_info::get_command_channel(sensor_id_t sensor, command_channel **cmd_channel)
-{
-       auto it_channel = m_command_channels.find(sensor);
-
-       if (it_channel == m_command_channels.end()) {
-               _W("%s doesn't have command_channel for %s", get_client_name(), get_sensor_name(sensor));
-               return false;
-       }
-
-       *cmd_channel = it_channel->second;
-
-       return true;
-}
-
-bool sensor_client_info::close_command_channel(void)
-{
-       auto it_channel = m_command_channels.begin();
-
-       if (it_channel != m_command_channels.end()) {
-               delete it_channel->second;
-               ++it_channel;
-       }
-
-       m_command_channels.clear();
-
-       return true;
-}
-
-bool sensor_client_info::close_command_channel(sensor_id_t sensor_id)
-{
-       auto it_channel = m_command_channels.find(sensor_id);
-
-       if (it_channel == m_command_channels.end()) {
-               _W("%s doesn't have command_channel for %s", get_client_name(), get_sensor_name(sensor_id));
-               return false;
-       }
-
-       delete it_channel->second;
-
-       m_command_channels.erase(it_channel);
-
-       return true;
-}
-
-bool sensor_client_info::has_client_id(void)
-{
-       return (m_client_id != CLIENT_ID_INVALID);
-}
-
-int sensor_client_info::get_client_id(void)
-{
-       return m_client_id;
-}
-
-void sensor_client_info::set_client_id(int client_id)
-{
-       m_client_id = client_id;
-}
-
-bool sensor_client_info::get_active_batch(sensor_id_t sensor, unsigned int &interval, unsigned int &latency)
-{
-       unsigned int min_interval = POLL_MAX_HZ_MS;
-       unsigned int min_latency = std::numeric_limits<unsigned int>::max();
-
-       unsigned int _interval;
-       unsigned int _latency;
-
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end()) {
-               if ((it_handle->second.m_sensor_id == sensor) &&
-                   it_handle->second.is_started()) {
-                       it_handle->second.get_batch(_interval, _latency);
-                       min_interval = (_interval < min_interval) ? _interval : min_interval;
-                       min_latency = (_latency < min_latency) ? _latency : min_latency;
-               }
-
-               ++it_handle;
-       }
-
-       if (!is_sensor_active(sensor)) {
-               _D("Active sensor[%#llx] is not found for client %s", sensor, get_client_name());
-               return false;
-       }
-
-       interval = min_interval;
-       latency = min_latency;
-
-       return true;
-}
-
-unsigned int sensor_client_info::get_active_pause_policy(sensor_id_t sensor)
-{
-       int active_pause = SENSORD_PAUSE_ALL;
-       int pause;
-
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end()) {
-               if ((it_handle->second.m_sensor_id == sensor) &&
-                   it_handle->second.is_started()) {
-                       pause = it_handle->second.m_pause_policy;
-                       active_pause = (pause < active_pause) ? pause: active_pause;
-               }
-
-               ++it_handle;
-       }
-
-       if (!is_sensor_active(sensor))
-               _D("Active sensor[%#llx] is not found for client %s", sensor, get_client_name());
-
-       return active_pause;
-}
-
-bool sensor_client_info::get_sensor_id(int handle, sensor_id_t &sensor)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       sensor = it_handle->second.m_sensor_id;
-
-       return true;
-}
-
-bool sensor_client_info::get_sensor_state(int handle, int &sensor_state)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       sensor_state = it_handle->second.m_sensor_state;
-
-       return true;
-}
-
-void sensor_client_info::get_active_event_types(sensor_id_t sensor, event_type_vector &active_event_types)
-{
-       event_type_vector event_types;
-
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end()) {
-               if ((it_handle->second.m_sensor_id == sensor) &&
-                   it_handle->second.is_started())
-                       it_handle->second.get_reg_event_types(event_types);
-
-               ++it_handle;
-       }
-
-       if (event_types.empty())
-               return;
-
-       sort(event_types.begin(), event_types.end());
-
-       unique_copy(event_types.begin(), event_types.end(), back_inserter(active_event_types));
-}
-
-void sensor_client_info::get_all_handles(handle_vector &handles)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end()) {
-               handles.push_back(it_handle->first);
-               ++it_handle;
-       }
-}
-
-void sensor_client_info::get_sensor_handle_info(sensor_id_t sensor, sensor_handle_info_map &handles_info)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end()) {
-               if (it_handle->second.m_sensor_id == sensor)
-                       handles_info.insert(pair<int, sensor_handle_info>(it_handle->first, it_handle->second));
-
-               ++it_handle;
-       }
-}
-
-void sensor_client_info::get_all_handle_info(sensor_handle_info_map &handles_info)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end()) {
-               handles_info.insert(pair<int, sensor_handle_info>(it_handle->first, it_handle->second));
-               ++it_handle;
-       }
-}
-
-bool sensor_client_info::is_sensor_registered(sensor_id_t sensor)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end()) {
-               if (it_handle->second.m_sensor_id == sensor)
-                       return true;
-
-               ++it_handle;
-       }
-
-       return false;
-}
-
-bool sensor_client_info::is_sensor_active(sensor_id_t sensor)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end()) {
-               if ((it_handle->second.m_sensor_id == sensor) &&
-                   it_handle->second.is_started())
-                       return true;
-
-               ++it_handle;
-       }
-
-       return false;
-}
-
-bool sensor_client_info::is_event_active(int handle, unsigned int event_type, unsigned long long event_id)
-{
-       reg_event_info *event_info;
-
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end())
-               return false;
-
-       event_info = it_handle->second.get_reg_event_info(event_type);
-       if (!event_info)
-               return false;
-
-       if (event_info->m_id != event_id)
-               return false;
-
-       return true;
-}
-
-void sensor_client_info::set_pause_policy(sensor_id_t sensor, int pause_policy)
-{
-       sensor_handle_info_map handles_info;
-
-       get_sensor_handle_info(sensor, handles_info);
-
-       for (auto it_handle = handles_info.begin(); it_handle != handles_info.end(); ++it_handle) {
-               if (it_handle->second.m_sensor_id != sensor)
-                       continue;
-
-               if (pause_policy && (it_handle->second.m_pause_policy & pause_policy)) {
-                       if (it_handle->second.m_sensor_state == SENSOR_STATE_STARTED) {
-                               set_sensor_state(it_handle->first, SENSOR_STATE_PAUSED);
-                               _I("%s's %s[%d] is paused", get_client_name(), get_sensor_name(sensor), it_handle->first);
-                       }
-               } else {
-                       if (it_handle->second.m_sensor_state == SENSOR_STATE_PAUSED) {
-                               set_sensor_state(it_handle->first, SENSOR_STATE_STARTED);
-                               _I("%s's %s[%d] is resumed", get_client_name(), get_sensor_name(sensor), it_handle->first);
-                       }
-               }
-       }
-}
-
-bool sensor_client_info::set_attribute(int handle, int attribute, int value)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       it_handle->second.attributes_int[attribute] = value;
-
-       return true;
-}
-
-bool sensor_client_info::set_attribute(int handle, int attribute, const char *value, int len)
-{
-       AUTOLOCK(m_handle_info_lock);
-
-       auto it_handle = m_sensor_handle_infos.find(handle);
-
-       if (it_handle == m_sensor_handle_infos.end()) {
-               _W("Handle[%d] is not found for client %s", handle, get_client_name());
-               return false;
-       }
-
-       auto it_attr = it_handle->second.attributes_str.find(attribute);
-
-       if (it_attr != it_handle->second.attributes_str.end()) {
-               it_attr->second->set(value, len);
-               return true;
-       }
-
-       attribute_info *info = new(std::nothrow) attribute_info();
-       retvm_if(!info, false, "Failed to allocate memory");
-
-       info->set(value, len);
-       it_handle->second.attributes_str[attribute] = info;
-
-       return true;
-}
-
-void sensor_client_info::clear(void)
-{
-       auto it_handle = m_sensor_handle_infos.begin();
-
-       while (it_handle != m_sensor_handle_infos.end())
-               it_handle->second.clear();
-
-       close_command_channel();
-       m_sensor_handle_infos.clear();
-       m_command_channels.clear();
-       set_client_id(CLIENT_ID_INVALID);
-}
diff --git a/src/client/sensor_client_info.h b/src/client/sensor_client_info.h
deleted file mode 100644 (file)
index 15f2677..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_CLIENT_INFO_H_
-#define _SENSOR_CLIENT_INFO_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <csocket.h>
-#include <string.h>
-#include <algorithm>
-#include <sstream>
-#include <unordered_map>
-#include <vector>
-#include <cmutex.h>
-#include <sensor_handle_info.h>
-#include <command_channel.h>
-
-typedef std::vector<unsigned int> handle_vector;
-typedef std::vector<sensor_id_t> sensor_id_vector;
-typedef std::unordered_map<int, sensor_handle_info> sensor_handle_info_map;
-typedef std::unordered_map<sensor_id_t, command_channel *> sensor_command_channel_map;
-
-typedef struct sensor_rep {
-       bool active;
-       int pause_policy;
-       unsigned int interval;
-       unsigned int latency;
-       event_type_vector event_types;
-} sensor_rep;
-
-class sensor_client_info {
-public:
-       static sensor_client_info& get_instance(void);
-       int create_handle(sensor_id_t sensor_id);
-       bool delete_handle(int handle);
-       bool register_event(int handle, unsigned int event_type,
-                       unsigned int interval, unsigned int latency, void *cb, void* user_data);
-       bool unregister_event(int handle, unsigned int event_type);
-
-       bool register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void* user_data);
-       bool unregister_accuracy_cb(int handle);
-
-       bool set_sensor_params(int handle, int sensor_state, int sensor_pause_policy);
-       bool get_sensor_params(int handle, int &sensor_state, int &sensor_pause_policy);
-       bool set_sensor_state(int handle, int sensor_state);
-
-       bool get_passive_mode(int handle);
-       bool set_passive_mode(int handle, bool passive);
-
-       bool set_attribute(int handle, int attribute, int value);
-       bool set_attribute(int handle, int attribute, const char *value, int len);
-
-       bool set_sensor_pause_policy(int handle, int pause_policy);
-       bool set_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency);
-       bool set_accuracy(int handle, int accuracy);
-       bool set_bad_accuracy(int handle, int bad_accuracy);
-       bool get_event_info(int handle, unsigned int event_type, unsigned int &interval, unsigned int &latency, void* &cb, void* &user_data);
-       void get_listening_sensors(sensor_id_vector &sensors);
-       void get_sensor_rep(sensor_id_t sensor, sensor_rep& rep);
-
-       bool get_active_batch(sensor_id_t sensor, unsigned int &interval, unsigned int &latency);
-       unsigned int get_active_pause_policy(sensor_id_t sensor_id);
-       void get_active_event_types(sensor_id_t sensor_id, event_type_vector &active_event_types);
-
-       bool get_sensor_id(int handle, sensor_id_t &sensor_id);
-       bool get_sensor_state(int handle, int &state);
-
-       bool has_client_id(void);
-       int get_client_id(void);
-       void set_client_id(int client_id);
-
-       bool is_active(void);
-       bool is_sensor_registered(sensor_id_t sensor_id);
-       bool is_sensor_active(sensor_id_t sensor_id);
-       bool is_event_active(int handle, unsigned int event_type, unsigned long long event_id);
-
-       bool add_command_channel(sensor_id_t sensor_id, command_channel *cmd_channel);
-       bool get_command_channel(sensor_id_t sensor_id, command_channel **cmd_channel);
-       bool close_command_channel(void);
-       bool close_command_channel(sensor_id_t sensor_id);
-
-       void get_all_handles(handle_vector &handles);
-       void get_sensor_handle_info(sensor_id_t sensor, sensor_handle_info_map &handles_info);
-       void get_all_handle_info(sensor_handle_info_map &handles_info);
-
-       void set_pause_policy(sensor_id_t sensor, int power_save_state);
-
-       void clear(void);
-
-       sensor_client_info();
-       ~sensor_client_info();
-
-private:
-       sensor_handle_info_map m_sensor_handle_infos;
-       sensor_command_channel_map m_command_channels;
-
-       int m_client_id;
-
-       cmutex m_handle_info_lock;
-};
-
-#endif /* _SENSOR_CLIENT_INFO_H_ */
diff --git a/src/client/sensor_event_listener.cpp b/src/client/sensor_event_listener.cpp
deleted file mode 100644 (file)
index fd11d4f..0000000
+++ /dev/null
@@ -1,477 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_event_listener.h>
-#include <client_common.h>
-#include <sensor_info_manager.h>
-
-#include <thread>
-#include <chrono>
-#include <vector>
-
-#include <sensor_types.h>
-
-/* TODO: this macro should be adjusted(4224 = 4096(data) + 128(header)) */
-#define EVENT_BUFFER_SIZE sizeof(sensor_event_t)
-
-using std::thread;
-using std::pair;
-using std::vector;
-
-struct free_data {
-       void operator()(void *data) {
-               free(data);
-       }
-};
-
-sensor_event_listener::sensor_event_listener()
-: m_poller(NULL)
-, m_thread_state(THREAD_STATE_TERMINATE)
-, m_hup_observer(NULL)
-, m_client_info(sensor_client_info::get_instance())
-, m_axis(SENSORD_AXIS_DISPLAY_ORIENTED)
-, m_display_rotation(AUTO_ROTATION_DEGREE_UNKNOWN)
-{
-}
-
-sensor_event_listener::~sensor_event_listener()
-{
-       stop_event_listener();
-}
-
-sensor_event_listener& sensor_event_listener::get_instance(void)
-{
-       static sensor_event_listener inst;
-       return inst;
-}
-
-client_callback_info* sensor_event_listener::handle_calibration_cb(sensor_handle_info &handle_info, unsigned event_type, unsigned long long time, int accuracy)
-{
-       unsigned int cal_event_type = get_calibration_event_type(event_type);
-       reg_event_info *event_info = NULL;
-       reg_event_info *cal_event_info = NULL;
-       client_callback_info* cal_callback_info = NULL;
-
-       if (!cal_event_type)
-               return NULL;
-
-       cal_event_info = handle_info.get_reg_event_info(cal_event_type);
-       if ((accuracy == SENSOR_ACCURACY_BAD) && !handle_info.m_bad_accuracy && cal_event_info) {
-               cal_event_info->m_previous_event_time = time;
-
-               event_info = handle_info.get_reg_event_info(event_type);
-               if (!event_info)
-                       return NULL;
-
-               sensor_data_t *cal_data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
-               retvm_if(!cal_data, NULL, "Failed to allocate memory");
-
-               cal_data->accuracy = accuracy;
-               cal_data->timestamp = time;
-               cal_data->values[0] = accuracy;
-               cal_data->value_count = 1;
-               std::shared_ptr<void> cal_sensor_data(cal_data, free_data());
-
-               cal_callback_info = get_callback_info(handle_info.m_sensor_id, cal_event_info, cal_sensor_data);
-
-               m_client_info.set_bad_accuracy(handle_info.m_handle, true);
-
-               print_event_occurrence_log(handle_info);
-       }
-
-       if ((accuracy != SENSOR_ACCURACY_BAD) && handle_info.m_bad_accuracy)
-               m_client_info.set_bad_accuracy(handle_info.m_handle, false);
-
-       return cal_callback_info;
-}
-
-void sensor_event_listener::handle_events(void* event)
-{
-       unsigned long long cur_time;
-       reg_event_info *event_info = NULL;
-       sensor_id_t sensor_id;
-       sensor_handle_info_map handles_info;
-
-       int accuracy = SENSOR_ACCURACY_GOOD;
-
-       unsigned int event_type = *((unsigned int *)(event));
-
-       client_callback_info* callback_info = NULL;
-
-       sensor_event_t *sensor_event = (sensor_event_t *)event;
-       sensor_id = sensor_event->sensor_id;
-       cur_time = sensor_event->data->timestamp;
-       accuracy = sensor_event->data->accuracy;
-
-       align_sensor_axis(sensor_id, sensor_event->data);
-
-       std::shared_ptr<void> sensor_data(sensor_event->data, free_data());
-
-       {       /* scope for the lock */
-               m_client_info.get_all_handle_info(handles_info);
-
-               for (auto it_handle = handles_info.begin(); it_handle != handles_info.end(); ++it_handle) {
-                       sensor_handle_info &sensor_handle_info = it_handle->second;
-
-                       event_info = sensor_handle_info.get_reg_event_info(event_type);
-                       if ((sensor_handle_info.m_sensor_id != sensor_id) ||
-                           !sensor_handle_info.is_started() ||
-                           !event_info)
-                               continue;
-
-                       if (event_info->m_fired)
-                               continue;
-
-                       event_info->m_previous_event_time = cur_time;
-
-                       client_callback_info* cal_callback_info = handle_calibration_cb(sensor_handle_info, event_type, cur_time, accuracy);
-
-                       if (cal_callback_info)
-                               m_cb_deliverer->push(cal_callback_info);
-
-                       callback_info = get_callback_info(sensor_id, event_info, sensor_data);
-
-                       if (!callback_info) {
-                               _E("Failed to get callback_info");
-                               continue;
-                       }
-
-                       if (sensor_handle_info.m_accuracy != accuracy) {
-                               m_client_info.set_accuracy(sensor_handle_info.m_handle, accuracy);
-
-                               callback_info->accuracy_cb = sensor_handle_info.m_accuracy_cb;
-                               callback_info->timestamp = cur_time;
-                               callback_info->accuracy = accuracy;
-                               callback_info->accuracy_user_data = sensor_handle_info.m_accuracy_user_data;
-                       }
-
-                       m_cb_deliverer->push(callback_info);
-
-                       print_event_occurrence_log(sensor_handle_info);
-               }
-       }
-}
-
-client_callback_info* sensor_event_listener::get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, std::shared_ptr<void> sensor_data)
-{
-       client_callback_info* callback_info;
-
-       callback_info = new(std::nothrow)client_callback_info;
-       retvm_if(!callback_info, NULL, "Failed to allocate memory");
-
-       callback_info->sensor = sensor_info_to_sensor(sensor_info_manager::get_instance().get_info(sensor_id));
-       callback_info->event_id = event_info->m_id;
-       callback_info->handle = event_info->m_handle;
-       callback_info->cb = (sensor_cb_t)(event_info->m_cb);
-       callback_info->event_type = event_info->type;
-       callback_info->user_data = event_info->m_user_data;
-       callback_info->accuracy_cb = NULL;
-       callback_info->timestamp = 0;
-       callback_info->accuracy = -1;
-       callback_info->accuracy_user_data = NULL;
-       callback_info->sensor_data = sensor_data;
-
-       return callback_info;
-}
-
-void sensor_event_listener::set_sensor_axis(int axis)
-{
-       m_axis = axis;
-}
-
-void sensor_event_listener::align_sensor_axis(sensor_id_t sensor, sensor_data_t *data)
-{
-       sensor_id_t type = CONVERT_ID_TYPE(sensor);
-
-       if (m_axis != SENSORD_AXIS_DISPLAY_ORIENTED)
-               return;
-
-       if (type != ACCELEROMETER_SENSOR && type != GYROSCOPE_SENSOR && type != GRAVITY_SENSOR && type != LINEAR_ACCEL_SENSOR)
-               return;
-
-       float x, y;
-
-       switch (m_display_rotation) {
-       case AUTO_ROTATION_DEGREE_90:   /* Landscape Left */
-               x = -data->values[1];
-               y = data->values[0];
-               break;
-       case AUTO_ROTATION_DEGREE_180:  /* Portrait Bottom */
-               x = -data->values[0];
-               y = -data->values[1];
-               break;
-       case AUTO_ROTATION_DEGREE_270:  /* Landscape Right */
-               x = data->values[1];
-               y = -data->values[0];
-               break;
-       default:
-               return;
-       }
-
-       data->values[0] = x;
-       data->values[1] = y;
-}
-
-ssize_t sensor_event_listener::sensor_event_poll(void* buffer, int buffer_len, struct epoll_event &event)
-{
-       ssize_t len;
-
-       len = m_event_socket.recv(buffer, buffer_len);
-
-       if (!len) {
-               if (!m_poller->poll(event))
-                       return -1;
-               len = m_event_socket.recv(buffer, buffer_len);
-
-               if (!len) {
-                       _E("%s failed to read after poll!", get_client_name());
-                       return -1;
-               }
-       }
-
-       if (len < 0) {
-               _E("%s failed to recv event from event socket", get_client_name());
-               return -1;
-       }
-
-       return len;
-}
-
-void sensor_event_listener::listen_events(void)
-{
-       char buffer[EVENT_BUFFER_SIZE];
-       struct epoll_event event;
-       ssize_t len = -1;
-
-       event.events = EPOLLIN | EPOLLPRI;
-
-       do {
-               void *buffer_data;
-               int data_len;
-
-               lock l(m_thread_mutex);
-               if (m_thread_state != THREAD_STATE_START)
-                       break;
-
-               len = sensor_event_poll(buffer, sizeof(sensor_event_t), event);
-               if (len <= 0) {
-                       _E("Failed to sensor_event_poll()");
-                       break;
-               }
-
-               sensor_event_t *sensor_event = reinterpret_cast<sensor_event_t *>(buffer);
-               data_len = sensor_event->data_length;
-
-               if (data_len == 0)
-                       continue;
-
-               buffer_data = malloc(data_len);
-
-               len = sensor_event_poll(buffer_data, data_len, event);
-               if (len <= 0) {
-                       _E("Failed to sensor_event_poll() for sensor_data");
-                       free(buffer_data);
-                       break;
-               }
-
-               sensor_event->data = reinterpret_cast<sensor_data_t *>(buffer_data);
-
-               handle_events((void *)buffer);
-       } while (true);
-
-       if (m_poller) {
-               delete m_poller;
-               m_poller = NULL;
-       }
-
-       close_event_channel();
-
-       { /* the scope for the lock */
-               lock l(m_thread_mutex);
-               m_thread_state = THREAD_STATE_TERMINATE;
-               m_thread_cond.notify_one();
-       }
-
-       _I("Event listener thread is terminated.");
-
-       if (m_client_info.has_client_id() && (event.events & EPOLLHUP)) {
-               if (m_hup_observer)
-                       m_hup_observer();
-       }
-}
-
-bool sensor_event_listener::create_event_channel(void)
-{
-       const int client_type = CLIENT_TYPE_SENSOR_CLIENT;
-       int client_id;
-       channel_ready_t event_channel_ready;
-
-       if (!m_event_socket.create(SOCK_SEQPACKET))
-               return false;
-
-       if (!m_event_socket.connect(EVENT_CHANNEL_PATH)) {
-               _E("Failed to connect event channel for client %s, event socket fd[%d]", get_client_name(), m_event_socket.get_socket_fd());
-               return false;
-       }
-
-       if (!m_event_socket.set_connection_mode()) {
-               _E("Failed to set connection mode for client %s", get_client_name());
-               return false;
-       }
-
-       if (m_event_socket.send(&client_type, sizeof(client_type)) <= 0) {
-               _E("Failed to send client type in client %s, event socket fd[%d]", get_client_name(), m_event_socket.get_socket_fd());
-               return false;
-       }
-
-       client_id = m_client_info.get_client_id();
-
-       if (m_event_socket.send(&client_id, sizeof(client_id)) <= 0) {
-               _E("Failed to send client id for client %s on event socket[%d]", get_client_name(), m_event_socket.get_socket_fd());
-               return false;
-       }
-
-       if (m_event_socket.recv(&event_channel_ready, sizeof(event_channel_ready)) <= 0) {
-               _E("%s failed to recv event_channel_ready packet on event socket[%d] with client id [%d]",
-                       get_client_name(), m_event_socket.get_socket_fd(), client_id);
-               return false;
-       }
-
-       if ((event_channel_ready.magic != CHANNEL_MAGIC_NUM) || (event_channel_ready.client_id != client_id)) {
-               _E("Event_channel_ready packet is wrong, magic = %#x, client id = %d",
-                       event_channel_ready.magic, event_channel_ready.client_id);
-               return false;
-       }
-
-       _I("Event channel is established for client %s on socket[%d] with client id : %d",
-               get_client_name(), m_event_socket.get_socket_fd(), client_id);
-
-       return true;
-}
-
-void sensor_event_listener::close_event_channel(void)
-{
-       m_event_socket.close();
-}
-
-void sensor_event_listener::set_thread_state(thread_state state)
-{
-       lock l(m_thread_mutex);
-       m_thread_state = state;
-}
-
-void sensor_event_listener::clear(void)
-{
-       close_event_channel();
-       stop_event_listener();
-       m_client_info.close_command_channel();
-       m_client_info.clear();
-       m_client_info.set_client_id(CLIENT_ID_INVALID);
-}
-
-void sensor_event_listener::set_hup_observer(hup_observer_t observer)
-{
-       m_hup_observer = observer;
-}
-
-bool sensor_event_listener::start_event_listener(void)
-{
-       if (!create_event_channel()) {
-               _E("Event channel is not established for %s", get_client_name());
-               return false;
-       }
-
-       if (!start_deliverer())
-               return false;
-
-       m_event_socket.set_transfer_mode();
-
-       m_poller = new(std::nothrow) poller(m_event_socket.get_socket_fd());
-       retvm_if(!m_poller, false, "Failed to allocate memory");
-
-       set_thread_state(THREAD_STATE_START);
-
-       thread listener(&sensor_event_listener::listen_events, this);
-       listener.detach();
-
-       return true;
-}
-
-void sensor_event_listener::stop_event_listener(void)
-{
-       const int THREAD_TERMINATING_TIMEOUT = 2;
-       std::cv_status status;
-
-       ulock u(m_thread_mutex);
-
-       /* TOBE: it can be changed to join() simply */
-       if (m_thread_state != THREAD_STATE_TERMINATE) {
-               m_thread_state = THREAD_STATE_STOP;
-
-               _D("%s is waiting listener thread[state: %d] to be terminated", get_client_name(), m_thread_state);
-
-               status = m_thread_cond.wait_for(u, std::chrono::seconds(THREAD_TERMINATING_TIMEOUT));
-               if (status == std::cv_status::timeout)
-                       _E("Fail to stop listener thread after waiting %d seconds", THREAD_TERMINATING_TIMEOUT);
-               else
-                       _D("Listener thread for %s is terminated", get_client_name());
-       }
-
-       if (m_poller) {
-               delete m_poller;
-               m_poller = NULL;
-       }
-
-       stop_deliverer();
-       close_event_channel();
-}
-
-bool sensor_event_listener::start_deliverer(void)
-{
-       if (!m_cb_deliverer) {
-               m_cb_deliverer = new(std::nothrow) sensor_callback_deliverer();
-               retvm_if(!m_cb_deliverer, false, "Failed to allocated memory");
-       }
-
-       m_cb_deliverer->start();
-       return true;
-}
-
-bool sensor_event_listener::stop_deliverer(void)
-{
-       if (!m_cb_deliverer)
-               return false;
-
-       if (!m_cb_deliverer->stop())
-               return false;
-
-       delete m_cb_deliverer;
-       m_cb_deliverer = NULL;
-       return true;
-}
-
-void sensor_event_listener::set_display_rotation(int rt)
-{
-       _D("New display rotation: %d", rt);
-
-       if (rt < AUTO_ROTATION_DEGREE_0 || rt > AUTO_ROTATION_DEGREE_270)
-               return;
-
-       m_display_rotation = rt;
-}
diff --git a/src/client/sensor_event_listener.h b/src/client/sensor_event_listener.h
deleted file mode 100644 (file)
index 63dd6d9..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_EVENT_LISTENER_H_
-#define _SENSOR_EVENT_LISTENER_H_
-
-#include <glib.h>
-#include <sys/types.h>
-#include <sys/epoll.h>
-#include <unistd.h>
-#include <csocket.h>
-#include <string.h>
-#include <algorithm>
-#include <sstream>
-#include <unordered_map>
-#include <vector>
-#include <string>
-#include <queue>
-#include <mutex>
-#include <condition_variable>
-#include <memory>
-#include <cmutex.h>
-#include <poller.h>
-
-#include <sensor_handle_info.h>
-#include <sensor_client_info.h>
-#include <command_channel.h>
-#include <sensor_callback_deliverer.h>
-
-typedef std::vector<unsigned int> handle_vector;
-typedef std::vector<sensor_id_t> sensor_id_vector;
-typedef std::unordered_map<int, sensor_handle_info> sensor_handle_info_map;
-typedef std::unordered_map<sensor_id_t, command_channel*> sensor_command_channel_map;
-
-typedef void (*hup_observer_t)(void);
-
-class sensor_event_listener {
-public:
-       static sensor_event_listener& get_instance(void);
-
-       void get_listening_sensors(sensor_id_vector &sensors);
-
-       bool start_event_listener(void);
-       void stop_event_listener(void);
-       void clear(void);
-
-       void set_hup_observer(hup_observer_t observer);
-
-       void set_sensor_axis(int axis);
-       void set_display_rotation(int rt);
-
-private:
-       enum thread_state {
-               THREAD_STATE_START,
-               THREAD_STATE_STOP,
-               THREAD_STATE_TERMINATE,
-       };
-       typedef std::lock_guard<std::mutex> lock;
-       typedef std::unique_lock<std::mutex> ulock;
-
-       csocket m_event_socket;
-       poller *m_poller;
-
-       thread_state m_thread_state;
-       std::mutex m_thread_mutex;
-       std::condition_variable m_thread_cond;
-
-       hup_observer_t m_hup_observer;
-
-       sensor_client_info &m_client_info;
-
-       sensor_callback_deliverer *m_cb_deliverer;
-
-       /* WC1's rotation control */
-       /* SENSORD_AXIS_DEVICE_ORIENTED, SENSORD_AXIS_DISPLAY_ORIENTED */
-       int m_axis;
-       int m_display_rotation;
-
-       sensor_event_listener();
-       ~sensor_event_listener();
-
-       bool create_event_channel(void);
-       void close_event_channel(void);
-
-       ssize_t sensor_event_poll(void *buffer, int buffer_len, struct epoll_event &event);
-
-       void listen_events(void);
-       void handle_events(void* event);
-
-       client_callback_info* handle_calibration_cb(sensor_handle_info &handle_info, unsigned event_type, unsigned long long time, int accuracy);
-       client_callback_info* get_callback_info(sensor_id_t sensor_id, const reg_event_info *event_info, std::shared_ptr<void> sensor_data);
-
-       unsigned long long renew_event_id(void);
-
-       void set_thread_state(thread_state state);
-
-       /* WC1's sensor axis alignment */
-       void align_sensor_axis(sensor_id_t sensor, sensor_data_t *data);
-
-       bool start_deliverer(void);
-       bool stop_deliverer(void);
-};
-
-#endif /* _SENSOR_EVENT_LISTENER_H_ */
diff --git a/src/client/sensor_handle_info.cpp b/src/client/sensor_handle_info.cpp
deleted file mode 100644 (file)
index 5f10930..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <client_common.h>
-#include <sensor_handle_info.h>
-#include <limits>
-
-using std::pair;
-
-unsigned long long sensor_handle_info::m_event_id = 0;
-
-attribute_info::attribute_info()
-: m_attr(NULL)
-, m_len(0)
-{
-}
-
-attribute_info::~attribute_info()
-{
-       if (m_attr) {
-               delete m_attr;
-               m_attr = NULL;
-       }
-       m_len = 0;
-}
-
-bool attribute_info::set(const char *value, int len)
-{
-       retvm_if(len < 0, false, "Invalid length");
-
-       if (m_attr)
-               delete m_attr;
-
-       m_attr = new(std::nothrow) char[len];
-       retvm_if(!m_attr, false, "Failed to allocate memory");
-
-       memcpy(m_attr, value, (unsigned int)len);
-       m_len = len;
-
-       return true;
-}
-
-char *attribute_info::get(void)
-{
-       return m_attr;
-}
-
-unsigned int attribute_info::size(void)
-{
-       return m_len;
-}
-
-sensor_handle_info::sensor_handle_info()
-: m_handle(0)
-, m_sensor_id(UNKNOWN_SENSOR)
-, m_sensor_state(SENSOR_STATE_UNKNOWN)
-, m_pause_policy(SENSORD_PAUSE_ALL)
-, m_bad_accuracy(false)
-, m_accuracy(-1)
-, m_accuracy_cb(NULL)
-, m_accuracy_user_data(NULL)
-, m_passive(false)
-{
-}
-
-sensor_handle_info::~sensor_handle_info()
-{
-       clear_all_events();
-}
-
-reg_event_info* sensor_handle_info::get_reg_event_info(unsigned int event_type)
-{
-       auto it_event = m_reg_event_infos.find(event_type);
-
-       if (it_event == m_reg_event_infos.end())
-               return NULL;
-
-       return &(it_event->second);
-}
-
-void sensor_handle_info::get_reg_event_types(event_type_vector &event_types)
-{
-       auto it_event = m_reg_event_infos.begin();
-
-       while (it_event != m_reg_event_infos.end()) {
-               event_types.push_back(it_event->first);
-               ++it_event;
-       }
-}
-
-bool sensor_handle_info::add_reg_event_info(unsigned int event_type, unsigned int interval, unsigned int latency, void *cb, void *user_data)
-{
-       reg_event_info event_info;
-
-       auto it_event = m_reg_event_infos.find(event_type);
-
-       if (it_event != m_reg_event_infos.end()) {
-               _E("Event %s[%#x] is already registered for client %s", get_event_name(event_type), event_type, get_client_name());
-               return false;
-       }
-
-       event_info.m_id = renew_event_id();
-       event_info.m_handle = m_handle;
-       event_info.type = event_type;
-       event_info.m_interval = interval;
-       event_info.m_latency = latency;
-       event_info.m_cb = cb;
-       event_info.m_user_data = user_data;
-
-       m_reg_event_infos.insert(pair<unsigned int, reg_event_info>(event_type, event_info));
-
-       return true;
-}
-
-bool sensor_handle_info::delete_reg_event_info(unsigned int event_type)
-{
-       auto it_event = m_reg_event_infos.find(event_type);
-
-       if (it_event == m_reg_event_infos.end()) {
-               _E("Event %s[%#x] is not registered for client %s", get_event_name(event_type), event_type, get_client_name());
-               return false;
-       }
-
-       m_reg_event_infos.erase(it_event);
-
-       return true;
-}
-
-void sensor_handle_info::clear(void)
-{
-       sensor_attribute_str_map::iterator it_attr;
-
-       for (it_attr = attributes_str.begin(); it_attr != attributes_str.end(); ++it_attr)
-               delete it_attr->second;
-
-       attributes_int.clear();
-       attributes_str.clear();
-}
-
-void sensor_handle_info::clear_all_events(void)
-{
-       m_reg_event_infos.clear();
-}
-
-unsigned long long sensor_handle_info::renew_event_id(void)
-{
-       return m_event_id++;
-}
-
-bool sensor_handle_info::change_reg_event_batch(unsigned int event_type, unsigned int interval, unsigned int latency)
-{
-       auto it_event = m_reg_event_infos.find(event_type);
-
-       if (it_event == m_reg_event_infos.end()) {
-               _E("Event %s[%#x] is not registered for client %s", get_event_name(event_type), event_type, get_client_name());
-               return false;
-       }
-
-       it_event->second.m_id = renew_event_id();
-       it_event->second.m_interval = interval;
-       it_event->second.m_latency = latency;
-
-       return true;
-}
-
-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_10HZ_MS;
-               latency = 0;
-               return;
-       }
-
-       unsigned int min_interval = POLL_MAX_HZ_MS;
-       unsigned int min_latency = std::numeric_limits<unsigned int>::max();
-
-       unsigned int _interval;
-       unsigned int _latency;
-
-       auto it_event = m_reg_event_infos.begin();
-
-       while (it_event != m_reg_event_infos.end()) {
-               _interval = it_event->second.m_interval;
-               _latency = it_event->second.m_latency;
-
-               min_interval = (_interval < min_interval) ? _interval : min_interval;
-               min_latency = (_latency < min_latency) ? _latency : min_latency;
-               ++it_event;
-       }
-
-       interval = min_interval;
-       latency = min_latency;
-}
-
-unsigned int sensor_handle_info::get_reg_event_count(void)
-{
-       return m_reg_event_infos.size();
-}
-
-bool sensor_handle_info::get_passive_mode(void)
-{
-       return m_passive;
-}
-
-void sensor_handle_info::set_passive_mode(bool passive)
-{
-       m_passive = passive;
-}
-
-bool sensor_handle_info::is_started(void)
-{
-       return (m_sensor_state == SENSOR_STATE_STARTED) || m_passive;
-}
diff --git a/src/client/sensor_handle_info.h b/src/client/sensor_handle_info.h
deleted file mode 100644 (file)
index 6ede304..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#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 <string>
-#include <map>
-
-class attribute_info {
-public:
-       attribute_info();
-       ~attribute_info();
-
-       char *get(void);
-       bool set(const char *value, int len);
-
-       unsigned int size(void);
-
-private:
-       char *m_attr;
-       unsigned int m_len;
-};
-
-typedef std::unordered_map<unsigned int, reg_event_info> event_info_map;
-typedef std::map<int, int> sensor_attribute_int_map;
-typedef std::map<int, attribute_info *> sensor_attribute_str_map;
-
-class sensor_handle_info {
-public:
-       sensor_handle_info();
-       ~sensor_handle_info();
-
-       bool add_reg_event_info(unsigned int event_type, unsigned int interval, unsigned int latency, void *cb, void *user_data);
-       bool delete_reg_event_info(unsigned int event_type);
-
-       bool change_reg_event_batch(unsigned int event_type, unsigned int interval, unsigned int latency);
-
-       reg_event_info* get_reg_event_info(const unsigned int event_type);
-       void get_reg_event_types(event_type_vector &event_types);
-       void get_batch(unsigned int &interval, unsigned int &latency);
-       unsigned int get_reg_event_count(void);
-
-       void clear(void);
-       void clear_all_events(void);
-       static unsigned long long renew_event_id(void);
-
-       bool get_passive_mode(void);
-       void set_passive_mode(bool passive);
-       bool is_started(void);
-
-       int m_handle;
-       sensor_id_t m_sensor_id;
-       int m_sensor_state;
-       int m_pause_policy;
-       int m_bad_accuracy;
-       int m_accuracy;
-       sensor_accuracy_changed_cb_t m_accuracy_cb;
-       void *m_accuracy_user_data;
-       bool m_passive;
-       sensor_attribute_int_map attributes_int;
-       sensor_attribute_str_map attributes_str;
-
-private:
-       event_info_map m_reg_event_infos;
-       static unsigned long long m_event_id;
-};
-
-#endif /* _SENSOR_HANDLE_INFO_H_ */
diff --git a/src/client/sensor_info_manager.cpp b/src/client/sensor_info_manager.cpp
deleted file mode 100644 (file)
index a7a7810..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_info_manager.h>
-#include <utility>
-#include <vector>
-
-using std::pair;
-using std::make_pair;
-using std::vector;
-
-sensor_info_manager::sensor_info_manager()
-{
-}
-
-sensor_info_manager::~sensor_info_manager()
-{
-       auto it_info = m_sensor_infos.begin();
-
-       while (it_info != m_sensor_infos.end()) {
-               delete it_info->second;
-               ++it_info;
-       }
-}
-
-sensor_info_manager& sensor_info_manager::get_instance(void)
-{
-       static sensor_info_manager inst;
-       return inst;
-}
-
-const sensor_info* sensor_info_manager::get_info(sensor_type_t type)
-{
-       auto it_info = m_sensor_infos.find(type);
-
-       if (it_info == m_sensor_infos.end())
-               return NULL;
-
-       return it_info->second;
-}
-
-void sensor_info_manager::add_info(sensor_info* info)
-{
-       m_sensor_infos.insert(make_pair(info->get_type(), info));
-       m_id_to_info_map.insert(make_pair(info->get_id(), info));
-       m_info_set.insert(info);
-}
-
-vector<sensor_info *> sensor_info_manager::get_infos(sensor_type_t type)
-{
-       vector<sensor_info *> sensor_infos;
-
-       pair<sensor_infos::iterator, sensor_infos::iterator> ret;
-
-       if (type == ALL_SENSOR)
-               ret = std::make_pair(m_sensor_infos.begin(), m_sensor_infos.end());
-       else
-               ret = m_sensor_infos.equal_range(type);
-
-       for (auto it_info = ret.first; it_info != ret.second; ++it_info)
-               sensor_infos.push_back(it_info->second);
-
-       return sensor_infos;
-}
-
-const sensor_info* sensor_info_manager::get_info(sensor_id_t id)
-{
-       auto it_info = m_id_to_info_map.find(id);
-
-       if (it_info == m_id_to_info_map.end())
-               return NULL;
-
-       return it_info->second;
-}
-
-bool sensor_info_manager::is_valid(sensor_info* info)
-{
-       auto it_info = m_info_set.find(info);
-
-       if (it_info == m_info_set.end())
-               return false;
-
-       return true;
-}
diff --git a/src/client/sensor_info_manager.h b/src/client/sensor_info_manager.h
deleted file mode 100644 (file)
index 86fa8fe..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_INFO_MANAGER_H_
-#define _SENSOR_INFO_MANAGER_H_
-
-#include <sensor_common.h>
-#include <sensor_info.h>
-#include <map>
-#include <unordered_map>
-#include <unordered_set>
-
-class sensor_info_manager {
-public:
-       static sensor_info_manager& get_instance(void);
-       const sensor_info* get_info(sensor_type_t type);
-       std::vector<sensor_info *> get_infos(sensor_type_t type);
-       const sensor_info* get_info(sensor_id_t id);
-       bool is_valid(sensor_info* info);
-       void add_info(sensor_info* info);
-
-private:
-       typedef std::multimap<sensor_type_t, sensor_info*> sensor_infos;
-       typedef std::unordered_map<sensor_id_t, sensor_info*> id_to_info_map;
-       typedef std::unordered_set<sensor_info*> info_set;
-
-       sensor_info_manager();
-       ~sensor_info_manager();
-
-       sensor_info_manager(const sensor_info_manager&) {};
-       sensor_info_manager& operator=(const sensor_info_manager&);
-
-       sensor_infos m_sensor_infos;
-       id_to_info_map m_id_to_info_map;
-       info_set m_info_set;
-};
-
-#endif /* _SENSOR_INFO_MANAGER_H_ */
index 272b547..0339c23 100644 (file)
@@ -2,15 +2,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 PROJECT(sensors CXX)
 INCLUDE(GNUInstallDirs)
 
-SET(HRM "ON")
+SET(ACC "OFF")
+SET(HRM "OFF")
 SET(HRM_VIRT "OFF")
-SET(AUTO_ROTATION "ON")
-SET(GRAVITY "ON")
-SET(LINEAR_ACCEL "ON")
-SET(RV "ON")
-SET(ORIENTATION "ON")
-SET(FACE_DOWN "ON")
-SET(SENSORHUB "ON")
+SET(AUTO_ROTATION "OFF")
+SET(GRAVITY "OFF")
+SET(LINEAR_ACCEL "OFF")
+SET(RV "OFF")
+SET(ORIENTATION "OFF")
+SET(FACE_DOWN "OFF")
+SET(SENSORHUB "OFF")
 
 INCLUDE_DIRECTORIES(
        ${CMAKE_SOURCE_DIR}/src/shared
@@ -21,9 +22,11 @@ INCLUDE_DIRECTORIES(
 FILE(GLOB SENSOR_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
 SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR})
 
+IF("${ACC}" STREQUAL "ON")
 FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/accel/*.cpp)
 SET(SENSOR_HEADERS ${SENSOR_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/accel)
 SET(SENSOR_DEFINITIONS ${SENSOR_DEFINITIONS} "-DENABLE_ACCEL")
+ENDIF()
 
 IF("${HRM}" STREQUAL "ON")
        FILE(GLOB_RECURSE SENSOR_SRCS ${SENSOR_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/hrm/*.cpp)
diff --git a/src/server/client_info_manager.cpp b/src/server/client_info_manager.cpp
deleted file mode 100644 (file)
index 4a72308..0000000
+++ /dev/null
@@ -1,438 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <command_common.h>
-#include <client_info_manager.h>
-#include <sensor_log.h>
-#include <csocket.h>
-
-using std::pair;
-using std::string;
-
-client_info_manager::client_info_manager()
-{
-}
-
-client_info_manager::~client_info_manager()
-{
-       AUTOLOCK(m_mutex);
-
-       m_clients.clear();
-}
-
-client_info_manager& client_info_manager::get_instance(void)
-{
-       static client_info_manager inst;
-       return inst;
-}
-
-bool client_info_manager::get_registered_events(int client_id, sensor_id_t sensor_id, event_type_vector &event_vec)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       if (!it_record->second.get_registered_events(sensor_id, event_vec))
-               return false;
-
-       return true;
-}
-
-bool client_info_manager::register_event(int client_id, sensor_id_t sensor_id, unsigned int event_type)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       if (!it_record->second.register_event(sensor_id, event_type))
-               return false;
-
-       return true;
-}
-
-bool client_info_manager::unregister_event(int client_id, sensor_id_t sensor_id, unsigned int event_type)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       if (!it_record->second.unregister_event(sensor_id, event_type))
-               return false;
-
-       return true;
-}
-
-bool client_info_manager::set_batch(int client_id, sensor_id_t sensor_id, unsigned int interval, unsigned latency)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       return it_record->second.set_batch(sensor_id, interval, latency);
-}
-
-bool client_info_manager::get_batch(int client_id, sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       return it_record->second.get_batch(sensor_id, interval, latency);
-}
-
-bool client_info_manager::set_pause_policy(int client_id, sensor_id_t sensor_id, int pause_policy)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       if (!it_record->second.set_pause_policy(sensor_id, pause_policy))
-               return false;
-
-       return true;
-}
-
-bool client_info_manager::set_start(int client_id, sensor_id_t sensor_id, bool start)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       if (!it_record->second.set_start(sensor_id, start))
-               return false;
-
-       return true;
-}
-
-bool client_info_manager::is_started(int client_id, sensor_id_t sensor_id)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       return it_record->second.is_started(sensor_id);
-}
-
-int client_info_manager::create_client_record(void)
-{
-       AUTOLOCK(m_mutex);
-
-       int client_id = 0;
-
-       client_sensor_record client_record;
-
-       while (m_clients.count(client_id) > 0)
-               client_id++;
-
-       if (client_id == MAX_HANDLE) {
-               _E("Sensor records of clients are full");
-               return MAX_HANDLE_REACHED;
-       }
-
-       client_record.set_client_id(client_id);
-
-       m_clients.insert(pair<int, client_sensor_record>(client_id, client_record));
-
-       return client_id;
-}
-
-bool client_info_manager::remove_client_record(int client_id)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       m_clients.erase(it_record);
-
-       _I("Client record for client[%d] is removed from client info manager", client_id);
-
-       return true;
-}
-
-bool client_info_manager::has_client_record(int client_id)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       return (it_record != m_clients.end());
-}
-
-void client_info_manager::set_client_info(int client_id, pid_t pid, const string &name)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return;
-       }
-
-       it_record->second.set_client_info(pid, name);
-
-       return;
-}
-
-const char* client_info_manager::get_client_info(int client_id)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), NULL, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _D("Client[%d] is not found", client_id);
-               return NULL;
-       }
-
-       return it_record->second.get_client_info();
-}
-
-bool client_info_manager::set_permission(int client_id, int permission)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _D("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       it_record->second.set_permission(permission);
-       return true;
-}
-
-bool client_info_manager::get_permission(int client_id, int &permission)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _D("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       permission = it_record->second.get_permission();
-       return true;
-}
-
-bool client_info_manager::create_sensor_record(int client_id, sensor_id_t sensor_id)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client record[%d] is not registered", client_id);
-               return false;
-       }
-
-       it_record->second.add_sensor_usage(sensor_id);
-
-       return true;
-}
-
-bool client_info_manager::remove_sensor_record(int client_id, sensor_id_t sensor_id)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       if (!it_record->second.remove_sensor_usage(sensor_id))
-               return false;
-
-       if (!it_record->second.has_sensor_usage())
-               remove_client_record(client_id);
-
-       return true;
-}
-
-bool client_info_manager::has_sensor_record(int client_id, sensor_id_t sensor_id)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _D("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       if (!it_record->second.has_sensor_usage(sensor_id))
-               return false;
-
-       return true;
-}
-
-bool client_info_manager::has_sensor_record(int client_id)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _D("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       if (!it_record->second.has_sensor_usage())
-               return false;
-
-       return true;
-}
-
-bool client_info_manager::get_listener_ids(sensor_id_t sensor_id, unsigned int event_type, client_id_vec &id_vec)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.begin();
-
-       while (it_record != m_clients.end()) {
-               if (it_record->second.is_listening_event(sensor_id, event_type))
-                       id_vec.push_back(it_record->first);
-
-               ++it_record;
-       }
-
-       return true;
-}
-
-bool client_info_manager::get_event_socket(int client_id, csocket &socket)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       it_record->second.get_event_socket(socket);
-
-       return true;
-}
-
-bool client_info_manager::set_event_socket(int client_id, const csocket &socket)
-{
-       AUTOLOCK(m_mutex);
-
-       retvm_if(m_clients.empty(), false, "client list is empty");
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       it_record->second.set_event_socket(socket);
-
-       return true;
-}
diff --git a/src/server/client_info_manager.h b/src/server/client_info_manager.h
deleted file mode 100644 (file)
index ad7add8..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _CLIENT_INFO_MANAGER_H_
-#define _CLIENT_INFO_MANAGER_H_
-
-#include <client_sensor_record.h>
-#include <unordered_map>
-#include <sensor_log.h>
-#include <cmutex.h>
-#include <vector>
-
-typedef std::unordered_map<int, client_sensor_record> client_id_sensor_record_map;
-typedef std::vector<int> client_id_vec;
-
-class client_info_manager {
-public:
-       static client_info_manager& get_instance(void);
-       int create_client_record(void);
-       bool remove_client_record(int client_id);
-       bool has_client_record(int client_id);
-
-       void set_client_info(int client_id, pid_t pid, const std::string &name);
-       const char* get_client_info(int client_id);
-
-       bool set_permission(int client_id, int permission);
-       bool get_permission(int client_id, int &permission);
-
-       bool create_sensor_record(int client_id, sensor_id_t sensor_id);
-       bool remove_sensor_record(int client_id, sensor_id_t sensor_id);
-       bool has_sensor_record(int client_id, sensor_id_t sensor_id);
-       bool has_sensor_record(int client_id);
-
-       bool register_event(int client_id, sensor_id_t sensor_id, unsigned int event_type);
-       bool unregister_event(int client_id, sensor_id_t sensor_id, unsigned int event_type);
-
-       bool set_batch(int client_id, sensor_id_t sensor_id, unsigned int interval, unsigned int latency);
-       bool get_batch(int client_id, sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency);
-       bool set_pause_policy(int client_id, sensor_id_t sensor_id, int pause_policy);
-
-       bool set_start(int client_id, sensor_id_t sensor_id, bool start);
-       bool is_started(int client_id, sensor_id_t sensor_id);
-
-       bool get_registered_events(int client_id, sensor_id_t sensor_id, event_type_vector &event_vec);
-
-       bool get_listener_ids(sensor_id_t sensor_id, unsigned int event_type, client_id_vec &id_vec);
-       bool get_event_socket(int client_id, csocket &sock);
-       bool set_event_socket(int client_id, const csocket &sock);
-private:
-       client_id_sensor_record_map m_clients;
-       cmutex m_mutex;
-
-       client_info_manager();
-       ~client_info_manager();
-       client_info_manager(client_info_manager const&) {};
-       client_info_manager& operator=(client_info_manager const&);
-};
-
-#endif /* _CLIENT_INFO_MANAGER_H_ */
diff --git a/src/server/client_sensor_record.cpp b/src/server/client_sensor_record.cpp
deleted file mode 100644 (file)
index 8eeafca..0000000
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <client_sensor_record.h>
-#include <sensor_log.h>
-
-using std::pair;
-using std::string;
-
-client_sensor_record::client_sensor_record()
-: m_client_id(0)
-, m_pid(-1)
-, m_permission(SENSOR_PERMISSION_NONE)
-{
-}
-
-client_sensor_record::~client_sensor_record()
-{
-       m_sensor_usages.clear();
-       close_event_socket();
-}
-
-bool client_sensor_record::register_event(sensor_id_t sensor_id, unsigned int event_type)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end()) {
-               sensor_usage usage;
-               usage.register_event(event_type);
-               m_sensor_usages.insert(pair<sensor_id_t, sensor_usage>(sensor_id, usage));
-               return true;
-       }
-
-       if (!it_usage->second.register_event(event_type)) {
-               _E("Event[%#x] is already registered", event_type);
-               return false;
-       }
-
-       return true;
-}
-
-bool client_sensor_record::unregister_event(sensor_id_t sensor_id, unsigned int event_type)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end()) {
-               _E("Sensor[%#x] is not registered", sensor_id);
-               return false;
-       }
-
-       if (!it_usage->second.unregister_event(event_type)) {
-               _E("Event[%#x] is already registered", event_type);
-               return false;
-       }
-
-       return true;
-}
-
-bool client_sensor_record::set_pause_policy(sensor_id_t sensor_id, int pause_policy)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end()) {
-               sensor_usage usage;
-               usage.m_pause_policy = pause_policy;
-               m_sensor_usages.insert(pair<sensor_id_t, sensor_usage>(sensor_id, usage));
-       } else {
-               it_usage->second.m_pause_policy = pause_policy;
-       }
-
-       return true;
-}
-
-bool client_sensor_record::set_start(sensor_id_t sensor_id, bool start)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end()) {
-               sensor_usage usage;
-               usage.m_start = start;
-               m_sensor_usages.insert(pair<sensor_id_t, sensor_usage>(sensor_id, usage));
-       } else {
-               it_usage->second.m_start = start;
-       }
-
-       return true;
-}
-
-bool client_sensor_record::is_started(sensor_id_t sensor_id)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end())
-               return false;
-
-       return it_usage->second.m_start;
-}
-
-bool client_sensor_record::set_batch(sensor_id_t sensor_id, unsigned int interval, unsigned int latency)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end()) {
-               sensor_usage usage;
-               usage.m_interval = interval;
-               usage.m_latency = latency;
-               m_sensor_usages.insert(pair<sensor_id_t, sensor_usage>(sensor_id, usage));
-       } else {
-               it_usage->second.m_interval = interval;
-               it_usage->second.m_latency = latency;
-       }
-
-       return true;
-}
-
-bool client_sensor_record::get_batch(sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end()) {
-               _E("Sensor[%#x] is not found", sensor_id);
-               return false;
-       }
-
-       interval = it_usage->second.m_interval;
-       latency = it_usage->second.m_latency;
-
-       return true;
-}
-
-bool client_sensor_record::is_listening_event(sensor_id_t sensor_id, unsigned int event_type)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end())
-               return false;
-
-       if (it_usage->second.is_event_registered(event_type))
-               return true;
-
-       return false;
-}
-
-bool client_sensor_record::add_sensor_usage(sensor_id_t sensor_id)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage != m_sensor_usages.end()) {
-               _E("Sensor[%#x] is already registered", sensor_id);
-               return false;
-       }
-
-       sensor_usage usage;
-       m_sensor_usages.insert(pair<sensor_id_t, sensor_usage>(sensor_id, usage));
-       return true;
-}
-
-bool client_sensor_record::remove_sensor_usage(sensor_id_t sensor_id)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end()) {
-               _E("Sensor[%#x] is not found", sensor_id);
-               return false;
-       }
-       m_sensor_usages.erase(it_usage);
-       return true;
-}
-
-bool client_sensor_record::has_sensor_usage(void)
-{
-       if (m_sensor_usages.empty())
-               return false;
-
-       return true;
-}
-
-bool client_sensor_record::has_sensor_usage(sensor_id_t sensor_id)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end()) {
-               _D("Sensor[%#x] is not found", sensor_id);
-               return false;
-       }
-
-       return true;
-}
-
-bool client_sensor_record::get_registered_events(sensor_id_t sensor_id, event_type_vector &event_vec)
-{
-       auto it_usage = m_sensor_usages.find(sensor_id);
-
-       if (it_usage == m_sensor_usages.end()) {
-               _D("Sensor[%#x] is not found", sensor_id);
-               return false;
-       }
-
-       copy(it_usage->second.m_reg_events.begin(), it_usage->second.m_reg_events.end(), back_inserter(event_vec));
-
-       return true;
-}
-
-void client_sensor_record::set_client_id(int client_id)
-{
-       m_client_id = client_id;
-}
-
-void client_sensor_record::set_client_info(pid_t pid, const string &name)
-{
-       char client_info[NAME_MAX + 32];
-       m_pid = pid;
-
-       snprintf(client_info, sizeof(client_info), "%s[pid=%d, id=%d]", name.c_str(), m_pid, m_client_id);
-       m_client_info.assign(client_info);
-}
-
-const char* client_sensor_record::get_client_info(void)
-{
-       return m_client_info.c_str();
-}
-
-void client_sensor_record::set_permission(int permission)
-{
-       m_permission = permission;
-}
-
-int client_sensor_record::get_permission(void)
-{
-       return  m_permission;
-}
-
-void client_sensor_record::set_event_socket(const csocket &socket)
-{
-       m_event_socket = socket;
-}
-
-void client_sensor_record::get_event_socket(csocket &socket)
-{
-       socket = m_event_socket;
-}
-
-bool client_sensor_record::close_event_socket(void)
-{
-       return m_event_socket.close();
-}
diff --git a/src/server/client_sensor_record.h b/src/server/client_sensor_record.h
deleted file mode 100644 (file)
index ad4835c..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _CLIENT_SENSOR_RECORD_H_
-#define _CLIENT_SENSOR_RECORD_H_
-
-#include <sensor_common.h>
-#include <sensor_types.h>
-#include <sensor_usage.h>
-#include <csocket.h>
-#include <unordered_map>
-#include <string>
-
-typedef std::unordered_map<sensor_id_t, sensor_usage> sensor_usage_map;
-
-class client_sensor_record {
-public:
-       client_sensor_record();
-       ~client_sensor_record();
-
-       void set_client_id(int client_id);
-
-       void set_client_info(pid_t pid, const std::string &name);
-       const char* get_client_info(void);
-
-       void set_permission(int permission);
-       int get_permission(void);
-
-       bool register_event(sensor_id_t sensor_id, unsigned int event_type);
-       bool unregister_event(sensor_id_t sensor_id, unsigned int event_type);
-
-       bool set_batch(sensor_id_t sensor_id, unsigned int interval, unsigned int latency);
-       bool get_batch(sensor_id_t sensor_id, unsigned int &interval, unsigned int &latency);
-       bool set_pause_policy(sensor_id_t sensor_id, int pause_policy);
-
-       bool set_start(sensor_id_t sensor_id, bool start);
-       bool is_started(sensor_id_t sensor_id);
-
-       bool is_listening_event(sensor_id_t sensor_id, unsigned int event_type);
-       bool has_sensor_usage(void);
-       bool has_sensor_usage(sensor_id_t sensor_id);
-
-       bool get_registered_events(sensor_id_t sensor_id, event_type_vector &event_vec);
-
-       bool add_sensor_usage(sensor_id_t sensor_id);
-       bool remove_sensor_usage(sensor_id_t sensor_id);
-
-       void set_event_socket(const csocket &socket);
-       void get_event_socket(csocket &socket);
-       bool close_event_socket(void);
-
-private:
-       int m_client_id;
-       pid_t m_pid;
-       int m_permission;
-       std::string m_client_info;
-       csocket m_event_socket;
-       sensor_usage_map m_sensor_usages;
-};
-
-#endif /* _CLIENT_SENSOR_RECORD_H_ */
diff --git a/src/server/command_queue.cpp b/src/server/command_queue.cpp
deleted file mode 100644 (file)
index 0eadaab..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_log.h>
-#include <command_queue.h>
-
-command_queue& command_queue::get_instance(void)
-{
-       static command_queue inst;
-       return inst;
-}
-
-void command_queue::push(std::shared_ptr<external_command_t> &command)
-{
-       lock l(m_mutex);
-
-       bool wake = m_queue.empty();
-
-       if (m_queue.size() >= QUEUE_FULL_SIZE) {
-               _E("Queue is full, drop it!");
-       } else {
-               m_queue.push(command);
-       }
-
-       if (wake)
-               m_cond_var.notify_one();
-}
-
-std::shared_ptr<external_command_t> command_queue::pop(void)
-{
-       ulock u(m_mutex);
-
-       while (m_queue.empty())
-               m_cond_var.wait(u);
-
-       std::shared_ptr<external_command_t> command = m_queue.front();
-       m_queue.pop();
-       return command;
-}
diff --git a/src/server/command_queue.h b/src/server/command_queue.h
deleted file mode 100644 (file)
index d5ab195..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _COMMAND_QUEUE_H_
-#define _COMMAND_QUEUE_H_
-
-#include <command_common.h>
-#include <queue>
-#include <mutex>
-#include <condition_variable>
-#include <memory>
-
-class command_queue {
-private:
-       command_queue() {};
-       ~command_queue() {};
-       command_queue(const command_queue&) {};
-       command_queue& operator=(const command_queue&);
-
-       static const unsigned int QUEUE_FULL_SIZE = 1000;
-
-       std::queue<std::shared_ptr<external_command_t>> m_queue;
-       std::mutex m_mutex;
-       std::condition_variable m_cond_var;
-
-       typedef std::lock_guard<std::mutex> lock;
-       typedef std::unique_lock<std::mutex> ulock;
-public:
-       static command_queue& get_instance();
-       void push(std::shared_ptr<external_command_t> &command);
-       std::shared_ptr<external_command_t> pop(void);
-};
-
-#endif
diff --git a/src/server/command_worker.cpp b/src/server/command_worker.cpp
deleted file mode 100644 (file)
index 2436ab8..0000000
+++ /dev/null
@@ -1,872 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_common.h>
-#include <command_common.h>
-#include <sensor_loader.h>
-#include <sensor_info.h>
-#include <sensor_log.h>
-#include <thread>
-#include <string>
-#include <vector>
-#include <utility>
-#include <permission_checker.h>
-#include <command_worker.h>
-
-#define WAIT_TIME(X) ((1 << ((X) < 4 ? (X) : 4)) * 10000)      /* 20, 40, 80, 160, 160ms, ... */
-
-using std::string;
-using std::vector;
-using std::make_pair;
-
-command_worker::cmd_handler_t command_worker::m_cmd_handlers[];
-sensor_raw_data_map command_worker::m_sensor_raw_data_map;
-cpacket command_worker::m_sensor_list;
-cmutex command_worker::m_shared_mutex;
-
-command_worker::command_worker(const csocket& socket)
-: m_client_id(CLIENT_ID_INVALID)
-, m_permission(SENSOR_PERMISSION_NONE)
-, m_socket(socket)
-, m_module(NULL)
-, m_sensor_id(UNKNOWN_SENSOR)
-{
-       static bool init = false;
-
-       AUTOLOCK(m_shared_mutex);
-
-       if (!init) {
-               init_cmd_handlers();
-
-               init = true;
-       }
-
-       m_worker.set_context(this);
-       m_worker.set_working(working);
-       m_worker.set_stopped(stopped);
-}
-
-command_worker::~command_worker()
-{
-       m_socket.close();
-}
-
-bool command_worker::start(void)
-{
-       return m_worker.start();
-}
-
-void command_worker::init_cmd_handlers(void)
-{
-       m_cmd_handlers[CMD_GET_ID]                              = &command_worker::cmd_get_id;
-       m_cmd_handlers[CMD_GET_SENSOR_LIST]             = &command_worker::cmd_get_sensor_list;
-       m_cmd_handlers[CMD_HELLO]                               = &command_worker::cmd_hello;
-       m_cmd_handlers[CMD_BYEBYE]                              = &command_worker::cmd_byebye;
-       m_cmd_handlers[CMD_START]                               = &command_worker::cmd_start;
-       m_cmd_handlers[CMD_STOP]                                = &command_worker::cmd_stop;
-       m_cmd_handlers[CMD_REG]                                 = &command_worker::cmd_register_event;
-       m_cmd_handlers[CMD_UNREG]                               = &command_worker::cmd_unregister_event;
-       m_cmd_handlers[CMD_SET_PAUSE_POLICY]    = &command_worker::cmd_set_pause_policy;
-       m_cmd_handlers[CMD_SET_BATCH]                   = &command_worker::cmd_set_batch;
-       m_cmd_handlers[CMD_UNSET_BATCH]                 = &command_worker::cmd_unset_batch;
-       m_cmd_handlers[CMD_GET_DATA]                    = &command_worker::cmd_get_data;
-       m_cmd_handlers[CMD_SET_ATTRIBUTE_INT]   = &command_worker::cmd_set_attribute_int;
-       m_cmd_handlers[CMD_SET_ATTRIBUTE_STR]   = &command_worker::cmd_set_attribute_str;
-       m_cmd_handlers[CMD_FLUSH]                               = &command_worker::cmd_flush;
-}
-
-size_t command_worker::create_sensor_raw_list(int client_perms, std::vector<raw_data_t *> &raw_list)
-{
-       size_t total_raw_data_size = 0;
-       vector<sensor_base *> sensors;
-       vector<sensor_type_t> types;
-       sensor_info info;
-       int permission;
-
-       types = sensor_loader::get_instance().get_sensor_types();
-
-       for (auto it_type = types.begin(); it_type != types.end(); ++it_type) {
-               sensor_type_t type = *it_type;
-               sensors = sensor_loader::get_instance().get_sensors(type);
-
-               for (auto it_sensor = sensors.begin(); it_sensor != sensors.end(); ++it_sensor) {
-                       (*it_sensor)->get_sensor_info(info);
-                       permission = (*it_sensor)->get_permission();
-                       permission = (client_perms & permission);
-
-                       if (!permission) {
-                               info.clear();
-                               info.set_id((sensor_id_t)-EACCES);
-                               info.set_type(type);
-                       }
-
-                       raw_data_t *raw_data = new(std::nothrow) raw_data_t();
-                       retvm_if(!raw_data, -1, "Failed to allocated memory");
-                       info.get_raw_data(*raw_data);
-
-                       total_raw_data_size += raw_data->size();
-                       raw_list.push_back(raw_data);
-
-                       info.clear();
-               }
-       }
-
-       return total_raw_data_size;
-}
-
-void command_worker::get_sensor_list(int client_perms, cpacket &sensor_list)
-{
-       size_t total_raw_data_size = 0;
-       vector<raw_data_t *> raw_list;
-       int sensor_cnt;
-       int idx = 0;
-
-       total_raw_data_size = create_sensor_raw_list(client_perms, raw_list);
-
-       sensor_cnt = raw_list.size();
-
-       sensor_list.set_payload_size(sizeof(cmd_get_sensor_list_done_t) + (sizeof(size_t) * sensor_cnt) + total_raw_data_size);
-       sensor_list.set_cmd(CMD_GET_SENSOR_LIST);
-
-       cmd_get_sensor_list_done_t *cmd_get_sensor_list_done;
-
-       cmd_get_sensor_list_done = (cmd_get_sensor_list_done_t*)sensor_list.data();
-       cmd_get_sensor_list_done->sensor_cnt = sensor_cnt;
-       size_t* size_field = (size_t *) cmd_get_sensor_list_done->data;
-
-       for (int i = 0; i < sensor_cnt; ++i)
-               size_field[i] = raw_list[i]->size();
-
-       char* raw_data_field = cmd_get_sensor_list_done->data + (sizeof(size_t) * sensor_cnt);
-
-       for (int i = 0; i < sensor_cnt; ++i) {
-               copy(raw_list[i]->begin(), raw_list[i]->end(), raw_data_field + idx);
-               idx += raw_list[i]->size();
-       }
-
-       for (auto it = raw_list.begin(); it != raw_list.end(); ++it)
-               delete *it;
-}
-
-bool command_worker::working(void *ctx)
-{
-       bool ret;
-       command_worker *inst = (command_worker *)ctx;
-
-       packet_header header;
-       char *payload;
-
-       if (inst->m_socket.recv(&header, sizeof(header)) <= 0) {
-               string info;
-               inst->get_info(info);
-               _D("%s failed to receive header", info.c_str());
-               return false;
-       }
-
-       if (header.size > 0) {
-               payload = new(std::nothrow) char[header.size];
-               retvm_if(!payload, false, "Failed to allocate memory");
-
-               if (inst->m_socket.recv(payload, header.size) <= 0) {
-                       string info;
-                       inst->get_info(info);
-                       _D("%s failed to receive data of packet", info.c_str());
-                       delete[] payload;
-                       return false;
-               }
-       } else {
-               payload = NULL;
-       }
-
-       ret = inst->dispatch_command(header.cmd, payload);
-
-       if (payload)
-               delete[] payload;
-
-       return ret;
-}
-
-bool command_worker::stopped(void *ctx)
-{
-       string info;
-       command_worker *inst = (command_worker *)ctx;
-
-       inst->get_info(info);
-       _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);
-                       inst->m_module->delete_batch(inst->m_client_id);
-                       inst->m_module->delete_attribute(inst->m_client_id);
-                       inst->m_module->stop();
-               }
-
-               if (inst->m_sensor_id > UNKNOWN_SENSOR) {
-                       if (get_client_info_manager().has_sensor_record(inst->m_client_id, inst->m_sensor_id)) {
-                               _I("Removing sensor[%#llx] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id);
-                               get_client_info_manager().remove_sensor_record(inst->m_client_id, inst->m_sensor_id);
-                       }
-               }
-       }
-
-       delete inst;
-       return true;
-}
-
-bool command_worker::dispatch_command(int cmd, void* payload)
-{
-       int ret = false;
-
-       if (!(cmd > 0 && cmd < CMD_CNT)) {
-               _E("Unknown command: %d", cmd);
-       } else {
-               cmd_handler_t cmd_handler;
-               cmd_handler = command_worker::m_cmd_handlers[cmd];
-               if (cmd_handler)
-                       ret = (this->*cmd_handler)(payload);
-       }
-
-       return ret;
-}
-
-bool command_worker::send_cmd_done(long value)
-{
-       cpacket* ret_packet;
-       cmd_done_t *cmd_done;
-
-       ret_packet = new(std::nothrow) cpacket(sizeof(cmd_done_t));
-       retvm_if(!ret_packet, false, "Failed to allocate memory");
-
-       ret_packet->set_cmd(CMD_DONE);
-
-       cmd_done = (cmd_done_t*)ret_packet->data();
-       cmd_done->value = value;
-
-       if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
-               _E("Failed to send a cmd_done to client_id [%d] with value [%ld]", m_client_id, value);
-               delete ret_packet;
-               return false;
-       }
-
-       delete ret_packet;
-       return true;
-}
-
-bool command_worker::send_cmd_get_id_done(int client_id)
-{
-       cpacket* ret_packet;
-       cmd_get_id_done_t *cmd_get_id_done;
-
-       ret_packet = new(std::nothrow) cpacket(sizeof(cmd_get_id_done_t));
-       retvm_if(!ret_packet, false, "Failed to allocate memory");
-
-       ret_packet->set_cmd(CMD_GET_ID);
-
-       cmd_get_id_done = (cmd_get_id_done_t*)ret_packet->data();
-       cmd_get_id_done->client_id = client_id;
-
-       if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
-               _E("Failed to send a cmd_get_id_done with client_id [%d]", client_id);
-               delete ret_packet;
-               return false;
-       }
-
-       delete ret_packet;
-       return true;
-}
-
-bool command_worker::send_cmd_get_data_done(int state, sensor_data_t *data)
-{
-       cpacket* ret_packet;
-       cmd_get_data_done_t *cmd_get_data_done;
-
-       ret_packet = new(std::nothrow) cpacket(sizeof(cmd_get_data_done_t));
-       retvm_if(!ret_packet, false, "Failed to allocate memory");
-
-       ret_packet->set_cmd(CMD_GET_DATA);
-
-       cmd_get_data_done = (cmd_get_data_done_t*)ret_packet->data();
-       cmd_get_data_done->state = state;
-
-       if (data)
-               memcpy(&cmd_get_data_done->base_data, data, sizeof(sensor_data_t));
-
-       if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
-               _E("Failed to send a cmd_get_data_done");
-               free(data);
-               delete ret_packet;
-               return false;
-       }
-
-       free(data);
-       delete ret_packet;
-       return true;
-}
-
-bool command_worker::send_cmd_get_sensor_list_done(void)
-{
-       cpacket sensor_list;
-
-       int permission = get_permission();
-
-       _I("permission = %#x", permission);
-
-       get_sensor_list(permission, sensor_list);
-
-       if (m_socket.send(sensor_list.packet(), sensor_list.size()) <= 0) {
-               _E("Failed to send a cmd_get_sensor_list_done");
-               return false;
-       }
-
-       /*
-        * TODO: get_sensor_list() command is processed on one-time connection in the current architecture.
-        *       but it doesn't need to use one-time connection.
-        */
-       m_socket.close();
-
-       return true;
-}
-
-bool command_worker::cmd_get_id(void *payload)
-{
-       cmd_get_id_t *cmd;
-       int client_id;
-       struct ucred cr;
-       socklen_t opt_len = sizeof(cr);
-
-       _D("CMD_GET_ID Handler invoked\n");
-       cmd = (cmd_get_id_t*)payload;
-
-       if (getsockopt(m_socket.get_socket_fd(), SOL_SOCKET, SO_PEERCRED, &cr, &opt_len)) {
-               _E("Failed to get socket option with SO_PEERCRED");
-               return false;
-       }
-
-       client_id = get_client_info_manager().create_client_record();
-
-       get_client_info_manager().set_client_info(client_id, cr.pid, cmd->name);
-
-       m_permission = get_permission();
-
-       get_client_info_manager().set_permission(client_id, m_permission);
-
-       _I("New client id [%d] created", client_id);
-
-       if (!send_cmd_get_id_done(client_id))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_get_sensor_list(void *payload)
-{
-       _D("CMD_GET_SENSOR_LIST Handler invoked\n");
-
-       if (!send_cmd_get_sensor_list_done())
-               _E("Failed to send cmd_get_sensor_list_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_hello(void *payload)
-{
-       cmd_hello_t *cmd;
-       long ret_value = OP_ERROR;
-
-       _D("CMD_HELLO Handler invoked\n");
-       cmd = (cmd_hello_t*)payload;
-
-       m_sensor_id = cmd->sensor;
-       m_client_id = cmd->client_id;
-
-       if (m_permission == SENSOR_PERMISSION_NONE)
-               get_client_info_manager().get_permission(m_client_id, m_permission);
-
-       m_module = (sensor_base *)sensor_loader::get_instance().get_sensor(cmd->sensor);
-
-       if (!m_module) {
-               _W("Sensor type[%d] is not supported", cmd->sensor);
-               if (!get_client_info_manager().has_sensor_record(m_client_id))
-                       get_client_info_manager().remove_client_record(m_client_id);
-
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to connect sensor[%#llx] for client [%d]", m_sensor_id, m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       _D("Hello sensor [%#llx], client id [%d]", m_sensor_id, m_client_id);
-       get_client_info_manager().create_sensor_record(m_client_id, m_sensor_id);
-       _I("New sensor record created for sensor [%#llx], sensor name [%s] on client id [%d]\n", m_sensor_id, m_module->get_name(), m_client_id);
-       ret_value = OP_SUCCESS;
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_byebye(void *payload)
-{
-       long ret_value = OP_ERROR;
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to stop sensor[%#llx] for client [%d]", m_sensor_id, m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       _D("CMD_BYEBYE for client [%d], sensor [%#llx]", m_client_id, m_sensor_id);
-
-       if (!get_client_info_manager().remove_sensor_record(m_client_id, m_sensor_id)) {
-               _E("Error removing sensor_record for client [%d]", m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       m_client_id = CLIENT_ID_INVALID;
-       ret_value = OP_SUCCESS;
-
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       if (ret_value == OP_SUCCESS)
-               return false;
-
-       return true;
-}
-
-bool command_worker::cmd_start(void *payload)
-{
-       long ret_value = OP_ERROR;
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to start sensor[%#llx] for client [%d]", m_sensor_id, m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       _D("START Sensor [%#llx], called from client [%d]", m_sensor_id, m_client_id);
-
-       if (m_module->start()) {
-               get_client_info_manager().set_start(m_client_id, m_sensor_id, true);
-/*
- *     Rotation could be changed even LCD is off by pop sync rotation
- *     and a client listening rotation event with always-on option.
- *     To reflect the last rotation state, request it to event dispatcher.
- */
-               get_event_dispathcher().request_last_event(m_client_id, m_sensor_id);
-               ret_value = OP_SUCCESS;
-       } else {
-               _E("Failed to start sensor [%#llx] for client [%d]", m_sensor_id, m_client_id);
-               ret_value = OP_ERROR;
-       }
-
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_stop(void *payload)
-{
-       long ret_value = OP_ERROR;
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to stop sensor[%#llx] for client [%d]", m_sensor_id, m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       _D("STOP Sensor [%#llx], called from client [%d]", m_sensor_id, m_client_id);
-
-       if (m_module->stop()) {
-               get_client_info_manager().set_start(m_client_id, m_sensor_id, false);
-               m_module->delete_attribute(m_client_id);
-               ret_value = OP_SUCCESS;
-       } else {
-               _E("Failed to stop sensor [%#llx] for client [%d]", m_sensor_id, m_client_id);
-               ret_value = OP_ERROR;
-       }
-
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_register_event(void *payload)
-{
-       cmd_reg_t *cmd;
-       long ret_value = OP_ERROR;
-
-       cmd = (cmd_reg_t*)payload;
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to register event [%#x] for client [%d] to client info manager",
-                       cmd->event_type, m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!get_client_info_manager().register_event(m_client_id, m_sensor_id, cmd->event_type)) {
-               _I("Failed to register event [%#x] for client [%d] to client info manager",
-                       cmd->event_type, m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       ret_value = OP_SUCCESS;
-       _D("Registering Event [%#x] is done for client [%d]", cmd->event_type, m_client_id);
-
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_unregister_event(void *payload)
-{
-       cmd_unreg_t *cmd;
-       long ret_value = OP_ERROR;
-
-       cmd = (cmd_unreg_t*)payload;
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to unregister event [%#x] for client [%d] to client info manager",
-                       cmd->event_type, m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!get_client_info_manager().unregister_event(m_client_id, m_sensor_id, cmd->event_type)) {
-               _E("Failed to unregister event [%#x] for client [%d] from client info manager",
-                       cmd->event_type, m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       ret_value = OP_SUCCESS;
-       _D("Unregistering Event [%#x] is done for client [%d]",
-               cmd->event_type, m_client_id);
-
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_set_batch(void *payload)
-{
-       cmd_set_batch_t *cmd;
-       long ret_value = OP_ERROR;
-
-       cmd = (cmd_set_batch_t*)payload;
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to set batch for client [%d], for sensor [%#llx] with batch [%d, %d] to client info manager",
-                       m_client_id, m_sensor_id, cmd->interval, cmd->latency);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, cmd->interval, cmd->latency)) {
-               _E("Failed to set batch for client [%d], for sensor [%#llx] with batch [%d, %d] to client info manager",
-                       m_client_id, m_sensor_id, cmd->interval, cmd->latency);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!m_module->add_interval(m_client_id, cmd->interval, false)) {
-               _E("Failed to set interval for client [%d], for sensor [%#llx] with interval [%d]",
-                       m_client_id, m_sensor_id, cmd->interval);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!m_module->add_batch(m_client_id, cmd->latency)) {
-               _E("Failed to set latency for client [%d], for sensor [%#llx] with latency [%d]",
-                       m_client_id, m_sensor_id, cmd->latency);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       ret_value = OP_SUCCESS;
-
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_unset_batch(void *payload)
-{
-       long ret_value = OP_ERROR;
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to unset batch for client [%d], for sensor [%#llx] to client info manager",
-                       m_client_id, m_sensor_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!get_client_info_manager().set_batch(m_client_id, m_sensor_id, 0, 0)) {
-               _E("Failed to unset batch for client [%d], for sensor [%#llx] to client info manager",
-                       m_client_id, m_sensor_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!m_module->delete_interval(m_client_id, false)) {
-               _E("Failed to delete interval for client [%d]", m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!m_module->delete_batch(m_client_id)) {
-               _E("Failed to delete latency for client [%d]", m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       ret_value = OP_SUCCESS;
-
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_set_pause_policy(void *payload)
-{
-       cmd_set_pause_policy_t *cmd;
-       long ret_value = OP_ERROR;
-
-       cmd = (cmd_set_pause_policy_t*)payload;
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to set interval for client [%d], for sensor [%#llx] with pause_policy [%d] to client info manager",
-                       m_client_id, m_sensor_id, cmd->pause_policy);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!get_client_info_manager().set_pause_policy(m_client_id, m_sensor_id, cmd->pause_policy)) {
-               _E("Failed to set pause_policy for client [%d], for sensor [%#llx] with pause_policy [%d] to client info manager",
-                       m_client_id, m_sensor_id, cmd->pause_policy);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       ret_value = OP_SUCCESS;
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_get_data(void *payload)
-{
-       const unsigned int GET_DATA_MIN_INTERVAL = 10;
-       int state;
-       bool adjusted = false;
-
-       sensor_data_t *data = NULL;
-
-       _D("CMD_GET_VALUE Handler invoked\n");
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to get data for client [%d], for sensor [%#llx]",
-                       m_client_id, m_sensor_id);
-               state = -EACCES;
-               goto out;
-       }
-
-       state = m_module->get_cache(&data);
-
-       /* if there is no cached data, wait short time and retry to get data again */
-       if (state == -ENODATA) {
-               const int RETRY_CNT = 10;
-               int retry = 0;
-
-               unsigned int interval = m_module->get_interval(m_client_id, false);
-
-                /* 1. change interval to 10ms. */
-               if (interval > GET_DATA_MIN_INTERVAL) {
-                       m_module->add_interval(m_client_id, GET_DATA_MIN_INTERVAL, false);
-                       adjusted = true;
-               }
-
-               /* 2. try to get sensor data increasing the waited time(20ms, 40ms, 80ms, 160ms, 160ms...) */
-               /* 3. if data cannot be found in 10 times, stop it. */
-               while ((state == -ENODATA) && (retry++ < RETRY_CNT)) {
-                       _I("Wait sensor[%#llx] data updated for client [%d] #%d", m_sensor_id, m_client_id, retry);
-                       usleep(WAIT_TIME(retry));
-                       state = m_module->get_cache(&data);
-               }
-
-               /* 4. revert to original interval */
-               if (adjusted)
-                       m_module->add_interval(m_client_id, interval, false);
-       }
-
-       if (state < 0) {
-               _E("Failed to get data for client [%d], for sensor [%#llx]",
-                       m_client_id, m_sensor_id);
-       }
-
-out:
-       send_cmd_get_data_done(state < 0 ? OP_ERROR : OP_SUCCESS, data);
-
-       return true;
-}
-
-bool command_worker::cmd_set_attribute_int(void *payload)
-{
-       cmd_set_attribute_int_t *cmd;
-       long ret_value = OP_ERROR;
-
-       _D("CMD_SET_COMMAND Handler invoked\n");
-
-       cmd = (cmd_set_attribute_int_t*)payload;
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to set attribute for client [%d], for sensor [%#llx] with attribute [%d]",
-                       m_client_id, m_sensor_id, cmd->attribute);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       ret_value = m_module->add_attribute(m_client_id, cmd->attribute, cmd->value);
-
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_set_attribute_str(void *payload)
-{
-       cmd_set_attribute_str_t *cmd;
-       long ret_value = OP_ERROR;
-
-       _D("CMD_SEND_SENSORHUB_DATA Handler invoked");
-
-       cmd = (cmd_set_attribute_str_t*)payload;
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to set attribute for client [%d], for sensor [%#llx]",
-                       m_client_id, m_sensor_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       ret_value = m_module->add_attribute(m_client_id, cmd->attribute, cmd->value, cmd->len);
-
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool command_worker::cmd_flush(void *payload)
-{
-       long ret_value = OP_ERROR;
-
-       _D("CMD_FLUSH Handler invoked");
-
-       if (!is_permission_allowed()) {
-               _E("Permission denied to flush sensor data for client [%d], for sensor [%#llx]",
-                       m_client_id, m_sensor_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!m_module->flush()) {
-               _E("Failed to flush sensor_data [%d]", m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       ret_value = OP_SUCCESS;
-
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-void command_worker::get_info(string &info)
-{
-       const char *client_info = NULL;
-       const char *sensor_info = NULL;
-
-       if (m_client_id != CLIENT_ID_INVALID)
-               client_info = get_client_info_manager().get_client_info(m_client_id);
-
-       if (m_module)
-               sensor_info = m_module->get_name();
-
-       info = string("Command worker for ") + (client_info ? client_info : "Unknown") + "'s "
-               + (sensor_info ? sensor_info : "Unknown");
-}
-
-int command_worker::get_permission(void)
-{
-       return permission_checker::get_instance().get_permission(m_socket.get_socket_fd());
-}
-
-bool command_worker::is_permission_allowed(void)
-{
-       if (!m_module)
-               return false;
-
-       if (m_module->get_permission() & m_permission)
-               return true;
-
-       return false;
-}
-
-client_info_manager& command_worker::get_client_info_manager(void)
-{
-       return client_info_manager::get_instance();
-}
-
-sensor_event_dispatcher& command_worker::get_event_dispathcher(void)
-{
-       return sensor_event_dispatcher::get_instance();
-}
-
diff --git a/src/server/command_worker.h b/src/server/command_worker.h
deleted file mode 100644 (file)
index e6dff1d..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#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>
-
-typedef std::multimap<int, raw_data_t> sensor_raw_data_map;
-
-class command_worker {
-private:
-       typedef bool (command_worker::*cmd_handler_t)(void *payload);
-
-       int m_client_id;
-       int m_permission;
-       csocket m_socket;
-       worker_thread m_worker;
-       sensor_base *m_module;
-       sensor_id_t m_sensor_id;
-       static cmd_handler_t m_cmd_handlers[CMD_CNT];
-       static cpacket m_sensor_list;
-       static sensor_raw_data_map m_sensor_raw_data_map;
-
-       static void init_cmd_handlers(void);
-       static size_t create_sensor_raw_list(int client_perms, std::vector<raw_data_t *> &raw_list);
-       static void get_sensor_list(int permissions, cpacket &sensor_list);
-
-       static bool working(void *ctx);
-       static bool stopped(void *ctx);
-
-       bool dispatch_command(int cmd, void *payload);
-
-       bool send_cmd_done(long value);
-       bool send_cmd_get_id_done(int client_id);
-       bool send_cmd_get_data_done(int state, sensor_data_t *data);
-       bool send_cmd_get_sensor_list_done(void);
-
-       bool cmd_get_id(void *payload);
-       bool cmd_get_sensor_list(void *payload);
-       bool cmd_hello(void *payload);
-       bool cmd_byebye(void *payload);
-       bool cmd_get_value(void *payload);
-       bool cmd_start(void *payload);
-       bool cmd_stop(void *payload);
-       bool cmd_register_event(void *payload);
-       bool cmd_unregister_event(void *payload);
-       bool cmd_set_batch(void *payload);
-       bool cmd_unset_batch(void *payload);
-       bool cmd_set_pause_policy(void *payload);
-       bool cmd_get_data(void *payload);
-       bool cmd_set_attribute_int(void *payload);
-       bool cmd_set_attribute_str(void *payload);
-       bool cmd_flush(void *payload);
-
-       void get_info(std::string &info);
-
-       int get_permission(void);
-       bool is_permission_allowed(void);
-
-       static client_info_manager& get_client_info_manager(void);
-       static sensor_event_dispatcher& get_event_dispathcher(void);
-
-protected:
-       static cmutex m_shared_mutex;
-
-public:
-       command_worker(const csocket& socket);
-       virtual ~command_worker();
-
-       bool start(void);
-};
-
-#endif /* _COMMAND_WORKER_H_ */
diff --git a/src/server/external_client_manager.cpp b/src/server/external_client_manager.cpp
deleted file mode 100644 (file)
index a19d502..0000000
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <command_common.h>
-#include <external_client_manager.h>
-#include <sensor_common.h>
-
-using std::shared_ptr;
-using std::make_shared;
-using std::pair;
-using std::string;
-
-external_client_manager::external_client_manager()
-{
-}
-external_client_manager::~external_client_manager()
-{
-}
-
-external_client_manager& external_client_manager::get_instance(void)
-{
-       static external_client_manager instance;
-       return instance;
-}
-
-int external_client_manager::create_client_record(void)
-{
-       AUTOLOCK(m_mutex);
-
-       int client_id = 0;
-
-       shared_ptr<external_sensor_record> client_record = make_shared<external_sensor_record>();
-
-       while (m_clients.count(client_id) > 0)
-               client_id++;
-
-       if (client_id == MAX_HANDLE) {
-               _E("Sensor records of clients are full");
-               return MAX_HANDLE_REACHED;
-       }
-
-       client_record->set_client_id(client_id);
-
-       m_clients.insert(pair<int, shared_ptr<external_sensor_record>>(client_id, client_record));
-
-       return client_id;
-}
-
-bool external_client_manager::remove_client_record(int client_id)
-{
-       AUTOLOCK(m_mutex);
-
-       if (!m_clients.erase(client_id)) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       _I("Client record for client[%d] is removed from external client manager", client_id);
-       return true;
-}
-
-bool external_client_manager::has_client_record(int client_id)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.find(client_id);
-
-       return (it_record != m_clients.end());
-}
-
-void external_client_manager::set_client_info(int client_id, pid_t pid, const string &name)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return;
-       }
-
-       it_record->second->set_client_info(pid, name);
-
-       return;
-}
-
-const char* external_client_manager::get_client_info(int client_id)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _D("Client[%d] is not found", client_id);
-               return NULL;
-       }
-
-       return it_record->second->get_client_info();
-}
-
-bool external_client_manager::create_sensor_record(int client_id, sensor_id_t sensor)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client record[%d] is not registered", client_id);
-               return false;
-       }
-
-       return it_record->second->add_usage(sensor);
-}
-
-bool external_client_manager::remove_sensor_record(int client_id, sensor_id_t sensor)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       if (!it_record->second->remove_usage(sensor))
-               return false;
-
-       if (!it_record->second->has_usage())
-               remove_client_record(client_id);
-
-       return true;
-}
-
-bool external_client_manager::has_sensor_record(int client_id, sensor_id_t sensor)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _D("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       return it_record->second->has_usage(sensor);
-}
-
-bool external_client_manager::has_sensor_record(int client_id)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _D("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       return it_record->second->has_usage();
-}
-
-bool external_client_manager::get_listener_socket(sensor_id_t sensor, csocket &sock)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.begin();
-
-       while (it_record != m_clients.end()) {
-               if (it_record->second->has_usage(sensor)) {
-                       it_record->second->get_command_socket(sock);
-                       return true;
-               }
-
-               ++it_record;
-       }
-
-       return false;
-}
-
-bool external_client_manager::get_command_socket(int client_id, csocket &socket)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       it_record->second->get_command_socket(socket);
-
-       return true;
-}
-
-bool external_client_manager::set_command_socket(int client_id, const csocket &socket)
-{
-       AUTOLOCK(m_mutex);
-
-       auto it_record = m_clients.find(client_id);
-
-       if (it_record == m_clients.end()) {
-               _E("Client[%d] is not found", client_id);
-               return false;
-       }
-
-       it_record->second->set_command_socket(socket);
-
-       return true;
-}
diff --git a/src/server/external_client_manager.h b/src/server/external_client_manager.h
deleted file mode 100644 (file)
index 9934d8d..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _EXTERNAL_CLIENT_MANAGER_H_
-#define _EXTERNAL_CLIENT_MANAGER_H_
-
-#include <external_sensor_record.h>
-#include <cmutex.h>
-#include <unordered_map>
-#include <memory>
-
-class external_client_manager {
-public:
-       static external_client_manager& get_instance(void);
-       int create_client_record(void);
-       bool remove_client_record(int client_id);
-       bool has_client_record(int client_id);
-
-       void set_client_info(int client_id, pid_t pid, const std::string &name);
-       const char* get_client_info(int client_id);
-
-       bool create_sensor_record(int client_id, sensor_id_t sensor);
-       bool remove_sensor_record(int client_id, sensor_id_t sensor);
-       bool has_sensor_record(int client_id, sensor_id_t sensor);
-       bool has_sensor_record(int client_id);
-
-       bool get_listener_socket(sensor_id_t sensor, csocket &sock);
-       bool get_command_socket(int client_id, csocket &sock);
-       bool set_command_socket(int client_id, const csocket &sock);
-private:
-       external_client_manager();
-       ~external_client_manager();
-       external_client_manager(const external_client_manager&) {};
-       external_client_manager& operator=(const external_client_manager&);
-
-       std::unordered_map<int, std::shared_ptr<external_sensor_record>> m_clients;
-       cmutex m_mutex;
-};
-#endif /* _EXTERNAL_CLIENT_MANAGER_H_ */
diff --git a/src/server/external_sensor.cpp b/src/server/external_sensor.cpp
deleted file mode 100644 (file)
index 9046739..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <external_sensor.h>
-#include <external_sensor_service.h>
-#include <sensor_event_queue.h>
-#include <command_queue.h>
-
-using std::string;
-using std::shared_ptr;
-using std::make_shared;
-
-external_sensor::external_sensor()
-: m_source_connected(false)
-{
-}
-
-external_sensor::~external_sensor()
-{
-       unregister_key();
-}
-
-bool external_sensor::register_key(const string &key)
-{
-       m_key = key;
-       return external_sensor_service::get_instance().register_sensor(this);
-}
-
-bool external_sensor::unregister_key(void)
-{
-       return external_sensor_service::get_instance().unregister_sensor(this);
-}
-
-string external_sensor::get_key(void)
-{
-       return m_key;
-}
-
-bool external_sensor::set_source_connected(bool connected)
-{
-       AUTOLOCK(m_source_mutex);
-
-       if (m_source_connected && connected) {
-               _E("Source is already connected");
-               return false;
-       }
-
-       m_source_connected = connected;
-       return true;
-}
-
-bool external_sensor::get_source_connected(void)
-{
-       AUTOLOCK(m_source_mutex);
-
-       return m_source_connected;
-}
-
-int external_sensor::set_attribute(int32_t attribute, char *value, int value_size)
-{
-       shared_ptr<external_command_t> external_command = make_shared<external_command_t>();
-
-       external_command->header.sensor_id = get_id();
-       external_command->header.command_len = value_size;
-       external_command->command.assign(value, value + value_size);
-
-       command_queue::get_instance().push(external_command);
-
-       return 0;
-}
diff --git a/src/server/external_sensor.h b/src/server/external_sensor.h
deleted file mode 100644 (file)
index c52b325..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _EXTERNAL_SENSOR_H_
-#define _EXTERNAL_SENSOR_H_
-
-#include <sensor_base.h>
-#include <sensor_common.h>
-#include <cmutex.h>
-#include <string>
-
-class external_sensor : public sensor_base {
-public:
-       external_sensor();
-       virtual ~external_sensor();
-       int send_data(const char* data, int data_cnt);
-       std::string get_key(void);
-       bool set_source_connected(bool connected);
-       bool get_source_connected(void);
-       virtual void on_receive(unsigned long long timestamp, const float* data, int data_cnt) = 0;
-       virtual int set_attribute(int32_t attribute, char *value, int value_size);
-protected:
-       bool register_key(const std::string &key);
-private:
-       bool unregister_key(void);
-
-       std::string m_key;
-       bool m_source_connected;
-       cmutex m_source_mutex;
-};
-#endif /* _EXTERNAL_SENSOR_H_ */
diff --git a/src/server/external_sensor_record.cpp b/src/server/external_sensor_record.cpp
deleted file mode 100644 (file)
index 98d3c79..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <external_sensor_record.h>
-
-using std::string;
-
-external_sensor_record::external_sensor_record()
-: m_client_id(0)
-, m_pid(-1)
-{
-}
-
-external_sensor_record::~external_sensor_record()
-{
-       close_command_socket();
-}
-
-bool external_sensor_record::add_usage(sensor_id_t sensor)
-{
-       if (!m_usages.insert(sensor).second) {
-               _E("Sensor[%#x] is already registered", sensor);
-               return false;
-       }
-
-       return true;
-}
-
-bool external_sensor_record::remove_usage(sensor_id_t sensor)
-{
-       if (!m_usages.erase(sensor)) {
-               _E("Sensor[%#x] is not found", sensor);
-               return false;
-       }
-
-       return true;
-}
-
-bool external_sensor_record::has_usage(void)
-{
-       return !m_usages.empty();
-}
-
-bool external_sensor_record::has_usage(sensor_id_t sensor)
-{
-       auto it_usage = m_usages.find(sensor);
-
-       return (it_usage != m_usages.end());
-}
-
-void external_sensor_record::set_client_id(int client_id)
-{
-       m_client_id = client_id;
-}
-
-void external_sensor_record::set_client_info(pid_t pid, const string &name)
-{
-       char client_info[NAME_MAX + 32];
-       m_pid = pid;
-
-       snprintf(client_info, sizeof(client_info), "%s[pid=%d, id=%d]", name.c_str(), m_pid, m_client_id);
-       m_client_info.assign(client_info);
-}
-
-const char* external_sensor_record::get_client_info(void)
-{
-       return m_client_info.c_str();
-}
-
-void external_sensor_record::set_command_socket(const csocket &socket)
-{
-       m_command_socket = socket;
-}
-
-void external_sensor_record::get_command_socket(csocket &socket)
-{
-       socket = m_command_socket;
-}
-
-bool external_sensor_record::close_command_socket(void)
-{
-       return m_command_socket.close();
-}
-
diff --git a/src/server/external_sensor_record.h b/src/server/external_sensor_record.h
deleted file mode 100644 (file)
index 9b85640..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _EXTERNAL_SENSOR_RECORD_H_
-#define _EXTERNAL_SENSOR_RECORD_H_
-
-#include <csocket.h>
-#include <sensor_common.h>
-#include <string>
-#include <unordered_set>
-
-class external_sensor_record {
-public:
-       external_sensor_record();
-       ~external_sensor_record();
-
-       void set_client_id(int client_id);
-
-       void set_client_info(pid_t pid, const std::string &name);
-       const char* get_client_info(void);
-
-       bool has_usage(void);
-       bool has_usage(sensor_id_t sensor);
-
-       bool add_usage(sensor_id_t sensor);
-       bool remove_usage(sensor_id_t sensor);
-
-       void set_command_socket(const csocket &socket);
-       void get_command_socket(csocket &socket);
-       bool close_command_socket(void);
-
-private:
-       int m_client_id;
-       pid_t m_pid;
-       std::string m_client_info;
-       csocket m_command_socket;
-       std::unordered_set<sensor_id_t> m_usages;
-};
-
-#endif /* _EXTERNAL_SENSOR_RECORD_H_ */
diff --git a/src/server/external_sensor_service.cpp b/src/server/external_sensor_service.cpp
deleted file mode 100644 (file)
index c7d1e8e..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <external_sensor_service.h>
-#include <external_sensor.h>
-#include <external_client_manager.h>
-#include <command_queue.h>
-#include <thread>
-
-using std::thread;
-using std::pair;
-using std::string;
-using std::shared_ptr;
-
-external_sensor_service::external_sensor_service()
-{
-}
-
-external_sensor_service::~external_sensor_service()
-{
-}
-
-external_sensor_service& external_sensor_service::get_instance(void)
-{
-       static external_sensor_service instance;
-       return instance;
-}
-
-bool external_sensor_service::run(void)
-{
-       thread dispatcher(&external_sensor_service::dispatch_command, this);
-       dispatcher.detach();
-
-       return true;
-}
-
-external_client_manager& external_sensor_service::get_client_manager(void)
-{
-       return external_client_manager::get_instance();
-}
-
-void external_sensor_service::accept_command_channel(csocket client_socket)
-{
-       thread th = thread([&, client_socket]() mutable {
-               int client_id;
-               channel_ready_t command_channel_ready;
-               external_client_manager& client_manager = get_client_manager();
-
-               client_socket.set_connection_mode();
-
-               if (client_socket.recv(&client_id, sizeof(client_id)) <= 0) {
-                       _E("Failed to receive client id on socket fd[%d]", client_socket.get_socket_fd());
-                       return;
-               }
-
-               client_socket.set_transfer_mode();
-
-               if (!client_manager.set_command_socket(client_id, client_socket)) {
-                       _E("Failed to store event socket[%d] for %s", client_socket.get_socket_fd(),
-                               client_manager.get_client_info(client_id));
-                       return;
-               }
-
-               command_channel_ready.magic = CHANNEL_MAGIC_NUM;
-               command_channel_ready.client_id = client_id;
-
-               _I("Command channel is accepted for %s on socket[%d]",
-                       client_manager.get_client_info(client_id), client_socket.get_socket_fd());
-
-               if (client_socket.send(&command_channel_ready, sizeof(command_channel_ready)) <= 0) {
-                       _E("Failed to send command channel_ready packet to %s on socket fd[%d]",
-                               client_manager.get_client_info(client_id), client_socket.get_socket_fd());
-                       return;
-               }
-       });
-
-       th.detach();
-}
-
-void external_sensor_service::dispatch_command(void)
-{
-       while (true) {
-               shared_ptr<external_command_t> command = command_queue::get_instance().pop();
-               csocket client_sock;
-               sensor_id_t sensor_id = command->header.sensor_id;
-               bool ret;
-
-               ret = external_client_manager::get_instance().get_listener_socket(sensor_id, client_sock);
-
-               if (!ret) {
-                       _E("Failed to get listener socket for sensor[%d]", sensor_id);
-                       continue;
-               }
-
-               if (client_sock.send(&(command->header), sizeof(command->header)) <= 0) {
-                       _E("Failed to send command header to the client of sensor[%d]", sensor_id);
-                       continue;
-               }
-
-               if (client_sock.send(command->command.data(), command->header.command_len) <= 0) {
-                       _E("Failed to send command header to the client of sensor[%d]", sensor_id);
-                       continue;
-               }
-       }
-}
-
-bool external_sensor_service::register_sensor(external_sensor *sensor)
-{
-       if (!m_external_sensors.insert(pair<string, external_sensor*>(sensor->get_key(), sensor)).second) {
-               _E("Failed to register sensor, key: %s", sensor->get_key().c_str());
-               return false;
-       }
-
-       return true;
-}
-
-bool external_sensor_service::unregister_sensor(external_sensor *sensor)
-{
-       if (!m_external_sensors.erase(sensor->get_key())) {
-               _E("Failed to unregister sensor, key: %s", sensor->get_key().c_str());
-               return false;
-       }
-
-       return true;
-}
-
-external_sensor* external_sensor_service::get_sensor(const string& key)
-{
-       auto it_sensor = m_external_sensors.find(key);
-
-       if (it_sensor == m_external_sensors.end()) {
-               _E("Sensor(key:%s) is not found", key.c_str());
-               return NULL;
-       }
-
-       return it_sensor->second;
-}
diff --git a/src/server/external_sensor_service.h b/src/server/external_sensor_service.h
deleted file mode 100644 (file)
index 28b1aa4..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _EXTERNAL_SENSOR_SERVICE_H_
-#define _EXTERNAL_SENSOR_SERVICE_H_
-
-#include <external_sensor.h>
-#include <csocket.h>
-#include <string>
-#include <unordered_map>
-
-class external_client_manager;
-
-class external_sensor_service {
-public:
-       static external_sensor_service& get_instance();
-       bool register_sensor(external_sensor *sensor);
-       bool unregister_sensor(external_sensor *sensor);
-       external_sensor* get_sensor(const std::string& key);
-
-       void accept_command_channel(csocket client_socket);
-       bool run(void);
-private:
-       external_sensor_service();
-       ~external_sensor_service();
-       external_sensor_service(const external_sensor_service&) {};
-       external_sensor_service& operator=(const external_sensor_service&);
-
-       static external_client_manager& get_client_manager(void);
-
-       void dispatch_command(void);
-
-       std::unordered_map<std::string, external_sensor*> m_external_sensors;
-};
-#endif /* _EXTERNAL_SENSOR_SERVICE_H_ */
-
diff --git a/src/server/external_sensor_worker.cpp b/src/server/external_sensor_worker.cpp
deleted file mode 100644 (file)
index f62dc28..0000000
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_common.h>
-#include <command_common.h>
-#include <external_sensor_worker.h>
-#include <external_client_manager.h>
-#include <external_sensor.h>
-#include <external_sensor_service.h>
-
-using std::string;
-
-external_sensor_worker::cmd_handler_t external_sensor_worker::m_cmd_handlers[];
-
-external_sensor_worker::external_sensor_worker(const csocket& socket)
-: m_client_id(CLIENT_ID_INVALID)
-, m_socket(socket)
-, m_sensor(NULL)
-, m_sensor_id(UNKNOWN_SENSOR)
-{
-       static bool init = false;
-
-       if (!init) {
-               init_cmd_handlers();
-               init = true;
-       }
-
-       m_worker.set_context(this);
-       m_worker.set_working(working);
-       m_worker.set_stopped(stopped);
-}
-
-external_sensor_worker::~external_sensor_worker()
-{
-       m_socket.close();
-}
-
-bool external_sensor_worker::start(void)
-{
-       return m_worker.start();
-}
-
-void external_sensor_worker::init_cmd_handlers(void)
-{
-       m_cmd_handlers[CMD_EXT_GET_ID]          = &external_sensor_worker::cmd_get_id;
-       m_cmd_handlers[CMD_EXT_CONNECT]         = &external_sensor_worker::cmd_connect;
-       m_cmd_handlers[CMD_EXT_DISCONNECT]      = &external_sensor_worker::cmd_disconnect;
-       m_cmd_handlers[CMD_EXT_POST]            = &external_sensor_worker::cmd_post;
-}
-
-bool external_sensor_worker::working(void *ctx)
-{
-       bool ret;
-       external_sensor_worker *inst = (external_sensor_worker *)ctx;
-
-       packet_header header;
-       char *payload;
-
-       if (inst->m_socket.recv(&header, sizeof(header)) <= 0) {
-               string info;
-               inst->get_info(info);
-               _D("%s failed to receive header", info.c_str());
-               return false;
-       }
-
-       retvm_if(header.size == 0, false, "Invalid header size");
-
-       payload = new(std::nothrow) char[header.size];
-       retvm_if(!payload, false, "Failed to allocate memory");
-
-       if (inst->m_socket.recv(payload, header.size) <= 0) {
-               string info;
-               inst->get_info(info);
-               _D("%s failed to receive data of packet", info.c_str());
-               delete[] payload;
-               return false;
-       }
-
-       ret = inst->dispatch_command(header.cmd, payload);
-
-       delete[] payload;
-       return ret;
-}
-
-bool external_sensor_worker::stopped(void *ctx)
-{
-       string info;
-       external_sensor_worker *inst = (external_sensor_worker *)ctx;
-
-       inst->get_info(info);
-       _I("%s is stopped", info.c_str());
-
-       if (inst->m_client_id != CLIENT_ID_INVALID) {
-               _I("Client:%d leaves without disconnecting", inst->m_client_id);
-               if (get_client_manager().has_sensor_record(inst->m_client_id, inst->m_sensor_id)) {
-                       _I("Removing sensor[%#x] record for client_id[%d]", inst->m_sensor_id, inst->m_client_id);
-                       get_client_manager().remove_sensor_record(inst->m_client_id, inst->m_sensor_id);
-
-                       if (inst->m_sensor)
-                               inst->m_sensor->set_source_connected(false);
-               }
-       }
-
-       delete inst;
-       return true;
-}
-
-bool external_sensor_worker::dispatch_command(int cmd, void* payload)
-{
-       int ret = false;
-
-       if (!(cmd > 0 && cmd < CMD_EXT_CNT)) {
-               _E("Unknown command: %d", cmd);
-       } else {
-               cmd_handler_t cmd_handler;
-               cmd_handler = external_sensor_worker::m_cmd_handlers[cmd];
-               if (cmd_handler)
-                       ret = (this->*cmd_handler)(payload);
-       }
-
-       return ret;
-}
-
-bool external_sensor_worker::send_cmd_done(long value)
-{
-       cpacket* ret_packet;
-       cmd_ext_done_t *cmd_ext_done;
-
-       ret_packet = new(std::nothrow) cpacket(sizeof(cmd_ext_done_t));
-       retvm_if(!ret_packet, false, "Failed to allocate memory");
-
-       ret_packet->set_cmd(CMD_EXT_DONE);
-
-       cmd_ext_done = (cmd_ext_done_t*)ret_packet->data();
-       cmd_ext_done->value = value;
-
-       if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
-               _E("Failed to send a cmd_done to client_id [%d] with value [%ld]", m_client_id, value);
-               delete ret_packet;
-               return false;
-       }
-
-       delete ret_packet;
-       return true;
-}
-
-bool external_sensor_worker::send_cmd_get_id_done(int client_id)
-{
-       cpacket* ret_packet;
-       cmd_ext_get_id_done_t *cmd_ext_get_id_done;
-
-       ret_packet = new(std::nothrow) cpacket(sizeof(cmd_ext_get_id_done_t));
-       retvm_if(!ret_packet, false, "Failed to allocate memory");
-
-       ret_packet->set_cmd(CMD_EXT_GET_ID);
-
-       cmd_ext_get_id_done = (cmd_ext_get_id_done_t*)ret_packet->data();
-       cmd_ext_get_id_done->client_id = client_id;
-
-       if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
-               _E("Failed to send a cmd_get_id_done with client_id [%d]", client_id);
-               delete ret_packet;
-               return false;
-       }
-
-       delete ret_packet;
-       return true;
-}
-
-bool external_sensor_worker::send_cmd_connect_done(sensor_id_t sensor_id)
-{
-       cpacket* ret_packet;
-       cmd_ext_connect_done_t *cmd_ext_connect_done;
-
-       ret_packet = new(std::nothrow) cpacket(sizeof(cmd_ext_connect_done_t));
-       retvm_if(!ret_packet, false, "Failed to allocate memory");
-
-       ret_packet->set_cmd(CMD_EXT_CONNECT);
-
-       cmd_ext_connect_done = (cmd_ext_connect_done_t*)ret_packet->data();
-       cmd_ext_connect_done->sensor_id = sensor_id;
-
-       if (m_socket.send(ret_packet->packet(), ret_packet->size()) <= 0) {
-               _E("Failed to send a cmd_connect done");
-               delete ret_packet;
-               return false;
-       }
-
-       delete ret_packet;
-       return true;
-}
-
-bool external_sensor_worker::cmd_get_id(void *payload)
-{
-       cmd_ext_get_id_t *cmd = static_cast<cmd_ext_get_id_t *>(payload);
-       int client_id;
-       struct ucred cr;
-       socklen_t opt_len = sizeof(cr);
-
-       if (getsockopt(m_socket.get_socket_fd(), SOL_SOCKET, SO_PEERCRED, &cr, &opt_len)) {
-               _E("Failed to get socket option with SO_PEERCRED");
-               return false;
-       }
-
-       client_id = get_client_manager().create_client_record();
-
-       if (client_id != MAX_HANDLE_REACHED) {
-               get_client_manager().set_client_info(client_id, cr.pid, cmd->name);
-               _I("New client id [%d] created", client_id);
-       }
-
-       if (!send_cmd_get_id_done(client_id))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-bool external_sensor_worker::cmd_connect(void *payload)
-{
-       cmd_ext_connect_t *cmd = static_cast<cmd_ext_connect_t *>(payload);
-       m_client_id = cmd->client_id;
-
-       external_sensor *sensor;
-       sensor = external_sensor_service::get_instance().get_sensor(string(cmd->key));
-       if (!sensor) {
-               _E("No matched external sensor with key: %s", cmd->key);
-               goto out;
-       }
-
-       if (!sensor->set_source_connected(true)) {
-               _E("External sensor(%s) is already connected", cmd->key);
-               goto out;
-       }
-
-       m_sensor = sensor;
-       m_sensor_id = sensor->get_id();
-
-       if (!get_client_manager().create_sensor_record(m_client_id, m_sensor_id)) {
-               _E("Failed to create sensor record for client: %d, sensor_id: %d", m_client_id, m_sensor_id);
-               m_sensor_id = UNKNOWN_SENSOR;
-               goto out;
-       }
-
-out:
-       if (!send_cmd_connect_done(m_sensor_id))
-               _E("Failed to send cmd_connect_done to a client : %d", m_client_id);
-
-       return true;
-}
-
-bool external_sensor_worker::cmd_disconnect(void *payload)
-{
-       long ret_value = OP_ERROR;
-
-       if (!m_sensor) {
-               _E("External sensor is not connected");
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       if (!get_client_manager().remove_sensor_record(m_client_id, m_sensor_id)) {
-               _E("Failed to remove sensor record for client [%d]", m_client_id);
-               ret_value = OP_ERROR;
-               goto out;
-       }
-
-       m_sensor->set_source_connected(false);
-
-       m_sensor = NULL;
-       m_client_id = CLIENT_ID_INVALID;
-       m_sensor_id = UNKNOWN_SENSOR;
-       ret_value = OP_SUCCESS;
-out:
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       if (ret_value == OP_SUCCESS)
-               return false;
-
-       return true;
-}
-
-bool external_sensor_worker::cmd_post(void *payload)
-{
-       long ret_value = OP_SUCCESS;
-       cmd_ext_post_t *cmd = static_cast<cmd_ext_post_t *>(payload);
-
-       m_sensor->on_receive(cmd->timestamp, cmd->data, cmd->data_cnt);
-
-       if (!send_cmd_done(ret_value))
-               _E("Failed to send cmd_done to a client");
-
-       return true;
-}
-
-external_client_manager& external_sensor_worker::get_client_manager(void)
-{
-       return external_client_manager::get_instance();
-}
-
-void external_sensor_worker::get_info(string &info)
-{
-       const char *client_info = NULL;
-
-       if (m_client_id != CLIENT_ID_INVALID)
-               client_info = get_client_manager().get_client_info(m_client_id);
-
-       info = string("Command worker for ") + (client_info ? string(client_info) : string("Unknown"));
-}
diff --git a/src/server/external_sensor_worker.h b/src/server/external_sensor_worker.h
deleted file mode 100644 (file)
index 982dd09..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _EXTERNAL_SENSOR_WORKER_H_
-#define _EXTERNAL_SENSOR_WORKER_H_
-
-#include <worker_thread.h>
-#include <csocket.h>
-#include <sensor_common.h>
-#include <string>
-
-class external_client_manager;
-class external_sensor;
-
-class external_sensor_worker {
-private:
-       typedef bool (external_sensor_worker::*cmd_handler_t)(void *payload);
-
-       int m_client_id;
-       csocket m_socket;
-       worker_thread m_worker;
-       external_sensor *m_sensor;
-       sensor_id_t m_sensor_id;
-       static cmd_handler_t m_cmd_handlers[CMD_EXT_CNT];
-
-       static void init_cmd_handlers(void);
-       static bool working(void *ctx);
-       static bool stopped(void *ctx);
-
-       bool dispatch_command(int cmd, void *payload);
-
-       bool send_cmd_done(long value);
-       bool send_cmd_get_id_done(int client_id);
-       bool send_cmd_connect_done(sensor_id_t sensor_id);
-
-       bool cmd_get_id(void *payload);
-       bool cmd_connect(void *payload);
-       bool cmd_disconnect(void *payload);
-       bool cmd_post(void *payload);
-
-       static external_client_manager& get_client_manager(void);
-
-       void get_info(std::string &info);
-public:
-       external_sensor_worker(const csocket& socket);
-       ~external_sensor_worker();
-
-       bool start(void);
-};
-
-#endif /* _EXTERNAL_SENSOR_WORKER_H_ */
index e3e9f73..2ce210c 100644 (file)
  *
  */
 
-#include <signal.h>
-#include <sensor_log.h>
-#include <server.h>
-#include <dbus_util.h>
-#include <sensor_loader.h>
-#include <string>
-
+/* TODO: create conf file for calibration paths */
 #define CAL_NODE_PATH "/sys/class/sensors/ssp_sensor/set_cal_data"
-#define SET_CAL 1
-
-#define TIMEOUT 10
-
-static void sig_term_handler(int signo, siginfo_t *info, void *data)
-{
-       char proc_name[NAME_MAX];
-
-       get_proc_name(info->si_pid, proc_name);
-
-       _E("Received SIGTERM(%d) from %s(%d)\n", signo, proc_name, info->si_pid);
-
-       server::get_instance().stop();
-}
-
-static void signal_init(void)
-{
-       struct sigaction sig_act;
-       memset(&sig_act, 0, sizeof(struct sigaction));
-
-       sig_act.sa_handler = SIG_IGN;
-       sigaction(SIGCHLD, &sig_act, NULL);
-       sigaction(SIGPIPE, &sig_act, NULL);
-
-       sig_act.sa_handler = NULL;
-       sig_act.sa_sigaction = sig_term_handler;
-       sig_act.sa_flags = SA_SIGINFO;
-       sigaction(SIGTERM, &sig_act, NULL);
-       sigaction(SIGABRT, &sig_act, NULL);
-       sigaction(SIGINT, &sig_act, NULL);
-}
-
-static void set_cal_data(void)
-{
-       FILE *fp = fopen(CAL_NODE_PATH, "w");
-
-       if (!fp) {
-               _I("Not support calibration_node");
-               return;
-       }
-
-       fprintf(fp, "%d", SET_CAL);
-
-       if (fp)
-               fclose(fp);
-
-       _I("Succeeded to set calibration data");
-
-       return;
-}
-
-static gboolean terminate(gpointer data)
-{
-       std::vector<sensor_base *> sensors = sensor_loader::get_instance().get_sensors(ALL_SENSOR);
-
-       if (sensors.size() == 0) {
-               _I("Terminating sensord..");
-               server::get_instance().stop();
-       }
-
-       return FALSE;
-}
 
 int main(int argc, char *argv[])
 {
-       _I("Sensord started");
-
-       signal_init();
-
-       init_dbus();
-
-       set_cal_data();
-
-       /* TODO: loading sequence has to be moved to server */
-       sensor_loader::get_instance().load();
-       g_timeout_add_seconds(TIMEOUT, terminate, NULL);
-
-       server::get_instance().run();
-       server::get_instance().stop();
-
-       fini_dbus();
-
-       _I("Sensord terminated");
        return 0;
 }
index 3da9ac6..20b03ec 100644 (file)
  *
  */
 
+#include <permission_checker.h>
 #include <cynara-client.h>
 #include <cynara-creds-socket.h>
 #include <cynara-session.h>
-#include <permission_checker.h>
-#include <sensor_common.h>
-#include <sensor_log.h>
-#include <sensor_loader.h>
-#include <sensor_base.h>
-#include <vector>
 
 #define CACHE_SIZE 16
 
-static cynara *cynara_env = NULL;
-
 static bool check_privilege_by_sockfd(int sock_fd, const char *priv, const char *access)
 {
-       retvm_if(cynara_env == NULL, false, "Cynara not initialized");
-
-       int ret;
-       int pid = -1;
-       char *client = NULL;
-       char *session = NULL;
-       char *user = NULL;
-
-       retvm_if(cynara_creds_socket_get_pid(sock_fd, &pid) != CYNARA_API_SUCCESS, false, "Getting PID failed");
-
-       if (cynara_creds_socket_get_client(sock_fd, CLIENT_METHOD_DEFAULT, &client) != CYNARA_API_SUCCESS ||
-                       cynara_creds_socket_get_user(sock_fd, USER_METHOD_DEFAULT, &user) != CYNARA_API_SUCCESS ||
-                       (session = cynara_session_from_pid(pid)) == NULL) {
-               _E("Getting client info failed");
-               free(client);
-               free(user);
-               free(session);
-               return false;
-       }
-
-       ret = cynara_check(cynara_env, client, session, user, priv);
-
-       free(client);
-       free(session);
-       free(user);
-
-       return (ret == CYNARA_API_ACCESS_ALLOWED);
+       return true;
 }
 
 permission_checker::permission_checker()
-: m_permission_set(0)
 {
-       init();
-       init_cynara();
 }
 
 permission_checker::~permission_checker()
 {
-       deinit_cynara();
-}
-
-permission_checker& permission_checker::get_instance(void)
-{
-       static permission_checker inst;
-       return inst;
-}
-
-void permission_checker::init(void)
-{
-       m_permission_infos.push_back(std::make_shared<permission_info>(SENSOR_PERMISSION_BIO, "http://tizen.org/privilege/healthinfo", ""));
-
-       std::vector<sensor_base *> sensors;
-       sensors = sensor_loader::get_instance().get_sensors(ALL_SENSOR);
-
-       for (unsigned int i = 0; i < sensors.size(); ++i)
-               m_permission_set |= sensors[i]->get_permission();
-
-       _I("Permission Set = %d", m_permission_set);
-}
-
-void permission_checker::init_cynara(void)
-{
-       AUTOLOCK(m_mutex);
-
-       cynara_configuration *conf;
-
-       int err = cynara_configuration_create(&conf);
-       retm_if(err != CYNARA_API_SUCCESS, "Failed to create cynara configuration");
-
-       err = cynara_configuration_set_cache_size(conf, CACHE_SIZE);
-       if (err != CYNARA_API_SUCCESS) {
-               _E("Failed to set cynara cache");
-               cynara_configuration_destroy(conf);
-               return;
-       }
-
-       err = cynara_initialize(&cynara_env, conf);
-       cynara_configuration_destroy(conf);
-
-       if (err != CYNARA_API_SUCCESS) {
-               _E("Failed to initialize cynara");
-               cynara_env = NULL;
-               return;
-       }
-
-       _I("Cynara initialized");
-}
-
-void permission_checker::deinit_cynara(void)
-{
-       AUTOLOCK(m_mutex);
-
-       if (cynara_env)
-               cynara_finish(cynara_env);
-
-       cynara_env = NULL;
-}
-
-int permission_checker::get_permission(int sock_fd)
-{
-       AUTOLOCK(m_mutex);
-
-       int permission = SENSOR_PERMISSION_STANDARD;
-
-       for (unsigned int i = 0; i < m_permission_infos.size(); ++i) {
-               if (!(m_permission_set & m_permission_infos[i]->permission))
-                       continue;
-
-               if (check_privilege_by_sockfd(sock_fd, m_permission_infos[i]->privilege.c_str(), m_permission_infos[i]->access.c_str()))
-                       permission |= m_permission_infos[i]->permission;
-       }
-
-       return permission;
 }
index d42ba09..01cc8b4 100644 (file)
 #ifndef _PERMISSION_CHECKER_H_
 #define _PERMISSION_CHECKER_H_
 
-#include <cmutex.h>
 #include <string>
 #include <vector>
 #include <memory>
 
 class permission_checker {
-public:
-       static permission_checker& get_instance(void);
-
-       int get_permission(int sock_fd);
-
-private:
-       class permission_info {
-               public:
-               permission_info(int _permission, std::string _priv, std::string _access)
-               : permission(_permission)
-               , privilege(_priv)
-               , access(_access)
-               {
-               }
-               int permission;
-               std::string privilege;
-               std::string access;
-       };
-
-       typedef std::vector<std::shared_ptr<permission_info>> permission_info_vector;
-
        permission_checker();
-       permission_checker(permission_checker const&) {};
-       permission_checker& operator=(permission_checker const&);
-
        ~permission_checker();
-
-       void init(void);
-
-private:
-       permission_info_vector m_permission_infos;
-       int m_permission_set;
-       cmutex m_mutex;
-
-private:
-       void init_cynara(void);
-       void deinit_cynara(void);
 };
 
 #endif /* _PERMISSION_CHECKER_H_ */
index 65ab74e..f1943f6 100644 (file)
  *
  */
 
-#include <sensor_common.h>
 #include <physical_sensor.h>
-#include <sensor_event_queue.h>
-
-#define UNKNOWN_NAME "UNKNOWN_SENSOR"
-
-cmutex physical_sensor::m_mutex;
 
 physical_sensor::physical_sensor()
-: m_sensor_device(NULL)
 {
 }
 
 physical_sensor::~physical_sensor()
 {
-       _I("physical sensor is destroyed");
-}
-
-void physical_sensor::set_sensor_info(const sensor_info_t *info)
-{
-       m_info = info;
-}
-
-void physical_sensor::set_sensor_device(sensor_device *device)
-{
-       m_sensor_device = device;
-}
-
-sensor_type_t physical_sensor::get_type(void)
-{
-       return static_cast<sensor_type_t>(m_info->type);
-}
-
-unsigned int physical_sensor::get_event_type(void)
-{
-       return m_info->event_type;
-}
-
-const char* physical_sensor::get_name(void)
-{
-       retv_if(!m_info, UNKNOWN_NAME);
-       retv_if(!m_info->name, UNKNOWN_NAME);
-
-       return m_info->name;
-}
-
-uint32_t physical_sensor::get_hal_id(void)
-{
-       return m_info->id;
-}
-
-int physical_sensor::get_poll_fd(void)
-{
-       AUTOLOCK(m_mutex);
-
-       if (!m_sensor_device)
-               return OP_ERROR;
-
-       return m_sensor_device->get_poll_fd();
-}
-
-bool physical_sensor::on_event(const sensor_data_t *data, int data_len, int remains)
-{
-       return true;
-}
-
-bool physical_sensor::read_fd(std::vector<uint32_t> &ids)
-{
-       AUTOLOCK(m_mutex);
-       int size;
-       uint32_t *_ids;
-
-       if (!m_sensor_device)
-               return false;
-
-       size = m_sensor_device->read_fd(&_ids);
-
-       if (size == 0)
-               return false;
-
-       for (int i = 0; i < size; ++i)
-               ids.push_back(_ids[i]);
-
-       return true;
-}
-
-int physical_sensor::get_data(sensor_data_t **data, int *length)
-{
-       AUTOLOCK(m_mutex);
-
-       if (!m_sensor_device)
-               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 OP_ERROR;
-       }
-
-       return remains;
-}
-
-bool physical_sensor::flush(void)
-{
-       AUTOLOCK(m_mutex);
-
-       if (!m_sensor_device)
-               return false;
-
-       return m_sensor_device->flush(m_info->id);
-}
-
-bool physical_sensor::set_interval(unsigned long interval)
-{
-       AUTOLOCK(m_mutex);
-
-       if (!m_sensor_device)
-               return false;
-
-       _I("Polling interval is set to %dms", interval);
-
-       return m_sensor_device->set_interval(m_info->id, interval);
-}
-
-bool physical_sensor::set_batch_latency(unsigned long latency)
-{
-       AUTOLOCK(m_mutex);
-
-       if (!m_sensor_device)
-               return false;
-
-       _I("Batch latency is set to %dms", latency);
-
-       return m_sensor_device->set_batch_latency(m_info->id, latency);
 }
 
-int physical_sensor::set_attribute(int32_t attribute, int32_t value)
-{
-       AUTOLOCK(m_mutex);
-
-       if (!m_sensor_device)
-               return OP_ERROR;
-
-       if (!m_sensor_device->set_attribute_int(m_info->id, attribute, value))
-               return OP_ERROR;
-
-       return OP_SUCCESS;
-}
-
-int physical_sensor::set_attribute(int32_t attribute, char *value, int len)
-{
-       AUTOLOCK(m_mutex);
-
-       if (!m_sensor_device)
-               return OP_ERROR;
-
-       if (!m_sensor_device->set_attribute_str(m_info->id, attribute, value, len))
-               return OP_ERROR;
-
-       return OP_SUCCESS;
-}
-
-bool physical_sensor::on_start(void)
-{
-       AUTOLOCK(m_mutex);
-
-       if (!m_sensor_device)
-               return false;
-
-       return m_sensor_device->enable(m_info->id);
-}
-
-bool physical_sensor::on_stop(void)
-{
-       AUTOLOCK(m_mutex);
-
-       if (!m_sensor_device)
-               return false;
-
-       return m_sensor_device->disable(m_info->id);
-}
-
-bool physical_sensor::get_sensor_info(sensor_info &info)
-{
-       info.set_type(get_type());
-       info.set_id(get_id());
-       info.set_privilege(SENSOR_PRIVILEGE_PUBLIC); // FIXME
-       info.set_name(m_info->model_name);
-       info.set_vendor(m_info->vendor);
-       info.set_min_range(m_info->min_range);
-       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);
-       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);
-
-       return true;
-}
index 1264931..669bbeb 100644 (file)
 #ifndef _PHYSICAL_SENSOR_H_
 #define _PHYSICAL_SENSOR_H_
 
-#include <sensor_base.h>
-#include <worker_thread.h>
-#include <sensor_hal.h>
-
-class physical_sensor : public sensor_base {
+class physical_sensor {
 public:
        physical_sensor();
        virtual ~physical_sensor();
-
-       /* setting module */
-       void set_sensor_info(const sensor_info_t *info);
-       void set_sensor_device(sensor_device *device);
-
-       /* module info */
-       virtual sensor_type_t get_type(void);
-       virtual unsigned int get_event_type(void);
-       virtual const char* get_name(void);
-       virtual uint32_t get_hal_id(void);
-
-       int get_poll_fd(void);
-
-       virtual bool on_event(const sensor_data_t *data, int data_len, int remains);
-
-       virtual bool read_fd(std::vector<uint32_t> &ids);
-       virtual int get_data(sensor_data_t **data, int *length);
-       virtual bool flush(void);
-
-protected:
-       const sensor_info_t *m_info;
-       sensor_device *m_sensor_device;
-       uint32_t hal_id;
-
-       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 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_ */
diff --git a/src/server/sensor_base.cpp b/src/server/sensor_base.cpp
deleted file mode 100644 (file)
index 24e16a7..0000000
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdint.h>
-#include <limits.h>
-#include <sensor_hal_types.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_last_data(NULL)
-, m_id(SENSOR_ID_INVALID)
-, m_permission(SENSOR_PERMISSION_STANDARD)
-, m_started(false)
-, m_client(0)
-{
-}
-
-sensor_base::~sensor_base()
-{
-}
-
-void sensor_base::set_id(sensor_id_t id)
-{
-       m_id = id;
-}
-
-sensor_id_t sensor_base::get_id(void)
-{
-       if (m_id == SENSOR_ID_INVALID)
-               return UNKNOWN_SENSOR;
-
-       return m_id;
-}
-
-sensor_type_t sensor_base::get_type(void)
-{
-       return UNKNOWN_SENSOR;
-}
-
-unsigned int sensor_base::get_event_type(void)
-{
-       return -1;
-}
-
-const char* sensor_base::get_name(void)
-{
-       return NULL;
-}
-
-bool sensor_base::get_sensor_info(sensor_info &info)
-{
-       return false;
-}
-
-bool sensor_base::is_virtual(void)
-{
-       return false;
-}
-
-int sensor_base::get_data(sensor_data_t **data, int *length)
-{
-       return OP_ERROR;
-}
-
-bool sensor_base::flush(void)
-{
-       return true;
-}
-
-int sensor_base::add_attribute(int client_id, int32_t attribute, int32_t value)
-{
-       return set_attribute(attribute, value);
-}
-
-int sensor_base::add_attribute(int client_id, int32_t attribute, char *value, int value_size)
-{
-       return set_attribute(attribute, value, value_size);
-}
-
-bool sensor_base::delete_attribute(int client_id)
-{
-       return true;
-}
-
-int sensor_base::set_attribute(int32_t attribute, int32_t value)
-{
-       return OP_SUCCESS;
-}
-
-int sensor_base::set_attribute(int32_t attribute, char *value, int value_size)
-{
-       return OP_SUCCESS;
-}
-
-bool sensor_base::start(void)
-{
-       AUTOLOCK(m_client_mutex);
-
-       if (!pre_start())
-               return false;
-
-       ++m_client;
-
-       if (m_client == 1) {
-               if (!on_start()) {
-                       _E("[%s] sensor failed to start", get_name());
-                       return false;
-               }
-
-               m_started = true;
-       }
-
-       _I("[%s] sensor started, #client = %d", get_name(), m_client);
-
-       return true;
-}
-
-bool sensor_base::stop(void)
-{
-       AUTOLOCK(m_client_mutex);
-
-       --m_client;
-
-       if (m_client == 0) {
-               if (!on_stop()) {
-                       _E("[%s] sensor faild to stop", get_name());
-                       return false;
-               }
-
-               m_started = false;
-
-               free(m_last_data);
-               m_last_data = NULL;
-       }
-
-       _I("[%s] sensor stopped, #client = %d", get_name(), m_client);
-
-       return true;
-}
-
-bool sensor_base::is_started(void)
-{
-       AUTOLOCK(m_client_mutex);
-
-       return m_started;
-}
-
-bool sensor_base::add_interval(int client_id, unsigned int interval, bool is_processor)
-{
-       unsigned int prev_min, cur_min;
-
-       AUTOLOCK(m_sensor_info_list_mutex);
-
-       prev_min = m_sensor_info_list.get_min_interval();
-
-       if (!m_sensor_info_list.add_interval(client_id, interval, is_processor))
-               return false;
-
-       cur_min = m_sensor_info_list.get_min_interval();
-
-       if (cur_min != prev_min) {
-               _I("Min interval for sensor[%#llx] is changed from %dms to %dms"
-                       " by%sclient[%d] adding interval",
-                       get_id(), prev_min, cur_min,
-                       is_processor ? " processor " : " ", client_id);
-
-               set_interval(cur_min);
-       }
-
-       return true;
-}
-
-bool sensor_base::delete_interval(int client_id, bool is_processor)
-{
-       unsigned int prev_min, cur_min;
-       AUTOLOCK(m_sensor_info_list_mutex);
-
-       prev_min = m_sensor_info_list.get_min_interval();
-
-       if (!m_sensor_info_list.delete_interval(client_id, is_processor))
-               return false;
-
-       cur_min = m_sensor_info_list.get_min_interval();
-
-       if (!cur_min) {
-               _I("No interval for sensor[%#llx] by%sclient[%d] deleting interval, "
-                        "so set to default %dms",
-                        get_id(), is_processor ? " processor " : " ",
-                        client_id, POLL_1HZ_MS);
-
-               set_interval(POLL_1HZ_MS);
-       } else if (cur_min != prev_min) {
-               _I("Min interval for sensor[%#llx] is changed from %dms to %dms"
-                       " by%sclient[%d] deleting interval",
-                       get_id(), prev_min, cur_min,
-                       is_processor ? " processor " : " ", client_id);
-
-               set_interval(cur_min);
-       }
-
-       return true;
-}
-
-unsigned int sensor_base::get_interval(int client_id, bool is_processor)
-{
-       AUTOLOCK(m_sensor_info_list_mutex);
-
-       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_sensor_info_list_mutex);
-
-       prev_max = m_sensor_info_list.get_max_batch();
-
-       if (!m_sensor_info_list.add_batch(client_id, latency))
-               return false;
-
-       cur_max = m_sensor_info_list.get_max_batch();
-
-       if (cur_max != prev_max) {
-               _I("Max latency for sensor[%#llx] is changed from %dms to %dms by client[%d] adding latency",
-                       get_id(), prev_max, cur_max, client_id);
-               set_batch_latency(cur_max);
-       }
-
-       return true;
-}
-
-bool sensor_base::delete_batch(int client_id)
-{
-       unsigned int prev_max, cur_max;
-       AUTOLOCK(m_sensor_info_list_mutex);
-
-       prev_max = m_sensor_info_list.get_max_batch();
-
-       if (!m_sensor_info_list.delete_batch(client_id))
-               return false;
-
-       cur_max = m_sensor_info_list.get_max_batch();
-
-       if (!cur_max) {
-               _I("No latency for sensor[%#llx] by client[%d] deleting latency, so set to default count",
-                        get_id(), client_id);
-
-               set_batch_latency(UINT_MAX);
-       } else if (cur_max != prev_max) {
-               _I("Max latency for sensor[%#llx] is changed from %dms to %dms by client[%d] deleting latency",
-                       get_id(), prev_max, cur_max, client_id);
-
-               set_batch_latency(cur_max);
-       }
-
-       return true;
-}
-
-unsigned int sensor_base::get_batch(int client_id)
-{
-       AUTOLOCK(m_sensor_info_list_mutex);
-
-       return m_sensor_info_list.get_batch(client_id);
-}
-
-int sensor_base::get_permission(void)
-{
-       return m_permission;
-}
-
-void sensor_base::set_permission(int permission)
-{
-       m_permission = permission;
-}
-
-bool sensor_base::push(sensor_event_t *event)
-{
-       if (!event || !(event->data))
-               return false;
-
-       set_cache(event->data);
-
-       AUTOLOCK(m_client_mutex);
-
-       if (m_client <= 0)
-               return false;
-
-       sensor_event_queue::get_instance().push(event);
-       return true;
-}
-
-void sensor_base::set_cache(sensor_data_t *data)
-{
-       AUTOLOCK(m_data_cache_mutex);
-
-       /* Caching the last known data for sync-read support */
-       if (m_last_data == NULL) {
-               m_last_data = (sensor_data_t*)malloc(sizeof(sensor_data_t));
-               retm_if(m_last_data == NULL, "Memory allocation failed");
-       }
-
-       memcpy(m_last_data, data, sizeof(sensor_data_t));
-}
-
-int sensor_base::get_cache(sensor_data_t **data)
-{
-       retv_if(m_last_data == NULL, -ENODATA);
-
-       *data = (sensor_data_t *)malloc(sizeof(sensor_data_t));
-       retvm_if(*data == NULL, -ENOMEM, "Memory allocation failed");
-
-       AUTOLOCK(m_data_cache_mutex);
-
-       memcpy(*data, m_last_data, sizeof(sensor_data_t));
-       return 0;
-}
-
-bool sensor_base::set_interval(unsigned long interval)
-{
-       return true;
-}
-
-bool sensor_base::set_batch_latency(unsigned long latency)
-{
-       return true;
-}
-
-bool sensor_base::pre_start(void)
-{
-       return true;
-}
-
-bool sensor_base::on_start(void)
-{
-       return true;
-}
-
-bool sensor_base::on_stop(void)
-{
-       return true;
-}
-
-unsigned long long sensor_base::get_timestamp(void)
-{
-       struct timespec t;
-       clock_gettime(CLOCK_MONOTONIC, &t);
-       return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
-}
-
-unsigned long long sensor_base::get_timestamp(timeval *t)
-{
-       if (!t) {
-               _E("t is NULL");
-               return 0;
-       }
-
-       return ((unsigned long long)(t->tv_sec)*1000000LL +t->tv_usec);
-}
diff --git a/src/server/sensor_base.h b/src/server/sensor_base.h
deleted file mode 100644 (file)
index 89b88ed..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_BASE_H_
-#define _SENSOR_BASE_H_
-
-#include <sensor_types.h>
-#include <sensor_info_list.h>
-#include <cmutex.h>
-
-#include <sensor_log.h>
-#include <sensor_common.h>
-#include <worker_thread.h>
-#include <sensor_info.h>
-#include <sensor_hal_types.h>
-#include <vector>
-
-class sensor_base {
-public:
-       sensor_base();
-       virtual ~sensor_base();
-
-       /* id */
-       void set_id(sensor_id_t id);
-       sensor_id_t get_id(void);
-
-       /* sensor info */
-       virtual sensor_type_t get_type(void);
-       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);
-
-       /* set/get data */
-       virtual int get_data(sensor_data_t **data, int *length);
-       int get_cache(sensor_data_t **data);
-
-       virtual bool flush(void);
-       virtual int add_attribute(int client_id, int32_t attribute, int32_t value);
-       virtual int add_attribute(int client_id, int32_t attribute, char *value, int value_size);
-       virtual bool delete_attribute(int client_id);
-
-       /* start/stop */
-       bool start(void);
-       bool stop(void);
-       bool is_started(void);
-
-       /* interval / batch */
-       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);
-
-       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 push(sensor_event_t *event);
-
-       /* permission(privilege) */
-       int get_permission(void);
-
-protected:
-       sensor_data_t *m_last_data;
-
-       void set_permission(int permission);
-
-       unsigned long long get_timestamp(void);
-       unsigned long long get_timestamp(timeval *t);
-
-private:
-       sensor_id_t m_id;
-       int m_permission;
-
-       sensor_info_list m_sensor_info_list;
-       cmutex m_sensor_info_list_mutex;
-
-       bool m_started;
-       unsigned int m_client;
-       cmutex m_client_mutex;
-
-       cmutex m_data_cache_mutex;
-
-       virtual int set_attribute(int32_t attribute, int32_t value);
-       virtual int set_attribute(int32_t attribute, char *value, int value_size);
-
-       virtual bool set_interval(unsigned long interval);
-       virtual bool set_batch_latency(unsigned long latency);
-
-       virtual bool pre_start(void);
-       virtual bool on_start(void);
-       virtual bool on_stop(void);
-
-       void set_cache(sensor_data_t *data);
-};
-
-#endif /* _SENSOR_BASE_H_ */
diff --git a/src/server/sensor_event_dispatcher.cpp b/src/server/sensor_event_dispatcher.cpp
deleted file mode 100644 (file)
index eeb4236..0000000
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_common.h>
-#include <command_common.h>
-#include <sensor_event_dispatcher.h>
-#include <sensor_log.h>
-#include <thread>
-#include <vector>
-
-using std::thread;
-using std::vector;
-using std::pair;
-
-#define MAX_PENDING_CONNECTION 32
-
-sensor_event_dispatcher::sensor_event_dispatcher()
-: m_running(false)
-{
-}
-
-sensor_event_dispatcher::~sensor_event_dispatcher()
-{
-}
-
-sensor_event_dispatcher& sensor_event_dispatcher::get_instance(void)
-{
-       static sensor_event_dispatcher inst;
-       return inst;
-}
-
-bool sensor_event_dispatcher::run(void)
-{
-       m_running = true;
-
-       thread dispatcher(&sensor_event_dispatcher::dispatch_event, this);
-       dispatcher.detach();
-
-       return true;
-}
-
-bool sensor_event_dispatcher::stop(void)
-{
-       m_running = false;
-
-       return true;
-}
-
-void sensor_event_dispatcher::accept_event_channel(csocket client_socket)
-{
-       int client_id;
-       channel_ready_t event_channel_ready;
-       client_info_manager& client_info_manager = get_client_info_manager();
-
-       client_socket.set_connection_mode();
-
-       if (client_socket.recv(&client_id, sizeof(client_id)) <= 0) {
-               _E("Failed to receive client id on socket fd[%d]", client_socket.get_socket_fd());
-               return;
-       }
-
-       client_socket.set_transfer_mode();
-
-       if (!get_client_info_manager().set_event_socket(client_id, client_socket)) {
-               _E("Failed to store event socket[%d] for %s", client_socket.get_socket_fd(),
-                       client_info_manager.get_client_info(client_id));
-               return;
-       }
-
-       event_channel_ready.magic = CHANNEL_MAGIC_NUM;
-       event_channel_ready.client_id = client_id;
-
-       _I("Event channel is accepted for %s on socket[%d]",
-               client_info_manager.get_client_info(client_id), client_socket.get_socket_fd());
-
-       if (client_socket.send(&event_channel_ready, sizeof(event_channel_ready)) <= 0) {
-               _E("Failed to send event_channel_ready packet to %s on socket fd[%d]",
-                       client_info_manager.get_client_info(client_id), client_socket.get_socket_fd());
-               return;
-       }
-}
-
-void sensor_event_dispatcher::accept_event_connections(csocket client_socket)
-{
-       thread event_channel_creator(&sensor_event_dispatcher::accept_event_channel, this, client_socket);
-       event_channel_creator.detach();
-}
-
-void sensor_event_dispatcher::dispatch_event(void)
-{
-       const int MAX_SYNTH_PER_SENSOR = 5;
-
-       vector<sensor_event_t> v_sensor_events(MAX_SYNTH_PER_SENSOR);
-
-       _I("Event Dispatcher started");
-
-       while (m_running) {
-               void *seed_event = get_event_queue().pop();
-
-               vector<void *> sensor_events;
-               sensor_events.push_back(seed_event);
-
-               virtual_sensors v_sensors = get_active_virtual_sensors();
-
-               auto it_v_sensor = v_sensors.begin();
-
-               while (it_v_sensor != v_sensors.end()) {
-                       int synthesized_cnt;
-                       v_sensor_events.clear();
-                       (*it_v_sensor)->synthesize(*((sensor_event_t *)seed_event));
-                       synthesized_cnt = v_sensor_events.size();
-
-                       for (int i = 0; i < synthesized_cnt; ++i) {
-                               sensor_event_t *v_event = (sensor_event_t*)malloc(sizeof(sensor_event_t));
-                               if (!v_event) {
-                                       _E("Failed to allocate memory");
-                                       continue;
-                               }
-
-                               memcpy(v_event, &v_sensor_events[i], sizeof(sensor_event_t));
-                               sensor_events.push_back(v_event);
-                       }
-
-                       ++it_v_sensor;
-               }
-
-               sort_sensor_events(sensor_events);
-
-               for (unsigned int i = 0; i < sensor_events.size(); ++i) {
-                       if (is_record_event(((sensor_event_t *)(sensor_events[i]))->event_type))
-                               put_last_event(((sensor_event_t *)(sensor_events[i]))->event_type, *((sensor_event_t *)(sensor_events[i])));
-               }
-
-               send_sensor_events(sensor_events);
-       }
-}
-
-void sensor_event_dispatcher::send_sensor_events(vector<void *> &events)
-{
-       sensor_event_t *sensor_event = NULL;
-       client_info_manager& client_info_manager = get_client_info_manager();
-
-       const int RESERVED_CLIENT_CNT = 20;
-       static client_id_vec id_vec(RESERVED_CLIENT_CNT);
-
-       for (unsigned int i = 0; i < events.size(); ++i) {
-               sensor_id_t sensor_id;
-               unsigned int event_type;
-
-               sensor_event = (sensor_event_t*)events[i];
-               sensor_id = sensor_event->sensor_id;
-               event_type = sensor_event->event_type;
-
-               id_vec.clear();
-               client_info_manager.get_listener_ids(sensor_id, event_type, id_vec);
-
-               auto it_client_id = id_vec.begin();
-
-               while (it_client_id != id_vec.end()) {
-                       csocket client_socket;
-                       client_info_manager.get_event_socket(*it_client_id, client_socket);
-                       bool ret = (client_socket.send(sensor_event, sizeof(sensor_event_t)) > 0);
-
-                       ret = (ret & (client_socket.send(sensor_event->data, sensor_event->data_length) > 0));
-
-                       if (!ret)
-                               _E("Failed to send event[%#x] to %s on socket[%d]", event_type, client_info_manager.get_client_info(*it_client_id), client_socket.get_socket_fd());
-
-                       ++it_client_id;
-               }
-
-               free(sensor_event->data);
-               free(sensor_event);
-       }
-}
-
-client_info_manager& sensor_event_dispatcher::get_client_info_manager(void)
-{
-       return client_info_manager::get_instance();
-}
-
-sensor_event_queue& sensor_event_dispatcher::get_event_queue(void)
-{
-       return sensor_event_queue::get_instance();
-}
-
-bool sensor_event_dispatcher::is_record_event(unsigned int event_type)
-{
-       return false;
-}
-
-void sensor_event_dispatcher::put_last_event(unsigned int event_type, const sensor_event_t &event)
-{
-       AUTOLOCK(m_last_events_mutex);
-       m_last_events[event_type] = event;
-}
-
-bool sensor_event_dispatcher::get_last_event(unsigned int event_type, sensor_event_t &event)
-{
-       AUTOLOCK(m_last_events_mutex);
-
-       auto it_event = m_last_events.find(event_type);
-
-       if (it_event == m_last_events.end())
-               return false;
-
-       event = it_event->second;
-       return true;
-}
-
-bool sensor_event_dispatcher::has_active_virtual_sensor(virtual_sensor *sensor)
-{
-       AUTOLOCK(m_active_virtual_sensors_mutex);
-
-       auto it_v_sensor = find(m_active_virtual_sensors.begin(), m_active_virtual_sensors.end(), sensor);
-
-       return (it_v_sensor != m_active_virtual_sensors.end());
-}
-
-virtual_sensors sensor_event_dispatcher::get_active_virtual_sensors(void)
-{
-       AUTOLOCK(m_active_virtual_sensors_mutex);
-
-       return m_active_virtual_sensors;
-}
-
-struct sort_comp {
-       bool operator()(const void *left, const void *right) {
-               return ((sensor_event_t *)left)->data->timestamp < ((sensor_event_t *)right)->data->timestamp;
-       }
-};
-
-void sensor_event_dispatcher::sort_sensor_events(vector<void *> &events)
-{
-       std::sort(events.begin(), events.end(), sort_comp());
-}
-
-void sensor_event_dispatcher::request_last_event(int client_id, sensor_id_t sensor_id)
-{
-       client_info_manager& client_info_manager = get_client_info_manager();
-       event_type_vector event_vec;
-       csocket client_socket;
-
-       if (client_info_manager.get_registered_events(client_id, sensor_id, event_vec)) {
-               if (!client_info_manager.get_event_socket(client_id, client_socket)) {
-                       _E("Failed to get event socket from %s",
-                                       client_info_manager.get_client_info(client_id));
-                       return;
-               }
-
-               auto it_event = event_vec.begin();
-               while (it_event != event_vec.end()) {
-                       sensor_event_t event;
-                       if (is_record_event(*it_event) && get_last_event(*it_event, event)) {
-                               if (client_socket.send(&event, sizeof(event)) > 0)
-                                       _I("Send the last event[%#x] to %s on socket[%d]", event.event_type,
-                                               client_info_manager.get_client_info(client_id), client_socket.get_socket_fd());
-                               else
-                                       _E("Failed to send event[%#x] to %s on socket[%d]", event.event_type,
-                                               client_info_manager.get_client_info(client_id), client_socket.get_socket_fd());
-                       }
-                       ++it_event;
-               }
-       }
-}
-
-bool sensor_event_dispatcher::add_active_virtual_sensor(virtual_sensor *sensor)
-{
-       AUTOLOCK(m_active_virtual_sensors_mutex);
-
-       if (!m_running)
-               return true;
-
-       if (has_active_virtual_sensor(sensor)) {
-               _E("[%s] sensor is already added on active virtual sensors", sensor->get_name());
-               return false;
-       }
-
-       m_active_virtual_sensors.push_back(sensor);
-
-       return true;
-}
-
-bool sensor_event_dispatcher::delete_active_virtual_sensor(virtual_sensor *sensor)
-{
-       AUTOLOCK(m_active_virtual_sensors_mutex);
-
-       if (!m_running)
-               return true;
-
-       if (sensor)
-               m_active_virtual_sensors.remove(sensor);
-
-       return true;
-}
diff --git a/src/server/sensor_event_dispatcher.h b/src/server/sensor_event_dispatcher.h
deleted file mode 100644 (file)
index 6d79e44..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#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 <virtual_sensor.h>
-#include <unordered_map>
-#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 {
-public:
-       static sensor_event_dispatcher& get_instance(void);
-
-       bool run(void);
-       bool stop(void);
-       void accept_event_connections(csocket client_socket);
-
-       void request_last_event(int client_id, sensor_id_t sensor_id);
-
-       bool add_active_virtual_sensor(virtual_sensor *sensor);
-       bool delete_active_virtual_sensor(virtual_sensor *sensor);
-
-private:
-       csocket m_accept_socket;
-       cmutex m_mutex;
-       cmutex m_last_events_mutex;
-       event_type_last_event_map m_last_events;
-       virtual_sensors m_active_virtual_sensors;
-       cmutex m_active_virtual_sensors_mutex;
-       bool m_running;
-
-       sensor_event_dispatcher();
-       ~sensor_event_dispatcher();
-       sensor_event_dispatcher(sensor_event_dispatcher const&) {};
-       sensor_event_dispatcher& operator=(sensor_event_dispatcher const&);
-
-       void accept_event_channel(csocket client_socket);
-
-       void dispatch_event(void);
-       void send_sensor_events(std::vector<void *> &events);
-       static client_info_manager& get_client_info_manager(void);
-       static sensor_event_queue& get_event_queue(void);
-
-       bool is_record_event(unsigned int event_type);
-       void put_last_event(unsigned int event_type, const sensor_event_t &event);
-       bool get_last_event(unsigned int event_type, sensor_event_t &event);
-
-       bool has_active_virtual_sensor(virtual_sensor *sensor);
-       virtual_sensors get_active_virtual_sensors(void);
-
-       void sort_sensor_events(std::vector<void *> &events);
-};
-
-#endif /* _SENSOR_EVENT_DISPATCHER_H_ */
diff --git a/src/server/sensor_event_poller.cpp b/src/server/sensor_event_poller.cpp
deleted file mode 100644 (file)
index fa23e6f..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <signal.h>
-#include <sys/signalfd.h>
-#include <sensor_base.h>
-#include <physical_sensor.h>
-#include <sensor_event_poller.h>
-#include <sensor_loader.h>
-#include <algorithm>
-#include <vector>
-
-sensor_event_poller::sensor_event_poller()
-{
-       init_sensor_map();
-       init_fd();
-       init_signal_fd();
-}
-
-sensor_event_poller::~sensor_event_poller()
-{
-       fd_sensors_t::iterator it;
-       for (it = m_fd_sensors.begin(); it != m_fd_sensors.end(); it = m_fd_sensors.upper_bound(it->first))
-               m_poller.del_fd(it->first);
-}
-
-void sensor_event_poller::init_sensor_map(void)
-{
-       int fd;
-       physical_sensor *sensor;
-
-       std::vector<sensor_base *> sensors;
-       sensors = sensor_loader::get_instance().get_sensors(ALL_SENSOR);
-
-       std::vector<sensor_base *>::iterator it;
-
-       for (it = sensors.begin(); it != sensors.end(); ++it) {
-               sensor = dynamic_cast<physical_sensor *>(*it);
-               if (sensor == NULL)
-                       continue;
-
-               fd = sensor->get_poll_fd();
-
-               if (fd < 0)
-                       continue;
-
-               m_fd_sensors.insert(std::make_pair(fd, sensor));
-       }
-}
-
-void sensor_event_poller::init_fd(void)
-{
-       fd_sensors_t::iterator it;
-       for (it = m_fd_sensors.begin(); it != m_fd_sensors.end(); it = m_fd_sensors.upper_bound(it->first)) {
-               /* if fd is not valid, it is not added to poller */
-               add_poll_fd(it->first);
-       }
-}
-
-void sensor_event_poller::init_signal_fd(void)
-{
-       int sfd;
-       sigset_t mask;
-
-       sigemptyset(&mask);
-       sigaddset(&mask, SIGTERM);
-       sigaddset(&mask, SIGABRT);
-       sigaddset(&mask, SIGINT);
-
-       sfd = signalfd(-1, &mask, 0);
-       m_poller.add_signal_fd(sfd);
-}
-
-bool sensor_event_poller::add_poll_fd(int fd)
-{
-       return m_poller.add_fd(fd);
-}
-
-bool sensor_event_poller::poll(void)
-{
-       std::vector<uint32_t> ids;
-       while (true) {
-               int fd;
-               struct epoll_event poll_event;
-
-               if (!m_poller.poll(poll_event))
-                       return false;
-
-               fd = poll_event.data.fd;
-               ids.clear();
-
-               if (!read_fd(fd, ids))
-                       continue;
-
-               if (!process_event(fd, ids))
-                       continue;
-       }
-}
-
-bool sensor_event_poller::read_fd(int fd, std::vector<uint32_t> &ids)
-{
-       fd_sensors_t::iterator it;
-       physical_sensor *sensor;
-
-       it = m_fd_sensors.find(fd);
-       sensor = dynamic_cast<physical_sensor *>(it->second);
-
-       if (!sensor) {
-               _E("Failed to get sensor");
-               return false;
-       }
-
-       if (!sensor->read_fd(ids))
-               return false;
-
-       return true;
-}
-
-bool sensor_event_poller::process_event(int fd, const std::vector<uint32_t> &ids)
-{
-       physical_sensor *sensor;
-       std::pair<fd_sensors_t::iterator, fd_sensors_t::iterator> ret;
-
-       /* find sensors which is based on same device(fd) */
-       ret = m_fd_sensors.equal_range(fd);
-
-       for (auto it_sensor = ret.first; it_sensor != ret.second; ++it_sensor) {
-               sensor_event_t *event;
-               sensor_data_t *data;
-               int data_length;
-               int remains = 1;
-
-               sensor = it_sensor->second;
-
-               /* check whether the id of this sensor is in id list(parameter) or not */
-               auto result = std::find(std::begin(ids), std::end(ids), sensor->get_hal_id());
-
-               if (result == std::end(ids))
-                       continue;
-
-               while (remains > 0) {
-                       remains = sensor->get_data(&data, &data_length);
-                       if (remains < 0) {
-                               _E("Failed to get sensor data");
-                               break;
-                       }
-
-                       if (!sensor->on_event(data, data_length, remains)) {
-                               free(data);
-                               continue;
-                       }
-
-                       event = (sensor_event_t *)malloc(sizeof(sensor_event_t));
-                       if (!event) {
-                               _E("Memory allocation failed");
-                               break;
-                       }
-
-                       event->sensor_id = sensor->get_id();
-                       event->event_type = sensor->get_event_type();
-                       event->data_length = data_length;
-                       event->data = data;
-
-                       if (!sensor->push(event)) {
-                               free(event);
-                               free(data);
-                       }
-               }
-       }
-
-       return true;
-}
diff --git a/src/server/sensor_event_poller.h b/src/server/sensor_event_poller.h
deleted file mode 100644 (file)
index c6c9ade..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_EVENT_POLLER_H_
-#define _SENSOR_EVENT_POLLER_H_
-
-#include <map>
-#include <poller.h>
-#include <physical_sensor.h>
-
-typedef std::multimap<int, physical_sensor *> fd_sensors_t;
-
-class sensor_event_poller {
-public:
-       sensor_event_poller();
-       virtual ~sensor_event_poller();
-
-       bool poll(void);
-
-private:
-       poller m_poller;
-       fd_sensors_t m_fd_sensors;
-
-private:
-       void init_sensor_map(void);
-       void init_fd(void);
-       void init_signal_fd(void);
-
-       bool add_poll_fd(int fd);
-       bool read_fd(int fd, std::vector<uint32_t> &ids);
-       bool process_event(int fd, const std::vector<uint32_t> &ids);
-};
-
-#endif /* _SENSOR_EVENT_POLLER_H_ */
diff --git a/src/server/sensor_event_queue.cpp b/src/server/sensor_event_queue.cpp
deleted file mode 100644 (file)
index d143d49..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_event_queue.h>
-#include <sensor_log.h>
-
-sensor_event_queue& sensor_event_queue::get_instance(void)
-{
-       static sensor_event_queue inst;
-       return inst;
-}
-
-void sensor_event_queue::push_internal(void *event)
-{
-       lock l(m_mutex);
-       bool wake = m_queue.empty();
-
-       if (m_queue.size() >= QUEUE_FULL_SIZE) {
-               _E("Queue is full, drop it!");
-               free(event);
-       } else {
-               m_queue.push(event);
-       }
-
-       if (wake)
-               m_cond_var.notify_one();
-}
-
-void* sensor_event_queue::pop(void)
-{
-       ulock u(m_mutex);
-       while (m_queue.empty())
-               m_cond_var.wait(u);
-
-       void *event = m_queue.front();
-       m_queue.pop();
-
-       return event;
-}
-
-void sensor_event_queue::push(sensor_event_t *event)
-{
-       push_internal(event);
-}
diff --git a/src/server/sensor_event_queue.h b/src/server/sensor_event_queue.h
deleted file mode 100644 (file)
index 4f776ef..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_EVENT_QUEUE_H_
-#define _SENSOR_EVENT_QUEUE_H_
-
-#include <sensor_common.h>
-#include <queue>
-#include <mutex>
-#include <condition_variable>
-
-class sensor_event_queue {
-public:
-       static sensor_event_queue& get_instance(void);
-
-       void push(sensor_event_t *event);
-       void* pop(void);
-
-private:
-       static const unsigned int QUEUE_FULL_SIZE = 1000;
-
-       std::queue<void *> m_queue;
-       std::mutex m_mutex;
-       std::condition_variable m_cond_var;
-
-       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& operator=(const sensor_event_queue &);
-       void push_internal(void *event);
-};
-
-#endif /* _SENSOR_EVENT_QUEUE_H_*/
diff --git a/src/server/sensor_fusion.cpp b/src/server/sensor_fusion.cpp
deleted file mode 100644 (file)
index c82e152..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_fusion.h>
-
-sensor_fusion::sensor_fusion()
-{
-}
-
-sensor_fusion::~sensor_fusion()
-{
-}
-
-bool sensor_fusion::is_fusion(void)
-{
-       return true;
-}
-
-bool sensor_fusion::is_virtual(void)
-{
-       return false;
-}
-
-bool sensor_fusion::is_data_ready(void)
-{
-       return true;
-}
-
-void sensor_fusion::clear_data(void)
-{
-       return;
-}
-
-bool sensor_fusion::get_rotation_matrix(arr33_t &rot, int &accuracy)
-{
-       return false;
-}
-
-bool sensor_fusion::get_attitude(float &x, float &y, float &z, float &w)
-{
-       return false;
-}
-
-bool sensor_fusion::get_gyro_bias(float &x, float &y, float &z)
-{
-       return false;
-}
-
-bool sensor_fusion::get_rotation_vector(float &x, float &y, float &z, float &w, float &heading_accuracy, int &accuracy)
-{
-       return false;
-}
-
-bool sensor_fusion::get_linear_acceleration(float &x, float &y, float &z, int &accuracy)
-{
-       return false;
-}
-
-bool sensor_fusion::get_gravity(float &x, float &y, float &z, int &accuracy)
-{
-       return false;
-}
-
-bool sensor_fusion::get_rotation_vector_6axis(float &x, float &y, float &z, float &w, float &heading_accuracy, int &accuracy)
-{
-       return false;
-}
-
-bool sensor_fusion::get_geomagnetic_rotation_vector(float &x, float &y, float &z, float &w, int &accuracy)
-{
-       return false;
-}
-
-bool sensor_fusion::get_orientation(float &azimuth, float &pitch, float &roll, int &accuracy)
-{
-       return false;
-}
-
-bool sensor_fusion::set_interval(unsigned int event_type, int client_id, unsigned int interval)
-{
-       return sensor_base::add_interval(client_id, interval, true);
-}
-
-bool sensor_fusion::unset_interval(unsigned int event_type, int client_id)
-{
-       return sensor_base::delete_interval(client_id, true);
-}
-
diff --git a/src/server/sensor_fusion.h b/src/server/sensor_fusion.h
deleted file mode 100644 (file)
index c8a8a11..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_FUSION_H_
-#define _SENSOR_FUSION_H_
-
-#include <array>
-#include <sensor_base.h>
-
-enum fusion_event_type {
-       FUSION_EVENT_AG = (FUSION_SENSOR << 16) | 0x0001,
-       FUSION_EVENT_AM = (FUSION_SENSOR << 16) | 0x0002,
-       FUSION_EVENT_AGM = (FUSION_SENSOR << 16) | 0x0004,
-};
-
-typedef std::array<std::array<float, 3>, 3> arr33_t;
-
-class sensor_fusion : public sensor_base {
-public:
-       sensor_fusion();
-       virtual ~sensor_fusion();
-
-       virtual void fuse(const sensor_event_t& event) = 0;
-       bool is_fusion(void);
-       bool is_virtual(void);
-       virtual bool is_data_ready(void);
-       virtual void clear_data(void);
-       virtual bool set_interval(unsigned int event_type, int client_id, unsigned int interval);
-       virtual bool unset_interval(unsigned int event_type, int client_id);
-       virtual unsigned long long get_data_timestamp(void) = 0;
-
-       virtual bool get_rotation_matrix(arr33_t &rot, int &accuracy);
-       virtual bool get_attitude(float &x, float &y, float &z, float &w);
-       virtual bool get_gyro_bias(float &x, float &y, float &z);
-       virtual bool get_rotation_vector(float &x, float &y, float &z, float &w, float &heading_accuracy, int &accuracy);
-       virtual bool get_linear_acceleration(float &x, float &y, float &z, int &accuracy);
-       virtual bool get_gravity(float &x, float &y, float &z, int &accuracy);
-       virtual bool get_rotation_vector_6axis(float &x, float &y, float &z, float &w, float &heading_accuracy, int &accuracy);
-       virtual bool get_geomagnetic_rotation_vector(float &x, float &y, float &z, float &w, int &accuracy);
-       virtual bool get_orientation(float &azimuth, float &pitch, float &roll, int &accuracy);
-};
-
-#endif /* _SENSOR_FUSION_H_ */
diff --git a/src/server/sensor_info_list.cpp b/src/server/sensor_info_list.cpp
deleted file mode 100644 (file)
index 8cbc879..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_info_list.h>
-#include <algorithm>
-
-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;
-}
-
-batch_info::batch_info(int client_id, unsigned int latency)
-{
-       this->client_id = client_id;
-       this->latency = latency;
-}
-
-bool sensor_info_list::comp_interval_info(interval_info a, interval_info b)
-{
-       return a.interval < b.interval;
-}
-
-bool sensor_info_list::comp_batch_info(batch_info a, batch_info b)
-{
-       return a.latency < b.latency;
-}
-
-interval_info_iterator sensor_info_list::find_if_interval_info(int client_id, bool is_processor)
-{
-       auto iter = m_interval_info_list.begin();
-
-       while (iter != m_interval_info_list.end()) {
-               if ((iter->client_id == client_id) && (iter->is_processor == is_processor))
-                       break;
-
-               ++iter;
-       }
-
-       return iter;
-}
-
-batch_info_iterator sensor_info_list::find_if_batch_info(int client_id)
-{
-       auto iter = m_batch_info_list.begin();
-
-       while (iter != m_batch_info_list.end()) {
-               if ((iter->client_id == client_id))
-                       break;
-
-               ++iter;
-       }
-
-       return iter;
-}
-
-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 = interval_info(client_id, is_processor, interval);
-       else
-               m_interval_info_list.push_back(interval_info(client_id, is_processor, interval));
-
-       return true;
-}
-
-bool sensor_info_list::delete_interval(int client_id, bool is_processor)
-{
-       auto iter = find_if_interval_info(client_id, is_processor);
-
-       if (iter == m_interval_info_list.end())
-               return false;
-
-       m_interval_info_list.erase(iter);
-
-       return true;
-}
-
-unsigned int sensor_info_list::get_interval(int client_id, bool is_processor)
-{
-       auto iter = find_if_interval_info(client_id, is_processor);
-
-       if (iter == m_interval_info_list.end())
-               return 0;
-
-       return iter->interval;
-}
-
-unsigned int sensor_info_list::get_min_interval(void)
-{
-       if (m_interval_info_list.empty())
-               return 0;
-
-       auto iter = min_element(m_interval_info_list.begin(), m_interval_info_list.end(), comp_interval_info);
-
-       return iter->interval;
-}
-
-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 = batch_info(client_id, latency);
-       else
-               m_batch_info_list.push_back(batch_info(client_id, latency));
-
-       return true;
-}
-
-bool sensor_info_list::delete_batch(int client_id)
-{
-       auto iter = find_if_batch_info(client_id);
-
-       if (iter == m_batch_info_list.end())
-               return false;
-
-       m_batch_info_list.erase(iter);
-
-       return true;
-}
-
-unsigned int sensor_info_list::get_batch(int client_id)
-{
-       auto iter = find_if_batch_info(client_id);
-
-       if (iter == m_batch_info_list.end())
-               return 0;
-
-       return iter->latency;
-}
-
-unsigned int sensor_info_list::get_max_batch(void)
-{
-       if (m_batch_info_list.empty())
-               return 0;
-
-       auto iter = max_element(m_batch_info_list.begin(), m_batch_info_list.end(), comp_batch_info);
-
-       return iter->latency;
-}
-
diff --git a/src/server/sensor_info_list.h b/src/server/sensor_info_list.h
deleted file mode 100644 (file)
index 7e90743..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_INFO_LIST_H_
-#define _SENSOR_INFO_LIST_H_
-
-#include <list>
-
-class interval_info {
-public:
-       interval_info(int client_id, bool is_processor, unsigned int interval);
-       int client_id;
-       bool is_processor;
-       unsigned int interval;
-};
-
-typedef std::list<interval_info>::iterator interval_info_iterator;
-
-class batch_info {
-public:
-       batch_info(int client_id, unsigned int latency);
-       int client_id;
-       unsigned int latency;
-};
-
-typedef std::list<batch_info>::iterator batch_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);
-       unsigned int get_interval(int client_id, bool is_processor);
-       unsigned int get_min_interval(void);
-
-       bool add_batch(int client_id, unsigned int latency);
-       bool delete_batch(int client_id);
-       unsigned int get_batch(int client_id);
-       unsigned int get_max_batch(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);
-
-       std::list<interval_info> m_interval_info_list;
-       std::list<batch_info> m_batch_info_list;
-};
-
-#endif /* _SENSOR_INFO_LIST_H_ */
index 614e057..7676f40 100644 (file)
  *
  */
 
-#include <dlfcn.h>
-#include <dirent.h>
-#include <sensor_common.h>
-#include <sensor_loader.h>
-#include <sensor_hal.h>
-#include <sensor_base.h>
-#include <sensor_log.h>
-#include <physical_sensor.h>
-#include <virtual_sensor.h>
-#include <external_sensor.h>
-#include <unordered_set>
-#include <algorithm>
-#include <memory>
-
-#include <hrm_sensor.h>
-
-#ifdef ENABLE_AUTO_ROTATION
-#include <auto_rotation_sensor.h>
-#endif
-#ifdef ENABLE_GRAVITY
-#include <gravity_sensor.h>
-#endif
-#ifdef ENABLE_LINEAR_ACCEL
-#include <linear_accel_sensor.h>
-#endif
-#ifdef ENABLE_ORIENTATION
-#include <orientation_sensor.h>
-#endif
-#ifdef ENABLE_ROTATION_VECTOR
-#include <rv_sensor.h>
-#include <magnetic_rv_sensor.h>
-#include <gyro_rv_sensor.h>
-#endif
-#ifdef ENABLE_FACE_DOWN
-#include <face_down_sensor.h>
-#endif
-#ifdef ENABLE_SENSORHUB
-#include <pedometer_sensor.h>
-#endif
-
-using std::vector;
-using std::string;
-
-#define DEVICE_HAL_DIR_PATH LIBDIR "/sensor"
+#include "sensor_loader.h"
 
 sensor_loader::sensor_loader()
 {
@@ -68,378 +25,4 @@ sensor_loader::sensor_loader()
 
 sensor_loader::~sensor_loader()
 {
-       sensor_device_map_t::iterator it_device;
-       std::vector<void *>::iterator it_handle;
-
-       for (it_device = m_active_devices.begin(); it_device != m_active_devices.end();)
-               it_device = m_active_devices.erase(it_device);
-
-       for (it_handle = m_handles.begin(); it_handle != m_handles.end(); ++it_handle)
-               dlclose(*it_handle);
-
-       m_handles.clear();
-}
-
-sensor_loader& sensor_loader::get_instance(void)
-{
-       static sensor_loader inst;
-       return inst;
-}
-
-bool sensor_loader::load(void)
-{
-       std::vector<string> device_hal_paths;
-       std::vector<string> unique_device_hal_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) {
-               if (s.insert(path).second)
-                       paths.push_back(path);
-       };
-
-       for_each(device_hal_paths.begin(), device_hal_paths.end(),
-               [&](const string &path) {
-                       unique(unique_device_hal_paths, path);
-               }
-       );
-
-       for_each(unique_device_hal_paths.begin(), unique_device_hal_paths.end(),
-               [&](const string &path) {
-                       void *handle;
-                       if (load_sensor_devices(path, handle))
-                               m_handles.push_back(handle);
-               }
-       );
-
-       create_sensors();
-       show_sensor_info();
-
-       return true;
-}
-
-bool sensor_loader::load_sensor_devices(const string &path, void* &handle)
-{
-       sensor_device_t *_devices = NULL;
-       sensor_device *device = NULL;
-       const sensor_info_t *infos;
-
-       _I("load device: [%s]", path.c_str());
-
-       void *_handle = dlopen(path.c_str(), RTLD_NOW);
-       if (!_handle) {
-               _E("Failed to dlopen(%s), dlerror : %s", path.c_str(), dlerror());
-               return false;
-       }
-
-       dlerror();
-
-       /* TODO: The out-param of the create function should be const */
-       create_t create_devices = (create_t) dlsym(_handle, "create");
-       if (!create_devices) {
-               _E("Failed to find symbols in %s", path.c_str());
-               dlclose(_handle);
-               return false;
-       }
-
-       int device_size = create_devices(&_devices);
-       if (!_devices) {
-               _E("Failed to create devices, path is %s\n", path.c_str());
-               dlclose(_handle);
-               return false;
-       }
-
-       for (int i = 0; i < device_size; ++i) {
-               device = static_cast<sensor_device *>(_devices[i]);
-               std::shared_ptr<sensor_device> device_ptr(device);
-
-               int info_size = device_ptr->get_sensors(&infos);
-               for (int j = 0; j < info_size; ++j)
-                       m_devices[&infos[j]] = device_ptr;
-       }
-
-       handle = _handle;
-
-       return true;
-}
-
-void sensor_loader::create_sensors(void)
-{
-       /* HRM sensors need SENSOR_PERMISSION_BIO */
-       create_physical_sensors<hrm_sensor>(HRM_RAW_SENSOR);
-       create_physical_sensors<hrm_sensor>(HRM_SENSOR);
-       create_physical_sensors<hrm_sensor>(HRM_LED_GREEN_SENSOR);
-       create_physical_sensors<hrm_sensor>(HRM_LED_IR_SENSOR);
-       create_physical_sensors<hrm_sensor>(HRM_LED_RED_SENSOR);
-#ifdef ENABLE_SENSORHUB
-       create_physical_sensors<pedometer_sensor>(HUMAN_PEDOMETER_SENSOR);
-#endif
-
-       create_physical_sensors<physical_sensor>(UNKNOWN_SENSOR);
-
-#ifdef ENABLE_AUTO_ROTATION
-       create_virtual_sensors<auto_rotation_sensor>("Auto Rotation");
-#endif
-#ifdef ENABLE_ROTATION_VECTOR
-       create_virtual_sensors<rv_sensor>("Rotation Vector");
-       create_virtual_sensors<magnetic_rv_sensor>("Magnetic Rotation Vector");
-       create_virtual_sensors<gyro_rv_sensor>("Gyroscope Rotation Vector");
-#endif
-#ifdef ENABLE_GRAVITY
-       create_virtual_sensors<gravity_sensor>("Gravity");
-#endif
-#ifdef ENABLE_LINEAR_ACCEL
-       create_virtual_sensors<linear_accel_sensor>("Linear Accel");
-#endif
-#ifdef ENABLE_ORIENTATION
-       create_virtual_sensors<orientation_sensor>("Orientation");
-#endif
-#ifdef ENABLE_FACE_DOWN
-       create_virtual_sensors<face_down_sensor>("Face Down");
-#endif
-}
-
-template<typename _sensor>
-void sensor_loader::create_physical_sensors(sensor_type_t type)
-{
-       int32_t index;
-       const sensor_info_t *info;
-       physical_sensor *sensor;
-       sensor_device *device;
-
-       sensor_device_map_t::iterator it;
-
-       for (it = m_devices.begin(); it != m_devices.end(); ++it) {
-               info = it->first;
-               device = it->second.get();
-
-               if (type != UNKNOWN_SENSOR) {
-                       if (type != (sensor_type_t)(info->type))
-                               continue;
-               }
-
-               sensor = dynamic_cast<physical_sensor *>(create_sensor<_sensor>());
-
-               if (!sensor) {
-                       _E("Memory allocation failed[%s]", info->name);
-                       return;
-               }
-
-               sensor_type_t _type = (sensor_type_t)info->type;
-               index = (int32_t)m_sensors.count(_type);
-
-               sensor->set_id(((int64_t)_type << SENSOR_TYPE_SHIFT) | index);
-               sensor->set_sensor_info(info);
-               sensor->set_sensor_device(device);
-
-               std::shared_ptr<sensor_base> sensor_ptr(sensor);
-               m_sensors.insert(std::make_pair(_type, sensor_ptr));
-
-               m_active_devices[it->first] = it->second;
-               m_devices.erase(it->first);
-
-               _I("created [%s] sensor", sensor->get_name());
-       }
-}
-
-template <typename _sensor>
-void sensor_loader::create_virtual_sensors(const char *name)
-{
-       int32_t index;
-       sensor_type_t type;
-       virtual_sensor *instance;
-
-       instance = dynamic_cast<virtual_sensor *>(create_sensor<_sensor>());
-       if (!instance) {
-               _E("Memory allocation failed[%s]", name);
-               return;
-       }
-
-       if (!instance->init()) {
-               _W("Failed to init %s", name);
-               delete instance;
-               return;
-       }
-
-       std::shared_ptr<sensor_base> sensor(instance);
-       type = sensor->get_type();
-       index = (int32_t)(m_sensors.count(type));
-
-       sensor->set_id((int64_t)type << SENSOR_TYPE_SHIFT | index);
-
-       m_sensors.insert(std::make_pair(type, sensor));
-
-       _I("created [%s] sensor", sensor->get_name());
-}
-
-template <typename _sensor>
-void sensor_loader::create_external_sensors(const char *name)
-{
-       int32_t index;
-       sensor_type_t type;
-       external_sensor *instance;
-
-       instance = dynamic_cast<external_sensor *>(create_sensor<_sensor>());
-       if (!instance) {
-               _E("Memory allocation failed[%s]", name);
-               return;
-       }
-
-       std::shared_ptr<sensor_base> sensor(instance);
-       type = sensor->get_type();
-       index = (int32_t)(m_sensors.count(type));
-
-       sensor->set_id((int64_t)type << SENSOR_TYPE_SHIFT | index);
-
-       m_sensors.insert(std::make_pair(type, sensor));
-
-       _I("created [%s] sensor", sensor->get_name());
-}
-
-template <typename _sensor>
-sensor_base* sensor_loader::create_sensor(void)
-{
-       sensor_base *instance = NULL;
-
-       try {
-               instance = new _sensor;
-       } catch (std::exception &e) {
-               _E("Failed to create sensor, exception: %s", e.what());
-               return NULL;
-       } catch (int err) {
-               _ERRNO(errno, _E, "Failed to create sensor");
-               return NULL;
-       }
-
-       return instance;
-}
-
-void sensor_loader::show_sensor_info(void)
-{
-       _I("========== Loaded sensor information ==========\n");
-
-       int index = 0;
-
-       auto it = m_sensors.begin();
-
-       while (it != m_sensors.end()) {
-               sensor_base *sensor = it->second.get();
-
-               sensor_info info;
-               sensor->get_sensor_info(info);
-               _I("No:%d [%s]\n", ++index, sensor->get_name());
-               info.show();
-               it++;
-       }
-
-       _I("===============================================\n");
-}
-
-bool sensor_loader::get_paths_from_dir(const string &dir_path, vector<string> &hal_paths)
-{
-       DIR *dir = NULL;
-       struct dirent dir_entry;
-       struct dirent *result;
-       string name;
-       int ret;
-
-       dir = opendir(dir_path.c_str());
-
-       if (!dir) {
-               _E("Failed to open dir: %s", dir_path.c_str());
-               return false;
-       }
-
-       while (true) {
-               ret = readdir_r(dir, &dir_entry, &result);
-
-               if (ret != 0)
-                       continue;
-
-               if (result == NULL)
-                       break;
-
-               name = string(dir_entry.d_name);
-
-               if (name == "." || name == "..")
-                       continue;
-
-               hal_paths.push_back(dir_path + "/" + name);
-       }
-
-       closedir(dir);
-       return true;
-}
-
-sensor_base* sensor_loader::get_sensor(sensor_type_t type)
-{
-       auto it = m_sensors.find(type);
-
-       if (it == m_sensors.end())
-               return NULL;
-
-       return it->second.get();
-}
-
-sensor_base* sensor_loader::get_sensor(sensor_id_t id)
-{
-       vector<sensor_base *> sensors;
-
-       sensor_type_t type = static_cast<sensor_type_t>(id >> SENSOR_TYPE_SHIFT);
-       unsigned int index = (id & SENSOR_INDEX_MASK);
-
-       sensors = get_sensors(type);
-
-       if (index >= sensors.size())
-               return NULL;
-
-       return sensors[index];
-}
-
-vector<sensor_type_t> sensor_loader::get_sensor_types(void)
-{
-       vector<sensor_type_t> sensor_types;
-
-       auto it = m_sensors.begin();
-
-       while (it != m_sensors.end()) {
-               sensor_types.push_back((sensor_type_t)(it->first));
-               it = m_sensors.upper_bound(it->first);
-       }
-
-       return sensor_types;
-}
-
-vector<sensor_base *> sensor_loader::get_sensors(sensor_type_t type)
-{
-       vector<sensor_base *> sensor_list;
-       std::pair<sensor_map_t::iterator, sensor_map_t::iterator> ret;
-
-       if ((int)(type) == (int)SENSOR_DEVICE_ALL)
-               ret = std::make_pair(m_sensors.begin(), m_sensors.end());
-       else
-               ret = m_sensors.equal_range(type);
-
-       for (auto it = ret.first; it != ret.second; ++it)
-               sensor_list.push_back(it->second.get());
-
-       return sensor_list;
-}
-
-vector<sensor_base *> sensor_loader::get_virtual_sensors(void)
-{
-       vector<sensor_base *> virtual_list;
-       sensor_base* sensor;
-
-       for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) {
-               sensor = it->second.get();
-
-               if (!sensor || !sensor->is_virtual())
-                       continue;
-
-               virtual_list.push_back(sensor);
-       }
-
-       return virtual_list;
 }
index 4d9f179..22efa62 100644 (file)
 #ifndef _SENSOR_LOADER_H_
 #define _SENSOR_LOADER_H_
 
-#include <sensor_common.h>
-#include <sensor_types.h>
-#include <sensor_hal.h>
-
-#include <cmutex.h>
-#include <sstream>
-
-#include <string>
-#include <vector>
-#include <map>
-#include <set>
-#include <memory>
-
-class sensor_base;
-
-typedef std::multimap<sensor_type_t, std::shared_ptr<sensor_base>> sensor_map_t;
-typedef std::map<const sensor_info_t *, std::shared_ptr<sensor_device>> sensor_device_map_t;
-
 class sensor_loader {
 private:
        sensor_loader();
        virtual ~sensor_loader();
-
-       bool load_sensor_devices(const std::string &path, void* &handle);
-
-       void create_sensors(void);
-       template <typename _sensor> void create_physical_sensors(sensor_type_t type);
-       template <typename _sensor> void create_virtual_sensors(const char *name);
-       template <typename _sensor> void create_external_sensors(const char *name);
-       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> &hal_paths);
-
-       sensor_map_t m_sensors;
-       sensor_device_map_t m_devices;
-       sensor_device_map_t m_active_devices;
-       std::vector<void *> m_handles;
-public:
-       static sensor_loader& get_instance(void);
-       bool load(void);
-
-       sensor_base* get_sensor(sensor_type_t type);
-       sensor_base* get_sensor(sensor_id_t id);
-
-       std::vector<sensor_type_t> get_sensor_types(void);
-       std::vector<sensor_base *> get_sensors(sensor_type_t type);
-       std::vector<sensor_base *> get_virtual_sensors(void);
 };
 
 #endif /* _SENSOR_LOADER_H_ */
diff --git a/src/server/sensor_usage.cpp b/src/server/sensor_usage.cpp
deleted file mode 100644 (file)
index e4f0ffc..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_common.h>
-#include <sensor_types.h>
-#include <sensor_usage.h>
-#include <sensor_log.h>
-
-sensor_usage::sensor_usage()
-: m_interval(POLL_1HZ_MS)
-, m_latency(0)
-, m_pause_policy(SENSORD_PAUSE_ALL)
-, m_start(false)
-{
-}
-
-sensor_usage::~sensor_usage()
-{
-       m_reg_events.clear();
-}
-
-bool sensor_usage::register_event(unsigned int event_type)
-{
-       auto it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type);
-
-       if (it_event != m_reg_events.end()) {
-               _E("Event[%#x] is already registered", event_type);
-               return false;
-       }
-
-       m_reg_events.push_back(event_type);
-       return true;
-}
-
-bool sensor_usage::unregister_event(unsigned int event_type)
-{
-       auto it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type);
-
-       if (it_event == m_reg_events.end()) {
-               _E("Event[%#x] is not found", event_type);
-               return false;
-       }
-
-       m_reg_events.erase(it_event);
-
-       return true;
-}
-
-bool sensor_usage::is_event_registered(unsigned int event_type)
-{
-       auto it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type);
-
-       if (it_event == m_reg_events.end()) {
-               _D("Event[%#x] is not registered", event_type);
-               return false;
-       }
-
-       return true;
-}
diff --git a/src/server/sensor_usage.h b/src/server/sensor_usage.h
deleted file mode 100644 (file)
index e3fd247..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _SENSOR_USAGE_H_
-#define _SENSOR_USAGE_H_
-
-#include <algorithm>
-#include <vector>
-
-typedef std::vector<unsigned int> reg_event_vector;
-
-class sensor_usage {
-public:
-       unsigned int m_interval;
-       unsigned int m_latency;
-       int m_pause_policy;
-       reg_event_vector m_reg_events;
-       bool m_start;
-
-       sensor_usage();
-       ~sensor_usage();
-
-       bool register_event(unsigned int event_type);
-       bool unregister_event(unsigned int event_type);
-       bool is_event_registered(unsigned int event_type);
-};
-
-#endif /* _SENSOR_USAGE_H_ */
index 3e30174..0c1e624 100644 (file)
  *
  */
 
-#include <sys/epoll.h>
-#include <sys/socket.h>
-
-#include <systemd/sd-daemon.h>
-#include <server.h>
-#include <sensor_loader.h>
-#include <command_common.h>
-#include <command_worker.h>
-#include <external_sensor_worker.h>
-#include <external_sensor_service.h>
-#include <thread>
-#include <sensor_event_poller.h>
-#include <client_info_manager.h>
-
-#define SYSTEMD_SOCKET_MAX 2
-
-using std::thread;
+#include "server.h"
 
 server::server()
-: m_mainloop(NULL)
-, m_running(false)
 {
 }
 
@@ -45,317 +27,6 @@ server::~server()
 {
 }
 
-int server::get_systemd_socket(const char *name)
-{
-       int type = SOCK_STREAM;
-       int listening = 1;
-       size_t length = 0;
-       int fd = -1;
-       int fd_env = 1;
-       int fd_index;
-
-       if (!strcmp(name, EVENT_CHANNEL_PATH)) {
-               type = SOCK_SEQPACKET;
-               listening = -1;
-               fd_env = 0;
-       }
-
-       if (sd_listen_fds(fd_env) < 0) {
-               _E("Failed to listen fds from systemd");
-               return -1;
-       }
-
-       for (fd_index = 0; fd_index < SYSTEMD_SOCKET_MAX; ++fd_index) {
-               fd = SD_LISTEN_FDS_START + fd_index;
-
-               if (sd_is_socket_unix(fd, type, listening, name, length) > 0)
-                       return fd;
-       }
-
-       return -1;
-}
-
-void server::accept_command_channel(void)
-{
-       _I("Command channel acceptor is started");
-
-       while (m_running) {
-               csocket client_command_socket;
-
-               if (!m_command_channel_accept_socket.is_valid()) {
-                       _E("Failed to accept, event_channel_accept_socket is closed");
-                       break;
-               }
-
-               if (!m_command_channel_accept_socket.accept(client_command_socket)) {
-                       _E("Failed to accept command channel from a client");
-                       continue;
-               }
-
-               if (!m_running) {
-                       _E("server die");
-                       break;
-               }
-
-               _D("New client (socket_fd : %d) connected", client_command_socket.get_socket_fd());
-
-               /* TODO: if socket is closed, it should be erased */
-               client_command_sockets.push_back(client_command_socket);
-
-               thread worker_dispatcher(&server::dispatch_worker, this, client_command_socket);
-               worker_dispatcher.detach();
-       }
-
-       _I("Command channel acceptor is terminated");
-}
-
-void server::accept_event_channel(void)
-{
-       _I("Event channel acceptor is started!");
-
-       while (m_running) {
-               csocket client_event_socket;
-
-               if (!m_event_channel_accept_socket.is_valid()) {
-                       _E("Failed to accept, event_channel_accept_socket is closed");
-                       break;
-               }
-
-               if (!m_event_channel_accept_socket.accept(client_event_socket)) {
-                       _E("Failed to accept event channel from a client");
-                       continue;
-               }
-
-               if (!m_running) {
-                       _E("server die");
-                       break;
-               }
-
-               /* TODO: if socket is closed, it should be erased */
-               client_event_sockets.push_back(client_event_socket);
-
-               _D("New client(socket_fd : %d) connected", client_event_socket.get_socket_fd());
-
-               thread event_channel_creator(&server::dispatch_event_channel_creator, this, client_event_socket);
-               event_channel_creator.detach();
-       }
-
-       _I("Event channel acceptor is terminated");
-}
-
-void server::dispatch_worker(csocket socket)
-{
-       int worker_type;
-
-       if (socket.recv(&worker_type, sizeof(worker_type)) <= 0) {
-               _E("Failed to get worker type");
-               socket.close();
-               return;
-       }
-
-       if (worker_type == CLIENT_TYPE_SENSOR_CLIENT) {
-               command_worker *worker;
-               worker = new(std::nothrow) command_worker(socket);
-
-               if (!worker) {
-                       _E("Failed to allocate memory");
-                       socket.close();
-                       return;
-               }
-
-               if (!worker->start()) {
-                       _E("Failed to start command worker");
-                       delete worker;
-               }
-       } else if (worker_type == CLIENT_TYPE_EXTERNAL_SOURCE) {
-               external_sensor_worker *worker;
-               worker = new(std::nothrow) external_sensor_worker(socket);
-
-               if (!worker) {
-                       _E("Failed to allocate memory");
-                       socket.close();
-                       return;
-               }
-
-               if (!worker->start()) {
-                       _E("Failed to start external worker");
-                       delete worker;
-               }
-       } else {
-               _E("Not supported worker type: %d", worker_type);
-               socket.close();
-       }
-}
-
-void server::dispatch_event_channel_creator(csocket socket)
-{
-       int client_type;
-
-       if (socket.recv(&client_type, sizeof(client_type)) <= 0) {
-               _E("Failed to get client type");
-               socket.close();
-               return;
-       }
-
-       if (client_type == CLIENT_TYPE_SENSOR_CLIENT) {
-               sensor_event_dispatcher::get_instance().accept_event_connections(socket);
-       } else if (client_type == CLIENT_TYPE_EXTERNAL_SOURCE) {
-               external_sensor_service::get_instance().accept_command_channel(socket);
-       } else {
-               _E("Not supported client type: %d", client_type);
-               socket.close();
-       }
-}
-
-void server::poll_event(void)
-{
-       _I("Event poller is started");
-
-       sensor_event_poller poller;
-
-       if (!poller.poll()) {
-               _E("Failed to poll event");
-               return;
-       }
-}
-
-bool server::listen_command_channel(void)
-{
-       int sock_fd = -1;
-       const int MAX_PENDING_CONNECTION = 10;
-
-       sock_fd = get_systemd_socket(COMMAND_CHANNEL_PATH);
-
-       if (sock_fd >= 0) {
-               _I("Succeeded to get systemd socket(%d)", sock_fd);
-               m_command_channel_accept_socket = csocket(sock_fd);
-               return true;
-       }
-
-       INFO("Failed to get systemd socket, create it by myself!");
-       if (!m_command_channel_accept_socket.create(SOCK_STREAM)) {
-               _E("Failed to create command channel");
-               return false;
-       }
-
-       if (!m_command_channel_accept_socket.bind(COMMAND_CHANNEL_PATH)) {
-               _E("Failed to bind command channel");
-               m_command_channel_accept_socket.close();
-               return false;
-       }
-
-       if (!m_command_channel_accept_socket.listen(MAX_PENDING_CONNECTION)) {
-               _E("Failed to listen command channel");
-               return false;
-       }
-
-       return true;
-}
-
-bool server::listen_event_channel(void)
-{
-       int sock_fd = -1;
-       const int MAX_PENDING_CONNECTION = 32;
-
-       sock_fd = get_systemd_socket(EVENT_CHANNEL_PATH);
-
-       if (sock_fd >= 0) {
-               _I("Succeeded to get systemd socket(%d)", sock_fd);
-               m_event_channel_accept_socket = csocket(sock_fd);
-               return true;
-       }
-
-       INFO("Failed to get systemd socket, create it by myself!");
-
-       if (!m_event_channel_accept_socket.create(SOCK_SEQPACKET)) {
-               _E("Failed to create event channel");
-               return false;
-       }
-
-       if (!m_event_channel_accept_socket.bind(EVENT_CHANNEL_PATH)) {
-               _E("Failed to bind event channel");
-               m_event_channel_accept_socket.close();
-               return false;
-       }
-
-       if (!m_event_channel_accept_socket.listen(MAX_PENDING_CONNECTION)) {
-               _E("Failed to listen event channel");
-               m_event_channel_accept_socket.close();
-               return false;
-       }
-
-       return true;
-}
-
-void server::close_socket(void)
-{
-       m_command_channel_accept_socket.close();
-       m_event_channel_accept_socket.close();
-
-       for (unsigned int i = 0; i < client_command_sockets.size(); ++i)
-               client_command_sockets[i].close();
-
-       for (unsigned int i = 0; i < client_event_sockets.size(); ++i)
-               client_event_sockets[i].close();
-
-       client_command_sockets.clear();
-       client_event_sockets.clear();
-}
-
-void server::initialize(void)
-{
-       m_running = true;
-       m_mainloop = g_main_loop_new(NULL, false);
-
-       sensor_event_dispatcher::get_instance().run();
-       external_sensor_service::get_instance().run();
-
-       listen_command_channel();
-       listen_event_channel();
-
-       std::thread event_channel_accepter(&server::accept_event_channel, this);
-       event_channel_accepter.detach();
-
-       std::thread command_channel_accepter(&server::accept_command_channel, this);
-       command_channel_accepter.detach();
-
-       std::thread event_poller(&server::poll_event, this);
-       event_poller.detach();
-
-       sd_notify(0, "READY=1");
-
-       g_main_loop_run(m_mainloop);
-}
-
-void server::terminate(void)
-{
-       sensor_event_dispatcher::get_instance().stop();
-
-       close_socket();
-}
-
-void server::run(void)
-{
-       initialize();
-       terminate();
-}
-
-void server::stop(void)
-{
-       if (!m_running)
-               return;
-
-       m_running = false;
-
-       if (m_mainloop) {
-               g_main_loop_quit(m_mainloop);
-               g_main_loop_unref(m_mainloop);
-               m_mainloop = NULL;
-       }
-
-       _I("Sensord server stopped");
-}
-
 server& server::get_instance(void)
 {
        static server inst;
index 8f9daf7..017f461 100644 (file)
 #ifndef _SERVER_H_
 #define _SERVER_H_
 
-#include <glib.h>
-#include <csocket.h>
-#include <vector>
-#include <thread>
-
 class server {
 public:
-       static server& get_instance(void);
-
-public:
-       void run(void);
-       void stop(void);
-
-private:
-       GMainLoop *m_mainloop;
-       csocket m_command_channel_accept_socket;
-       csocket m_event_channel_accept_socket;
-
-       std::vector<csocket> client_command_sockets;
-       std::vector<csocket> client_event_sockets;
-
-       bool m_running;
-
-private:
        server();
        virtual ~server();
 
-       void initialize(void);
-       void terminate(void);
-
-       void poll_event(void);
-
-       bool listen_command_channel(void);
-       bool listen_event_channel(void);
-
-       void accept_command_channel(void);
-       void accept_event_channel(void);
-
-       void dispatch_worker(csocket socket);
-       void dispatch_event_channel_creator(csocket socket);
-
-       void close_socket(void);
-
-       /* TODO: move to socket class */
-       int get_systemd_socket(const char *name);
+       static server& get_instance(void);
 };
 
 #endif /* _SERVER_H_ */
index 0d297b3..59546b6 100644 (file)
@@ -17,8 +17,7 @@
  *
  */
 
-#include <virtual_sensor.h>
-#include <sensor_event_dispatcher.h>
+#include "virtual_sensor.h"
 
 virtual_sensor::virtual_sensor()
 {
@@ -27,23 +26,3 @@ virtual_sensor::virtual_sensor()
 virtual_sensor::~virtual_sensor()
 {
 }
-
-bool virtual_sensor::init(void)
-{
-       return false;
-}
-
-bool virtual_sensor::is_virtual(void)
-{
-       return true;
-}
-
-bool virtual_sensor::activate(void)
-{
-       return sensor_event_dispatcher::get_instance().add_active_virtual_sensor(this);
-}
-
-bool virtual_sensor::deactivate(void)
-{
-       return sensor_event_dispatcher::get_instance().delete_active_virtual_sensor(this);
-}
index a1d4363..745a0b4 100644 (file)
 #ifndef _VIRTUAL_SENSOR_H_
 #define _VIRTUAL_SENSOR_H_
 
-#include <sensor_base.h>
-
-class virtual_sensor : public sensor_base {
+class virtual_sensor {
 public:
        virtual_sensor();
        virtual ~virtual_sensor();
-
-       /* initialize sensor */
-       virtual bool init();
-
-       /* module info */
-       virtual sensor_type_t get_type() = 0;
-       virtual unsigned int get_event_type(void) = 0;
-       virtual const char* get_name(void) = 0;
-
-       virtual bool get_sensor_info(sensor_info &info) = 0;
-
-       /* synthesize event */
-       virtual void synthesize(const sensor_event_t& event) = 0;
-
-       /* get data */
-       virtual int get_data(sensor_data_t **data, int *length) = 0;
-
-       bool is_virtual(void);
-
-protected:
-       bool activate(void);
-       bool deactivate(void);
-
-private:
-       virtual bool set_interval(unsigned long interval) = 0;
-       virtual bool set_batch_latency(unsigned long latency) = 0;
-       virtual bool on_start(void) = 0;
-       virtual bool on_stop(void) = 0;
 };
 
 #endif /* _VIRTUAL_SENSOR_H_ */
diff --git a/src/server/worker_thread.cpp b/src/server/worker_thread.cpp
deleted file mode 100644 (file)
index 9108016..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_log.h>
-#include <worker_thread.h>
-#include <thread>
-
-using std::thread;
-
-worker_thread::worker_thread()
-: m_state(WORKER_STATE_INITIAL)
-, m_context(NULL)
-, m_thread_created(false)
-{
-       for (int i = 0; i < TRANS_FUNC_CNT; ++i)
-               m_trans_func[i] = NULL;
-}
-
-worker_thread::~worker_thread()
-{
-       stop();
-}
-
-bool worker_thread::transition_function(trans_func_index index)
-{
-       if (m_trans_func[index] != NULL) {
-               if (!m_trans_func[index](m_context)) {
-                       _W("Transition[%d] function returning false", index);
-                       return false;
-               }
-       }
-
-       return true;
-}
-
-worker_thread::worker_state_t worker_thread::get_state(void)
-{
-       lock l(m_mutex);
-       return m_state;
-}
-
-bool worker_thread::start(void)
-{
-       lock l(m_mutex);
-
-       if (m_state == WORKER_STATE_WORKING) {
-               _I("Worker thread is already working");
-               return true;
-       }
-
-       if ((m_state == WORKER_STATE_INITIAL) || (m_state == WORKER_STATE_STOPPED)) {
-               m_state = WORKER_STATE_WORKING;
-
-               if (!m_thread_created) {
-                       thread th(&worker_thread::main, this);
-                       th.detach();
-               }
-               return true;
-       }
-
-       if (m_state == WORKER_STATE_PAUSED) {
-               m_state = WORKER_STATE_WORKING;
-               m_cond_working.notify_one();
-               return true;
-       }
-
-       _E("Failed to start, because current state(%d) is not for START", m_state);
-
-       return false;
-}
-
-bool worker_thread::stop(void)
-{
-       lock l(m_mutex);
-
-       if (m_state == WORKER_STATE_STOPPED) {
-               _I("Worker thread is already stopped");
-               return true;
-       }
-
-       if ((m_state == WORKER_STATE_WORKING) || (m_state == WORKER_STATE_PAUSED)) {
-               if (m_state == WORKER_STATE_PAUSED)
-                       m_cond_working.notify_one();
-
-               m_state = WORKER_STATE_STOPPED;
-               return true;
-       }
-
-       _E("Failed to stop, because current state(%d) is not for STOP", m_state);
-       return false;
-}
-
-bool worker_thread::pause(void)
-{
-       lock l(m_mutex);
-
-       if (m_state == WORKER_STATE_PAUSED) {
-               _I("Worker thread is already paused");
-               return true;
-       }
-
-       if (m_state == WORKER_STATE_WORKING) {
-               m_state = WORKER_STATE_PAUSED;
-               return true;
-       }
-
-       _E("Failed to pause, because current state(%d) is not for PAUSE", m_state);
-
-       return false;
-}
-
-bool worker_thread::resume(void)
-{
-       lock l(m_mutex);
-
-       if (m_state == WORKER_STATE_WORKING) {
-               _I("Worker thread is already working");
-               return true;
-       }
-
-       if (m_state == WORKER_STATE_PAUSED) {
-               m_state = WORKER_STATE_WORKING;
-               m_cond_working.notify_one();
-               return true;
-       }
-
-       _E("Failed to resume, because current state(%d) is not for RESUME", m_state);
-       return false;
-}
-
-/*
- * After state changed to STOPPED, it should not access member fields,
-    because some transition funciton of STOPPED delete this pointer
- */
-
-void worker_thread::main(void)
-{
-       _D("Worker thread(%#x) is created", std::this_thread::get_id());
-
-       transition_function(STARTED);
-
-       while (true) {
-               worker_state_t state;
-               state = get_state();
-
-               if (state == WORKER_STATE_WORKING) {
-                       if (!transition_function(WORKING)) {
-                               m_state = WORKER_STATE_STOPPED;
-                               _D("Worker thread(%#x) exits from working state", std::this_thread::get_id());
-                               m_thread_created = false;
-                               transition_function(STOPPED);
-                               break;
-                       }
-                       continue;
-               }
-
-               ulock u(m_mutex);
-
-               if (m_state == WORKER_STATE_PAUSED) {
-                       transition_function(PAUSED);
-
-                       _D("Worker thread(%#x) is paused", std::this_thread::get_id());
-                       m_cond_working.wait(u);
-
-                       if (m_state == WORKER_STATE_WORKING) {
-                               transition_function(RESUMED);
-                               _D("Worker thread(%#x) is resumed", std::this_thread::get_id());
-                       } else if (m_state == WORKER_STATE_STOPPED) {
-                               m_thread_created = false;
-                               transition_function(STOPPED);
-                               break;
-                       }
-               } else if (m_state == WORKER_STATE_STOPPED) {
-                       m_thread_created = false;
-                       transition_function(STOPPED);
-                       break;
-               }
-       }
-       _I("Worker thread(%#x)'s main is terminated", std::this_thread::get_id());
-}
-
-void worker_thread::set_started(trans_func_t func)
-{
-       m_trans_func[STARTED] = func;
-}
-
-void worker_thread::set_stopped(trans_func_t func)
-{
-       m_trans_func[STOPPED] = func;
-}
-
-void worker_thread::set_paused(trans_func_t func)
-{
-       m_trans_func[PAUSED] = func;
-}
-
-void worker_thread::set_resumed(trans_func_t func)
-{
-       m_trans_func[RESUMED] = func;
-}
-
-void worker_thread::set_working(trans_func_t func)
-{
-       m_trans_func[WORKING] = func;
-}
-
-void worker_thread::set_context(void *ctx)
-{
-       m_context = ctx;
-}
diff --git a/src/server/worker_thread.h b/src/server/worker_thread.h
deleted file mode 100644 (file)
index 0aeff29..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _WORKER_THREAD_H_
-#define _WORKER_THREAD_H_
-
-#include <mutex>
-#include <condition_variable>
-
-class worker_thread {
-public:
-       enum worker_state_t {
-               WORKER_STATE_INITIAL,
-               WORKER_STATE_WORKING,
-               WORKER_STATE_PAUSED,
-               WORKER_STATE_STOPPED,
-       };
-
-       typedef bool(*trans_func_t)(void *data);
-private:
-       enum trans_func_index {
-               STARTED = 0,
-               STOPPED,
-               PAUSED,
-               RESUMED,
-               WORKING,
-               TRANS_FUNC_CNT,
-       };
-
-       typedef std::lock_guard<std::mutex>  lock;
-       typedef std::unique_lock<std::mutex> ulock;
-
-       worker_state_t m_state;
-       void *m_context;
-       std::mutex m_mutex;
-       std::condition_variable m_cond_working;
-       bool m_thread_created;
-
-       trans_func_t m_trans_func[TRANS_FUNC_CNT];
-
-       bool transition_function(trans_func_index index);
-       void main(void);
-public:
-       worker_thread();
-       virtual ~worker_thread();
-
-       bool start(void);
-       bool stop(void);
-       bool pause(void);
-       bool resume(void);
-
-       worker_state_t get_state(void);
-
-       void set_started(trans_func_t func);
-       void set_stopped(trans_func_t func);
-       void set_paused(trans_func_t func);
-       void set_resumed(trans_func_t func);
-       void set_working(trans_func_t func);
-
-       void set_context(void *ctx);
-};
-
-#endif /* _WORKER_THREAD_H_ */
diff --git a/src/shared/cbase_lock.cpp b/src/shared/cbase_lock.cpp
deleted file mode 100644 (file)
index 38f2f84..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <pthread.h>
-#include <stdio.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <cbase_lock.h>
-#include <sensor_log.h>
-
-cbase_lock::cbase_lock()
-{
-       m_history_mutex = PTHREAD_MUTEX_INITIALIZER;
-}
-
-cbase_lock::~cbase_lock()
-{
-       pthread_mutex_destroy(&m_history_mutex);
-}
-
-void cbase_lock::lock(lock_type type, const char* expr, const char *module, const char *func, int line)
-{
-       int ret = 0;
-       char m_curent_info[OWNER_INFO_LEN];
-       struct timeval sv;
-       unsigned long long lock_waiting_start_time = 0;
-       unsigned long long lock_acquired_time = 0;
-       unsigned long long waiting_time = 0;
-
-       snprintf(m_curent_info, OWNER_INFO_LEN, "%s:%s(%d)", module, func, line);
-
-       if (type == LOCK_TYPE_MUTEX)
-               ret = try_lock_impl();
-       else if (type == LOCK_TYPE_READ)
-               ret = try_read_lock_impl();
-       else if (type == LOCK_TYPE_WRITE)
-               ret = try_write_lock_impl();
-
-       if (ret == 0) {
-               pthread_mutex_lock(&m_history_mutex);
-               snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info);
-               pthread_mutex_unlock(&m_history_mutex);
-               return;
-       }
-
-       gettimeofday(&sv, NULL);
-       lock_waiting_start_time = MICROSECONDS(sv);
-
-       pthread_mutex_lock(&m_history_mutex);
-       _I("%s is waiting for getting %s(%#x) owned in %s",
-               m_curent_info, expr, this, m_owner_info);
-       pthread_mutex_unlock(&m_history_mutex);
-
-       if (type == LOCK_TYPE_MUTEX)
-               lock_impl();
-       else if (type == LOCK_TYPE_READ)
-               read_lock_impl();
-       else if (type == LOCK_TYPE_WRITE)
-               write_lock_impl();
-
-       gettimeofday(&sv, NULL);
-       lock_acquired_time = MICROSECONDS(sv);
-
-       waiting_time = lock_acquired_time - lock_waiting_start_time;
-
-       pthread_mutex_lock(&m_history_mutex);
-       _I("%s acquires lock after waiting %lluus, %s(%#x) was previously owned in %s",
-               m_curent_info, waiting_time, expr, this, m_owner_info);
-       snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info);
-       pthread_mutex_unlock(&m_history_mutex);
-}
-
-void cbase_lock::lock(lock_type type)
-{
-       if (type == LOCK_TYPE_MUTEX)
-               lock_impl();
-       else if (type == LOCK_TYPE_READ)
-               read_lock_impl();
-       else if (type == LOCK_TYPE_WRITE)
-               write_lock_impl();
-}
-
-void cbase_lock::unlock(void)
-{
-       unlock_impl();
-}
-
-int cbase_lock::lock_impl(void)
-{
-       return 0;
-}
-
-int cbase_lock::read_lock_impl(void)
-{
-       return 0;
-}
-
-int cbase_lock::write_lock_impl(void)
-{
-       return 0;
-}
-
-int cbase_lock::try_lock_impl(void)
-{
-       return 0;
-}
-
-int cbase_lock::try_read_lock_impl(void)
-{
-       return 0;
-}
-
-int cbase_lock::try_write_lock_impl(void)
-{
-       return 0;
-}
-
-int cbase_lock::unlock_impl(void)
-{
-       return 0;
-}
-
-Autolock::Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line)
-: m_lock(m)
-{
-       m_lock.lock(type, expr, module, func, line);
-}
-
-Autolock::Autolock(cbase_lock &m, lock_type type)
-: m_lock(m)
-{
-       m_lock.lock(type);
-}
-
-Autolock::~Autolock()
-{
-       m_lock.unlock();
-}
diff --git a/src/shared/cbase_lock.h b/src/shared/cbase_lock.h
deleted file mode 100644 (file)
index ad57562..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _CBASE_LOCK_H_
-#define _CBASE_LOCK_H_
-
-#include <pthread.h>
-
-enum lock_type {
-       LOCK_TYPE_MUTEX,
-       LOCK_TYPE_READ,
-       LOCK_TYPE_WRITE,
-};
-
-#ifdef _LOCK_DEBUG
-#define AUTOLOCK(x) Autolock x##_autolock((x), LOCK_TYPE_MUTEX, #x, __MODULE__, __func__, __LINE__)
-#define AUTOLOCK_R(x) Autolock x##_autolock_r((x), LOCK_TYPE_READ, #x,  __MODULE__, __func__, __LINE__)
-#define AUTOLOCK_W(x) Autolock x##_autolock_w((x), LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
-#define LOCK(x)                (x).lock(#x, __MODULE__, __func__, __LINE__)
-#define LOCK_R(x)      (x).lock(LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
-#define LOCK_W(x)      (x).lock(LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
-#define UNLOCK(x)      (x).unlock()
-#else
-#define AUTOLOCK(x) Autolock x##_autolock((x), LOCK_TYPE_MUTEX)
-#define AUTOLOCK_R(x) Autolock x##_autolock_r((x), LOCK_TYPE_READ)
-#define AUTOLOCK_W(x) Autolock x##_autolock_w((x), LOCK_TYPE_WRITE)
-#define LOCK(x)                (x).lock()
-#define LOCK_R(x)      (x).lock(LOCK_TYPE_READ)
-#define LOCK_W(x)      (x).lock(LOCK_TYPE_WRITE)
-#define UNLOCK(x)      (x).unlock()
-#endif
-
-class cbase_lock {
-public:
-       cbase_lock();
-       virtual ~cbase_lock();
-
-       void lock(lock_type type, const char* expr, const char *module, const char *func, int line);
-       void lock(lock_type type);
-       void unlock(void);
-
-protected:
-       virtual int lock_impl(void);
-       virtual int read_lock_impl(void);
-       virtual int write_lock_impl(void);
-
-       virtual int try_lock_impl(void);
-       virtual int try_read_lock_impl(void);
-       virtual int try_write_lock_impl(void);
-
-       virtual int unlock_impl(void);
-private:
-       pthread_mutex_t m_history_mutex;
-       static const int OWNER_INFO_LEN = 256;
-       char m_owner_info[OWNER_INFO_LEN];
-};
-
-class Autolock {
-private:
-       cbase_lock& m_lock;
-public:
-       Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line);
-       Autolock(cbase_lock &m, lock_type type);
-       ~Autolock();
-};
-
-#endif /* _CBASE_LOCK_H_ */
diff --git a/src/shared/cmutex.cpp b/src/shared/cmutex.cpp
deleted file mode 100644 (file)
index 6245b6e..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <cmutex.h>
-#include <sensor_log.h>
-
-cmutex::cmutex()
-{
-       pthread_mutexattr_t mutex_attr;
-       pthread_mutexattr_init(&mutex_attr);
-       pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
-       pthread_mutex_init(&m_mutex, &mutex_attr);
-       pthread_mutexattr_destroy(&mutex_attr);
-}
-
-cmutex::~cmutex()
-{
-       pthread_mutex_destroy(&m_mutex);
-}
-
-void cmutex::lock(void)
-{
-#ifdef _LOCK_DEBUG
-       cbase_lock::lock(LOCK_TYPE_MUTEX, "mutex", __MODULE__, __func__, __LINE__);
-#else
-       cbase_lock::lock(LOCK_TYPE_MUTEX);
-#endif
-}
-
-void cmutex::lock(const char* expr, const char *module, const char *func, int line)
-{
-       cbase_lock::lock(LOCK_TYPE_MUTEX, expr, module, func, line);
-}
-
-int cmutex::lock_impl(void)
-{
-       return pthread_mutex_lock(&m_mutex);
-}
-
-int cmutex::try_lock_impl(void)
-{
-       return pthread_mutex_trylock(&m_mutex);
-}
-
-int cmutex::unlock_impl(void)
-{
-       return pthread_mutex_unlock(&m_mutex);
-}
diff --git a/src/shared/cmutex.h b/src/shared/cmutex.h
deleted file mode 100644 (file)
index 94aa2b6..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _CMUTEX_H_
-#define _CMUTEX_H_
-
-#include "cbase_lock.h"
-
-class cmutex : public cbase_lock {
-public:
-       cmutex();
-       virtual ~cmutex();
-
-       void lock(void);
-       void lock(const char* expr, const char *module, const char *func, int line);
-
-protected:
-       int lock_impl(void);
-       int try_lock_impl(void);
-       int unlock_impl(void);
-
-private:
-       pthread_mutex_t m_mutex;
-};
-
-#endif /* _CMUTEX_H_ */
index 47c47b1..679bf08 100644 (file)
@@ -20,7 +20,6 @@
 #ifndef _COMMAND_COMMON_H_
 #define _COMMAND_COMMON_H_
 
-#include <cpacket.h>
 #include <sensor_common.h>
 #include <string>
 #include <vector>
diff --git a/src/shared/cpacket.cpp b/src/shared/cpacket.cpp
deleted file mode 100644 (file)
index a2ce0e0..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <new>
-#include <sensor_log.h>
-#include <cpacket.h>
-#include <command_common.h>
-
-cpacket::cpacket()
-{
-       m_packet = NULL;
-}
-
-cpacket::cpacket(size_t size)
-{
-       m_packet = NULL;
-       set_payload_size(size);
-}
-
-cpacket::~cpacket()
-{
-       delete[] (char*)m_packet;
-}
-
-void cpacket::set_cmd(int cmd)
-{
-       if (!m_packet)
-               set_payload_size(0);
-
-       m_packet->cmd = cmd;
-}
-
-int cpacket::cmd(void)
-{
-       if (!m_packet)
-               return CMD_NONE;
-
-       return m_packet->cmd;
-}
-
-void *cpacket::data(void)
-{
-       if (!m_packet)
-               return NULL;
-
-       return m_packet->data;
-}
-
-void *cpacket::packet(void)
-{
-       return (void*)m_packet;
-}
-
-size_t cpacket::size(void)
-{
-       if (!m_packet)
-               return 0;
-
-       return m_packet->size + sizeof(packet_header);
-}
-
-size_t cpacket::payload_size(void)
-{
-       if (!m_packet)
-               return 0;
-
-       return m_packet->size;
-}
-
-void cpacket::set_payload_size(size_t size)
-{
-       int prev_cmd = CMD_NONE;
-
-       if (m_packet) {
-               prev_cmd = m_packet->cmd;
-               delete []m_packet;
-       }
-
-       m_packet = (packet_header*) new(std::nothrow) char[size + sizeof(packet_header)];
-       retm_if(!m_packet, "Failed to allocate memory");
-       m_packet->size = size;
-
-       if (prev_cmd != CMD_NONE)
-               m_packet->cmd = prev_cmd;
-}
diff --git a/src/shared/cpacket.h b/src/shared/cpacket.h
deleted file mode 100644 (file)
index 64845e8..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _CPACKET_H_
-#define _CPACKET_H_
-
-#include <stddef.h>
-
-typedef struct packet_header {
-       int cmd;
-       size_t size;
-       char data[];
-} packet_header;
-
-class cpacket {
-public:
-       cpacket();
-       explicit cpacket(size_t size);
-       ~cpacket();
-
-       void set_cmd(int cmd);
-       int cmd(void);
-
-       void *data(void);
-       void *packet(void);
-
-       size_t size(void);
-       size_t payload_size(void);
-
-       void set_payload_size(size_t size);
-private:
-       packet_header *m_packet;
-};
-
-#endif /* _CPACKET_H_ */
diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp
deleted file mode 100644 (file)
index ca9ec4f..0000000
+++ /dev/null
@@ -1,548 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_log.h>
-#include <csocket.h>
-#include <attr/xattr.h>
-#include <sys/stat.h>
-#include <stdint.h>
-
-csocket::csocket()
-: m_sock_fd(-1)
-, m_sock_type(SOCK_SEQPACKET)
-, m_send_flags(MSG_NOSIGNAL)
-, m_recv_flags(MSG_NOSIGNAL)
-{
-       memset(&m_addr, 0, sizeof(m_addr));
-}
-
-csocket::csocket(int sock_fd)
-: m_sock_fd(-1)
-, m_sock_type(SOCK_SEQPACKET)
-, m_send_flags(MSG_NOSIGNAL)
-, m_recv_flags(MSG_NOSIGNAL)
-{
-       m_sock_fd = sock_fd;
-       set_sock_type();
-       memset(&m_addr, 0, sizeof(m_addr));
-}
-
-csocket::csocket(const csocket &sock)
-: m_sock_fd(-1)
-, m_sock_type(SOCK_SEQPACKET)
-, m_send_flags(MSG_NOSIGNAL)
-, m_recv_flags(MSG_NOSIGNAL)
-{
-       if (this == &sock)
-               return;
-
-       m_sock_fd = sock.m_sock_fd;
-       m_sock_type = sock.m_sock_type;
-       m_send_flags = sock.m_send_flags;
-       m_recv_flags = sock.m_recv_flags;
-
-       memcpy(&m_addr, &sock.m_addr, sizeof(sockaddr_un));
-}
-
-csocket::~csocket()
-{
-}
-
-bool csocket::create(int sock_type)
-{
-       m_sock_fd = socket(AF_UNIX, sock_type, 0);
-
-       if (!is_valid()) {
-               _ERRNO(errno, _E, "Failed to create socket for %s", get_client_name());
-               return false;
-       }
-
-       m_sock_type = sock_type;
-
-       return true;
-}
-
-bool csocket::bind(const char *sock_path)
-{
-       int length;
-       mode_t socket_mode;
-
-       if (!is_valid())
-               return false;
-
-       if (!access(sock_path, F_OK)) {
-               unlink(sock_path);
-       }
-
-       m_addr.sun_family = AF_UNIX;
-
-       strncpy(m_addr.sun_path, sock_path, strlen(sock_path));
-
-       length = strlen(m_addr.sun_path) + sizeof(m_addr.sun_family);
-
-       if (::bind(m_sock_fd, (struct sockaddr *)&m_addr, length) < 0) {
-               _ERRNO(errno, _E, "Failed to bind for socket[%d]", m_sock_fd);
-               close();
-               return false;
-       }
-
-       socket_mode = (S_IRWXU | S_IRWXG | S_IRWXO);
-       if (chmod(sock_path, socket_mode) < 0) {
-               _ERRNO(errno, _E, "Failed to chmod for socket[%d]", m_sock_fd);
-               close();
-               return false;
-       }
-
-       return true;
-}
-
-bool csocket::listen(const int max_connections)
-{
-       if (!is_valid())
-               return false;
-
-       if (::listen(m_sock_fd, max_connections) < 0) {
-               _ERRNO(errno, _E, "Failed to listen for socket[%d]", m_sock_fd);
-               close();
-               return false;
-       }
-
-       return true;
-}
-
-bool csocket::accept(csocket& client_socket) const
-{
-       const int TIMEOUT = 1;
-       struct timeval tv;
-       int addr_length = sizeof(m_addr);
-       int err = 0;
-
-       fd_set read_fds;
-
-       while (true) {
-               FD_ZERO(&read_fds);
-               FD_SET(m_sock_fd, &read_fds);
-
-               tv.tv_sec = TIMEOUT;
-               tv.tv_usec = 0;
-
-               err = ::select(m_sock_fd + 1, &read_fds, NULL, NULL, &tv);
-               if (err == -1) {
-                       _ERRNO(errno, _E, "Failed to select(), m_sock_fd : %d", m_sock_fd);
-                       return false;
-               }
-
-               if (!is_valid()) {
-                       _E("socket is closed, m_sock_fd : %d", m_sock_fd);
-                       return false;
-               }
-
-               /* timeout */
-               if (!err)
-                       continue;
-
-               if (FD_ISSET(m_sock_fd, &read_fds))
-                       break;
-
-               _ERRNO(errno, _E, "Failed to select(), msock_fd : %d", m_sock_fd);
-       }
-
-       if (!is_valid()) {
-               _E("socket is closed, m_sock_fd : %d", m_sock_fd);
-               return false;
-       }
-
-       do {
-               client_socket.m_sock_fd = ::accept(m_sock_fd, (sockaddr *)&m_addr, (socklen_t *)&addr_length);
-               client_socket.set_sock_type();
-               if (!client_socket.is_valid())
-                       err = errno;
-       } while (err == EINTR);
-
-       if (!client_socket.is_valid()) {
-               _ERRNO(errno, _E, "Failed to accept for socket[%d]", m_sock_fd);
-               return false;
-       }
-
-       return true;
-}
-
-ssize_t csocket::send_for_seqpacket(const void *buffer, size_t size) const
-{
-       ssize_t err, len;
-
-       do {
-               len = ::send(m_sock_fd, buffer, size, m_send_flags);
-               err = len < 0 ? errno : 0;
-       } while (err == EINTR);
-
-       if (err) {
-               _ERRNO(errno, _E, "Failed to send(%d, %#x, %d, %#x) = %d",
-                       m_sock_fd, buffer, size, m_send_flags, len);
-       }
-
-       return err == 0 ? len : -err;
-}
-
-ssize_t csocket::recv_for_seqpacket(void* buffer, size_t size) const
-{
-       ssize_t err, len;
-
-       do {
-               len = ::recv(m_sock_fd, buffer, size, m_recv_flags);
-
-               if (len > 0) {
-                       err = 0;
-               } else if (len == 0) {
-                       _E("recv(%d, %#p , %d) = %d, because the peer performed shutdown!",
-                               m_sock_fd, buffer, size, len);
-                       err = 1;
-               } else {
-                       err = errno;
-               }
-       } while (err == EINTR);
-
-       if ((err == EAGAIN) || (err == EWOULDBLOCK))
-               return 0;
-
-       if (err) {
-               _ERRNO(err, _E, "Failed to recv(%d, %#x, %d, %#x) = %d",
-                       m_sock_fd, buffer, size, m_recv_flags, len);
-       }
-
-       return err == 0 ? len : -err;
-}
-
-ssize_t csocket::send_for_stream(const void *buffer, size_t size) const
-{
-       ssize_t len;
-       ssize_t err = 0;
-       size_t total_sent_size = 0;
-
-       do {
-               len = ::send(m_sock_fd, (const void *)((uint8_t *)buffer + total_sent_size), size - total_sent_size, m_send_flags);
-
-               if (len < 0) {
-                       /*
-                        * If socket is not available to use it temporarily,
-                        * EAGAIN(EWOULDBLOCK) or EINTR is returned by ::send().
-                        * so in order to prevent that data are omitted, sleep&retry to send it
-                        */
-                       if ((errno == EINTR) || (errno == EAGAIN) || (errno == EWOULDBLOCK)) {
-                               usleep(10000);
-                               continue;
-                       }
-
-                       _ERRNO(errno, _E, "Failed to send(%d, %#p + %d, %d - %d) = %d for %s",
-                                       m_sock_fd, buffer, total_sent_size, size, total_sent_size,
-                                       len, get_client_name());
-
-                       err = errno;
-                       break;
-               }
-
-               total_sent_size += len;
-       } while (total_sent_size < size);
-
-       return err == 0 ? total_sent_size : -err;
-}
-
-ssize_t csocket::recv_for_stream(void* buffer, size_t size) const
-{
-       ssize_t len;
-       ssize_t err = 0;
-       size_t total_recv_size = 0;
-
-       do {
-               len = ::recv(m_sock_fd, (void *)((uint8_t *)buffer + total_recv_size), size - total_recv_size, m_recv_flags);
-
-               if (len == 0) {
-                       _E("recv(%d, %#p + %d, %d - %d) = %d, because the peer of %s performed shutdown!",
-                               m_sock_fd, buffer, total_recv_size, size, total_recv_size, len, get_client_name());
-                       err = 1;
-                       break;
-               }
-
-               if (len < 0) {
-                       /*
-                        * If socket is not available to use it temporarily,
-                        * EAGAIN(EWOULDBLOCK) is returned by ::recv().
-                        * so in order to prevent that data are omitted, sleep&retry to receive it
-                        */
-                       if ((errno != EINTR) || (errno == EAGAIN) || (errno == EWOULDBLOCK)) {
-                               usleep(10000);
-                               continue;
-                       }
-
-                       _ERRNO(errno, _E, "Failed to recv(%d, %#p + %d, %d - %d) = %d for %s",
-                                       m_sock_fd, buffer, total_recv_size, size, total_recv_size,
-                                       len, get_client_name());
-
-                       err = errno;
-                       break;
-               }
-
-               total_recv_size += len;
-       } while (total_recv_size < size);
-
-       return err == 0 ? total_recv_size : -err;
-}
-
-ssize_t csocket::send(const void *buffer, size_t size) const
-{
-       const int TIMEOUT = 5;
-       fd_set write_fds;
-       struct timeval tv;
-
-       if (!is_valid())
-               return -EINVAL;
-
-       FD_ZERO(&write_fds);
-       FD_SET(m_sock_fd, &write_fds);
-       tv.tv_sec = TIMEOUT;
-       tv.tv_usec = 0;
-
-       int ret;
-
-       ret = select(m_sock_fd + 1, NULL, &write_fds, NULL, &tv);
-
-       if (ret == -1) {
-               _ERRNO(errno, _E, "select error: sock_fd: %d\n for %s", m_sock_fd, get_client_name());
-               return 0;
-       } else if (!ret) {
-               _ERRNO(errno, _E, "select timeout: %d seconds elapsed for %s", tv.tv_sec, get_client_name());
-               return 0;
-       }
-
-       if (!FD_ISSET(m_sock_fd, &write_fds)) {
-               _ERRNO(errno, _E, "select failed for %s, nothing to write, m_sock_fd : %d", get_client_name(), m_sock_fd);
-               return 0;
-       }
-
-       if (m_sock_type == SOCK_STREAM)
-               return send_for_stream(buffer, size);
-
-       return send_for_seqpacket(buffer, size);
-}
-
-ssize_t csocket::recv(void* buffer, size_t size) const
-{
-       if (!is_valid())
-               return -EINVAL;
-
-       if (m_sock_type == SOCK_STREAM)
-               return recv_for_stream(buffer, size);
-
-       return recv_for_seqpacket(buffer, size);
-}
-
-bool csocket::connect(const char *sock_path)
-{
-       const int TIMEOUT = 5;
-       fd_set write_fds;
-       struct timeval tv;
-       int addr_len;
-       bool prev_blocking_mode;
-
-       if (!is_valid())
-               return false;
-
-       prev_blocking_mode = is_blocking_mode();
-
-       set_blocking_mode(false);
-
-       m_addr.sun_family = AF_UNIX;
-
-       strncpy(m_addr.sun_path, sock_path, strlen(sock_path));
-
-       addr_len = strlen(m_addr.sun_path) + sizeof(m_addr.sun_family);
-
-       if (::connect(m_sock_fd, (sockaddr *)&m_addr, addr_len) < 0) {
-               _ERRNO(errno, _E, "Failed to connect sock_fd: %d for %s",
-                               m_sock_fd, get_client_name());
-               return false;
-       }
-
-       FD_ZERO(&write_fds);
-       FD_SET(m_sock_fd, &write_fds);
-       tv.tv_sec = TIMEOUT;
-       tv.tv_usec = 0;
-
-       int ret;
-
-       ret = select(m_sock_fd + 1, NULL, &write_fds, NULL, &tv);
-
-       if (ret == -1) {
-               _ERRNO(errno, _E, "select error: sock_fd: %d\n for %s", m_sock_fd, get_client_name());
-               close();
-               return false;
-       } else if (!ret) {
-               _ERRNO(errno, _E, "select timeout: %d seconds elapsed for %s", tv.tv_sec, get_client_name());
-               close();
-               return false;
-       }
-
-       if (!FD_ISSET(m_sock_fd, &write_fds)) {
-               _ERRNO(errno, _E, "select failed for %s, nothing to write, m_sock_fd : %d", get_client_name(), m_sock_fd);
-               close();
-               return false;
-       }
-
-       int so_error;
-       socklen_t len = sizeof(so_error);
-
-       if (getsockopt(m_sock_fd, SOL_SOCKET, SO_ERROR, &so_error, &len) == -1) {
-               _ERRNO(errno, _E, "getsockopt failed for %s, m_sock_fd : %d", get_client_name(), m_sock_fd);
-               close();
-               return false;
-       }
-
-       if (so_error) {
-               _ERRNO(errno, _E, "SO_ERROR occurred for %s, m_sock_fd : %d, so_error : %d",
-                       get_client_name(), m_sock_fd, so_error);
-               close();
-               return false;
-       }
-
-       if (prev_blocking_mode)
-               set_blocking_mode(true);
-
-       return true;
-}
-
-bool csocket::set_blocking_mode(bool blocking)
-{
-       int flags;
-
-       if (!is_valid())
-               return false;
-
-       flags = fcntl(m_sock_fd, F_GETFL);
-
-       if (flags == -1) {
-               _ERRNO(errno, _E, "fcntl(F_GETFL) failed for %s, m_sock_fd: %d", get_client_name(), m_sock_fd);
-               return false;
-       }
-
-       flags = blocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK);
-
-       flags = fcntl(m_sock_fd, F_SETFL, flags);
-
-       if (flags == -1) {
-               _ERRNO(errno, _E, "fcntl(F_SETFL) failed for %s, m_sock_fd: %d", get_client_name(), m_sock_fd);
-               return false;
-       }
-
-       return true;
-}
-
-bool csocket::set_sock_type(void)
-{
-       socklen_t opt_len;
-       int sock_type;
-
-       opt_len = sizeof(sock_type);
-
-       if (!is_valid())
-               return false;
-
-       if (getsockopt(m_sock_fd, SOL_SOCKET, SO_TYPE, &sock_type, &opt_len) < 0) {
-          _ERRNO(errno, _E, "getsockopt(SOL_SOCKET, SO_TYPE) failed for %s, m_sock_fd: %d",
-                 get_client_name(), m_sock_fd);
-          return false;
-       }
-
-       m_sock_type = sock_type;
-       return true;
-}
-
-bool csocket::set_connection_mode(void)
-{
-       struct timeval tv;
-       const int TIMEOUT = 5;
-
-       set_blocking_mode(true);
-
-       tv.tv_sec = TIMEOUT;
-       tv.tv_usec = 0;
-
-       if (!is_valid())
-               return false;
-
-       if (setsockopt(m_sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
-               _ERRNO(errno, _E, "Set SO_RCVTIMEO failed for %s, m_sock_fd : %d", get_client_name(), m_sock_fd);
-               close();
-               return false;
-       }
-
-       m_send_flags = MSG_NOSIGNAL;
-       m_recv_flags = MSG_NOSIGNAL;
-
-       return true;
-}
-
-bool csocket::set_transfer_mode(void)
-{
-       set_blocking_mode(false);
-
-       m_send_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
-       m_recv_flags = MSG_DONTWAIT | MSG_NOSIGNAL;
-
-       return true;
-}
-
-bool csocket::is_blocking_mode(void)
-{
-       int flags;
-
-       if (!is_valid())
-               return false;
-
-       flags = fcntl(m_sock_fd, F_GETFL);
-
-       if (flags == -1) {
-               _ERRNO(errno, _E, "fcntl(F_GETFL) failed for %s, m_sock_fd: %d", get_client_name(), m_sock_fd);
-               return false;
-       }
-
-       return !(flags & O_NONBLOCK);
-}
-
-bool csocket::is_valid(void) const
-{
-       return (m_sock_fd >= 0);
-}
-
-int csocket::get_socket_fd(void) const
-{
-       return m_sock_fd;
-}
-
-bool csocket::close(void)
-{
-       if (m_sock_fd >= 0) {
-               if (::close(m_sock_fd) < 0) {
-                       _ERRNO(errno, _W, "Failed to close socket[%d]", m_sock_fd);
-                       return false;
-               }
-               m_sock_fd = -1;
-       }
-
-       return true;
-}
diff --git a/src/shared/csocket.h b/src/shared/csocket.h
deleted file mode 100644 (file)
index 1391531..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _CSOCKET_H_
-#define _CSOCKET_H_
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sensor_log.h>
-
-class csocket {
-public:
-       csocket();
-       virtual ~csocket();
-       csocket(int sock_fd);
-       csocket(const csocket &sock);
-
-       //Server
-       bool create(int sock_type);
-       bool bind(const char *sock_path);
-       bool listen(const int max_connections);
-       bool accept(csocket& client_socket) const;
-
-       //Client
-       bool connect(const char *sock_path);
-
-       //Data Transfer
-       ssize_t send(const void *buffer, size_t size) const;
-       ssize_t recv(void* buffer, size_t size) const;
-
-       bool set_connection_mode(void);
-       bool set_transfer_mode(void);
-       bool is_blocking_mode(void);
-
-       //check if socket is created
-       bool is_valid(void) const;
-       int get_socket_fd(void) const;
-
-       bool close(void);
-
-       bool is_block_mode(void);
-
-private:
-       bool set_blocking_mode(bool blocking);
-       bool set_sock_type(void);
-
-       ssize_t send_for_seqpacket(const void *buffer, size_t size) const;
-       ssize_t send_for_stream(const void *buffer, size_t size) const;
-       ssize_t recv_for_seqpacket(void* buffer, size_t size) const;
-       ssize_t recv_for_stream(void* buffer, size_t size) const;
-
-private:
-       int m_sock_fd;
-       int m_sock_type;
-       sockaddr_un m_addr;
-       int m_send_flags;
-       int m_recv_flags;
-};
-
-#endif /* _CSOCKET_H_ */
diff --git a/src/shared/poller.cpp b/src/shared/poller.cpp
deleted file mode 100644 (file)
index 8e05af8..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <errno.h>
-#include <string.h>
-#include <sensor_log.h>
-#include <poller.h>
-
-#define EPOLL_MAX 32
-
-poller::poller()
-: m_epfd(-1)
-, sfd(-1)
-{
-       init_poll_fd();
-}
-
-poller::poller(int fd)
-: m_epfd(-1)
-{
-       init_poll_fd();
-       add_fd(fd);
-}
-
-poller::~poller()
-{
-       if (m_epfd >= 0)
-               ::close(m_epfd);
-}
-
-void poller::init_poll_fd(void)
-{
-       m_epfd = epoll_create(EPOLL_MAX);
-}
-
-bool poller::add_signal_fd(int fd)
-{
-       sfd = fd;
-       return add_fd(fd);
-}
-
-bool poller::add_fd(int fd)
-{
-       struct epoll_event event;
-
-       event.data.fd = fd;
-       event.events = EPOLLIN | EPOLLERR | EPOLLHUP;
-
-       if (epoll_ctl(m_epfd, EPOLL_CTL_ADD, fd, &event)) {
-               _ERRNO(errno, _E, "Failed to add fd[%d]", fd);
-               return false;
-       }
-
-       return true;
-}
-
-bool poller::del_fd(int fd)
-{
-       struct epoll_event event;
-
-       event.data.fd = fd;
-
-       if (epoll_ctl(m_epfd, EPOLL_CTL_DEL, fd, &event)) {
-               _ERRNO(errno, _E, "Failed to del fd[%d]", fd);
-               return false;
-       }
-
-       return true;
-}
-
-bool poller::fill_event_queue(void)
-{
-       const int EPOLL_MAX_EVENT = 1;
-
-       struct epoll_event event_items[EPOLL_MAX_EVENT];
-       int nr_events = epoll_wait(m_epfd, event_items, EPOLL_MAX_EVENT, -1);
-
-       if (nr_events < 0) {
-               if (errno == EINTR)
-                       return true;
-
-               _ERRNO(errno, _E, "Failed to fill event queue");
-               return false;
-       }
-
-       if (nr_events == 0) {
-               _E("Epoll timeout!");
-               return false;
-       }
-
-       for (int i = 0; i < nr_events; i++)
-               m_event_queue.push(event_items[i]);
-
-       return true;
-}
-
-bool poller::poll(struct epoll_event &event)
-{
-       while (true) {
-               if (m_event_queue.empty()) {
-                       if (!fill_event_queue())
-                               return false;
-               }
-
-               if (!m_event_queue.empty()) {
-                       event = m_event_queue.front();
-                       m_event_queue.pop();
-
-                       if (event.events & EPOLLERR) {
-                               _E("Poll error!");
-                               return false;
-                       }
-
-                       if (event.events & EPOLLHUP) {
-                               _I("Poll: Connetion is closed from the other side");
-                               return false;
-                       }
-
-                       if (event.data.fd == sfd) {
-                               _E("received signal");
-                               return false;
-                       }
-
-                       return true;
-               }
-       }
-}
diff --git a/src/shared/poller.h b/src/shared/poller.h
deleted file mode 100644 (file)
index e61408d..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef _POLLER_H_
-#define _POLLER_H_
-
-#include <sys/types.h>
-#include <sys/epoll.h>
-#include <unistd.h>
-#include <queue>
-
-class poller {
-public:
-       poller();
-       poller(int fd);
-       virtual ~poller();
-
-       bool add_signal_fd(int fd);
-
-       bool add_fd(int fd);
-       bool del_fd(int fd);
-
-       bool poll(struct epoll_event &event);
-
-private:
-       int m_epfd;
-       int sfd;
-
-       std::queue<struct epoll_event> m_event_queue;
-
-private:
-       void init_poll_fd(void);
-       bool fill_event_queue(void);
-};
-
-#endif /* _POLLER_H_ */
diff --git a/src/shared/sensor_types.cpp b/src/shared/sensor_types.cpp
deleted file mode 100644 (file)
index 037ddc9..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <sensor_types.h>
-
-DECLARE_SENSOR_ENUM_UTIL(sensor_type_t, SENSOR_TYPE)