added dlog plugin, and default dlog logger for native resources 88/68488/7 accepted/tizen/common/20160513.123222 accepted/tizen/ivi/20160513.004146 accepted/tizen/mobile/20160513.004024 accepted/tizen/tv/20160513.004124 accepted/tizen/wearable/20160513.004050 submit/tizen/20160512.051443
authorIevgen Vagin <i.vagin@samsung.com>
Wed, 4 May 2016 18:52:06 +0000 (21:52 +0300)
committerIevgen Vagin <i.vagin@samsung.com>
Wed, 11 May 2016 09:22:44 +0000 (12:22 +0300)
Note: to enable plugin, it has to be loaded in configuration file
      (/etc/murphy/murphy.lua) by m:try_load_plugin('dlog') command;
      dlog support is enabled by default; use --disable-dlog
      configure command to build without dlog support

Change-Id: I1e85f52a5ac58f24e1639e4b2945e9555b79289b
Signed-off-by: Ievgen Vagin <i.vagin@samsung.com>
configure.ac
packaging/murphy.spec
packaging/murphyd.service
src/Makefile.am
src/plugins/plugin-dlog.c [new file with mode: 0644]
src/plugins/resource-native/libmurphy-resource/resource-log.c

index 032758466363e4b9b7225abebb977fa9e11f2731..9afa18bbfdf29768fad43d0d5352800052c57bf3 100644 (file)
@@ -463,6 +463,30 @@ AC_SUBST(SYSTEMD_ENABLED)
 AC_SUBST(SYSTEMD_CFLAGS)
 AC_SUBST(SYSTEMD_LIBS)
 
+# Check if dlog support should be enabled.
+AC_ARG_ENABLE(dlog,
+              [  --enable-dlog          enable dlog support],
+          [enable_dlog=$enableval], [enable_dlog=auto])
+
+if test "$enable_dlog" != "no"; then
+    PKG_CHECK_MODULES(DLOG, dlog, [have_dlog=yes], [have_dlog=no])
+    if test "$have_dlog" = "no" -a "$enable_dlog" = "yes"; then
+        AC_MSG_ERROR([dlog development libraries not found.])
+    fi
+
+    enable_dlog="$have_dlog"
+else
+    AC_MSG_NOTICE([dlog support is disabled.])
+fi
+
+if test "$enable_dlog" = "yes"; then
+    AC_DEFINE([DLOG_ENABLED], 1, [Enable dlog support ?])
+fi
+AM_CONDITIONAL(DLOG_ENABLED, [test "$enable_dlog" = "yes"])
+AC_SUBST(DLOG_ENABLED)
+AC_SUBST(DLOG_CFLAGS)
+AC_SUBST(DLOG_LIBS)
+
 # Set up murphy CFLAGS and LIBS.
 MURPHY_CFLAGS=""
 MURPHY_LIBS=""
@@ -508,7 +532,7 @@ esac
 internal=""; it=""
 external=""; et=""
 disabled=""; dt=""
