}
-API bool sensord_set_wakeup(int handle, int wakeup)
-{
- sensor_id_t sensor_id;
- command_channel *cmd_channel;
- int client_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;
- }
-
- 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());
-
- sensor_client_info::get_instance().set_sensor_wakeup(handle, wakeup);
-
- 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 (!cmd_channel->cmd_set_wakeup(wakeup)) {
- _E("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_set_attribute_int(int handle, int attribute, int value)
{
sensor_id_t sensor_id;
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;
-
- _I("%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)) {
- _E("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) {
- _E("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;
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);
return true;
}
-bool sensor_client_info::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()) {
- _E("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 sensor_client_info::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()) {
- _E("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 sensor_client_info::get_active_event_types(sensor_id_t sensor, event_type_vector &active_event_types)
{
event_type_vector event_types;
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);
bool has_client_id(void);
int get_client_id(void);
, 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)
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;
*/
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 Set the attribute to a connected sensor
*
* @param[in] handle a handle represensting a connected sensor.
return true;
}
-bool client_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()) {
- _E("Client[%d] is not found", client_id);
- return false;
- }
-
- if(!it_record->second.set_wakeup(sensor_id, wakeup))
- return false;
-
- return true;
-}
bool client_info_manager::set_start(int client_id, sensor_id_t sensor_id, bool start)
{
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);
return true;
}
-bool client_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()) {
- sensor_usage usage;
- usage.m_wakeup = wakeup;
- m_sensor_usages.insert(pair<sensor_id_t, sensor_usage>(sensor_id, usage));
- } else {
- it_usage->second.m_wakeup = wakeup;
- }
-
- return true;
-}
bool client_sensor_record::set_start(sensor_id_t sensor_id, bool start)
{
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);
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_GET_DATA] = &command_worker::cmd_get_data;
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()) {
- _E("Permission denied to set wakeup for client [%d], for sensor [0x%llx] 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)) {
- _E("Failed to set wakeup for client [%d], for sensor [0x%llx] 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))
- _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;
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_get_data(void *payload);
bool cmd_set_attribute_int(void *payload);
bool cmd_set_attribute_str(void *payload);
return OP_SUCCESS;
}
-bool physical_sensor::set_wakeup(int wakeup)
-{
- return false;
-}
-
bool physical_sensor::on_start()
{
AUTOLOCK(m_mutex);
virtual bool set_batch_latency(unsigned long latency);
virtual int set_attribute(int32_t attribute, int32_t value);
virtual int set_attribute(int32_t attribute, char *value, int value_len);
- virtual bool set_wakeup(int wakeup);
virtual bool on_start(void);
virtual bool on_stop(void);
virtual bool get_sensor_info(sensor_info &info);
return m_sensor_info_list.get_batch(client_id);
}
-bool sensor_base::add_wakeup(int client_id, int wakeup)
-{
- int prev_wakeup, cur_wakeup;
-
- AUTOLOCK(m_sensor_info_list_mutex);
-
- prev_wakeup = m_sensor_info_list.is_wakeup_on();
-
- if (!m_sensor_info_list.add_wakeup(client_id, wakeup))
- return false;
-
- cur_wakeup = m_sensor_info_list.is_wakeup_on();
-
- if ((cur_wakeup == SENSOR_WAKEUP_ON) && (prev_wakeup < SENSOR_WAKEUP_ON)) {
- _I("Wakeup for sensor[0x%llx] is changed from %d to %d by client[%d] adding wakeup",
- get_id(), prev_wakeup, cur_wakeup, client_id);
- set_wakeup(SENSOR_WAKEUP_ON);
- }
-
- return true;
-}
-
-bool sensor_base::delete_wakeup(int client_id)
-{
- int prev_wakeup, cur_wakeup;
- AUTOLOCK(m_sensor_info_list_mutex);
-
- prev_wakeup = m_sensor_info_list.is_wakeup_on();
-
- if (!m_sensor_info_list.delete_wakeup(client_id))
- return false;
-
- cur_wakeup = m_sensor_info_list.is_wakeup_on();
-
- if ((cur_wakeup < SENSOR_WAKEUP_ON) && (prev_wakeup == SENSOR_WAKEUP_ON)) {
- _I("Wakeup for sensor[0x%llx] is changed from %d to %d by client[%d] deleting wakeup",
- get_id(), prev_wakeup, cur_wakeup, client_id);
- set_wakeup(SENSOR_WAKEUP_OFF);
- }
-
- return true;
-}
-
-int sensor_base::get_wakeup(int client_id)
-{
- AUTOLOCK(m_sensor_info_list_mutex);
-
- return m_sensor_info_list.is_wakeup_on();
-}
-
-bool sensor_base::is_wakeup_supported(void)
-{
- return false;
-}
-
int sensor_base::get_permission(void)
{
return m_permission;
return false;
}
-bool sensor_base::set_wakeup(int wakeup)
-{
- return false;
-}
-
bool sensor_base::on_start()
{
return false;
bool stop(void);
bool is_started(void);
- /* interval / batch / wakeup */
+ /* 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 delete_batch(int client_id);
unsigned int get_batch(int client_id);
- virtual bool add_wakeup(int client_id, int wakeup);
- virtual bool delete_wakeup(int client_id);
- int get_wakeup(int client_id);
- bool is_wakeup_supported(void);
-
bool push(sensor_event_t *event);
/* permission(privilege) */
virtual bool set_interval(unsigned long interval);
virtual bool set_batch_latency(unsigned long latency);
- virtual bool set_wakeup(int wakeup);
virtual bool on_start(void);
virtual bool on_stop(void);
this->latency = latency;
}
-wakeup_info::wakeup_info(int client_id, int wakeup)
-{
- this->client_id = client_id;
- this->wakeup = wakeup;
-}
-
bool sensor_info_list::comp_interval_info(interval_info a, interval_info b)
{
return a.interval < b.interval;
return iter;
}
-wakeup_info_iterator sensor_info_list::find_if_wakeup_info(int client_id)
-{
- auto iter = m_wakeup_info_list.begin();
-
- while (iter != m_wakeup_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);
return iter->latency;
}
-bool sensor_info_list::add_wakeup(int client_id, int wakeup)
-{
- auto iter = find_if_wakeup_info(client_id);
-
- if (iter != m_wakeup_info_list.end())
- *iter = wakeup_info(client_id, wakeup);
- else
- m_wakeup_info_list.push_back(wakeup_info(client_id, wakeup));
-
- return true;
-}
-
-bool sensor_info_list::delete_wakeup(int client_id)
-{
- auto iter = find_if_wakeup_info(client_id);
-
- if (iter == m_wakeup_info_list.end())
- return false;
-
- m_wakeup_info_list.erase(iter);
-
- return true;
-}
-
-int sensor_info_list::get_wakeup(int client_id)
-{
- auto iter = find_if_wakeup_info(client_id);
-
- if (iter == m_wakeup_info_list.end())
- return -1;
-
- return iter->wakeup;
-}
-
-int sensor_info_list::is_wakeup_on(void)
-{
- if (m_wakeup_info_list.empty())
- return -1;
-
- auto iter = m_wakeup_info_list.begin();
-
- while (iter != m_wakeup_info_list.end()) {
- if (iter->wakeup == true)
- break;
-
- ++iter;
- }
-
- return iter->wakeup;
-}
-
typedef std::list<batch_info>::iterator batch_info_iterator;
-class wakeup_info {
-public:
- wakeup_info(int client_id, int wakeup);
- int client_id;
- int wakeup;
-};
-
-typedef std::list<wakeup_info>::iterator wakeup_info_iterator;
-
class sensor_info_list {
public:
bool add_interval(int client_id, unsigned int interval, bool is_processor);
unsigned int get_batch(int client_id);
unsigned int get_max_batch(void);
- 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);
-
private:
static bool comp_interval_info(interval_info a, interval_info b);
interval_info_iterator find_if_interval_info(int client_id, bool is_processor);
static bool comp_batch_info(batch_info a, batch_info b);
batch_info_iterator find_if_batch_info(int client_id);
- wakeup_info_iterator find_if_wakeup_info(int client_id);
-
std::list<interval_info> m_interval_info_list;
std::list<batch_info> m_batch_info_list;
- std::list<wakeup_info> m_wakeup_info_list;
};
#endif /* _SENSOR_INFO_LIST_H_ */
: m_interval(POLL_MAX_HZ_MS)
, m_latency(0)
, m_option(SENSOR_OPTION_DEFAULT)
-, m_wakeup(SENSOR_WAKEUP_OFF)
, m_start(false)
{
unsigned int m_interval;
unsigned int m_latency;
int m_option;
- int m_wakeup;
reg_event_vector m_reg_events;
bool m_start;
private:
virtual bool set_interval(unsigned long interval) = 0;
virtual bool set_batch_latency(unsigned long latency) = 0;
- virtual bool set_wakeup(int wakeup) = 0;
-
virtual bool on_start(void) = 0;
virtual bool on_stop(void) = 0;
};
CMD_REG,
CMD_UNREG,
CMD_SET_OPTION,
- CMD_SET_WAKEUP,
CMD_SET_BATCH,
CMD_UNSET_BATCH,
CMD_GET_DATA,
int option;
} cmd_set_option_t;
-typedef struct {
- int wakeup;
-} cmd_set_wakeup_t;
typedef struct {
int attribute;
typedef enum sensor_option_t sensor_option_e;
#endif
-enum sensor_wakeup_t {
- SENSOR_WAKEUP_UNKNOWN = -1,
- SENSOR_WAKEUP_OFF = 0,
- SENSOR_WAKEUP_ON = 1,
-};
-
enum poll_interval_t {
POLL_100HZ_MS = 10,
POLL_50HZ_MS = 20,