aboutsummaryrefslogtreecommitdiff
path: root/src/mm-context.c
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-02-05 08:38:30 +0100
committerGuido Günther <agx@sigxcpu.org>2014-02-05 08:38:30 +0100
commit13ed135b9ae78c692dc359976eb8b54d0a3629b8 (patch)
treeae2ea713ad51d73980cf83db1411d6589dac5e8b /src/mm-context.c
parent14d771b90f5a7d3887e5e900d1fb4737477ad305 (diff)
Imported Upstream version 0.7.991upstream/0.7.991
Diffstat (limited to 'src/mm-context.c')
-rw-r--r--src/mm-context.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/mm-context.c b/src/mm-context.c
new file mode 100644
index 0000000..4a44456
--- /dev/null
+++ b/src/mm-context.c
@@ -0,0 +1,91 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details:
+ *
+ * Copyright (C) 2012 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#include <stdlib.h>
+
+#include "mm-context.h"
+
+/* Application context */
+static gboolean debug;
+static const gchar *log_level;
+static const gchar *log_file;
+static gboolean show_ts;
+static gboolean rel_ts;
+
+static const GOptionEntry entries[] = {
+ { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Run with extended debugging capabilities", NULL },
+ { "log-level", 0, 0, G_OPTION_ARG_STRING, &log_level, "Log level: one of [ERR, WARN, INFO, DEBUG]", "INFO" },
+ { "log-file", 0, 0, G_OPTION_ARG_STRING, &log_file, "Path to log file", NULL },
+ { "timestamps", 0, 0, G_OPTION_ARG_NONE, &show_ts, "Show timestamps in log output", NULL },
+ { "relative-timestamps", 0, 0, G_OPTION_ARG_NONE, &rel_ts, "Use relative timestamps (from MM start)", NULL },
+ { NULL }
+};
+
+gboolean
+mm_context_get_debug (void)
+{
+ return debug;
+}
+
+const gchar *
+mm_context_get_log_level (void)
+{
+ return log_level;
+}
+
+const gchar *
+mm_context_get_log_file (void)
+{
+ return log_file;
+}
+
+gboolean
+mm_context_get_timestamps (void)
+{
+ return show_ts;
+}
+
+gboolean
+mm_context_get_relative_timestamps (void)
+{
+ return rel_ts;
+}
+
+void
+mm_context_init (gint argc,
+ gchar **argv)
+{
+ GError *error = NULL;
+ GOptionContext *ctx;
+
+ ctx = g_option_context_new (NULL);
+ g_option_context_set_summary (ctx, "DBus system service to communicate with modems.");
+ g_option_context_add_main_entries (ctx, entries, NULL);
+
+ if (!g_option_context_parse (ctx, &argc, &argv, &error)) {
+ g_warning ("%s\n", error->message);
+ g_error_free (error);
+ exit (1);
+ }
+
+ g_option_context_free (ctx);
+
+ /* Additional setup to be done on debug mode */
+ if (debug) {
+ log_level = "DEBUG";
+ if (!show_ts && !rel_ts)
+ show_ts = TRUE;
+ }
+}