sensor-hal: add interface of sensorhub 82/58982/1
authorkibak.yoon <kibak.yoon@samsung.com>
Fri, 5 Feb 2016 12:43:08 +0000 (21:43 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Fri, 5 Feb 2016 12:43:08 +0000 (21:43 +0900)
* it doesn't have specific implementation of sensorhub

Change-Id: I232ecff56f1a3c18eea8622c7655199da72b8408
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
17 files changed:
CMakeLists.txt
src/create.cpp
src/sensor_hal.h
src/sensorhub/dbus_util.cpp [new file with mode: 0644]
src/sensorhub/dbus_util.h [new file with mode: 0644]
src/sensorhub/sensorhub.cpp [new file with mode: 0644]
src/sensorhub/sensorhub.h [new file with mode: 0644]
src/sensorhub/sensorhub_controller.cpp [new file with mode: 0644]
src/sensorhub/sensorhub_controller.h [new file with mode: 0644]
src/sensorhub/sensorhub_manager.cpp [new file with mode: 0644]
src/sensorhub/sensorhub_manager.h [new file with mode: 0644]
src/sensorhub/sensorhub_sensor.cpp [new file with mode: 0644]
src/sensorhub/sensorhub_sensor.h [new file with mode: 0644]
src/sensorhub/system_state.cpp [new file with mode: 0644]
src/sensorhub/system_state.h [new file with mode: 0644]
src/sensorhub/wristup.cpp [new file with mode: 0644]
src/sensorhub/wristup.h [new file with mode: 0644]

index 37c0dde..c8c66df 100644 (file)
@@ -5,6 +5,7 @@ INCLUDE(GNUInstallDirs)
 
 SET(ACCEL "ON")
 SET(PROXIMITY "ON")
+SET(SENSORHUB "ON")
 
 # Common Options
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -omit-frame-pointer -std=gnu++0x")
@@ -17,7 +18,7 @@ MESSAGE("FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
 #ADD_DEFINITIONS(-Wall -g -D_DEBUG)
 
 INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(hal_pkgs REQUIRED dlog)
+PKG_CHECK_MODULES(hal_pkgs REQUIRED dlog glib-2.0 gio-2.0 gobject-2.0 vconf)
 
 FOREACH(flag ${hal_pkgs_LDFLAGS})
        SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
@@ -42,6 +43,11 @@ FILE(GLOB_RECURSE SRCS ${SRCS} src/proxi/*.cpp)
 ADD_DEFINITIONS(-DENABLE_PROXIMITY)
 ENDIF()
 
+IF("${SENSORHUB}" STREQUAL "ON")
+FILE(GLOB_RECURSE SRCS ${SRCS} src/sensorhub/*.cpp)
+ADD_DEFINITIONS(-DENABLE_SENSORHUB)
+ENDIF()
+
 MESSAGE("Sources: ${SRCS}")
 ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${hal_pkgs_LDFLAGS})
index d568544..5140fb3 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "accel/accel.h"
 #include "proxi/proxi.h"
+#include "sensorhub/sensorhub.h"
 
 static std::vector<sensor_device_t> devs;
 
@@ -51,6 +52,10 @@ extern "C" int create(sensor_device_t **devices)
        create_sensor<proxi_device>("Proximity");
 #endif
 
+#ifdef ENABLE_SENSORHUB
+       create_sensor<sensorhub_device>("Sensorhub");
+#endif
+
        *devices = &devs[0];
 
        return devs.size();
index 5530c7c..7cdd40a 100644 (file)
@@ -135,17 +135,27 @@ typedef struct sensor_data_t {
        float values[SENSOR_DATA_VALUE_SIZE];
 } sensor_data_t;
 
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+#define SENSORHUB_DATA_VALUE_SIZE 4096
+
+/* sensorhub_data_t */
+typedef struct sensorhub_data_t {
+       int accuracy;
+       unsigned long long timestamp;
+       int value_count;
+       char values[SENSORHUB_DATA_VALUE_SIZE];
+} sensorhub_data_t;
 
-#ifdef __cplusplus
 /*
  * Create devices
  */
 typedef void *sensor_device_t;
 typedef int (*create_t)(sensor_device_t **devices);
 
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#ifdef __cplusplus
 /*
  * Sensor device interface
  * 1 device must be abstracted from 1 device event node
diff --git a/src/sensorhub/dbus_util.cpp b/src/sensorhub/dbus_util.cpp
new file mode 100644 (file)
index 0000000..adeaf57
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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 <gio/gio.h>
+#include <sensor_logs.h>
+#include "dbus_util.h"
+
+void init_dbus(void)
+{
+}
+
+void fini_dbus(void)
+{
+}
diff --git a/src/sensorhub/dbus_util.h b/src/sensorhub/dbus_util.h
new file mode 100644 (file)
index 0000000..39ac187
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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 _DBUS_UTIL_H_
+#define _DBUS_UTIL_H_
+
+void init_dbus(void);
+void fini_dbus(void);
+
+#endif /* _DBUS_UTIL_H_ */
diff --git a/src/sensorhub/sensorhub.cpp b/src/sensorhub/sensorhub.cpp
new file mode 100644 (file)
index 0000000..1d522e4
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * 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 <algorithm>
+#include <sensor_logs.h>
+
+#include "sensorhub.h"
+#include "sensorhub_controller.h"
+#include "sensorhub_manager.h"
+#include "system_state.h"
+
+sensorhub_device::sensorhub_device()
+{
+       controller = new(std::nothrow) sensorhub_controller();
+       if (!controller) {
+               ERR("Failed to allocated memory");
+               throw;
+       }
+
+       manager = new(std::nothrow) sensorhub_manager();
+       if (!manager) {
+               ERR("Failed to allocated memory");
+               throw;
+       }
+       manager->set_controller(controller);
+       system_state_handler::get_instance().set_controller(controller);
+
+       INFO("sensorhub_device is created!");
+}
+
+sensorhub_device::~sensorhub_device()
+{
+       delete controller;
+       delete manager;
+
+       INFO("sensorhub_device is destroyed!");
+}
+
+int sensorhub_device::get_poll_fd(void)
+{
+       return controller->get_poll_fd();
+}
+
+int sensorhub_device::get_sensors(const sensor_handle_t **sensors)
+{
+       int size;
+       size = manager->get_sensors(sensors);
+
+       return size;
+}
+
+bool sensorhub_device::enable(uint16_t id)
+{
+       system_state_handler::get_instance().initialize();
+
+       controller->enable();
+       sensorhub_sensor *sensor = manager->get_sensor(id);
+
+       if (!sensor) {
+               ERR("Failed to enable sensor(0x%x)", id);
+               return false;
+       }
+
+       return sensor->enable();
+}
+
+bool sensorhub_device::disable(uint16_t id)
+{
+       system_state_handler::get_instance().finalize();
+
+       controller->disable();
+       sensorhub_sensor *sensor = manager->get_sensor(id);
+
+       if (!sensor) {
+               ERR("Failed to disable sensor(0x%x)", id);
+               return false;
+       }
+
+       return sensor->disable();
+}
+
+bool sensorhub_device::set_interval(uint16_t id, unsigned long val)
+{
+       sensorhub_sensor *sensor = manager->get_sensor(id);
+
+       if (!sensor) {
+               ERR("Failed to set interval to sensor(0x%x)", id);
+               return false;
+       }
+
+       return sensor->set_interval(val);
+}
+
+bool sensorhub_device::set_batch_latency(uint16_t id, unsigned long val)
+{
+       sensorhub_sensor *sensor = manager->get_sensor(id);
+
+       if (!sensor) {
+               ERR("Failed to set batch latency to sensor(0x%x)", id);
+               return false;
+       }
+
+       return sensor->set_batch_latency(val);
+}
+
+bool sensorhub_device::set_attribute(uint16_t id, int32_t attribute, int32_t value)
+{
+       int ret;
+
+       sensorhub_sensor *sensor = manager->get_sensor(id);
+
+       if (!sensor) {
+               ERR("Failed to set attribute to sensor(0x%x)", id);
+               return false;
+       }
+
+       ret = sensor->set_attribute(attribute, value);
+
+       if ((ret < 0) && (ret != -EBUSY)) {
+               ERR("Failed to send sensorhub data");
+               return false;
+       }
+
+       if (ret == -EBUSY) {
+               WARN("Command is sent during sensorhub firmware update");
+               return false;
+       }
+
+       return true;
+}
+
+bool sensorhub_device::set_attribute_str(uint16_t id, char *attribute, char *value, int value_len)
+{
+       int ret;
+
+       sensorhub_sensor *sensor = manager->get_sensor(id);
+
+       if (!sensor) {
+               ERR("Failed to set attribute to sensor(0x%x)", id);
+               return false;
+       }
+
+       ret = sensor->set_attribute_str(attribute, value, value_len);
+
+       if ((ret < 0) && (ret != -EBUSY)) {
+               ERR("Failed to send sensorhub data");
+               return false;
+       }
+
+       if (ret == -EBUSY) {
+               WARN("Command is sent during sensorhub firmware update");
+               return false;
+       }
+
+       return true;
+}
+
+int sensorhub_device::read_fd(uint16_t **ids)
+{
+       sensorhub_data_t data;
+
+       // step 1
+       if (!controller->read_fd(data))
+               return 0;
+
+       // step 2
+       const char *hub_data = data.values;
+       int data_len = data.value_count;
+
+       // step 3
+       event_ids.clear();
+
+       while (data_len > 0) {
+               DBG("Remaining data length: %d", data_len);
+               int parsed = parse(hub_data, data_len);
+               if (parsed < 0) {
+                       ERR("Parsing failed");
+                       break;
+               }
+
+               data_len -= parsed;
+               hub_data += parsed;
+       }
+
+       // step 4
+       int size = event_ids.size();
+
+       if (event_ids.empty())
+               return 0;
+
+       *ids = &event_ids[0];
+
+       return size;
+}
+
+int sensorhub_device::get_data(uint16_t id, sensor_data_t **data, int *length)
+{
+       int remains = 1;
+
+       sensorhub_sensor *sensor = manager->get_sensor(id);
+       if (!sensor) {
+               ERR("Failed to get data from sensor(0x%x)", id);
+               return -1;
+       }
+
+       remains = sensor->get_data(data, length);
+
+       return remains;
+}
+
+bool sensorhub_device::flush(uint16_t id)
+{
+       return false;
+}
+
+int sensorhub_device::parse(const char *hub_data, int data_len)
+{
+       return parse_data(hub_data, data_len);
+}
+
+int sensorhub_device::parse_data(const char *hub_data, int data_len)
+{
+       const char *cursor = hub_data;
+       char libtype = 0;
+
+       sensorhub_sensor *sensor = manager->get_sensor(libtype);
+       if (!sensor) {
+               ERR("Unknown Sensorhub lib type: %d", libtype);
+               return -1;
+       }
+
+       event_ids.push_back(sensor->get_id());
+
+       return sensor->parse(cursor, data_len);
+}
+
+int sensorhub_device::parse_debug(const char *hub_data, int data_len)
+{
+       return 0;
+}
+
diff --git a/src/sensorhub/sensorhub.h b/src/sensorhub/sensorhub.h
new file mode 100644 (file)
index 0000000..d4c3bd7
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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 _SENSORHUB_DEVICE_H_
+#define _SENSORHUB_DEVICE_H_
+
+#include <vector>
+#include <sensor_hal.h>
+
+#include "sensorhub_controller.h"
+#include "sensorhub_manager.h"
+
+class sensorhub_device : public sensor_device {
+public:
+       sensorhub_device();
+       virtual ~sensorhub_device();
+
+       int get_poll_fd(void);
+       int get_sensors(const sensor_handle_t **sensors);
+
+       bool enable(uint16_t id);
+       bool disable(uint16_t id);
+
+       bool set_interval(uint16_t id, unsigned long val);
+       bool set_batch_latency(uint16_t id, unsigned long val);
+       bool set_attribute(uint16_t id, int32_t attribute, int32_t value);
+       bool set_attribute_str(uint16_t id, char *key, char *value, int value_len);
+
+       int read_fd(uint16_t **ids);
+       int get_data(uint16_t id, sensor_data_t **data, int *length);
+
+       bool flush(uint16_t id);
+
+private:
+       sensorhub_manager *manager;
+       sensorhub_controller *controller;
+       std::vector<uint16_t> event_ids;
+
+       int parse(const char *hub_data, int data_len);
+       int parse_data(const char *hub_data, int data_len);
+       int parse_debug(const char *hub_data, int data_len);
+};
+
+#endif /* _SENSORHUB_DEVICE_H_ */
diff --git a/src/sensorhub/sensorhub_controller.cpp b/src/sensorhub/sensorhub_controller.cpp
new file mode 100644 (file)
index 0000000..53c5a2f
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * 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 <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <linux/input.h>
+#include <sys/ioctl.h>
+#include <fstream>
+
+#include <sensor_logs.h>
+#include <util.h>
+#include "sensorhub_controller.h"
+
+sensorhub_controller::sensorhub_controller()
+: m_enabled(false)
+, m_poll_node(-1)
+, m_data_node(-1)
+{
+}
+
+sensorhub_controller::~sensorhub_controller()
+{
+}
+
+int sensorhub_controller::get_poll_fd(void)
+{
+       return -1;
+}
+
+bool sensorhub_controller::enable(void)
+{
+       m_enabled = true;
+       INFO("Enable Sensorhub");
+       return true;
+}
+
+bool sensorhub_controller::disable(void)
+{
+       m_enabled = false;
+       INFO("Disable Sensorhub");
+       return true;
+}
+
+int sensorhub_controller::open_input_node(const char* input_node)
+{
+       return -1;
+}
+
+bool sensorhub_controller::read_fd(sensorhub_data_t &data)
+{
+       return false;
+}
+
+int sensorhub_controller::read_sensorhub_data(void)
+{
+       return -1;
+}
+
+int sensorhub_controller::read_large_sensorhub_data(void)
+{
+       return -1;
+}
+
+int sensorhub_controller::send_sensorhub_data(const char *data, int data_len)
+{
+       return -1;
+}
+
+int sensorhub_controller::print_sensorhub_data(const char* name, const char *data, int length)
+{
+       return 0;
+}
+
diff --git a/src/sensorhub/sensorhub_controller.h b/src/sensorhub/sensorhub_controller.h
new file mode 100644 (file)
index 0000000..67dd9a8
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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 _SENSORHUB_CONTROLLER_H_
+#define _SENSORHUB_CONTROLLER_H_
+
+#include <sensor_hal.h>
+
+class sensorhub_controller {
+public:
+       sensorhub_controller();
+       virtual ~sensorhub_controller();
+
+       int open_input_node(const char* input_node);
+       int get_poll_fd(void);
+
+       bool enable(void);
+       bool disable(void);
+
+       bool read_fd(sensorhub_data_t &data);
+
+       int read_sensorhub_data(void);
+       int read_large_sensorhub_data(void);
+       int send_sensorhub_data(const char *data, int data_len);
+
+private:
+       bool m_enabled;
+       int m_poll_node;
+       int m_data_node;
+
+       int print_sensorhub_data(const char* name, const char *data, int length);
+};
+
+#endif /* _SENSORHUB_CONTROLLER_H_ */
diff --git a/src/sensorhub/sensorhub_manager.cpp b/src/sensorhub/sensorhub_manager.cpp
new file mode 100644 (file)
index 0000000..a955fc6
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * 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 "sensorhub_controller.h"
+#include "sensorhub_manager.h"
+#include "sensorhub_sensor.h"
+
+std::map<uint16_t, sensorhub_sensor *> sensorhub_manager::m_id_sensor;
+std::map<char, sensorhub_sensor *> sensorhub_manager::m_key_sensor;
+std::vector<sensor_handle_t> sensorhub_manager::m_handles;
+
+sensorhub_manager::sensorhub_manager()
+{
+}
+
+sensorhub_manager::~sensorhub_manager()
+{
+       for (auto &it : m_id_sensor)
+               delete it.second;
+
+       m_id_sensor.clear();
+       m_key_sensor.clear();
+       m_handles.clear();
+}
+
+bool sensorhub_manager::add_sensor(sensor_handle_t handle, char key, sensorhub_sensor *sensor)
+{
+       m_handles.push_back(handle);
+       m_id_sensor[handle.id] = sensor;
+       m_key_sensor[key] = sensor;
+
+       return true;
+}
+
+void sensorhub_manager::set_controller(sensorhub_controller *controller)
+{
+       for (auto const &it : m_id_sensor) {
+               sensorhub_sensor *sensor = it.second;
+               sensor->set_controller(controller);
+       }
+}
+
+sensorhub_sensor *sensorhub_manager::get_sensor(uint16_t id)
+{
+       return m_id_sensor[id];
+}
+
+sensorhub_sensor *sensorhub_manager::get_sensor(char key)
+{
+       return m_key_sensor[key];
+}
+
+int sensorhub_manager::get_sensors(const sensor_handle_t **sensors)
+{
+       int size;
+
+       if (m_handles.empty()) {
+               *sensors = 0;
+               return 0;
+       }
+
+       size = m_handles.size();
+       *sensors = &m_handles[0];
+
+       return size;
+}
diff --git a/src/sensorhub/sensorhub_manager.h b/src/sensorhub/sensorhub_manager.h
new file mode 100644 (file)
index 0000000..8939144
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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 _SENSORHUB_MANAGER_H_
+#define _SENSORHUB_MANAGER_H_
+
+#include <map>
+#include <vector>
+
+#include "sensorhub_controller.h"
+#include "sensorhub_sensor.h"
+
+#define REGISTER_SENSOR(handle, key, sensor_class) \
+static void __attribute__((constructor)) add_sensorhub_sensor(void) \
+{ \
+       sensorhub_sensor *sensor = new(std::nothrow) (sensor_class)(); \
+       if (!sensor) { \
+               _E("ERROR: Failed to allocate memory(%s)", #sensor_class); \
+               return; \
+       } \
+       sensorhub_manager::add_sensor((handle), (key), (sensor)); \
+}
+
+class sensorhub_manager {
+public:
+       sensorhub_manager();
+       virtual ~sensorhub_manager();
+
+       sensorhub_sensor *get_sensor(uint16_t id);
+       sensorhub_sensor *get_sensor(char key);
+       int get_sensors(const sensor_handle_t **sensors);
+
+       void set_controller(sensorhub_controller *controller);
+
+       static bool add_sensor(sensor_handle_t handle, char key, sensorhub_sensor *sensor);
+private:
+       static std::map<uint16_t, sensorhub_sensor *> m_id_sensor;
+       static std::map<char, sensorhub_sensor *> m_key_sensor;
+       static std::vector<sensor_handle_t> m_handles;
+};
+#endif /* _SENSORHUB_MANAGER_H_ */
diff --git a/src/sensorhub/sensorhub_sensor.cpp b/src/sensorhub/sensorhub_sensor.cpp
new file mode 100644 (file)
index 0000000..b1b9963
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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_logs.h>
+#include <time.h>
+#include "sensorhub_controller.h"
+#include "sensorhub_sensor.h"
+
+void sensorhub_sensor::set_controller(sensorhub_controller *controller)
+{
+       m_controller = controller;
+}
+
+bool sensorhub_sensor::set_interval(unsigned long val)
+{
+       return false;
+}
+
+bool sensorhub_sensor::set_batch_latency(unsigned long val)
+{
+       return false;
+}
+
+bool sensorhub_sensor::set_attribute(int32_t attribute, int32_t value)
+{
+       return false;
+}
+
+bool sensorhub_sensor::set_attribute_str(char *attribute, char *value, int value_len)
+{
+       return false;
+}
+
+bool sensorhub_sensor::flush(void)
+{
+       return false;
+}
+
+unsigned long long sensorhub_sensor::get_timestamp(void)
+{
+       struct timespec t;
+       clock_gettime(CLOCK_REALTIME, &t);
+       return ((unsigned long long)(t.tv_sec)*1000000000LL + t.tv_nsec) / 1000;
+}
+
diff --git a/src/sensorhub/sensorhub_sensor.h b/src/sensorhub/sensorhub_sensor.h
new file mode 100644 (file)
index 0000000..c3c7918
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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 _SENSORHUB_SENSOR_H_
+#define _SENSORHUB_SENSOR_H_
+
+class sensorhub_sensor {
+public:
+       sensorhub_sensor() {}
+       virtual ~sensorhub_sensor() {}
+
+       virtual int16_t get_id(void) = 0;
+
+       virtual bool enable(void) = 0;
+       virtual bool disable(void) = 0;
+       virtual int parse(const char *hub_data, int data_len) = 0;
+       virtual int get_data(sensor_data_t **data, int *length) = 0;
+
+       void set_controller(sensorhub_controller *controller);
+
+       virtual bool set_interval(unsigned long val);
+       virtual bool set_batch_latency(unsigned long val);
+       virtual bool set_attribute(int32_t attribute, int32_t value);
+       virtual bool set_attribute_str(char *key, char *value, int value_len);
+
+       virtual bool flush(void);
+protected:
+       sensorhub_controller *m_controller;
+
+       unsigned long long get_timestamp(void);
+};
+
+#endif /* _SENSORHUB_SENSOR_H_ */
diff --git a/src/sensorhub/system_state.cpp b/src/sensorhub/system_state.cpp
new file mode 100644 (file)
index 0000000..7bfdb84
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * 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_logs.h>
+#include "dbus_util.h"
+#include "system_state.h"
+
+#define CPU_BOOST_DURATION 400
+#define WAKEUP_LCD_CUSTOM_PARAM 7000
+
+system_state_handler::system_state_handler()
+{
+}
+
+system_state_handler::~system_state_handler()
+{
+       INFO("system_state_handler is destroyed!\n");
+}
+
+system_state_handler& system_state_handler::get_instance()
+{
+       static system_state_handler instance;
+       return instance;
+}
+
+void system_state_handler::set_controller(sensorhub_controller *controller)
+{
+       m_controller = controller;
+}
+
+bool system_state_handler::initialize()
+{
+       return true;
+}
+
+void system_state_handler::finalize(void)
+{
+}
+
+void system_state_handler::set_poweroff_state(void)
+{
+}
+
+void system_state_handler::display_signal_handler(GDBusConnection *conn,
+               const gchar *name, const gchar *path, const gchar *interface,
+               const gchar *sig, GVariant *param, gpointer user_data)
+{
+}
+
+bool system_state_handler::start_listen_display_state()
+{
+       return true;
+}
+
+void system_state_handler::stop_listen_display_state()
+{
+
+}
+
+void system_state_handler::poweroff_signal_handler(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface,
+               const gchar *sig, GVariant *param, gpointer user_data)
+{
+}
+
+bool system_state_handler::start_listen_poweroff_state(void)
+{
+       return true;
+}
+
+void system_state_handler::stop_listen_poweroff_state(void)
+{
+}
+
+void system_state_handler::charger_state_cb(keynode_t *node, void *user_data)
+{
+}
+
+bool system_state_handler::is_display_on(void)
+{
+       return true;
+}
+
+bool system_state_handler::inform_display_state(bool display_on)
+{
+       return inform_display_state();
+}
+
+bool system_state_handler::inform_display_state()
+{
+       return true;
+}
+
+bool system_state_handler::is_charger_connected(void)
+{
+       return false;
+}
+
+bool system_state_handler::is_powering_off()
+{
+       return false;
+}
+
+bool system_state_handler::inform_charger_state()
+{
+       return true;
+}
+
+bool system_state_handler::inform_ssp_sleep(void)
+{
+       return true;
+}
+
+bool system_state_handler::inform_ssp_wakeup(void)
+{
+       return true;
+}
+
+bool system_state_handler::inform_current_time(void)
+{
+       return true;
+}
+
+void system_state_handler::request_display_lock(int msec)
+{
+       return;
+}
+
+void system_state_handler::request_display_wakeup()
+{
+       return;
+}
diff --git a/src/sensorhub/system_state.h b/src/sensorhub/system_state.h
new file mode 100644 (file)
index 0000000..025955d
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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 _SYSTEM_STATE_HANDLER_H_
+#define _SYSTEM_STATE_HANDLER_H_
+
+#include <glib.h>
+#include <vconf.h>
+#include <gio/gio.h>
+
+#include "sensorhub_controller.h"
+
+class system_state_handler {
+private:
+       system_state_handler();
+       ~system_state_handler();
+
+       void set_poweroff_state(void);
+
+       bool start_listen_display_state(void);
+       bool start_listen_poweroff_state(void);
+       void stop_listen_display_state(void);
+       void stop_listen_poweroff_state(void);
+
+       bool inform_display_state(bool display_on);
+       bool inform_display_state(void);
+       bool inform_ssp_sleep(void);
+       bool inform_ssp_wakeup(void);
+
+       static void display_signal_handler(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface,
+               const gchar *sig, GVariant *param, gpointer user_data);
+
+       static void poweroff_signal_handler(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface,
+               const gchar *sig, GVariant *param, gpointer user_data);
+
+       static void display_state_cb(keynode_t *node, void *user_data);
+       static void charger_state_cb(keynode_t *node, void *user_data);
+       static void sleep_state_cb(keynode_t *node, void *user_data);
+
+       sensorhub_controller *m_controller;
+
+public:
+       void set_controller(sensorhub_controller *controller);
+       bool initialize(void);
+       void finalize(void);
+
+       bool is_display_on(void);
+       bool is_charger_connected(void);
+       bool is_powering_off(void);
+
+       bool inform_charger_state(void);
+       bool inform_current_time(void);
+       void request_display_lock(int msec);
+       void request_display_wakeup(void);
+
+       static system_state_handler& get_instance(void);
+};
+
+#endif
diff --git a/src/sensorhub/wristup.cpp b/src/sensorhub/wristup.cpp
new file mode 100644 (file)
index 0000000..0a9bdae
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * 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 <algorithm>
+#include <sensor_hal.h>
+#include <sensor_logs.h>
+
+#include "sensorhub_manager.h"
+#include "system_state.h"
+#include "wristup.h"
+
+#define SENSOR_NAME "WRIST_UP_SENSOR"
+#define SHUB_LIB_WRIST_UP      0
+#define WRIST_UP_PACKET_SIZE   1
+
+static const sensor_handle_t handle = {
+       id: 0x1,
+       name: SENSOR_NAME,
+       type: SENSOR_DEVICE_GESTURE_WRIST_UP,
+       event_type: (SENSOR_DEVICE_GESTURE_WRIST_UP << 16) | 0x0001,
+       model_name: "Wristup",
+       vendor: "Samsung Electronics",
+       min_range: 0,
+       max_range: 1,
+       resolution: 1,
+       min_interval: 0,
+       max_batch_count: 0,
+       wakeup_supported: true
+};
+
+wristup_sensor::wristup_sensor()
+{
+}
+
+wristup_sensor::~wristup_sensor()
+{
+       INFO("wristup_sensor is destroyed!");
+}
+
+int16_t wristup_sensor::get_id(void)
+{
+       return handle.id;
+}
+
+bool wristup_sensor::enable(void)
+{
+       return false;
+}
+
+bool wristup_sensor::disable(void)
+{
+       return false;
+}
+
+int wristup_sensor::parse(const char *data, int data_len)
+{
+       return WRIST_UP_PACKET_SIZE;
+}
+
+int wristup_sensor::get_data(sensor_data_t **data, int *length)
+{
+       return -1;
+}
+
+bool wristup_sensor::set_attribute(int32_t attribute, int32_t value)
+{
+       return false;
+}
+
+bool wristup_sensor::set_attribute_str(char *key, char *value, int value_len)
+{
+       return false;
+}
+
+REGISTER_SENSOR(handle, (char)SHUB_LIB_WRIST_UP, wristup_sensor)
diff --git a/src/sensorhub/wristup.h b/src/sensorhub/wristup.h
new file mode 100644 (file)
index 0000000..4d1036f
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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 _WRISTUP_SENSOR_H_
+#define _WRISTUP_SENSOR_H_
+
+#include "sensorhub_sensor.h"
+
+class wristup_sensor : public sensorhub_sensor {
+public:
+       wristup_sensor();
+       virtual ~wristup_sensor();
+
+       int16_t get_id(void);
+
+       bool enable(void);
+       bool disable(void);
+
+       int parse(const char *data, int data_len);
+       int get_data(sensor_data_t **data, int *length);
+
+       bool set_attribute(int32_t attribute, int32_t value);
+       bool set_attribute_str(char *attribute, char *value, int value_len);
+
+private:
+       sensorhub_data_t m_data;
+};
+
+#endif /* _WRISTUP_SENSOR_H_ */