unit: Fix wrong include of common header
[framework/connectivity/connman.git] / unit / manager-api.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2011  BWM CarIT GmbH. 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 <stdio.h>
27
28 #include "test-connman.h"
29
30 static DBusMessage *set_property(DBusConnection *connection,
31                                 const char *property, int type, void *value)
32 {
33         DBusMessage *message, *reply;
34         DBusError error;
35         DBusMessageIter iter;
36
37         message = dbus_message_new_method_call(CONNMAN_SERVICE,
38                                                 CONNMAN_MANAGER_PATH,
39                                                 CONNMAN_MANAGER_INTERFACE,
40                                                 "SetProperty");
41         if (message == NULL)
42                 return NULL;
43
44         dbus_message_iter_init_append(message, &iter);
45         connman_dbus_property_append_basic(&iter, property, type, value);
46
47         dbus_error_init(&error);
48
49         reply = dbus_connection_send_with_reply_and_block(connection,
50                                                         message, -1, &error);
51         if (reply == NULL) {
52                 if (dbus_error_is_set(&error) == TRUE) {
53                         LOG("%s", error.message);
54                         dbus_error_free(&error);
55                 } else {
56                         LOG("Failed to get properties");
57                 }
58                 dbus_message_unref(message);
59                 return NULL;
60         }
61
62         dbus_message_unref(message);
63
64         return reply;
65 }
66
67 DBusMessage *manager_get_services(DBusConnection *connection)
68 {
69         DBusMessage *message, *reply;
70         DBusError error;
71
72         message = dbus_message_new_method_call(CONNMAN_SERVICE,
73                                                 CONNMAN_MANAGER_PATH,
74                                                 CONNMAN_MANAGER_INTERFACE,
75                                                         "GetServices");
76         if (message == NULL)
77                 return NULL;
78
79         dbus_error_init(&error);
80
81         reply = dbus_connection_send_with_reply_and_block(connection,
82                                                         message, -1, &error);
83         if (reply == NULL) {
84                 if (dbus_error_is_set(&error) == TRUE) {
85                         LOG("%s", error.message);
86                         dbus_error_free(&error);
87                 } else {
88                         LOG("Failed to get properties");
89                 }
90                 dbus_message_unref(message);
91                 return NULL;
92         }
93
94         dbus_message_unref(message);
95
96         return reply;
97 }
98
99 DBusMessage *manager_create_session(DBusConnection *connection,
100                                         struct test_session_info *info,
101                                         const char *notifier_path)
102 {
103         DBusMessage *message, *reply;
104         DBusError error;
105         DBusMessageIter array, dict;
106
107         message = dbus_message_new_method_call(CONNMAN_SERVICE,
108                                                 CONNMAN_MANAGER_PATH,
109                                                 CONNMAN_MANAGER_INTERFACE,
110                                                         "CreateSession");
111         if (message == NULL)
112                 return NULL;
113
114         dbus_error_init(&error);
115
116         dbus_message_iter_init_append(message, &array);
117
118         connman_dbus_dict_open(&array, &dict);
119
120         session_append_settings(&dict, info);
121
122         connman_dbus_dict_close(&array, &dict);
123
124         dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
125                                 &notifier_path);
126
127         reply = dbus_connection_send_with_reply_and_block(connection,
128                                                         message, -1, &error);
129         if (reply == NULL) {
130                 if (dbus_error_is_set(&error) == TRUE) {
131                         LOG("%s", error.message);
132                         dbus_error_free(&error);
133                 } else {
134                         LOG("Failed to get properties");
135                 }
136                 dbus_message_unref(message);
137                 return NULL;
138         }
139
140         dbus_message_unref(message);
141
142         return reply;
143 }
144
145 DBusMessage *manager_destroy_session(DBusConnection *connection,
146                                         const char *notifier_path)
147 {
148         DBusMessage *message, *reply;
149         DBusError error;
150         DBusMessageIter array;
151
152         message = dbus_message_new_method_call(CONNMAN_SERVICE,
153                                                 CONNMAN_MANAGER_PATH,
154                                                 CONNMAN_MANAGER_INTERFACE,
155                                                         "DestroySession");
156         if (message == NULL)
157                 return NULL;
158
159         dbus_error_init(&error);
160
161         dbus_message_iter_init_append(message, &array);
162
163         dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
164                                 &notifier_path);
165
166         reply = dbus_connection_send_with_reply_and_block(connection,
167                                                         message, -1, &error);
168         if (reply == NULL) {
169                 if (dbus_error_is_set(&error) == TRUE) {
170                         LOG("%s", error.message);
171                         dbus_error_free(&error);
172                 } else {
173                         LOG("%s", error.message);
174                 }
175                 dbus_message_unref(message);
176                 return NULL;
177         }
178
179         dbus_message_unref(message);
180
181         return reply;
182 }
183
184 DBusMessage *manager_set_session_mode(DBusConnection *connection,
185                                         connman_bool_t enable)
186 {
187         return set_property(connection, "SessionMode",
188                                 DBUS_TYPE_BOOLEAN, &enable);
189 }