sensord: wakeup mode support 63/49863/1
authorHongkuk, Son <hongkuk.son@samsung.com>
Wed, 21 Oct 2015 04:41:06 +0000 (13:41 +0900)
committerHongkuk, Son <hongkuk.son@samsung.com>
Wed, 21 Oct 2015 04:41:49 +0000 (13:41 +0900)
Signed-off-by: Hongkuk, Son <hongkuk.son@samsung.com>
Change-Id: I476e3da1a2e5797b38b914e3e9614bd0beb841a9

27 files changed:
src/libsensord/client.cpp
src/libsensord/command_channel.cpp
src/libsensord/command_channel.h
src/libsensord/csensor_event_listener.cpp
src/libsensord/csensor_event_listener.h
src/libsensord/csensor_handle_info.cpp
src/libsensord/csensor_handle_info.h
src/libsensord/sensor_internal.h
src/server/command_worker.cpp
src/server/command_worker.h
src/shared/CMakeLists.txt
src/shared/cclient_info_manager.cpp
src/shared/cclient_info_manager.h
src/shared/cclient_sensor_record.cpp
src/shared/cclient_sensor_record.h
src/shared/csensor_usage.cpp
src/shared/csensor_usage.h
src/shared/cwakeup_info_list.cpp [new file with mode: 0644]
src/shared/cwakeup_info_list.h [new file with mode: 0644]
src/shared/sensor_base.cpp [changed mode: 0755->0644]
src/shared/sensor_base.h [changed mode: 0755->0644]
src/shared/sensor_common.h
src/shared/sensor_hal.cpp [changed mode: 0755->0644]
src/shared/sensor_hal.h [changed mode: 0755->0644]
src/shared/sensor_info.cpp [changed mode: 0755->0644]
src/shared/sensor_info.h [changed mode: 0755->0644]
src/shared/sf_common.h

index 943e5a9..9167a7a 100644 (file)
@@ -602,6 +602,16 @@ API bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_typ
        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);
+
+       return info->is_wakeup_supported();
+}
+
 API int sensord_connect(sensor_t sensor)
 {
        command_channel *cmd_channel = NULL;
@@ -1064,6 +1074,40 @@ API bool sensord_set_option(int handle, int option)
 
 }
 
+API bool sensord_set_wakeup(int handle, int wakeup)
+{
+       sensor_id_t sensor_id;
+       command_channel *cmd_channel;
+       int client_id;
+
+       AUTOLOCK(lock);
+
+       if (!event_listener.get_sensor_id(handle, sensor_id)) {
+               ERR("client %s failed to get handle information", get_client_name());
+               return false;
+       }
+
+       retvm_if ((wakeup != SENSOR_WAKEUP_ON) && (wakeup != SENSOR_WAKEUP_OFF), false, "Invalid wakeup value : %d, handle: %d, %s, %s",
+               wakeup, handle, get_sensor_name(sensor_id), get_client_name());
+
+       event_listener.set_sensor_wakeup(handle, wakeup);
+
+       if (!event_listener.get_command_channel(sensor_id, &cmd_channel)) {
+               ERR("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
+               return false;
+       }
+
+       client_id = event_listener.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 (!cmd_channel->cmd_set_wakeup(wakeup)) {
+               ERR("Sending cmd_set_wakeup(%d, %s, %d) failed for %s", client_id, get_sensor_name(sensor_id), wakeup, get_client_name());
+               return false;
+       }
+
+       return true;
+}
+
 API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len)
 {
        sensor_id_t sensor_id;
index c46a1a1..92bc9dd 100644 (file)
@@ -373,6 +373,45 @@ bool command_channel::cmd_set_option(int option)
        return true;
 }
 
