<EP-584CD5AB95AE4A3A879836122994DB42>
---
 client/commands.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/client/commands.c b/client/commands.c
index 9208016..5e342a5 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -725,6 +725,67 @@ static int cmd_disconnect(char *args[], int num, struct 
connman_option *options)
                                        disconnect_return, path, NULL, NULL);
 }
 
+struct move_service {
+       char *service;
+       char *target;
+};
+
+static int move_before_return(DBusMessageIter *iter, const char *error,
+               void *user_data)
+{
+       struct move_service *services = user_data;
+
+       if (!error) {
+               char *service = strrchr(services->service, '/');
+               service++;
+               char *target = strrchr(services->target, '/');
+               target++;
+               fprintf(stdout, "Moved %s before %s\n", service, target);
+       } else
+               fprintf(stderr, "Error %s: %s\n", services->service, error);
+
+       g_free(services->service);
+       g_free(services->target);
+       g_free(user_data);
+
+       return 0;
+}
+
+static void move_before_append_args(DBusMessageIter *iter, void *user_data)
+{
+       char *path = user_data;
+
+       dbus_message_iter_append_basic(iter,
+                               DBUS_TYPE_OBJECT_PATH, &path);
+
+       return;
+}
+
+static int cmd_service_move_before(char *args[], int num,
+               struct connman_option *options)
+{
+       const char *iface = "net.connman.Service";
+       struct move_service *services = g_new(struct move_service, 1);
+
+       if (num > 3)
+               return -E2BIG;
+
+       if (num < 3)
+               return -EINVAL;
+
+       if (check_dbus_name(args[1]) == false)
+               return -EINVAL;
+
+       services->service = g_strdup_printf("/net/connman/service/%s", args[1]);
+       services->target = g_strdup_printf("/net/connman/service/%s", args[2]);
+
+       return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+                                       services->service, iface, "MoveBefore",
+                                       move_before_return, services,
+                                       move_before_append_args,
+                                       services->target);
+}
+
 static int config_return(DBusMessageIter *iter, const char *error,
                void *user_data)
 {
@@ -2398,6 +2459,9 @@ static const struct {
          "Connect a given service or peer", lookup_service_arg },
        { "disconnect",   "<service/peer>", NULL,          cmd_disconnect,
          "Disconnect a given service or peer", lookup_service_arg },
+       { "move-before",   "<service> <target service>  ", NULL,
+         cmd_service_move_before, "Move a service before another service",
+         lookup_service_arg },
        { "config",       "<service>",    config_options,  cmd_config,
          "Set service configuration options", lookup_config },
        { "monitor",      "[off]",        monitor_options, cmd_monitor,
-- 
1.9.1

_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman

Reply via email to