sensord: remove useless privilege and macros
[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
46 private:
47         int manager_connect(ipc::channel *ch, ipc::message &msg);
48         int manager_disconnect(ipc::channel *ch, ipc::message &msg);
49         int manager_get_sensor_list(ipc::channel *ch, ipc::message &msg);
50
51
52         int listener_connect(ipc::channel *ch, ipc::message &msg);
53         int listener_disconnect(ipc::channel *ch, ipc::message &msg);
54         int listener_start(ipc::channel *ch, ipc::message &msg);
55         int listener_stop(ipc::channel *ch, ipc::message &msg);
56         int listener_attr_int(ipc::channel *ch, ipc::message &msg);
57         int listener_attr_str(ipc::channel *ch, ipc::message &msg);
58         int listener_get_data(ipc::channel *ch, ipc::message &msg);
59
60         int provider_connect(ipc::channel *ch, ipc::message &msg);
61         int provider_disconnect(ipc::channel *ch, ipc::message &msg);
62         int provider_publish(ipc::channel *ch, ipc::message &msg);
63
64         int has_privileges(ipc::channel *ch, ipc::message &msg);
65
66         bool has_privilege(int fd, std::string &priv);
67         bool has_privileges(int fd, std::string priv);
68
69         int send_reply(ipc::channel *ch, int error);
70
71         sensor_manager *m_manager;
72
73         /* {id, listener} */
74         static std::unordered_map<uint32_t, sensor_listener_proxy *> m_listeners;
75
76         /* {channel, id} */
77         static std::unordered_map<ipc::channel *, uint32_t> m_listener_ids;
78
79         /* {channel, application_sensor_handler} */
80         /* it should move to sensor_manager */
81         static std::unordered_map<ipc::channel *, application_sensor_handler *> m_app_sensors;
82 };
83
84 }
85
86 #endif /* __SERVER_CHANNEL_HANDLER_H__ */