+bool command_channel::cmd_set_wakeup(int wakeup)
+{
+       cpacket *packet;
+       cmd_set_wakeup_t *cmd_set_wakeup;
+       cmd_done_t *cmd_done;
+
+       packet = new(std::nothrow) cpacket(sizeof(cmd_set_wakeup_t));
+       retvm_if(!packet, false, "Failed to allocate memory");
+
+       packet->set_cmd(CMD_SET_WAKEUP);
+
+       cmd_set_wakeup = (cmd_set_wakeup_t*)packet->data();
+       cmd_set_wakeup->wakeup = wakeup;
+
+       INFO("%s send cmd_set_wakeup(client_id=%d, %s, wakeup=%d)",
+               get_client_name(), m_client_id, get_sensor_name(m_sensor_id), wakeup);
+
+       if (!command_handler(packet, (void **)&cmd_done)) {
+               ERR("Client %s failed to send/receive command for sensor[%s] with client_id [%d], wakeup[%d]",
+                       get_client_name(), get_sensor_name(m_sensor_id), m_client_id, wakeup);
+               delete packet;
+               return false;
+       }
+
+       if (cmd_done->value < 0) {
+               ERR("Client %s got error[%d] from server for sensor[%s] with client_id [%d], wakeup[%d]",
+                       get_client_name(), cmd_done->value, get_sensor_name(m_sensor_id), m_client_id, wakeup);
+
+               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;
index ae1ba6a..c4f85b5 100644 (file)
@@ -41,6 +41,7 @@ public:
        bool cmd_start(void);
        bool cmd_stop(void);
        bool cmd_set_option(int option);
+       bool cmd_set_wakeup(int wakeup);
        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);
index 628726a..af804e1 100644 (file)
@@ -527,6 +527,38 @@ bool csensor_event_listener::get_sensor_state(int handle, int &sensor_state)
        return true;
 }
 
