Initialize a local variable (WGID-202395)
[platform/upstream/connman.git] / include / dbus.h
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifndef __CONNMAN_DBUS_H
23 #define __CONNMAN_DBUS_H
24
25 #include <dbus/dbus.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #define CONNMAN_SERVICE                 "net.connman"
32 #define CONNMAN_PATH                    "/net/connman"
33
34 #define CONNMAN_DEBUG_INTERFACE         CONNMAN_SERVICE ".Debug"
35 #define CONNMAN_ERROR_INTERFACE         CONNMAN_SERVICE ".Error"
36 #define CONNMAN_AGENT_INTERFACE         CONNMAN_SERVICE ".Agent"
37 #define CONNMAN_COUNTER_INTERFACE       CONNMAN_SERVICE ".Counter"
38
39 #define CONNMAN_MANAGER_INTERFACE       CONNMAN_SERVICE ".Manager"
40 #define CONNMAN_MANAGER_PATH            "/"
41
42 #define CONNMAN_CLOCK_INTERFACE         CONNMAN_SERVICE ".Clock"
43 #define CONNMAN_TASK_INTERFACE          CONNMAN_SERVICE ".Task"
44 #define CONNMAN_SERVICE_INTERFACE       CONNMAN_SERVICE ".Service"
45 #define CONNMAN_PROVIDER_INTERFACE      CONNMAN_SERVICE ".Provider"
46 #define CONNMAN_TECHNOLOGY_INTERFACE    CONNMAN_SERVICE ".Technology"
47 #define CONNMAN_SESSION_INTERFACE       CONNMAN_SERVICE ".Session"
48 #define CONNMAN_NOTIFICATION_INTERFACE  CONNMAN_SERVICE ".Notification"
49 #define CONNMAN_PEER_INTERFACE          CONNMAN_SERVICE ".Peer"
50
51 #define CONNMAN_PRIVILEGE_MODIFY        1
52 #define CONNMAN_PRIVILEGE_SECRET        2
53
54 typedef void (* connman_dbus_append_cb_t) (DBusMessageIter *iter,
55                                                         void *user_data);
56
57 DBusConnection *connman_dbus_get_connection(void);
58
59 void connman_dbus_property_append_basic(DBusMessageIter *iter,
60                                         const char *key, int type, void *val);
61 void connman_dbus_property_append_dict(DBusMessageIter *iter, const char *key,
62                         connman_dbus_append_cb_t function, void *user_data);
63 void connman_dbus_property_append_array(DBusMessageIter *iter,
64                                                 const char *key, int type,
65                         connman_dbus_append_cb_t function, void *user_data);
66 void connman_dbus_property_append_fixed_array(DBusMessageIter *iter,
67                                 const char *key, int type, void *val, int len);
68
69 dbus_bool_t connman_dbus_property_changed_basic(const char *path,
70                                 const char *interface, const char *key,
71                                                         int type, void *val);
72 dbus_bool_t connman_dbus_property_changed_dict(const char *path,
73                                 const char *interface, const char *key,
74                         connman_dbus_append_cb_t function, void *user_data);
75 dbus_bool_t connman_dbus_property_changed_array(const char *path,
76                         const char *interface, const char *key, int type,
77                         connman_dbus_append_cb_t function, void *user_data);
78
79 dbus_bool_t connman_dbus_setting_changed_basic(const char *owner,
80                                 const char *path, const char *key,
81                                 int type, void *val);
82 dbus_bool_t connman_dbus_setting_changed_dict(const char *owner,
83                                 const char *path, const char *key,
84                                 connman_dbus_append_cb_t function,
85                                 void *user_data);
86 dbus_bool_t connman_dbus_setting_changed_array(const char *owner,
87                                 const char *path, const char *key, int type,
88                                 connman_dbus_append_cb_t function,
89                                 void *user_data);
90
91 static inline void connman_dbus_dict_open(DBusMessageIter *iter,
92                                                         DBusMessageIter *dict)
93 {
94         dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
95                         DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
96                         DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
97                         DBUS_DICT_ENTRY_END_CHAR_AS_STRING, dict);
98 }
99
100 static inline void connman_dbus_dict_open_variant(DBusMessageIter *iter,
101                                                         DBusMessageIter *dict)
102 {
103         dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
104                         DBUS_TYPE_ARRAY_AS_STRING
105                         DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
106                         DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
107                         DBUS_DICT_ENTRY_END_CHAR_AS_STRING, dict);
108 }
109
110 static inline void connman_dbus_array_open(DBusMessageIter *iter,
111                                                         DBusMessageIter *dict)
112 {
113         dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
114                         DBUS_TYPE_ARRAY_AS_STRING
115                         DBUS_TYPE_STRING_AS_STRING,
116                         dict);
117 }
118
119 static inline void connman_dbus_dict_close(DBusMessageIter *iter,
120                                                         DBusMessageIter *dict)
121 {
122         dbus_message_iter_close_container(iter, dict);
123 }
124
125 static inline void connman_dbus_dict_append_basic(DBusMessageIter *dict,
126                                         const char *key, int type, void *val)
127 {
128         DBusMessageIter entry;
129
130         dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
131                                                                 NULL, &entry);
132         connman_dbus_property_append_basic(&entry, key, type, val);
133         dbus_message_iter_close_container(dict, &entry);
134 }
135
136 static inline void connman_dbus_dict_append_dict(DBusMessageIter *dict,
137                         const char *key, connman_dbus_append_cb_t function,
138                                                         void *user_data)
139 {
140         DBusMessageIter entry;
141
142         dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
143                                                                 NULL, &entry);
144         connman_dbus_property_append_dict(&entry, key, function, user_data);
145         dbus_message_iter_close_container(dict, &entry);
146 }
147
148 static inline void connman_dbus_dict_append_array(DBusMessageIter *dict,
149                 const char *key, int type, connman_dbus_append_cb_t function,
150                                                         void *user_data)
151 {
152         DBusMessageIter entry;
153
154         dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
155                                                                 NULL, &entry);
156         connman_dbus_property_append_array(&entry, key,
157                                                 type, function, user_data);
158         dbus_message_iter_close_container(dict, &entry);
159 }
160
161 static inline void connman_dbus_dict_append_fixed_array(DBusMessageIter *dict,
162                                 const char *key, int type, void *val, int len)
163 {
164         DBusMessageIter entry;
165
166         dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
167                                                                 NULL, &entry);
168         connman_dbus_property_append_fixed_array(&entry, key, type, val, len);
169         dbus_message_iter_close_container(dict, &entry);
170 }
171
172 dbus_bool_t connman_dbus_validate_ident(const char *ident);
173 char *connman_dbus_encode_string(const char *value);
174
175 typedef void (* connman_dbus_get_connection_unix_user_cb_t) (unsigned int uid,
176                                                 void *user_data, int err);
177
178 int connman_dbus_get_connection_unix_user(DBusConnection *connection,
179                                const char *bus_name,
180                                connman_dbus_get_connection_unix_user_cb_t func,
181                                void *user_data);
182
183 int connman_dbus_get_connection_unix_user_sync(DBusConnection *connection,
184                                 const char *bus_name,
185                                 unsigned int *user_id);
186
187 typedef void (* connman_dbus_get_context_cb_t) (const unsigned char *context,
188                                                 void *user_data, int err);
189
190 int connman_dbus_get_selinux_context(DBusConnection *connection,
191                                const char *service,
192                                connman_dbus_get_context_cb_t func,
193                                void *user_data);
194
195 void connman_dbus_reply_pending(DBusMessage *pending,
196                                         int error, const char *path);
197
198 #ifdef __cplusplus
199 }
200 #endif
201
202 #endif /* __CONNMAN_DBUS_H */