diff options
author | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-03-27 13:54:02 +0200 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-04-04 10:26:52 +0300 |
commit | 0bc79a37b387ed676ac88cb70667eb4d0266886e (patch) | |
tree | e437d69d80b008674b0d585a4fef18911cee103a | |
parent | 89c862fd565f3a1aafa551015f4bd682c65470d9 (diff) | |
download | connman-0bc79a37b387ed676ac88cb70667eb4d0266886e.tar.gz connman-0bc79a37b387ed676ac88cb70667eb4d0266886e.tar.bz2 connman-0bc79a37b387ed676ac88cb70667eb4d0266886e.zip |
client: Use D-Bus helper functions for Technology enabling/disabling
-rw-r--r-- | client/commands.c | 84 |
1 files changed, 58 insertions, 26 deletions
diff --git a/client/commands.c b/client/commands.c index f6abdbb9..561d55d0 100644 --- a/client/commands.c +++ b/client/commands.c @@ -88,10 +88,30 @@ static int parse_args(char *arg, struct option *options) return '?'; } +static void enable_return(DBusMessageIter *iter, const char *error, + void *user_data) +{ + char *tech = user_data; + char *str; + + str = strrchr(tech, '/'); + if (str != NULL) + str++; + else + str = tech; + + if (error == NULL) { + fprintf(stdout, "Enabled %s\n", str); + } else + fprintf(stderr, "Error %s: %s\n", str, error); + + g_free(user_data); +} + static int cmd_enable(char *args[], int num, struct option *options) { - DBusMessage *message; - int err; + char *tech; + dbus_bool_t b = TRUE; if (num > 2) return -E2BIG; @@ -100,26 +120,42 @@ static int cmd_enable(char *args[], int num, struct option *options) return -EINVAL; if (strcmp(args[1], "offlinemode") == 0) { - err = set_manager(connection, "OfflineMode", TRUE); - if (err == 0) - printf("OfflineMode enabled\n"); - - return 0; + tech = g_strdup(args[1]); + return __connmanctl_dbus_set_property(connection, "/", + "net.connman.Manager", enable_return, tech, + "OfflineMode", DBUS_TYPE_BOOLEAN, &b); } - message = get_message(connection, "GetTechnologies"); - if (message == NULL) - return -ENOMEM; + tech = g_strdup_printf("/net/connman/technology/%s", args[1]); + return __connmanctl_dbus_set_property(connection, tech, + "net.connman.Technology", enable_return, tech, + "Powered", DBUS_TYPE_BOOLEAN, &b); +} - set_technology(connection, message, "Powered", args[1], TRUE); +static void disable_return(DBusMessageIter *iter, const char *error, + void *user_data) +{ + char *tech = user_data; + char *str; - return 0; + str = strrchr(tech, '/'); + if (str != NULL) + str++; + else + str = tech; + + if (error == NULL) { + fprintf(stdout, "Disabled %s\n", str); + } else + fprintf(stderr, "Error %s: %s\n", str, error); + + g_free(user_data); } static int cmd_disable(char *args[], int num, struct option *options) { - DBusMessage *message; - int err; + char *tech; + dbus_bool_t b = FALSE; if (num > 2) return -E2BIG; @@ -128,20 +164,16 @@ static int cmd_disable(char *args[], int num, struct option *options) return -EINVAL; if (strcmp(args[1], "offlinemode") == 0) { - err = set_manager(connection, "OfflineMode", FALSE); - if (err == 0) - printf("OfflineMode enabled\n"); - - return 0; + tech = g_strdup(args[1]); + return __connmanctl_dbus_set_property(connection, "/", + "net.connman.Manager", disable_return, tech, + "OfflineMode", DBUS_TYPE_BOOLEAN, &b); } - message = get_message(connection, "GetTechnologies"); - if (message == NULL) - return -ENOMEM; - - set_technology(connection, message, "Powered", args[1], FALSE); - - return 0; + tech = g_strdup_printf("/net/connman/technology/%s", args[1]); + return __connmanctl_dbus_set_property(connection, tech, + "net.connman.Technology", disable_return, tech, + "Powered", DBUS_TYPE_BOOLEAN, &b); } static void state_print(DBusMessageIter *iter, const char *error, |