+bool csensor_event_listener::get_sensor_wakeup(int handle, int &sensor_wakeup)
+{
+       AUTOLOCK(m_handle_info_lock);
+
+       auto it_handle = m_sensor_handle_infos.find(handle);
+
+       if (it_handle == m_sensor_handle_infos.end()) {
+               ERR("Handle[%d] is not found for client %s", handle, get_client_name());
+               return false;
+       }
+
+       sensor_wakeup = it_handle->second.m_sensor_wakeup;
+
+       return true;
+}
+
+bool csensor_event_listener::set_sensor_wakeup(int handle, int sensor_wakeup)
+{
+       AUTOLOCK(m_handle_info_lock);
+
+       auto it_handle = m_sensor_handle_infos.find(handle);
+
+       if (it_handle == m_sensor_handle_infos.end()) {
+               ERR("Handle[%d] is not found for client %s", handle, get_client_name());
+               return false;
+       }
+
+       it_handle->second.m_sensor_wakeup = sensor_wakeup;
+
+       return true;
+}
+
 void csensor_event_listener::get_active_event_types(sensor_id_t sensor, event_type_vector &active_event_types)
 {
        event_type_vector event_types;
index 2986273..d65a97d 100644 (file)
@@ -98,6 +98,9 @@ public:
        bool get_sensor_id(int handle, sensor_id_t &sensor_id);
        bool get_sensor_state(int handle, int &state);
 
+       bool get_sensor_wakeup(int handle, int &sensor_wakeup);
+       bool set_sensor_wakeup(int handle, int sensor_wakeup);
+
        void get_sensor_rep(sensor_id_t sensor_id, sensor_rep& rep);
 
        bool has_client_id(void);
index 3aa173f..d6c7194 100644 (file)
@@ -30,6 +30,7 @@ csensor_handle_info::csensor_handle_info()
 , m_sensor_id(UNKNOWN_SENSOR)
 , m_sensor_state(SENSOR_STATE_UNKNOWN)
 , m_sensor_option(SENSOR_OPTION_DEFAULT)
+, m_sensor_wakeup(SENSOR_WAKEUP_OFF)
 , m_bad_accuracy(false)
 , m_accuracy(-1)
 , m_accuracy_cb(NULL)
index 3330dbe..51fb8be 100644 (file)
@@ -34,6 +34,7 @@ public:
        sensor_id_t m_sensor_id;
        int m_sensor_state;
        int m_sensor_option;
+       int m_sensor_wakeup;
        int m_bad_accuracy;
        int m_accuracy;
        sensor_accuracy_changed_cb_t m_accuracy_cb;
index ff107cb..b02ba89 100644 (file)
@@ -197,6 +197,14 @@ bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_typ
 bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported);
 
 /**
+ * @brief Check a wakeup supported or not by this sensor.
+ *
+ * @param[in] sensor a sensor to check a given event type is supporeted.
+ * @return true on success, otherwise false.
+ */
+bool sensord_is_wakeup_supported(sensor_t sensor);
+
+/**
  * @brief Connect a given sensor and get a handle of a given sensor.
  *
  * @param[in] sensor a sensor to connect
@@ -320,6 +328,17 @@ bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type,
 bool sensord_set_option(int handle, int option);
 
 /**
+ * @brief Change the wakeup mode of a connected sensor.
+ *
+ * @param[in] handle a handle represensting a connected sensor.
+ * @param[in] wakeup either one of SENSOR_WAKEUP_OFF and SENSOR_WAKEUP_ON.
+ *                                  with SENSOR_WAKEUP_OFF, it stops to listening events when AP is asleep.
+ *                                  with SENSOR_WAKEUP_ON, it continues to listening events even when AP is asleep.
+ * @return true on success, otherwise false.
+ */
+bool sensord_set_wakeup(int handle, int wakeup);
+
+/**
  * @brief Send data to sensorhub
  *
  * @param[in] handle a handle represensting a connected context sensor.
index e88c897..22c30fe 100644 (file)
@@ -87,6 +87,7 @@ void command_worker::init_cmd_handlers(void)
        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_OPTION]                  = &command_worker::cmd_set_option;
+       m_cmd_handlers[CMD_SET_WAKEUP]                  = &command_worker::cmd_set_wakeup;
        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_SET_COMMAND]                 = &command_worker::cmd_set_command;
@@ -710,6 +711,36 @@ out:
        return true;
 }
 
+bool command_worker::cmd_set_wakeup(void *payload)
+{
+       cmd_set_wakeup_t *cmd;
+       long ret_value = OP_ERROR;
+
+       cmd = (cmd_set_wakeup_t*)payload;
+
+       if (!is_permission_allowed()) {
+               ERR("Permission denied to set wakeup for client [%d], for sensor [0x%x] with wakeup [%d] to client info manager",
+                       m_client_id, m_sensor_id, cmd->wakeup);
+               ret_value = OP_ERROR;
+               goto out;
+       }
+
+       if (!get_client_info_manager().set_wakeup(m_client_id, m_sensor_id, cmd->wakeup)) {
+               ERR("Failed to set wakeup for client [%d], for sensor [0x%x] with wakeup [%d] to client info manager",
+                       m_client_id, m_sensor_id, cmd->wakeup);
+               ret_value = OP_ERROR;
+               goto out;
+       }
+
+       ret_value = m_module->add_wakeup(m_client_id, cmd->wakeup);
+
+out:
+       if (!send_cmd_done(ret_value))
+               ERR("Failed to send cmd_done to a client");
+
+       return true;
+}
+
 bool command_worker::cmd_set_command(void *payload)
 {
        cmd_set_command_t *cmd;
index 89796f5..88000c8 100644 (file)
@@ -72,6 +72,7 @@ private:
        bool cmd_set_batch(void *payload);
        bool cmd_unset_batch(void *payload);
        bool cmd_set_option(void *payload);
+       bool cmd_set_wakeup(void *payload);
        bool cmd_set_command(void *payload);
        bool cmd_get_data(void *payload);
        bool cmd_send_sensorhub_data(void *payload);
index cdc35ee..d869101 100644 (file)
@@ -29,6 +29,7 @@ add_library(sensord-server SHARED
        cclient_info_manager.cpp
        cclient_sensor_record.cpp
        cinterval_info_list.cpp
+       cwakeup_info_list.cpp
        batch_info_list.cpp
        sensor_plugin_loader.cpp
        sensor_hal.cpp
@@ -64,6 +65,7 @@ install(FILES
        cvirtual_sensor_config.h
        csensor_event_queue.h
        cinterval_info_list.h
+       cwakeup_info_list.h
        batch_info_list.h
        sensor_plugin_loader.h
        sensor_hal.h
index 1a142de..4877972 100644 (file)
@@ -135,6 +135,22 @@ bool cclient_info_manager::set_option(int client_id, sensor_id_t sensor_id, int
        return true;
 }
 
+bool cclient_info_manager::set_wakeup(int client_id, sensor_id_t sensor_id, int wakeup)
+{
+       AUTOLOCK(m_mutex);
+
+       auto it_record = m_clients.find(client_id);
+
+       if (it_record == m_clients.end()) {
+               ERR("Client[%d] is not found", client_id);
+               return false;
+       }
+
+       if(!it_record->second.set_wakeup(sensor_id, wakeup))
+               return false;
+
+       return true;
+}
 
 bool cclient_info_manager::set_start(int client_id, sensor_id_t sensor_id, bool start)
 {
index e36c2fb..c6f79e3 100644 (file)
@@ -54,6 +54,7 @@ public:
        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_option(int client_id, sensor_id_t sensor_id, int option);
+       bool set_wakeup(int client_id, sensor_id_t sensor_id, int wakeup);
 
        bool set_start(int client_id, sensor_id_t sensor_id, bool start);
        bool is_started(int client_id, sensor_id_t sensor_id);
index 6995862..d6b1432 100644 (file)
@@ -88,6 +88,20 @@ bool cclient_sensor_record::set_option(sensor_id_t sensor_id, int option)
        return true;
 }
 
+bool cclient_sensor_record::set_wakeup(sensor_id_t sensor_id, int wakeup)
+{
+       auto it_usage = m_sensor_usages.find(sensor_id);
+
+       if (it_usage == m_sensor_usages.end()) {
+               csensor_usage usage;
+               usage.m_wakeup = wakeup;
+               m_sensor_usages.insert(pair<sensor_id_t, csensor_usage>(sensor_id, usage));
+       } else {
+               it_usage->second.m_wakeup = wakeup;
+       }
+
+       return true;
+}
 
 bool cclient_sensor_record::set_start(sensor_id_t sensor_id, bool start)
 {
index d42093e..6ddde9c 100644 (file)
@@ -48,6 +48,7 @@ public:
        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_option(sensor_id_t sensor_id, int option);
+       bool set_wakeup(sensor_id_t sensor_id, int wakeup);
 
        bool set_start(sensor_id_t sensor_id, bool start);
        bool is_started(sensor_id_t sensor_id);
index 345c014..ad9d750 100644 (file)
@@ -25,6 +25,7 @@ csensor_usage::csensor_usage()
 : m_interval(POLL_MAX_HZ_MS)
 , m_latency(0)
 , m_option(SENSOR_OPTION_DEFAULT)
+, m_wakeup(SENSOR_WAKEUP_OFF)
 , m_start(false)
 {
 
index 3c71dcd..553ca51 100644 (file)
@@ -31,6 +31,7 @@ public:
        unsigned int m_interval;
        unsigned int m_latency;
        int m_option;
+       int m_wakeup;
        reg_event_vector m_reg_events;
        bool m_start;
 
diff --git a/src/shared/cwakeup_info_list.cpp b/src/shared/cwakeup_info_list.cpp
new file mode 100644 (file)
index 0000000..c695d4c
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * libsensord-share
+ *
+ * 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 <cwakeup_info_list.h>
+#include <algorithm>
+
+
+cwakeup_info::cwakeup_info(int client_id, int wakeup)
+{
+       this->client_id = client_id;
+       this->wakeup = wakeup;
+}
+
+cwakeup_info_iterator cwakeup_info_list::find_if(int client_id)
+{
+       auto iter = m_list.begin();
+
+       while (iter != m_list.end()) {
+               if (iter->client_id == client_id)
+                       break;
+
+               ++iter;
+       }
+
+       return iter;
+}
+
+
+bool cwakeup_info_list::add_wakeup(int client_id, int wakeup)
+{
+       auto iter = find_if(client_id);
+
+       if (iter != m_list.end())
+               *iter = cwakeup_info(client_id, wakeup);
+       else
+               m_list.push_back(cwakeup_info(client_id, wakeup));
+
+       return true;
+}
+
+bool cwakeup_info_list::delete_wakeup(int client_id)
+{
+       auto iter = find_if(client_id);
+
+       if (iter == m_list.end())
+               return false;
+
+       m_list.erase(iter);
+
+       return true;
+}
+
+int cwakeup_info_list::get_wakeup(int client_id)
+{
+       auto iter = find_if(client_id);
+
+       if (iter == m_list.end())
+               return -1;
+
+       return iter->wakeup;
+}
+
+int cwakeup_info_list::is_wakeup_on(void)
+{
+       if (m_list.empty())
+               return -1;
+
+       auto iter = m_list.begin();
+
+       while (iter != m_list.end()) {
+               if (iter->wakeup == true)
+                       break;
+
+               ++iter;
+       }
+
+       return iter->wakeup;
+}
+
diff --git a/src/shared/cwakeup_info_list.h b/src/shared/cwakeup_info_list.h
new file mode 100644 (file)
index 0000000..f11e7e8
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * libsensord-share
+ *
+ * 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 _CWAKEUP_INFO_LIST_CLASS_H_
+#define _CWAKEUP_INFO_LIST_CLASS_H_
+
+#include <list>
+
+class cwakeup_info
+{
+public:
+       cwakeup_info(int client_id, int wakeup);
+       int client_id;
+       int wakeup;
+};
+
+typedef std::list<cwakeup_info>::iterator cwakeup_info_iterator;
+
+class cwakeup_info_list
+{
+private:
+       cwakeup_info_iterator find_if(int client_id);
+
+       std::list<cwakeup_info> m_list;
+
+public:
+       bool add_wakeup(int client_id, int wakeup);
+       bool delete_wakeup(int client_id);
+       int get_wakeup(int client_id);
+       int is_wakeup_on(void);
+};
+#endif
old mode 100755 (executable)
new mode 100644 (file)
index 056e065..52915e7
@@ -264,9 +264,61 @@ unsigned int sensor_base::get_interval(int client_id, bool is_processor)
        return m_interval_info_list.get_interval(client_id, is_processor);
 }
 
+bool sensor_base::add_wakeup(int client_id, int wakeup)
+{
+       int prev_wakeup, cur_wakeup;
+
+       AUTOLOCK(m_wakeup_info_list_mutex);
+
+       prev_wakeup = m_wakeup_info_list.is_wakeup_on();
+
+       if (!m_wakeup_info_list.add_wakeup(client_id, wakeup))
+               return false;
+
+       cur_wakeup = m_wakeup_info_list.is_wakeup_on();
+
+       if ((cur_wakeup == SENSOR_WAKEUP_ON) && (prev_wakeup < SENSOR_WAKEUP_ON)) {
+               INFO("Wakeup for sensor[0x%x] is changed from %d to %d by client[%d] adding wakeup",
+                       get_id(), prev_wakeup, cur_wakeup, client_id);
+               set_wakeup(client_id, SENSOR_WAKEUP_ON);
+       }
+
+       return true;
+}
+
+bool sensor_base::delete_wakeup(int client_id)
+{
+       int prev_wakeup, cur_wakeup;
+       AUTOLOCK(m_wakeup_info_list_mutex);
+
+       prev_wakeup = m_wakeup_info_list.is_wakeup_on();
+
+       if (!m_wakeup_info_list.delete_wakeup(client_id))
+               return false;
+
+       cur_wakeup = m_wakeup_info_list.is_wakeup_on();
+
+       if ((cur_wakeup < SENSOR_WAKEUP_ON) && (prev_wakeup == SENSOR_WAKEUP_ON)) {
+               INFO("Wakeup for sensor[0x%x] is changed from %d to %d by client[%d] deleting wakeup",
+                       get_id(), prev_wakeup, cur_wakeup, client_id);
+               set_wakeup(client_id, SENSOR_WAKEUP_OFF);
+       }
+
+       return true;
+}
+
+int sensor_base::get_wakeup(int client_id)
+{
+       AUTOLOCK(m_wakeup_info_list_mutex);
+
+       return m_wakeup_info_list.is_wakeup_on();
+}
+
 void sensor_base::get_sensor_info(sensor_type_t sensor_type, sensor_info &info)
 {
        sensor_properties_s properties;
+       properties.wakeup_supported = false;
+
        get_properties(sensor_type, properties);
 
        info.set_type(sensor_type);
@@ -289,6 +341,7 @@ void sensor_base::get_sensor_info(sensor_type_t sensor_type, sensor_info &info)
        }
 
        info.set_supported_events(events);
+       info.set_wakeup_supported(properties.wakeup_supported);
 
        return;
 }
@@ -308,11 +361,21 @@ bool sensor_base::is_supported(unsigned int event_type)
        return true;
 }
 
+bool sensor_base::is_wakeup_supported(void)
+{
+       return false;
+}
+
 long sensor_base::set_command(unsigned int cmd, long value)
 {
        return -1;
 }
 
+bool sensor_base::set_wakeup(int client_id, int wakeup)
+{
+       return false;
+}
+
 int sensor_base::send_sensorhub_data(const char* data, int data_len)
 {
        return -1;
old mode 100755 (executable)
new mode 100644 (file)
index 353cee2..c4c4600
@@ -29,6 +29,7 @@
 #include <string>
 
 #include <cinterval_info_list.h>
+#include <cwakeup_info_list.h>
 #include <cmutex.h>
 
 #include <common.h>
@@ -66,12 +67,18 @@ public:
        virtual bool delete_interval(int client_id, bool is_processor);
        unsigned int get_interval(int client_id, bool is_processor);
 
+       virtual bool add_wakeup(int client_id, int wakeup);
+       virtual bool delete_wakeup(int client_id);
+       int get_wakeup(int client_id);
+
        void get_sensor_info(sensor_type_t sensor_type, sensor_info &info);
        virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties);
 
        bool is_supported(unsigned int event_type);
+       bool is_wakeup_supported(void);
 
        virtual long set_command(unsigned int cmd, long value);
+       virtual bool set_wakeup(int client_id, int wakeup);
        virtual int send_sensorhub_data(const char* data, int data_len);
 
        virtual int get_sensor_data(unsigned int type, sensor_data_t &data);
@@ -88,7 +95,9 @@ protected:
        int m_permission;
 
        cinterval_info_list m_interval_info_list;
+       cwakeup_info_list m_wakeup_info_list;
        cmutex m_interval_info_list_mutex;
+       cmutex m_wakeup_info_list_mutex;
 
        cmutex m_mutex;
 
index b70c4ef..16dfd26 100644 (file)
@@ -165,6 +165,19 @@ enum sensor_option_t {
 typedef enum sensor_option_t sensor_option_e;
 #endif
 
+/*
+ *     To prevent naming confliction as using same enums as sensor CAPI use
+ */
+#ifndef __SENSOR_H__
+enum sensor_wakeup_t {
+       SENSOR_WAKEUP_UNKNOWN = -1,
+       SENSOR_WAKEUP_OFF = 0,
+       SENSOR_WAKEUP_ON = 1,
+};
+
+typedef enum sensor_wakeup_t sensor_wakeup_e;
+#endif
+
 enum sensor_interval_t {
        SENSOR_INTERVAL_FASTEST = 0,
        SENSOR_INTERVAL_NORMAL = 200,
old mode 100755 (executable)
new mode 100644 (file)
index f5a315d..dc4fcfb
@@ -43,6 +43,11 @@ bool sensor_hal::init(void *data)
        return true;
 }
 
