manager: Implement service provisioning via dbus
authorHenri Bragge <henri.bragge@ixonos.com>
Fri, 1 Apr 2011 08:41:41 +0000 (11:41 +0300)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 11 Apr 2011 10:02:43 +0000 (12:02 +0200)
src/connman.h
src/manager.c
src/service.c

index 5a9e927..f912026 100644 (file)
@@ -518,6 +518,7 @@ int __connman_service_connect(struct connman_service *service);
 int __connman_service_disconnect(struct connman_service *service);
 int __connman_service_disconnect_all(void);
 int __connman_service_create_and_connect(DBusMessage *msg);
+int __connman_service_provision(DBusMessage *msg);
 void __connman_service_auto_connect(void);
 
 const char *__connman_service_type2string(enum connman_service_type type);
index 047d26d..4afed26 100644 (file)
@@ -437,6 +437,19 @@ static DBusMessage *connect_service(DBusConnection *conn,
        return NULL;
 }
 
+static DBusMessage *provision_service(DBusConnection *conn, DBusMessage *msg,
+                                       void *data)
+{
+       int err;
+
+       DBG("conn %p", conn);
+
+       err = __connman_service_provision(msg);
+       if (err < 0)
+               return __connman_error_failed(msg, -err);
+
+       return NULL;
+}
 
 static DBusMessage *connect_provider(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
@@ -592,6 +605,8 @@ static GDBusMethodTable manager_methods[] = {
        { "LookupService",     "s",     "o",     lookup_service,    },
        { "ConnectService",    "a{sv}", "o",     connect_service,
                                                G_DBUS_METHOD_FLAG_ASYNC },
+       { "ProvisionService",  "s",     "",      provision_service,
+                                               G_DBUS_METHOD_FLAG_ASYNC },
        { "ConnectProvider",   "a{sv}", "o",     connect_provider,
                                                G_DBUS_METHOD_FLAG_ASYNC },
        { "RegisterAgent",     "o",     "",      register_agent     },
index 7b1b2c7..46f7ade 100644 (file)
@@ -4237,6 +4237,64 @@ failed:
        return err;
 }
 
+int __connman_service_provision(DBusMessage *msg)
+{
+       GKeyFile *keyfile = NULL;
+       const char *config_str = NULL;
+       char *group = NULL, *ident = NULL;
+       int err = 0;
+
+       DBG("");
+
+       dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &config_str,
+                                                       DBUS_TYPE_INVALID);
+
+       if (config_str == NULL || strlen(config_str) == 0)
+               return -EINVAL;
+
+       keyfile = g_key_file_new();
+
+       /* populate GKeyFile with config_str */
+       if (g_key_file_load_from_data(keyfile, config_str,
+                                       strlen(config_str), 0, NULL) == FALSE) {
+               err = -EINVAL;
+               goto done;
+       }
+
+       /*
+        * read only one group of settings (only one service supported, no
+        * global settings)
+        */
+       group = g_key_file_get_start_group(keyfile);
+
+       if (group == NULL || g_str_has_prefix(group, "service_") == FALSE) {
+               err = -EINVAL;
+               goto done;
+       }
+
+       err = __connman_config_load_service(keyfile, group);
+       if (err < 0)
+               goto done;
+
+       ident = group + strlen("service_");
+
+       /* trigger service provisioning if service exists */
+       service = lookup_by_identifier(ident);
+       if (service != NULL)
+               __connman_config_provision_service(service);
+
+       g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
+
+done:
+       if (group != NULL)
+               g_free(group);
+
+       if (keyfile != NULL)
+               g_key_file_free(keyfile);
+
+       return err;
+}
+
 /**
  * __connman_service_get:
  * @identifier: service identifier