Re: [PATCHv2 2/2] client: Add support of MoveAfter Service API

2015-06-11 Thread Patrik Flykt
On Thu, 2015-06-11 at 10:35 +0530, Saurav Babu wrote:
 EP-584CD5AB95AE4A3A879836122994DB42

See previous patch.

 This patch handles MoveAfter() method from Service API in connman client.
 This can be used to move any VPN service after any other VPN Service. For
 Connman services this won't be much useful as the order is not remembered
 after service list sort.
 ---
  client/commands.c | 59 
 +++
  1 file changed, 59 insertions(+)
 
 diff --git a/client/commands.c b/client/commands.c
 index 5e342a5..2397883 100644
 --- a/client/commands.c
 +++ b/client/commands.c
 @@ -786,6 +786,62 @@ static int cmd_service_move_before(char *args[], int num,
   services-target);
  }
  
 +static int move_after_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, '/');

See previous patch.

 + target++;
 + fprintf(stdout, Moved %s after %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_after_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_after(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, MoveAfter,
 + move_after_return, services,
 + move_after_append_args,
 + services-target);
 +}
 +
  static int config_return(DBusMessageIter *iter, const char *error,
   void *user_data)
  {
 @@ -2462,6 +2518,9 @@ static const struct {
   { move-before,   service target service  , NULL,
 cmd_service_move_before, Move a service before another service,
 lookup_service_arg },
 + { move-after,   service target service   , NULL,
 +   cmd_service_move_after, Move a service after another service,
 +   lookup_service_arg },
   { config,   service,config_options,  cmd_config,
 Set service configuration options, lookup_config },
   { monitor,  [off],monitor_options, cmd_monitor,

Cheers,

Patrik

___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman


[PATCHv2 2/2] client: Add support of MoveAfter Service API

2015-06-10 Thread Saurav Babu
EP-584CD5AB95AE4A3A879836122994DB42

This patch handles MoveAfter() method from Service API in connman client.
This can be used to move any VPN service after any other VPN Service. For
Connman services this won't be much useful as the order is not remembered
after service list sort.
---
 client/commands.c | 59 +++
 1 file changed, 59 insertions(+)

diff --git a/client/commands.c b/client/commands.c
index 5e342a5..2397883 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -786,6 +786,62 @@ static int cmd_service_move_before(char *args[], int num,
services-target);
 }
 
+static int move_after_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 after %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_after_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_after(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, MoveAfter,
+   move_after_return, services,
+   move_after_append_args,
+   services-target);
+}
+
 static int config_return(DBusMessageIter *iter, const char *error,
void *user_data)
 {
@@ -2462,6 +2518,9 @@ static const struct {
{ move-before,   service target service  , NULL,
  cmd_service_move_before, Move a service before another service,
  lookup_service_arg },
+   { move-after,   service target service   , NULL,
+ cmd_service_move_after, Move a service after 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
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman