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-provider-channel-handler.h"
22 #include <command-types.h>
23 #include <sensor-log-private.h>
24 #include "sensor-provider.h"
26 using namespace sensor;
28 sensor_provider::channel_handler::channel_handler(sensor_provider *provider)
29 : m_provider(provider)
32 , m_interval_changed_cb(NULL)
33 , m_attribute_str_cb(NULL)
34 , m_start_user_data(NULL)
35 , m_stop_user_data(NULL)
36 , m_interval_changed_user_data(NULL)
37 , m_attribute_str_user_data(NULL)
41 void sensor_provider::channel_handler::connected(ipc::channel *ch)
46 void sensor_provider::channel_handler::disconnected(ipc::channel *ch)
49 /* m_provider->restore(); */
52 void sensor_provider::channel_handler::read(ipc::channel *ch, ipc::message &msg)
55 case CMD_PROVIDER_START:
57 m_start_cb(m_provider, m_start_user_data);
59 case CMD_PROVIDER_STOP:
61 m_stop_cb(m_provider, m_stop_user_data);
63 case CMD_PROVIDER_ATTR_INT:
64 cmd_provider_attr_int_t buf;
65 msg.disclose((char *)&buf, sizeof(buf));
67 if (buf.attribute == SENSORD_ATTRIBUTE_INTERVAL && m_interval_changed_cb)
68 m_interval_changed_cb(m_provider, buf.value, m_interval_changed_user_data);
70 case CMD_PROVIDER_ATTR_STR:
71 cmd_provider_attr_str_t *attr;
73 attr = (cmd_provider_attr_str_t *) new(std::nothrow) char[msg.size()];
74 retm_if(!attr, "Failed to allocate memory");
76 msg.disclose((char *)attr, msg.size());
78 if (m_attribute_str_cb)
79 m_attribute_str_cb(m_provider, attr->attribute, attr->value, attr->len, m_attribute_str_user_data);
86 void sensor_provider::channel_handler::read_complete(ipc::channel *ch)
90 void sensor_provider::channel_handler::error_caught(ipc::channel *ch, int error)
94 void sensor_provider::channel_handler::set_start_cb(sensord_provider_start_cb cb, void *user_data)
97 m_start_user_data = user_data;
100 void sensor_provider::channel_handler::set_stop_cb(sensord_provider_stop_cb cb, void *user_data)
103 m_stop_user_data = user_data;
106 void sensor_provider::channel_handler::set_interval_cb(sensord_provider_interval_changed_cb cb, void *user_data)
108 m_interval_changed_cb = cb;
109 m_interval_changed_user_data = user_data;
112 void sensor_provider::channel_handler::set_attribute_str_cb(sensord_provider_attribute_str_cb cb, void *user_data)
114 m_attribute_str_cb = cb;
115 m_attribute_str_user_data = user_data;