Commit 7d1c1d65 authored by Andrzej Bieniek's avatar Andrzej Bieniek Committed by Jens Georg
Browse files

examples/light-server: add --quiet and --help options

Quiet option is useful to disable printing overhead
when measuring library performance.

Example run:
gupnp/examples$ ./light-server -q
^C
gupnp/examples$ ./light-server --help
Usage:
  lt-light-server [OPTION...]

Help Options:
  -h, --help       Show help options

Application Options:
  -q, --quiet      Turn off output

https://bugzilla.gnome.org/show_bug.cgi?id=708575
parent 1c11743d
...@@ -14,6 +14,13 @@ ...@@ -14,6 +14,13 @@
#include <gmodule.h> #include <gmodule.h>
static gboolean status; static gboolean status;
static gboolean quiet;
static GOptionEntry entries[] =
{
{ "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "Turn off output", NULL },
{ NULL }
};
G_BEGIN_DECLS G_BEGIN_DECLS
G_MODULE_EXPORT void set_target_cb (GUPnPService *service, G_MODULE_EXPORT void set_target_cb (GUPnPService *service,
...@@ -55,7 +62,10 @@ set_target_cb (GUPnPService *service, ...@@ -55,7 +62,10 @@ set_target_cb (GUPnPService *service,
"Status", G_TYPE_BOOLEAN, status, "Status", G_TYPE_BOOLEAN, status,
NULL); NULL);
g_print ("The light is now %s.\n", status ? "on" : "off"); if (!quiet)
{
g_print ("The light is now %s.\n", status ? "on" : "off");
}
} }
/* Return success to the client */ /* Return success to the client */
...@@ -116,6 +126,7 @@ query_status_cb (G_GNUC_UNUSED GUPnPService *service, ...@@ -116,6 +126,7 @@ query_status_cb (G_GNUC_UNUSED GUPnPService *service,
int int
main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
{ {
GOptionContext *optionContext;
GMainLoop *main_loop; GMainLoop *main_loop;
GError *error = NULL; GError *error = NULL;
GUPnPContext *context; GUPnPContext *context;
...@@ -126,9 +137,20 @@ main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) ...@@ -126,9 +137,20 @@ main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
g_type_init (); g_type_init ();
#endif #endif
optionContext = g_option_context_new (NULL);
g_option_context_add_main_entries (optionContext, entries, NULL);
if (!g_option_context_parse (optionContext, &argc, &argv, &error))
{
g_print ("option parsing failed: %s\n", error->message);
exit (1);
}
/* By default the light is off */ /* By default the light is off */
status = FALSE; status = FALSE;
g_print ("The light is now %s.\n", status ? "on" : "off"); if (!quiet)
{
g_print ("The light is now %s.\n", status ? "on" : "off");
}
/* Create the UPnP context */ /* Create the UPnP context */
context = gupnp_context_new (NULL, NULL, 0, &error); context = gupnp_context_new (NULL, NULL, 0, &error);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment