fcb1735f3f7589d71a80e43735111324a1764b6c
[platform/core/system/sensord.git] / src / server / server_channel_handler.h
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 #ifndef __SERVER_CHANNEL_HANDLER_H__
21 #define __SERVER_CHANNEL_HANDLER_H__
22
23 #include <channel.h>
24 #include <channel_handler.h>
25 #include <unordered_map>
26 #include <functional>
27
28 #include "sensor_manager.h"
29 #include "sensor_listener_proxy.h"
30 #include "application_sensor_handler.h"
31
32 namespace sensor {
33
34 class server_channel_handler : public ipc::channel_handler
35 {
36 public:
37         server_channel_handler(sensor_manager *manager);
38         ~server_channel_handler();
39
40         void connected(ipc::channel *ch);
41         void disconnected(ipc::channel *ch);
42         void read(ipc::channel *ch, ipc::message &msg);
43         void read_complete(ipc::channel *ch) {}
44         void error_caught(ipc::channel *ch, int error) {}
45         void set_handler(int num, ipc::channel_handler* handler) {}
46         void disconnect(void) {}
47
48 private:
49         int manager_connect(ipc::channel *ch, ipc::message &msg);
50         int manager_disconnect(ipc::channel *ch, ipc::message &msg);
51         int manager_get_sensor_list(ipc::channel *ch, ipc::message &msg);
52
53
54         int listener_connect(ipc::channel *ch, ipc::message &msg);
55         int listener_disconnect(ipc::channel *ch, ipc::message &msg);
56         int listener_start(ipc::channel *ch, ipc::message &msg);
57         int listener_stop(ipc::channel *ch, ipc::message &msg);
58         int listener_set_attr_int(ipc::channel *ch, ipc::message &msg);
59         int listener_set_attr_str(ipc::channel *ch, ipc::message &msg);
60         int listener_get_data(ipc::channel *ch, ipc::message &msg);
61         int listener_get_attr_int(ipc::channel *ch, ipc::message &msg);
62         int listener_get_attr_str(ipc::channel *ch, ipc::message &msg);
63         int listener_get_data_list(ipc::channel *ch, ipc::message &msg);
64
65         int provider_connect(ipc::channel *ch, ipc::message &msg);
66         int provider_disconnect(ipc::channel *ch, ipc::message &msg);
67         int provider_publish(ipc::channel *ch, ipc::message &msg);
68
69         int has_privileges(ipc::channel *ch, ipc::message &msg);
70
71         bool has_privilege(int fd, std::string &priv);
72         bool has_privileges(int fd, std::string priv);
73
74         int send_reply(ipc::channel *ch, int error);
75
76         sensor_manager *m_manager;
77
78         /* {id, listener} */
79         static std::unordered_map<uint32_t, sensor_listener_proxy *> m_listeners;
80
81         /* {channel, id} */
82         static std::unordered_map<ipc::channel *, uint32_t> m_listener_ids;
83
84         /* {channel, application_sensor_handler} */
85         /* it should move to sensor_manager */
86         static std::unordered_map<ipc::channel *, application_sensor_handler *> m_app_sensors;
87 };
88
89 }
90
91 #endif /* __SERVER_CHANNEL_HANDLER_H__ */