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 #include "sensor_handler.h"
30 using namespace sensor;
32 sensor_listener_proxy::sensor_listener_proxy(uint32_t id,
33 std::string uri, sensor_manager *manager, ipc::channel *ch)
39 , m_pause_policy(SENSORD_PAUSE_ALL)
40 , m_axis_orientation(SENSORD_AXIS_DISPLAY_ORIENTED)
44 sensor_listener_proxy::~sensor_listener_proxy()
49 uint32_t sensor_listener_proxy::get_id(void)
54 int sensor_listener_proxy::update(const char *uri, ipc::message *msg)
56 retv_if(!m_ch || !m_ch->is_connected(), OP_CONTINUE);
58 /* TODO: check axis orientation */
59 msg->header()->type = CMD_LISTENER_EVENT;
60 msg->header()->err = OP_SUCCESS;
67 int sensor_listener_proxy::start(void)
69 sensor_handler *sensor = m_manager->get_sensor(m_uri);
70 retv_if(!sensor, -EINVAL);
72 /* TODO: listen pause policy */
73 return sensor->start(this);
76 int sensor_listener_proxy::stop(void)
78 sensor_handler *sensor = m_manager->get_sensor(m_uri);
79 retv_if(!sensor, -EINVAL);
81 /* TODO: listen pause policy */
84 ret = sensor->stop(this);
85 retv_if(ret < 0, OP_ERROR);
87 /* unset attributes */
88 set_interval(POLL_1HZ_MS);
89 set_max_batch_latency(0);
94 int sensor_listener_proxy::set_interval(unsigned int interval)
96 sensor_handler *sensor = m_manager->get_sensor(m_uri);
97 retv_if(!sensor, -EINVAL);
99 return sensor->set_interval(this, interval);
102 int sensor_listener_proxy::set_max_batch_latency(unsigned int max_batch_latency)
104 sensor_handler *sensor = m_manager->get_sensor(m_uri);
105 retv_if(!sensor, -EINVAL);
107 return sensor->set_batch_latency(this, max_batch_latency);
110 int sensor_listener_proxy::set_passive_mode(bool passive)
112 /* TODO: passive mode */
117 int sensor_listener_proxy::set_attribute(int attribute, int value)
119 sensor_handler *sensor = m_manager->get_sensor(m_uri);
120 retv_if(!sensor, -EINVAL);
122 if (attribute == SENSORD_ATTRIBUTE_PAUSE_POLICY) {
123 m_pause_policy = value;
125 } else if (attribute == SENSORD_ATTRIBUTE_AXIS_ORIENTATION) {
126 m_axis_orientation = value;
130 return sensor->set_attribute(this, attribute, value);
133 int sensor_listener_proxy::set_attribute(int attribute, const char *value, int len)
135 sensor_handler *sensor = m_manager->get_sensor(m_uri);
136 retv_if(!sensor, -EINVAL);
138 return sensor->set_attribute(this, attribute, value, len);
141 int sensor_listener_proxy::flush(void)
143 sensor_handler *sensor = m_manager->get_sensor(m_uri);
144 retv_if(!sensor, -EINVAL);
146 return sensor->flush(this);
149 int sensor_listener_proxy::get_data(sensor_data_t **data, int *len)
151 sensor_handler *sensor = m_manager->get_sensor(m_uri);
152 retv_if(!sensor, -EINVAL);
154 /* TODO : caching the last data & retry logic if there is no data */
155 return sensor->get_data(data, len);
158 std::string sensor_listener_proxy::get_required_privileges(void)
160 sensor_handler *sensor = m_manager->get_sensor(m_uri);
161 retv_if(!sensor, "");
163 sensor_info info = sensor->get_sensor_info();
164 return info.get_privilege();