Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mms-engine] Hooked up logging over D-Bus. JB#50406
  • Loading branch information
monich committed Jul 8, 2020
1 parent 16c6b2f commit e1c516c
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 39 deletions.
4 changes: 2 additions & 2 deletions mms-engine/Makefile
Expand Up @@ -17,7 +17,7 @@ include ../mms-lib/Config.mak
# Required packages
#

PKGS = gio-unix-2.0 gio-2.0 libdbusaccess libglibutil
PKGS = gio-unix-2.0 gio-2.0 libdbusaccess libglibutil libdbuslogserver-gio
LIB_PKGS = libwspcodec gmime-2.6 libgofono libsoup-2.4 dconf

ifdef SAILFISH
Expand All @@ -36,7 +36,7 @@ all: debug release
# Sources
#

SRC = main.c mms_engine.c
SRC = main.c mms_engine.c mms_log.c
GEN_SRC = org.nemomobile.MmsEngine.c

#
Expand Down
4 changes: 4 additions & 0 deletions mms-engine/main.c
Expand Up @@ -398,6 +398,7 @@ mms_app_parse_options(
char* root_dir = NULL;
gboolean log_modules = FALSE;
gboolean keep_running = FALSE;
gboolean disable_dbus_log = FALSE;
gint size_limit_kb = -1;
gdouble megapixels = -1;
char* root_dir_help = g_strdup_printf(
Expand Down Expand Up @@ -455,6 +456,8 @@ 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" },
{ "disable-dbus-log", 'D', 0, G_OPTION_ARG_NONE, &disable_dbus_log,
"Disable logging over D-Bus", NULL },
{ "log-modules", 0, 0, G_OPTION_ARG_NONE, &log_modules,
"List available log modules", NULL },
#ifdef MMS_VERSION_STRING
Expand Down Expand Up @@ -580,6 +583,7 @@ mms_app_parse_options(
root_dir = NULL;
}
if (keep_running) opt->flags |= MMS_ENGINE_FLAG_KEEP_RUNNING;
if (disable_dbus_log) opt->flags |= MMS_ENGINE_FLAG_DISABLE_DBUS_LOG;
if (session_bus) {
GDEBUG("Attaching to session bus");
opt->dbus.type = G_BUS_TYPE_SESSION;
Expand Down
6 changes: 4 additions & 2 deletions mms-engine/mms-engine.pro
@@ -1,7 +1,7 @@
TEMPLATE = app
CONFIG += link_pkgconfig
PKGCONFIG += gmime-2.6 gio-unix-2.0 gio-2.0 glib-2.0 libsoup-2.4 dconf
PKGCONFIG += libwspcodec libgofono libdbusaccess libglibutil
PKGCONFIG += libwspcodec libgofono libdbusaccess libglibutil libdbuslogserver-gio
QMAKE_CFLAGS += -Wno-unused-parameter

include(../mms-lib/mms-lib-config.pri)
Expand Down Expand Up @@ -34,9 +34,11 @@ INCLUDEPATH += $$MMS_TRANSFER_LIST_DIR/include

SOURCES += \
main.c \
mms_engine.c
mms_engine.c \
mms_log.c
HEADERS += \
mms_engine.h \
mms_log.h \
mms_version.h
OTHER_FILES += \
org.nemomobile.MmsEngine.push.conf \
Expand Down
56 changes: 37 additions & 19 deletions mms-engine/mms_engine.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2019 Jolla Ltd.
* Copyright (C) 2013-2019 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2019 Open Mobile Platform LLC.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -14,6 +14,8 @@
*/

#include "mms_engine.h"
#include "mms_log.h"

#include "mms_dispatcher.h"
#include "mms_settings.h"
#include "mms_lib_util.h"
Expand All @@ -32,6 +34,8 @@
/* Generated code */
#include "org.nemomobile.MmsEngine.h"

#include <dbuslog_util.h>

#include <dbusaccess_peer.h>
#include <dbusaccess_policy.h>

Expand All @@ -54,7 +58,7 @@ struct mms_engine {
MMSSettings* settings;
MMSDispatcher* dispatcher;
MMSDispatcherDelegate dispatcher_delegate;
MMSLogModule** log_modules;
MMSLog* log;
DAPolicy* dbus_access;
DA_BUS da_bus;
GDBusConnection* engine_bus;
Expand All @@ -63,6 +67,7 @@ struct mms_engine {
gboolean stopped;
gboolean stop_requested;
gboolean keep_running;
gboolean disable_dbus_log;
guint idle_timer_id;
gulong proxy_signal_id[MMS_ENGINE_METHOD_COUNT];
};
Expand Down Expand Up @@ -453,20 +458,9 @@ mms_engine_handle_set_log_level(
if (mms_engine_dbus_access_allowed(engine, call,
MMS_ENGINE_ACTION_SET_LOG_LEVEL)) {
GDEBUG_("%s:%d", module, level);
if (module && module[0]) {
MMSLogModule** ptr = engine->log_modules;

while (*ptr) {
MMSLogModule* log = *ptr++;

if (log->name && log->name[0] && !strcmp(log->name, module)) {
log->level = level;
break;
}
}
} else {
gutil_log_default.level = level;
}
dbus_log_server_set_category_level(engine->log->server,
module[0] ? module : gutil_log_default.name,
dbus_log_level_from_gutil(level));
org_nemomobile_mms_engine_complete_set_log_level(proxy, call);
}
mms_engine_idle_timer_check(engine);
Expand Down Expand Up @@ -599,10 +593,14 @@ mms_engine_new(
mms->keep_running = TRUE;
}

if (flags & MMS_ENGINE_FLAG_DISABLE_DBUS_LOG) {
mms->disable_dbus_log = TRUE;
}

mms->cm = cm;
mms->config = config;
mms->settings = settings;
mms->log_modules = log_modules;
mms->log = mms_log_new(dbus->type, log_modules);
mms->dbus_access = da_policy_ref(dbus->engine_access);
mms->da_bus = (dbus->type == G_BUS_TYPE_SESSION) ?
DA_BUS_SESSION : DA_BUS_SYSTEM;
Expand Down Expand Up @@ -664,14 +662,19 @@ mms_engine_run(
MMSEngine* engine,
GMainLoop* loop)
{
DBusLogServer* logger = engine->disable_dbus_log ? NULL :
engine->log->server;

GASSERT(!engine->loop);
engine->loop = loop;
engine->stopped = FALSE;
engine->stop_requested = FALSE;
mms_dispatcher_start(engine->dispatcher);
dbus_log_server_start(logger);
mms_engine_idle_timer_check(engine);
g_main_loop_run(loop);
mms_engine_idle_timer_stop(engine);
dbus_log_server_stop(logger);
engine->loop = NULL;
}

Expand Down Expand Up @@ -777,10 +780,24 @@ mms_engine_dispose(
mms_connman_unref(mms->cm);
mms->cm = NULL;
}
da_policy_unref(mms->dbus_access);
G_OBJECT_CLASS(mms_engine_parent_class)->dispose(object);
}

/**
* Final stage of deinitialization
*/
static
void
mms_engine_finalize(
GObject* object)
{
MMSEngine* engine = MMS_ENGINE(object);
GVERBOSE_("%p", engine);
da_policy_unref(engine->dbus_access);
mms_log_free(engine->log);
G_OBJECT_CLASS(mms_engine_parent_class)->finalize(object);
}

/**
* Per class initializer
*/
Expand All @@ -792,6 +809,7 @@ mms_engine_class_init(
GObjectClass* object_class = G_OBJECT_CLASS(klass);
GASSERT(object_class);
object_class->dispose = mms_engine_dispose;
object_class->finalize = mms_engine_finalize;
GVERBOSE_("done");
}

Expand Down
5 changes: 3 additions & 2 deletions mms-engine/mms_engine.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2019 Jolla Ltd.
* Copyright (C) 2013-2019 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2020 Jolla Ltd.
* Copyright (C) 2013-2020 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2019 Open Mobile Platform LLC.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -32,6 +32,7 @@
#define MMS_ENGINE_FLAG_OVERRIDE_SIZE_LIMIT (0x04)
#define MMS_ENGINE_FLAG_OVERRIDE_MAX_PIXELS (0x08)
#define MMS_ENGINE_FLAG_OVERRIDE_UAPROF (0x10)
#define MMS_ENGINE_FLAG_DISABLE_DBUS_LOG (0x20)

#ifndef MMS_ENGINE_CONFIG_FILE
/* Default config file */
Expand Down

0 comments on commit e1c516c

Please sign in to comment.