summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2018-08-16 18:25:30 +0200
committerWim Taymans <wtaymans@redhat.com>2018-08-17 09:38:08 +0200
commitd70e027a99fdb921a78d8b323c9029d5bfdf033e (patch)
treee65c10193a4a7617a3255acccd6ab8f4cac1d5a4
parent5eac8f76750a9ba5cd6e0f42a42d41247ffbabc1 (diff)
daemon: add some options
-rw-r--r--src/daemon/main.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/daemon/main.c b/src/daemon/main.c
index a7fae1a5..96f78b48 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -18,19 +18,34 @@
*/
#include <signal.h>
+#include <stdio.h>
+#include <getopt.h>
#include <pipewire/pipewire.h>
#include <pipewire/core.h>
#include <pipewire/module.h>
+#include "config.h"
#include "daemon-config.h"
+static const char *daemon_name = "pipewire-0";
+
static void do_quit(void *data, int signal_number)
{
struct pw_main_loop *loop = data;
pw_main_loop_quit(loop);
}
+static void show_help(const char *name)
+{
+ fprintf(stdout, "%s [options]\n"
+ " -h, --help Show this help\n"
+ " -v, --version Show version\n"
+ " -n, --name Daemon name (Default %s)\n",
+ name,
+ daemon_name);
+}
+
int main(int argc, char *argv[])
{
struct pw_core *core;
@@ -38,9 +53,38 @@ int main(int argc, char *argv[])
struct pw_daemon_config *config;
char *err = NULL;
struct pw_properties *props;
+ static const struct option long_options[] = {
+ {"help", 0, NULL, 'h'},
+ {"version", 0, NULL, 'v'},
+ {"name", 1, NULL, 'n'},
+ {NULL, 0, NULL, 0}
+ };
+ char c;
pw_init(&argc, &argv);
+ while ((c = getopt_long(argc, argv, "hvn:", long_options, NULL)) != -1) {
+ switch (c) {
+ case 'h' :
+ show_help(argv[0]);
+ return 0;
+ case 'v' :
+ fprintf(stdout, "%s\n"
+ "Compiled with libpipewire %s\n"
+ "Linked with libpipewire %s\n",
+ argv[0],
+ pw_get_headers_version(),
+ pw_get_library_version());
+ return 0;
+ case 'n' :
+ daemon_name = optarg;
+ fprintf(stdout, "set name %s\n", daemon_name);
+ break;
+ default:
+ return -1;
+ }
+ }
+
/* parse configuration */
config = pw_daemon_config_new();
if (pw_daemon_config_load(config, &err) < 0) {
@@ -49,7 +93,7 @@ int main(int argc, char *argv[])
return -1;
}
- props = pw_properties_new(PW_CORE_PROP_NAME, "pipewire-0",
+ props = pw_properties_new(PW_CORE_PROP_NAME, daemon_name,
PW_CORE_PROP_DAEMON, "1", NULL);
loop = pw_main_loop_new(props);