mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2025-01-23 04:43:35 +08:00
gatttool: add main loop
Also modify the option parsing to work properly with it.
This commit is contained in:
parent
2fe3ab0fc6
commit
fa7e72f64b
@ -37,6 +37,9 @@ static gchar *opt_src = NULL;
|
||||
static gchar *opt_dst = NULL;
|
||||
static int opt_start = 0x0001;
|
||||
static int opt_end = 0xffff;
|
||||
static gboolean opt_primary = FALSE;
|
||||
static gboolean opt_characteristics = FALSE;
|
||||
static GMainLoop *event_loop;
|
||||
|
||||
static int unix_connect(const char *address)
|
||||
{
|
||||
@ -66,8 +69,7 @@ static int unix_connect(const char *address)
|
||||
return sk;
|
||||
}
|
||||
|
||||
static gboolean primary(const gchar *name, const gchar *value,
|
||||
gpointer user_data, GError **gerr)
|
||||
static gboolean primary(gpointer user_data)
|
||||
{
|
||||
int sk;
|
||||
|
||||
@ -77,16 +79,9 @@ static gboolean primary(const gchar *name, const gchar *value,
|
||||
return FALSE;
|
||||
|
||||
/* FIXME: implement "discover all primary services */
|
||||
g_main_loop_quit(event_loop);
|
||||
|
||||
close(sk);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean characteristics(const gchar *name, const gchar *value,
|
||||
gpointer user_data, GError **gerr)
|
||||
{
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GOptionEntry primary_options[] = {
|
||||
@ -98,10 +93,10 @@ static GOptionEntry primary_options[] = {
|
||||
};
|
||||
|
||||
static GOptionEntry gatt_options[] = {
|
||||
{ "primary", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, primary,
|
||||
"Primary Service Discovery", NULL},
|
||||
{ "characteristics", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
|
||||
characteristics, "Characteristics Discovery", NULL},
|
||||
{ "primary", 0, 0, G_OPTION_ARG_NONE, &opt_primary,
|
||||
"Primary Service Discovery", NULL },
|
||||
{ "characteristics", 0, 0, G_OPTION_ARG_NONE, &opt_characteristics,
|
||||
"Characteristics Discovery", NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
@ -140,6 +135,11 @@ int main(int argc, char *argv[])
|
||||
g_error_free(gerr);
|
||||
}
|
||||
|
||||
event_loop = g_main_loop_new(NULL, FALSE);
|
||||
if (opt_primary)
|
||||
g_idle_add(primary, NULL);
|
||||
g_main_loop_run(event_loop);
|
||||
|
||||
g_option_context_free(context);
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user