Skip to content

Commit

Permalink
[mms-engine] Added option to print mms-engine version
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Apr 17, 2014
1 parent 96462e1 commit e831cf3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions mms-engine/Makefile
Expand Up @@ -96,6 +96,10 @@ RELEASE_FLAGS += -g
SUBMAKE_OPTS += KEEP_SYMBOLS=1
endif

ifdef MMS_VERSION
CFLAGS += -DMMS_VERSION="$(MMS_VERSION)"
endif

DEBUG_CFLAGS = $(DEBUG_FLAGS) $(DEBUG_DEFS) $(CFLAGS)
RELEASE_CFLAGS = $(RELEASE_FLAGS) $(RELEASE_DEFS) $(CFLAGS)

Expand Down
36 changes: 31 additions & 5 deletions mms-engine/main.c
Expand Up @@ -21,6 +21,9 @@
#include "mms_lib_util.h"
#include "mms_dispatcher.h"

#define RET_OK (0)
#define RET_ERR (1)

/* Options configurable from the command line */
typedef struct mms_app_options {
GBusType bus_type;
Expand Down Expand Up @@ -138,17 +141,25 @@ mms_app_option_verbose(
return TRUE;
}

/* Parses command line and sets up application options */
/**
* Parses command line and sets up application options. Returns TRUE if
* we should go ahead and run the application, FALSE if we should exit
* immediately.
*/
static
gboolean
mms_app_parse_options(
MMSAppOptions* opt,
int argc,
char* argv[])
char* argv[],
int* result)
{
gboolean ok;
GError* error = NULL;
gboolean session_bus = FALSE;
#ifdef MMS_VERSION
gboolean print_version = FALSE;
#endif
gint size_limit_kb = opt->config.size_limit/1024;
gdouble megapixels = opt->config.max_pixels / 1000000.0;
char* root_dir_help = g_strdup_printf(
Expand Down Expand Up @@ -198,6 +209,10 @@ mms_app_parse_options(
"Log output (stdout|syslog|glib) [stdout]", "TYPE" },
{ "log-level", 'l', 0, G_OPTION_ARG_CALLBACK, mms_app_option_loglevel,
"Set log level (repeatable)", "[MODULE:]LEVEL" },
#ifdef MMS_VERSION
{ "version", 0, 0, G_OPTION_ARG_NONE, &print_version,
"Print program version and exit", NULL },
#endif
{ NULL }
};

Expand All @@ -213,6 +228,16 @@ mms_app_parse_options(
g_free(megapixels_help);
g_free(description);

#ifdef MMS_VERSION
# define MMS_STRING__(x) #x
# define MMS_STRING_(x) MMS_STRING__(x)
if (print_version) {
printf("MMS engine %s\n", MMS_STRING_(MMS_VERSION));
*result = RET_OK;
return FALSE;
} else
#endif

if (ok) {
MMS_INFO("Starting");
if (size_limit_kb >= 0) {
Expand All @@ -233,22 +258,24 @@ mms_app_parse_options(
MMS_DEBUG("Attaching to system bus");
opt->bus_type = G_BUS_TYPE_SYSTEM;
}
*result = RET_OK;
return TRUE;
} else {
fprintf(stderr, "%s\n", MMS_ERRMSG(error));
g_error_free(error);
*result = RET_ERR;
return FALSE;
}
}

int main(int argc, char* argv[])
{
int result = 1;
int result = RET_ERR;
MMSAppOptions opt = {0};
mms_lib_init(argv[0]);
mms_log_default.name = MMS_APP_LOG_PREFIX;
mms_lib_default_config(&opt.config);
if (mms_app_parse_options(&opt, argc, argv)) {
if (mms_app_parse_options(&opt, argc, argv, &result)) {
MMSEngine* engine;
unsigned int engine_flags = 0;
if (opt.keep_running) engine_flags |= MMS_ENGINE_FLAG_KEEP_RUNNING;
Expand Down Expand Up @@ -278,7 +305,6 @@ int main(int argc, char* argv[])
mms_engine_unref(engine);
}
MMS_INFO("Exiting");
result = 0;
}
if (mms_log_func == mms_log_syslog) {
closelog();
Expand Down
2 changes: 1 addition & 1 deletion rpm/mms-engine.spec
Expand Up @@ -44,7 +44,7 @@ MMS command line utilities
%setup -q -n %{name}-%{version}

%build
make -C %{src} KEEP_SYMBOLS=1 release
make -C %{src} KEEP_SYMBOLS=1 MMS_VERSION="%{version}" release
make -C mms-dump KEEP_SYMBOLS=1 release
make -C mms-send KEEP_SYMBOLS=1 release

Expand Down

0 comments on commit e831cf3

Please sign in to comment.