aboutsummaryrefslogtreecommitdiff
path: root/src/mm-context.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-02-28 23:09:10 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-16 14:53:18 +0100
commit952b9164b9ae2af4d1fd18f77d4b97bfa4d78eab (patch)
tree23ddfedb9607b393ee82120d852bfecd83c4248f /src/mm-context.c
parent1701230f5164087bd7c279c35c8797ae1e80f0d5 (diff)
context: new source files to keep the daemon context
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 00000000..4a44456a
--- /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;
+ }
+}