tizen 2.3 release
[kernel/api/system-resource.git] / src / common / edbus-handler.h
1 /*
2  * resourced
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
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 /**
21  * @file edbus-handler.h
22  * @desc  dbus handler using edbus interface
23  **/
24
25 #ifndef __EDBUS_HANDLE_H__
26 #define __EDBUS_HANDLE_H__
27
28 #include <E_DBus.h>
29 #include <resourced.h>
30
31 struct edbus_method {
32         const char *member;
33         const char *signature;
34         const char *reply_signature;
35         E_DBus_Method_Cb func;
36 };
37
38 struct edbus_object {
39         const char *path;
40         const char *interface;
41         E_DBus_Object *obj;
42         E_DBus_Interface *iface;
43 };
44
45 #define DBUS_REPLY_TIMEOUT  (120 * 1000)
46
47 #define BUS_NAME                "org.tizen.resourced"
48 #define OBJECT_PATH             "/Org/Tizen/ResourceD"
49 #define INTERFACE_NAME          BUS_NAME
50
51 /*
52  * The EDbus method to update the resourced counters
53  * Signal is generated after the database update
54  * and store new values of the counters
55  */
56 #define RESOURCED_NETWORK_UPDATE                "Update"
57 #define RESOURCED_NETWORK_UPDATE_FINISH "UpdateFinish"
58 #define RESOURCED_NETWORK_PROCESS_RESTRICTION   "ProcessRestriction"
59 #define RESOURCED_NETWORK_CREATE_QUOTA          "CreateQuota"
60 #define RESOURCED_NETWORK_REMOVE_QUOTA          "RemoveQuota"
61 #define RESOURCED_NETWORK_JOIN_NET_STAT         "JoinNetStat"
62 #define RESOURCED_NETWORK_GET_STATS             "GetStats"
63
64 /*
65  * Core service
66  *   get/set swap status
67  *   operations about swap
68  */
69 #define RESOURCED_PATH_SWAP             OBJECT_PATH"/Swap"
70 #define RESOURCED_INTERFACE_SWAP        INTERFACE_NAME".swap"
71
72 #define RESOURCED_PATH_OOM              OBJECT_PATH"/Oom"
73 #define RESOURCED_INTERFACE_OOM         INTERFACE_NAME".oom"
74
75 #define RESOURCED_PATH_NETWORK          OBJECT_PATH"/Network"
76 #define RESOURCED_INTERFACE_NETWORK     INTERFACE_NAME".network"
77
78 #define RESOURCED_PATH_PROCESS          OBJECT_PATH"/Process"
79 #define RESOURCED_INTERFACE_PROCESS     INTERFACE_NAME".process"
80
81 /*
82  * Logging
83  */
84 #define RESOURCED_PATH_LOGGING          OBJECT_PATH"/Logging"
85 #define RESOURCED_INTERFACE_LOGGING     INTERFACE_NAME".logging"
86
87 /*
88  * System popup
89  */
90 #define SYSTEM_POPUP_BUS_NAME "org.tizen.system.popup"
91 #define SYSTEM_POPUP_PATH_NAME "/Org/Tizen/System/Popup"
92 #define SYSTEM_POPUP_IFACE_NAME SYSTEM_POPUP_BUS_NAME
93
94 #define SYSTEM_POPUP_PATH_WATCHDOG SYSTEM_POPUP_PATH_NAME"/System"
95 #define SYSTEM_POPUP_IFACE_WATCHDOG SYSTEM_POPUP_BUS_NAME".System"
96
97 /*
98  * Deviced
99  */
100 #define DEVICED_BUS_NAME                "org.tizen.system.deviced"
101 #define DEVICED_PATH_PROCESS            "/Org/Tizen/System/DeviceD/Process"
102 #define DEVICED_INTERFACE_PROCESS       DEVICED_BUS_NAME".Process"
103
104 #define DEVICED_PATH_DISPLAY               "/Org/Tizen/System/DeviceD/Display"
105 #define DEVICED_INTERFACE_DISPLAY       DEVICED_BUS_NAME".display"
106
107 #define SIGNAL_LCD_ON   "LCDOn"
108 #define SIGNAL_LCD_OFF  "LCDOff"
109
110 struct dbus_byte {
111         char *data;
112         int size;
113 };
114
115 #define RETRY_MAX 5
116
117 /*
118  * @desc helper function for filling params array
119  * That params array is used in dbus_method_sync/dbus_method_async
120  * */
121 void serialize_params(char *params[], size_t n, ...);
122
123
124 DBusMessage *dbus_method_sync(const char *dest, const char *path,
125                 const char *interface, const char *method,
126                 const char *sig, char *param[]);
127
128 int dbus_method_async(const char *dest, const char *path,
129                 const char *interface, const char *method,
130                 const char *sig, char *param[]);
131
132 int register_edbus_signal_handler(const char *path, const char *interface,
133                 const char *name, E_DBus_Signal_Cb cb);
134 E_DBus_Interface *get_edbus_interface(const char *path);
135 pid_t get_edbus_sender_pid(DBusMessage *msg);
136 int broadcast_edbus_signal_str(const char *path, const char *interface,
137                 const char *name, const char *sig, char *param[]);
138 int broadcast_edbus_signal(const char *path, const char *interface,
139                            const char *name, int type, void *value);
140 resourced_ret_c edbus_add_methods(const char *path,
141                        const struct edbus_method *const edbus_methods,
142                        const size_t size);
143 int register_edbus_interface(struct edbus_object *object);
144
145 void edbus_init(void);
146 void edbus_exit(void);
147
148 #endif /* __EDBUS_HANDLE_H__ */