unit: Add Manager API binding
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 7 Jun 2011 13:42:21 +0000 (15:42 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 7 Jun 2011 13:42:57 +0000 (15:42 +0200)
Makefile.am
unit/manager-api.c [new file with mode: 0644]
unit/test-connman.h

index c7e706a..f3ea3a6 100644 (file)
@@ -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 (file)
index 0000000..5b6c676
--- /dev/null
@@ -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);
+}
index 7c76332..894025f 100644 (file)
@@ -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>