Re: [PATCH 1/2] plugins: Add logcontrol plugin

2015-01-20 Thread Slava Monich



This plugin implements net.connman.DebugLog D-Bus interface which
allows changing debug log settings at runtime without restarting
connman.
---
  Makefile.plugins |   5 ++
  configure.ac |   5 ++
  plugins/logcontrol.c | 198 +++
  3 files changed, 208 insertions(+)
  create mode 100644 plugins/logcontrol.c


It was just noticed that --enable-logcontrol description is wrong, 
enable jolla GPS support needs to be replaced with something that 
makes more sense. I can resubmit the patch if necessary.


Regards,
-Slava
___
connman mailing list
connman@connman.net
https://lists.connman.net/mailman/listinfo/connman


[PATCH 1/2] plugins: Add logcontrol plugin

2015-01-19 Thread Slava Monich
This plugin implements net.connman.DebugLog D-Bus interface which
allows changing debug log settings at runtime without restarting
connman.
---
 Makefile.plugins |   5 ++
 configure.ac |   5 ++
 plugins/logcontrol.c | 198 +++
 3 files changed, 208 insertions(+)
 create mode 100644 plugins/logcontrol.c

diff --git a/Makefile.plugins b/Makefile.plugins
index e90ad19..a1f6f95 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -55,6 +55,11 @@ builtin_modules += dundee
 builtin_sources += plugins/dundee.c
 endif
 
+if LOGCONTROL
+builtin_modules += logcontrol
+builtin_sources += plugins/logcontrol.c
+endif
+
 if VPN
 builtin_modules += vpn
 builtin_sources += plugins/vpn.c
diff --git a/configure.ac b/configure.ac
index e3326ad..bc2b47d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -326,6 +326,11 @@ AC_ARG_ENABLE(wispr, AC_HELP_STRING([--disable-wispr],
[enable_wispr=${enableval}])
 AM_CONDITIONAL(WISPR, test ${enable_wispr} != no)
 
+AC_ARG_ENABLE(logcontrol,
+   AC_HELP_STRING([--enable-logcontrol], [enable jolla GPS support]),
+   [enable_logcontrol=${enableval}], 
[enable_logcontrol=no])
+AM_CONDITIONAL(LOGCONTROL, test ${enable_logcontrol} != no)
+
 AC_ARG_ENABLE(tools, AC_HELP_STRING([--disable-tools],
[disable testing tools]),
[enable_tools=${enableval}])
diff --git a/plugins/logcontrol.c b/plugins/logcontrol.c
new file mode 100644
index 000..203fe7b
--- /dev/null
+++ b/plugins/logcontrol.c
@@ -0,0 +1,198 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2015 Jolla Ltd. All rights reserved.
+ *  Contact: Slava Monich slava.mon...@jolla.com
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  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.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+
+#include gdbus.h
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
+#include connman/plugin.h
+#include connman/log.h
+#include connman.h
+
+#define LOG_INTERFACE  CONNMAN_SERVICE .DebugLog
+#define LOG_PATH   /
+
+static DBusConnection *connection = NULL;
+
+extern struct connman_debug_desc __start___debug[];
+extern struct connman_debug_desc __stop___debug[];
+
+static void logcontrol_update(const char* pattern, unsigned int set_flags,
+   unsigned int clear_flags)
+{
+   struct connman_debug_desc *start = __start___debug;
+   struct connman_debug_desc *stop = __stop___debug;
+   struct connman_debug_desc *desc;
+   const char *alias = NULL, *file = NULL;
+
+   if (!start || !stop)
+   return;
+
+   for (desc = start; desc  stop; desc++) {
+   const char* name;
+
+   if (desc-flags  CONNMAN_DEBUG_FLAG_ALIAS) {
+   file = desc-file;
+   alias = desc-name;
+   continue;
+   }
+
+   if (file  g_strcmp0(desc-file, file)) {
+   file = NULL;
+   alias = NULL;
+   }
+
+   name = desc-name ? desc-name : alias;
+   if ((name  g_pattern_match_simple(pattern, name)) ||
+   (desc-file  g_pattern_match_simple(pattern,
+   desc-file))) {
+   desc-flags |= set_flags;
+   desc-flags = ~clear_flags;
+   }
+   }
+}
+
+static DBusMessage *logcontrol_dbusmsg(DBusConnection *conn, DBusMessage *msg,
+   unsigned int set_flags, unsigned int clear_flags)
+{
+   const char *pattern;
+
+   if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, pattern,
+   DBUS_TYPE_INVALID)) {
+   logcontrol_update(pattern, set_flags, clear_flags);
+   return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+   } else {
+   return __connman_error_invalid_arguments(msg);
+   }
+}
+
+static DBusMessage *logcontrol_enable(DBusConnection *conn,
+   DBusMessage *msg, void *data)
+{
+   return logcontrol_dbusmsg(conn, msg, CONNMAN_DEBUG_FLAG_PRINT, 0);
+}
+
+static DBusMessage *logcontrol_disable(DBusConnection *conn,
+