+bool sensor_hal::is_wakeup_supported(void)
+{
+       return false;
+}
+
 bool sensor_hal::set_interval(unsigned long val)
 {
        return true;
@@ -53,6 +58,11 @@ long sensor_hal::set_command(unsigned int cmd, long val)
        return -1;
 }
 
+bool sensor_hal::set_wakeup(int wakeup)
+{
+       return false;
+}
+
 int sensor_hal::send_sensorhub_data(const char* data, int data_len)
 {
        return -1;
old mode 100755 (executable)
new mode 100644 (file)
index 09762a4..c1afba5
@@ -104,11 +104,13 @@ public:
        virtual bool disable(void) = 0;
        virtual bool set_interval(unsigned long val);
        virtual bool is_data_ready(bool wait) = 0;
+       virtual bool is_wakeup_supported(void);
        virtual bool get_properties(sensor_properties_s &properties) {return false;};
        virtual bool get_properties(sensor_type_t sensor_type, sensor_properties_s &properties) {return false;};
        virtual int get_sensor_data(sensor_data_t &data);
        virtual int get_sensor_data(sensorhub_data_t &data);
        virtual long set_command(unsigned int cmd, long val);
+       virtual bool set_wakeup(int wakeup);
        virtual int send_sensorhub_data(const char *data, int data_len);
 
 protected:
old mode 100755 (executable)
new mode 100644 (file)
index bed247e..c80c736
@@ -96,6 +96,11 @@ bool sensor_info::is_supported_event(unsigned int event)
        return true;
 }
 
