4 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "sensor_listener_proxy.h"
24 #include <command_types.h>
25 #include <sensor_log.h>
26 #include <sensor_types.h>
28 using namespace sensor;
30 sensor_listener_proxy::sensor_listener_proxy(
31 uint32_t id, sensor_handler *sensor, ipc::channel *ch)
36 , m_pause_policy(SENSORD_PAUSE_ALL)
37 , m_axis_orientation(SENSORD_AXIS_DISPLAY_ORIENTED)
41 sensor_listener_proxy::~sensor_listener_proxy()
46 uint32_t sensor_listener_proxy::get_id(void)
51 int sensor_listener_proxy::update(const char *uri, ipc::message *msg)
53 retv_if(!m_ch || !m_ch->is_connected(), OP_CONTINUE);
55 /* TODO: check axis orientation */
56 msg->header()->type = CMD_LISTENER_EVENT;
57 msg->header()->err = OP_SUCCESS;
64 int sensor_listener_proxy::start(void)
66 /* TODO: listen pause policy */
67 return m_sensor->start(this);
70 int sensor_listener_proxy::stop(void)
72 /* TODO: listen pause policy */
75 ret = m_sensor->stop(this);
76 retv_if(ret < 0, OP_ERROR);
78 /* unset attributes */
79 set_interval(POLL_1HZ_MS);
80 set_max_batch_latency(0);
85 int sensor_listener_proxy::set_interval(unsigned int interval)
87 return m_sensor->set_interval(this, interval);
90 int sensor_listener_proxy::set_max_batch_latency(unsigned int max_batch_latency)
92 return m_sensor->set_batch_latency(this, max_batch_latency);
95 int sensor_listener_proxy::set_passive_mode(bool passive)
97 /* TODO: passive mode */
102 int sensor_listener_proxy::set_attribute(int attribute, int value)
104 if (attribute == SENSORD_ATTRIBUTE_PAUSE_POLICY) {
105 m_pause_policy = value;
107 } else if (attribute == SENSORD_ATTRIBUTE_AXIS_ORIENTATION) {
108 m_axis_orientation = value;
112 return m_sensor->set_attribute(this, attribute, value);
115 int sensor_listener_proxy::set_attribute(int attribute, const char *value, int len)
117 return m_sensor->set_attribute(this, attribute, value, len);
120 int sensor_listener_proxy::flush(void)
122 return m_sensor->flush(this);
125 int sensor_listener_proxy::get_data(sensor_data_t **data, int *len)
127 /* TODO : caching the last data & retry logic if there is no data */
128 return m_sensor->get_data(data, len);
131 std::string sensor_listener_proxy::get_required_privileges(void)
133 sensor_info info = m_sensor->get_sensor_info();
134 return info.get_privilege();