summaryrefslogtreecommitdiff
path: root/attrib/gatttool.c
diff options
context:
space:
mode:
authorBruna Moreira <bruna.moreira@openbossa.org>2010-08-06 11:33:05 -0400
committerJohan Hedberg <johan.hedberg@nokia.com>2010-08-09 18:06:50 -0400
commitac81ac51758133b7fcc8a996aa611c5cdd875e20 (patch)
tree77a5f50879057bf47b87b7b16036962db96f05d0 /attrib/gatttool.c
parente43827833a80bbe63d162cc45f8d085628e51827 (diff)
downloadbluez-ac81ac51758133b7fcc8a996aa611c5cdd875e20.tar.gz
Exiting gatttool if no option is chosen
If no operation is chosen, print usage help and exit gatttool.
Diffstat (limited to 'attrib/gatttool.c')
-rw-r--r--attrib/gatttool.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index d5033f7cf..0a071034b 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -394,6 +394,7 @@ int main(int argc, char *argv[])
GAttrib *attrib;
GIOChannel *chan;
GSourceFunc callback;
+ int ret = 0;
context = g_option_context_new(NULL);
g_option_context_add_main_entries(context, options, NULL);
@@ -425,27 +426,39 @@ int main(int argc, char *argv[])
g_error_free(gerr);
}
- event_loop = g_main_loop_new(NULL, FALSE);
-
- chan = do_connect();
- if (chan == NULL)
- return 1;
- attrib = g_attrib_new(chan);
-
if (opt_primary)
callback = primary;
else if (opt_characteristics)
callback = characteristics;
else if (opt_char_read)
callback = characteristics_read;
+ else {
+ gchar *help = g_option_context_get_help(context, TRUE, NULL);
+ g_print("%s\n", help);
+ g_free(help);
+ ret = 1;
+ goto done;
+ }
+
+ chan = do_connect();
+ if (chan == NULL) {
+ ret = 1;
+ goto done;
+ }
+
+ attrib = g_attrib_new(chan);
+
+ event_loop = g_main_loop_new(NULL, FALSE);
g_idle_add(callback, attrib);
g_main_loop_run(event_loop);
-
- g_option_context_free(context);
+ g_main_loop_unref(event_loop);
g_attrib_unref(attrib);
- return 0;
+done:
+ g_option_context_free(context);
+
+ return ret;
}