From a943b07d27a6a97ea0f89ad3349dbb33e39db68f Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 7 Jun 2011 15:42:21 +0200 Subject: [PATCH] unit: Add Manager API binding --- Makefile.am | 2 +- unit/manager-api.c | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++++ unit/test-connman.h | 41 ++++++++++++ 3 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 unit/manager-api.c diff --git a/Makefile.am b/Makefile.am index c7e706a..f3ea3a6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -184,7 +184,7 @@ tools_iptables_test_LDADD = @GLIB_LIBS@ @XTABLES_LIBS@ tools_private_network_test_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ unit_test_session_SOURCES = $(gdbus_sources) src/log.c src/dbus.c \ - unit/test-session.c unit/utils.c + unit/test-session.c unit/utils.c unit/manager-api.c unit_test_session_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ unit_objects += $(unit_test_session_OBJECTS) endif diff --git a/unit/manager-api.c b/unit/manager-api.c new file mode 100644 index 0000000..5b6c676 --- /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 +#endif + +#include + +#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, + ¬ifier_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, + ¬ifier_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 7c76332..894025f 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 -- 2.7.4