+bool sensor_info::is_wakeup_supported(void)
+{
+       return m_wakeup_supported;
+}
+
 void sensor_info::set_type(sensor_type_t type)
 {
        m_type = type;
@@ -161,6 +166,11 @@ void sensor_info::set_supported_events(vector<unsigned int> &events)
        copy(events.begin(), events.end(), back_inserter(m_supported_events));
 }
 
+void sensor_info::set_wakeup_supported(bool supported)
+{
+       m_wakeup_supported = supported;
+}
+
 void sensor_info::get_raw_data(raw_data_t &data)
 {
        put(data, (int)m_type);
@@ -175,6 +185,7 @@ void sensor_info::get_raw_data(raw_data_t &data)
        put(data, m_fifo_count);
        put(data, m_max_batch_count);
        put(data, m_supported_events);
+       put(data, m_wakeup_supported);
 }
 
 void sensor_info::set_raw_data(const char *data, int data_len)
@@ -200,6 +211,7 @@ void sensor_info::set_raw_data(const char *data, int data_len)
        it_r_data = get(it_r_data, m_fifo_count);
        it_r_data = get(it_r_data, m_max_batch_count);
        it_r_data = get(it_r_data, m_supported_events);
+       it_r_data = get(it_r_data, m_wakeup_supported);
 }
 
 void sensor_info::show(void)
