summaryrefslogtreecommitdiff
path: root/unit
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2011-06-07 15:42:21 +0200
committerDaniel Wagner <daniel.wagner@bmw-carit.de>2011-06-07 15:42:57 +0200
commita943b07d27a6a97ea0f89ad3349dbb33e39db68f (patch)
tree69a332972c2f1ae6eae42f247931207f00fc1fcb /unit
parent71ed8535374a78b310a1be9acd2468eab9012148 (diff)
downloadconnman-a943b07d27a6a97ea0f89ad3349dbb33e39db68f.tar.gz
connman-a943b07d27a6a97ea0f89ad3349dbb33e39db68f.tar.bz2
connman-a943b07d27a6a97ea0f89ad3349dbb33e39db68f.zip
unit: Add Manager API binding
Diffstat (limited to 'unit')
-rw-r--r--unit/manager-api.c189
-rw-r--r--unit/test-connman.h41
2 files changed, 230 insertions, 0 deletions
diff --git a/unit/manager-api.c b/unit/manager-api.c
new file mode 100644
index 00000000..5b6c6765
--- /dev/null
+++ b/unit/manager-api.c
@@ -0,0 +1,189 @@
+/*
+ *
+ * Connection Manager
+ *
+ * Copyright (C) 2011 BWM CarIT GmbH. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#include "test-connman.h"
+
+static DBusMessage *set_property(DBusConnection *connection,
+ const char *property, int type, void *value)
+{
+ DBusMessage *message, *reply;
+ DBusError error;
+ DBusMessageIter iter;
+
+ message = dbus_message_new_method_call(CONNMAN_SERVICE,
+ CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE,
+ "SetProperty");
+ if (message == NULL)
+ return NULL;
+
+ dbus_message_iter_init_append(message, &iter);
+ connman_dbus_property_append_basic(&iter, property, type, value);
+
+ dbus_error_init(&error);
+
+ reply = dbus_connection_send_with_reply_and_block(connection,
+ message, -1, &error);
+ if (reply == NULL) {
+ if (dbus_error_is_set(&error) == TRUE) {
+ LOG("%s", error.message);
+ dbus_error_free(&error);
+ } else {
+ LOG("Failed to get properties");
+ }
+ dbus_message_unref(message);
+ return NULL;
+ }
+
+ dbus_message_unref(message);
+
+ return reply;
+}
+
+DBusMessage *manager_get_services(DBusConnection *connection)
+{
+ DBusMessage *message, *reply;
+ DBusError error;
+
+ message = dbus_message_new_method_call(CONNMAN_SERVICE,
+ CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE,
+ "GetServices");
+ if (message == NULL)
+ return NULL;
+
+ dbus_error_init(&error);
+
+ reply = dbus_connection_send_with_reply_and_block(connection,
+ message, -1, &error);
+ if (reply == NULL) {
+ if (dbus_error_is_set(&error) == TRUE) {
+ LOG("%s", error.message);
+ dbus_error_free(&error);
+ } else {
+ LOG("Failed to get properties");
+ }
+ dbus_message_unref(message);
+ return NULL;
+ }
+
+ dbus_message_unref(message);
+
+ return reply;
+}
+
+DBusMessage *manager_create_session(DBusConnection *connection,
+ struct test_session_info *info,
+ const char *notifier_path)
+{
+ DBusMessage *message, *reply;
+ DBusError error;
+ DBusMessageIter array, dict;
+
+ message = dbus_message_new_method_call(CONNMAN_SERVICE,
+ CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE,
+ "CreateSession");
+ if (message == NULL)
+ return NULL;
+
+ dbus_error_init(&error);
+
+ dbus_message_iter_init_append(message, &array);
+
+ connman_dbus_dict_open(&array, &dict);
+
+ /* session_append_settings(&dict, info); */
+
+ connman_dbus_dict_close(&array, &dict);
+
+ dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
+ &notifier_path);
+
+ reply = dbus_connection_send_with_reply_and_block(connection,
+ message, -1, &error);
+ if (reply == NULL) {
+ if (dbus_error_is_set(&error) == TRUE) {
+ LOG("%s", error.message);
+ dbus_error_free(&error);
+ } else {
+ LOG("Failed to get properties");
+ }
+ dbus_message_unref(message);
+ return NULL;
+ }
+
+ dbus_message_unref(message);
+
+ return reply;
+}
+
+DBusMessage *manager_destroy_session(DBusConnection *connection,
+ const char *notifier_path)
+{
+ DBusMessage *message, *reply;
+ DBusError error;
+ DBusMessageIter array;
+
+ message = dbus_message_new_method_call(CONNMAN_SERVICE,
+ CONNMAN_MANAGER_PATH,
+ CONNMAN_MANAGER_INTERFACE,
+ "DestroySession");
+ if (message == NULL)
+ return NULL;
+
+ dbus_error_init(&error);
+
+ dbus_message_iter_init_append(message, &array);
+
+ dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
+ &notifier_path);
+
+ reply = dbus_connection_send_with_reply_and_block(connection,
+ message, -1, &error);
+ if (reply == NULL) {
+ if (dbus_error_is_set(&error) == TRUE) {
+ LOG("%s", error.message);
+ dbus_error_free(&error);
+ } else {
+ LOG("%s", error.message);
+ }
+ dbus_message_unref(message);
+ return NULL;
+ }
+
+ dbus_message_unref(message);
+
+ return reply;
+}
+
+DBusMessage *manager_set_session_mode(DBusConnection *connection,
+ connman_bool_t enable)
+{
+ return set_property(connection, "SessionMode",
+ DBUS_TYPE_BOOLEAN, &enable);
+}
diff --git a/unit/test-connman.h b/unit/test-connman.h
index 7c76332a..894025f8 100644
--- a/unit/test-connman.h
+++ b/unit/test-connman.h
@@ -57,15 +57,56 @@ void util_teardown(struct test_fix *fix, gconstpointer data);
typedef void (* notify_cb) (struct test_session *session);
+enum connman_session_roaming_policy {
+ CONNMAN_SESSION_ROAMING_POLICY_UNKNOWN = 0,
+ CONNMAN_SESSION_ROAMING_POLICY_DEFAULT = 1,
+ CONNMAN_SESSION_ROAMING_POLICY_ALWAYS = 2,
+ CONNMAN_SESSION_ROAMING_POLICY_FORBIDDEN = 3,
+ CONNMAN_SESSION_ROAMING_POLICY_NATIONAL = 4,
+ CONNMAN_SESSION_ROAMING_POLICY_INTERNATIONAL = 5,
+};
+
+struct test_session_info {
+ char *bearer;
+ connman_bool_t online;
+ char *name;
+ /* ipv4, ipv6 dicts */
+ GSList *allowed_bearers;
+ connman_bool_t priority;
+ connman_bool_t avoid_handover;
+ connman_bool_t stay_connected;
+ unsigned int periodic_connect;
+ unsigned int idle_timeout;
+ connman_bool_t ecall;
+ enum connman_session_roaming_policy roaming_policy;
+ char *interface;
+ unsigned int marker;
+};
+
struct test_session {
gpointer user_data;
struct test_fix *fix;
DBusConnection *connection;
+ char *session_path;
+ char *notify_path;
notify_cb notify;
+
+ struct test_session_info *info;
};
+/* manager-api.c */
+DBusMessage *manager_get_services(DBusConnection *connection);
+DBusMessage *manager_create_session(DBusConnection *connection,
+ struct test_session_info *info,
+ const char *notifier_path);
+DBusMessage *manager_destroy_session(DBusConnection *connection,
+ const char *notifier_path);
+DBusMessage *manager_set_session_mode(DBusConnection *connection,
+ connman_bool_t enable);
+
+
/* #define DEBUG */
#ifdef DEBUG
#include <stdio.h>