Call disable callback before remove callback
[connman] / src / dbus.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2008  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 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <connman/dbus.h>
27
28 void connman_dbus_dict_append_array(DBusMessageIter *dict,
29                                 const char *key, int type, void *val, int len)
30 {
31         DBusMessageIter entry, value, array;
32         const char *variant_sig, *array_sig;
33
34         switch (type) {
35         case DBUS_TYPE_BYTE:
36                 variant_sig = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
37                 array_sig = DBUS_TYPE_BYTE_AS_STRING;
38                 break;
39         default:
40                 return;
41         }
42
43         dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
44                                                                 NULL, &entry);
45
46         dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
47
48         dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
49                                                         variant_sig, &value);
50
51         dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY,
52                                                         array_sig, &array);
53         dbus_message_iter_append_fixed_array(&array, type, val, len);
54         dbus_message_iter_close_container(&value, &array);
55
56         dbus_message_iter_close_container(&entry, &value);
57
58         dbus_message_iter_close_container(dict, &entry);
59 }
60
61 void connman_dbus_dict_append_variant(DBusMessageIter *dict,
62                                         const char *key, int type, void *val)
63 {
64         DBusMessageIter entry, value;
65         const char *signature;
66
67         dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
68                                                                 NULL, &entry);
69
70         dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
71
72         switch (type) {
73         case DBUS_TYPE_BOOLEAN:
74                 signature = DBUS_TYPE_BOOLEAN_AS_STRING;
75                 break;
76         case DBUS_TYPE_STRING:
77                 signature = DBUS_TYPE_STRING_AS_STRING;
78                 break;
79         case DBUS_TYPE_BYTE:
80                 signature = DBUS_TYPE_BYTE_AS_STRING;
81                 break;
82         case DBUS_TYPE_UINT16:
83                 signature = DBUS_TYPE_UINT16_AS_STRING;
84                 break;
85         case DBUS_TYPE_INT16:
86                 signature = DBUS_TYPE_INT16_AS_STRING;
87                 break;
88         case DBUS_TYPE_UINT32:
89                 signature = DBUS_TYPE_UINT32_AS_STRING;
90                 break;
91         case DBUS_TYPE_INT32:
92                 signature = DBUS_TYPE_INT32_AS_STRING;
93                 break;
94         case DBUS_TYPE_OBJECT_PATH:
95                 signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
96                 break;
97         default:
98                 signature = DBUS_TYPE_VARIANT_AS_STRING;
99                 break;
100         }
101
102         dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
103                                                         signature, &value);
104         dbus_message_iter_append_basic(&value, type, val);
105         dbus_message_iter_close_container(&entry, &value);
106
107         dbus_message_iter_close_container(dict, &entry);
108 }