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 "application_sensor_handler.h"
23 #include <command_types.h>
24 #include <sensor_log.h>
27 using namespace sensor;
29 application_sensor_handler::application_sensor_handler(const sensor_info &info, ipc::channel *ch)
30 : sensor_handler(info)
37 application_sensor_handler::~application_sensor_handler()
41 int application_sensor_handler::publish(sensor_data_t *data, int len)
43 std::string uri = m_info.get_uri();
44 return notify(uri.c_str(), data, len);
47 const sensor_info &application_sensor_handler::get_sensor_info(void)
52 int application_sensor_handler::start(sensor_observer *ob)
56 if (observer_count() > 1 || m_started.load())
57 return OP_SUCCESS; /* already started */
60 msg.set_type(CMD_PROVIDER_START);
61 m_ch->send_sync(&msg);
62 m_started.store(true);
64 _I("Started[%s]", m_info.get_uri().c_str());
69 int application_sensor_handler::stop(sensor_observer *ob)
73 if (observer_count() > 0 || !m_started.load())
74 return OP_SUCCESS; /* already started */
77 msg.set_type(CMD_PROVIDER_STOP);
78 m_ch->send_sync(&msg);
79 m_started.store(false);
81 _I("Stopped[%s]", m_info.get_uri().c_str());
86 int application_sensor_handler::get_min_interval(void)
89 std::vector<int> temp;
91 for (auto it = m_interval_map.begin(); it != m_interval_map.end(); ++it)
93 temp.push_back(it->second);
96 return m_info.get_min_interval();
98 interval = *std::min_element(temp.begin(), temp.end());
100 if (interval < m_info.get_min_interval())
101 return m_info.get_min_interval();
106 int application_sensor_handler::set_interval(sensor_observer *ob, int32_t interval)
108 retv_if(interval == m_prev_interval, OP_SUCCESS);
110 int32_t cur_interval = interval;
112 m_interval_map[ob] = cur_interval;
113 cur_interval = get_min_interval();
116 cmd_provider_attr_int_t buf;
117 buf.attribute = SENSORD_ATTRIBUTE_INTERVAL;
118 buf.value = cur_interval;
120 msg.set_type(CMD_PROVIDER_ATTR_INT);
121 msg.enclose((const char *)&buf, sizeof(cmd_provider_attr_int_t));
122 m_ch->send_sync(&msg);
124 m_prev_interval = cur_interval;
126 _I("Set interval[%d] to sensor[%s]", cur_interval, m_info.get_uri().c_str());
131 int application_sensor_handler::set_batch_latency(sensor_observer *ob, int32_t latency)
136 int application_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, int32_t value)
141 int application_sensor_handler::set_attribute(sensor_observer *ob, int32_t attr, const char *value, int len)
146 int application_sensor_handler::flush(sensor_observer *ob)
151 int application_sensor_handler::get_data(sensor_data_t **data, int *len)