From ccf1630f39874e22a589e809c491536b5ded1064 Mon Sep 17 00:00:00 2001 From: Julian Bouzas Date: Tue, 26 Jul 2022 16:02:02 -0400 Subject: [PATCH] main: add --version flag to show current version Fixes #317 --- lib/wp/wp.c | 20 ++++++++++++++++++++ lib/wp/wp.h | 6 ++++++ src/main.c | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/lib/wp/wp.c b/lib/wp/wp.c index 2175aae0..b13858d9 100644 --- a/lib/wp/wp.c +++ b/lib/wp/wp.c @@ -67,6 +67,26 @@ wp_init (WpInitFlags flags) g_type_ensure (WP_TYPE_FACTORY); } +/*! + * \brief Gets the WirePlumber library version + * \returns WirePlumber library version + */ +const char * +wp_get_library_version (void) +{ + return WIREPLUMBER_VERSION; +} + +/*! + * \brief Gets the WirePlumber library API version + * \returns WirePlumber library API version + */ +const char * +wp_get_library_api_version (void) +{ + return WIREPLUMBER_API_VERSION; +} + /*! * \brief Gets the WirePlumber module directory * \returns WirePlumber's module directory diff --git a/lib/wp/wp.h b/lib/wp/wp.h index fa09efa8..4e13391b 100644 --- a/lib/wp/wp.h +++ b/lib/wp/wp.h @@ -66,6 +66,12 @@ typedef enum { WP_API void wp_init (WpInitFlags flags); +WP_API +const char * wp_get_library_version (void); + +WP_API +const char * wp_get_library_api_version (void); + WP_API const gchar * wp_get_module_dir (void); diff --git a/src/main.c b/src/main.c index 8c791834..0e5f109b 100644 --- a/src/main.c +++ b/src/main.c @@ -24,10 +24,13 @@ enum WpExitCode WP_EXIT_CONFIG = 78, /* configuration error */ }; +static gboolean show_version = FALSE; static gchar * config_file = NULL; static GOptionEntry entries[] = { + { "version", 'v', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &show_version, + "Show version", NULL }, { "config-file", 'c', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &config_file, "The context configuration file", NULL }, { NULL } @@ -427,6 +430,16 @@ main (gint argc, gchar **argv) return WP_EXIT_USAGE; } + if (show_version) { + g_print ("%s\n" + "Compiled with libwireplumber %s\n" + "Linked with libwireplumber %s\n", + argv[0], + WIREPLUMBER_VERSION, + wp_get_library_version()); + return WP_EXIT_OK; + } + if (!config_file) config_file = "wireplumber.conf";