-for plugin in $all_plugins; do 
+for plugin in $all_plugins; do
     type=internal
 
     for p in ${dynamic_plugins//,/ }; do
@@ -564,6 +588,7 @@ AM_CONDITIONAL(DISABLED_PLUGIN_RESOURCE_WRT, [check_if_disabled resource-wrt])
 AM_CONDITIONAL(DISABLED_PLUGIN_DOMAIN_CONTROL,
                [check_if_disabled domain-control])
 AM_CONDITIONAL(DISABLED_PLUGIN_SYSTEMD,  [check_if_disabled systemd])
+AM_CONDITIONAL(DISABLED_PLUGIN_DLOG,  [check_if_disabled dlog])
 
 AM_CONDITIONAL(BUILTIN_PLUGIN_TEST,     [check_if_internal test])
 AM_CONDITIONAL(BUILTIN_PLUGIN_DBUS,     [check_if_internal dbus])
@@ -575,9 +600,10 @@ AM_CONDITIONAL(BUILTIN_PLUGIN_DOMAIN_CONTROL,
                [check_if_internal domain-control])
 AM_CONDITIONAL(BUILTIN_PLUGIN_LUA,      [check_if_internal lua])
 AM_CONDITIONAL(BUILTIN_PLUGIN_SYSTEMD,  [check_if_internal systemd])
+AM_CONDITIONAL(BUILTIN_PLUGIN_DLOG,  [check_if_internal dlog])
 
 # Check for Check (unit test framework).
-PKG_CHECK_MODULES(CHECK, 
+PKG_CHECK_MODULES(CHECK,
                   check >= 0.9.4,
                   [has_check="yes"], [has_check="no"])
 AM_CONDITIONAL(HAVE_CHECK, test "x$has_check" = "xyes")
index 285e28bbcd6cd30e190e4e71ce18b5969d67aa98..f8de76c025e684c8fecb2aac4e6566957c4d3373 100644 (file)
@@ -45,6 +45,7 @@ BuildRequires: bison
 BuildRequires: pkgconfig(lua)
 BuildRequires: pkgconfig(libsystemd-daemon)
 BuildRequires: pkgconfig(libsystemd-journal)
+BuildRequires: pkgconfig(dlog)
 #BuildRequires: pkgconfig(libcap)
 #BuildRequires: pkgconfig(libtzplatform-config)
 #%if %{with pulse}
@@ -489,4 +490,3 @@ ldconfig
 %{_bindir}/test-domain-controller
 %{_bindir}/murphy-console
 %manifest murphy.manifest
-
index 8b6fda2aabc99efda2be77dfdb59d11f5775414c..60842b1ee167ad5964c9d4216e89c5af62cd0fa3 100644 (file)
@@ -3,7 +3,7 @@ Description=Murphy Resource Policy Daemon
 
 [Service]
 Type=simple
-ExecStart=/usr/bin/murphyd -t systemd -vvv -f
+ExecStart=/usr/bin/murphyd -t dlog -vvv -f
 KillSignal=SIGTERM
 
 [Install]
index 605de80a122fe855829a085b3a1919155da39c43..07be7eafaa3c424bb0d2a9e76540e45d2e6acff7 100644 (file)
@@ -1051,6 +1051,11 @@ libmurphy_resource_la_LDFLAGS =  \
 libmurphy_resource_la_LIBADD =      \
                libmurphy-common.la
 
+if DLOG_ENABLED
+libmurphy_resource_la_CFLAGS += $(DLOG_CFLAGS) -DDLOG_ENABLED
+libmurphy_resource_la_LIBADD += $(DLOG_LIBS)
+endif
+
 libmurphy_resource_la_DEPENDENCIES =   \
                libmurphy-common.la     \
                linker-script.resource  \
@@ -1426,6 +1431,30 @@ endif
 endif
 endif
 
+# dlog (logging) plugin
+if DLOG_ENABLED
+DLOG_PLUGIN_SOURCES = plugins/plugin-dlog.c
+DLOG_PLUGIN_CFLAGS  = $(DLOG_CFLAGS)
+DLOG_PLUGIN_LIBS    = $(DLOG_LIBS)
+
+if !DISABLED_PLUGIN_DLOG
+if BUILTIN_PLUGIN_DLOG
+BUILTIN_PLUGINS += $(DLOG_PLUGIN_SOURCES)
+BUILTIN_CFLAGS  += $(DLOG_PLUGIN_CFLAGS)
+BUILTIN_LIBS    += $(DLOG_PLUGIN_LIBS)
+else
+plugin_dlog_la_SOURCES = $(DLOG_PLUGIN_SOURCES)
+plugin_dlog_la_CFLAGS  = $(DLOG_PLUGIN_CFLAGS) \
+                            $(MURPHY_CFLAGS) \
+                            $(AM_CFLAGS)
+plugin_dlog_la_LDFLAGS = -module -avoid-version
+plugin_dlog_la_LIBADD  = $(DLOG_PLUGIN_LIBS)
+
+plugin_LTLIBRARIES += plugin-dlog.la
+endif
+endif
+endif
+
 
 ###################################
 # murphy daemon
diff --git a/src/plugins/plugin-dlog.c b/src/plugins/plugin-dlog.c
new file mode 100644 (file)
index 0000000..be99417
--- /dev/null
@@ -0,0 +1,72 @@
+#include <stdlib.h>
+#include <dlog.h>
+
+#include <murphy/common.h>
+#include <murphy/core.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "MURPHYD"
+
+/* Logger function */
+
+static void dlogger(void *data, mrp_log_level_t level, const char *file,
+                     int line, const char *func, const char *format, va_list ap)
+{
+    va_list cp;
+    int     prio;
+    char    fbuf[1024];
+
+    MRP_UNUSED(data);
+
+    va_copy(cp, ap);
+    switch (level) {
+    case MRP_LOG_ERROR:   prio = DLOG_ERROR;    break;
+    case MRP_LOG_WARNING: prio = DLOG_WARN;     break;
+    case MRP_LOG_INFO:    prio = DLOG_INFO;     break;
+    case MRP_LOG_DEBUG:   prio = DLOG_DEBUG;    break;
+    default:              prio = DLOG_INFO;
+    }
+
+    snprintf(fbuf, sizeof(fbuf), "%s: %s(%d) > %s", file, func, line, format);
+    dlog_vprint(prio, LOG_TAG, fbuf, cp);
+
+    va_end(cp);
+}
+
+/* Plugin initialization */
+
+static int dlogger_init(mrp_plugin_t *plugin)
+{
+    MRP_UNUSED(plugin);
+
+    if (mrp_log_register_target("dlog", dlogger, NULL))
+        mrp_log_info("dlog: registered logging target.");
+    else
+        mrp_log_error("dlog: failed to register logging target.");
+
+    return TRUE;
+}
+
+/* Plugin deinitialization */
+
+static void dlogger_exit(mrp_plugin_t *plugin)
+{
+    MRP_UNUSED(plugin);
+
+    mrp_log_unregister_target("dlog");
+
+    return;
+}
+
+#define DLOGGER_DESCRIPTION "A dlog based logger for Murphy."
+#define DLOGGER_HELP        "dlog logger support for Murphy."
+#define DLOGGER_VERSION     MRP_VERSION_INT(0, 0, 1)
+#define DLOGGER_AUTHORS     "Ievgen Vagin <i.vagin@samsung.com>"
+
+MURPHY_REGISTER_PLUGIN("dlog",
+                       DLOGGER_VERSION, DLOGGER_DESCRIPTION,
+                       DLOGGER_AUTHORS, DLOGGER_HELP, MRP_SINGLETON,
+                       dlogger_init, dlogger_exit,
+                       NULL, 0, NULL, 0, NULL, 0, NULL);
index d5433f92413d990678ab5d15a9b63e2ccfe2da5d..e1a0e8fbdf6d5088322982ebf4e1203d9b39b978 100644 (file)
 #include "resource-api.h"
 #include "resource-private.h"
 
+#ifdef DLOG_ENABLED
+#include <dlog.h>
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "MURPHY_RESOURCE"
+#endif
+
 static void default_logger(mrp_log_level_t level, const char *file,
                            int line, const char *func,
                            const char *format, va_list args)
+#ifdef DLOG_ENABLED
+{
+    va_list cp;
+    int     prio;
+    char    fbuf[1024];
+
+    va_copy(cp, args);
+    switch (level) {
+    case MRP_LOG_ERROR:   prio = DLOG_ERROR;    break;
+    case MRP_LOG_WARNING: prio = DLOG_WARN;     break;
+    case MRP_LOG_INFO:    prio = DLOG_INFO;     break;
+    case MRP_LOG_DEBUG:   prio = DLOG_DEBUG;    break;
+    default:              prio = DLOG_INFO;
+    }
+
+    snprintf(fbuf, sizeof(fbuf), "%s: %s(%d) > %s", file, func, line, format);
+    dlog_vprint(prio, LOG_TAG, fbuf, cp);
+
+    va_end(cp);
+}
+#else
 {
     va_list ap;
 
@@ -43,7 +72,7 @@ static void default_logger(mrp_log_level_t level, const char *file,
     mrp_log_msgv(level, file, line, func, format, ap);
     va_end(ap);
 }
-
+#endif
 
 static mrp_res_logger_t __res_logger = default_logger;