@@ -218,6 +230,8 @@ void sensor_info::show(void)
 
        for (unsigned int i = 0; i < m_supported_events.size(); ++i)
                INFO("supported_events[%u] = 0x%x", i, m_supported_events[i]);
+
+       INFO("Wakeup_supported = %d", m_wakeup_supported);
 }
 
 
@@ -235,6 +249,7 @@ void sensor_info::clear(void)
        m_fifo_count = 0;
        m_max_batch_count = 0;
        m_supported_events.clear();
+       m_wakeup_supported = false;
 }
 
 
@@ -277,6 +292,16 @@ void sensor_info::put(raw_data_t &data, vector<unsigned int> &value)
        }
 }
 
+void sensor_info::put(raw_data_t &data, bool value)
+{
+       char buffer[sizeof(value)];
+
+       bool *temp = (bool *) buffer;
+       *temp = value;
+
+       copy(&buffer[0], &buffer[sizeof(buffer)], back_inserter(data));
+}
+
 raw_data_iterator sensor_info::get(raw_data_iterator it, int &value)
 {
        copy(it, it + sizeof(value), (char*) &value);
@@ -316,3 +341,10 @@ raw_data_iterator sensor_info::get(raw_data_iterator it, vector<unsigned int> &v
 
        return it;
 }
+
+raw_data_iterator sensor_info::get(raw_data_iterator it, bool &value)
+{
+       copy(it, it + sizeof(value), (char*) &value);
+
+       return it + sizeof(value);
+}
old mode 100755 (executable)
new mode 100644 (file)
index 185d249..53c57da
@@ -44,6 +44,7 @@ public:
        int get_max_batch_count(void);
        void get_supported_events(std::vector<unsigned int> &events);
        bool is_supported_event(unsigned int event);
+       bool is_wakeup_supported(void);
 
        void set_type(sensor_type_t type);
        void set_id(sensor_id_t id);
@@ -58,6 +59,7 @@ public:
        void set_max_batch_count(int max_batch_count);
        void register_supported_event(unsigned int event);
        void set_supported_events(std::vector<unsigned int> &events);
+       void set_wakeup_supported(bool supported);
 
        void clear(void);
 
@@ -77,16 +79,19 @@ private:
        int m_fifo_count;
        int m_max_batch_count;
        std::vector<unsigned int> m_supported_events;
+       bool m_wakeup_supported;
 
        void put(raw_data_t &data, int value);
        void put(raw_data_t &data, float value);
        void put(raw_data_t &data, std::string &value);
        void put(raw_data_t &data, std::vector<unsigned int> &value);
+       void put(raw_data_t &data, bool value);
 
        raw_data_iterator get(raw_data_iterator it, int &value);
        raw_data_iterator get(raw_data_iterator it, float &value);
        raw_data_iterator get(raw_data_iterator it, std::string &value);
        raw_data_iterator get(raw_data_iterator it, std::vector<unsigned int> &value);
+       raw_data_iterator get(raw_data_iterator it, bool &value);
 };
 
 #endif /* _SENSOR_INFO_H_ */
index 777421b..8c802de 100644 (file)
@@ -50,6 +50,7 @@ enum packet_type_t {
        CMD_REG,
        CMD_UNREG,
        CMD_SET_OPTION,
+       CMD_SET_WAKEUP,
        CMD_SET_BATCH,
        CMD_UNSET_BATCH,
        CMD_SET_COMMAND,
@@ -141,6 +142,10 @@ typedef struct {
        int option;
 } cmd_set_option_t;
 
+typedef struct {
+       int wakeup;
+} cmd_set_wakeup_t;
+
 typedef struct  {
        unsigned int cmd;
        long value;
@@ -168,6 +173,7 @@ typedef struct {
        int min_interval;
        int fifo_count;
        int max_batch_count;
+       bool wakeup_supported;
 } sensor_properties_s;