Merge "sensord: change unclear classes to inner class" into devel/tizen
[platform/core/system/sensord.git] / src / client / sensor_provider_channel_handler.cpp
1 /*
2  * sensord
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include "sensor_provider_channel_handler.h"
21
22 #include <command_types.h>
23 #include <sensor_log.h>
24 #include "sensor_provider.h"
25
26 using namespace sensor;
27
28 sensor_provider::channel_handler::channel_handler(sensor_provider *provider)
29 : m_provider(provider)
30 , m_start_cb(NULL)
31 , m_stop_cb(NULL)
32 , m_set_interval_cb(NULL)
33 , m_start_user_data(NULL)
34 , m_stop_user_data(NULL)
35 , m_set_interval_user_data(NULL)
36 {
37 }
38
39 void sensor_provider::channel_handler::connected(ipc::channel *ch)
40 {
41         _I("Connected");
42 }
43
44 void sensor_provider::channel_handler::disconnected(ipc::channel *ch)
45 {
46         /* TODO */
47         /* m_provider->restore(); */
48 }
49
50 void sensor_provider::channel_handler::read(ipc::channel *ch, ipc::message &msg)
51 {
52         switch (msg.type()) {
53         case CMD_PROVIDER_START:
54                 m_start_cb(m_provider, m_start_user_data);
55                 break;
56         case CMD_PROVIDER_STOP:
57                 m_stop_cb(m_provider, m_stop_user_data);
58                 break;
59         case CMD_PROVIDER_ATTR_INT:
60                 cmd_provider_attr_int_t buf;
61                 msg.disclose((char *)&buf);
62
63                 if (buf.attribute == SENSORD_ATTRIBUTE_INTERVAL)
64                         m_set_interval_cb(m_provider, buf.value, m_set_interval_user_data);
65                 break;
66         }
67 }
68
69 void sensor_provider::channel_handler::read_complete(ipc::channel *ch)
70 {
71 }
72
73 void sensor_provider::channel_handler::error_caught(ipc::channel *ch, int error)
74 {
75 }
76
77 void sensor_provider::channel_handler::set_start_cb(sensord_provider_start_cb cb, void *user_data)
78 {
79         m_start_cb = cb;
80         m_start_user_data = user_data;
81 }
82
83 void sensor_provider::channel_handler::set_stop_cb(sensord_provider_stop_cb cb, void *user_data)
84 {
85         m_stop_cb = cb;
86         m_stop_user_data = user_data;
87 }
88
89 void sensor_provider::channel_handler::set_interval_cb(sensord_provider_set_interval_cb cb, void *user_data)
90 {
91         m_set_interval_cb = cb;
92         m_set_interval_user_data = user_data;
93 }