Commit e1c516cf authored by Slava Monich's avatar Slava Monich

[mms-engine] Hooked up logging over D-Bus. JB#50406

parent 16c6b2f8
......@@ -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
......@@ -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
#
......
......@@ -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(
......@@ -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
......@@ -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;
......
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)
......@@ -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 \
......
/*
* 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
......@@ -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"
......@@ -32,6 +34,8 @@
/* Generated code */
#include "org.nemomobile.MmsEngine.h"
#include <dbuslog_util.h>
#include <dbusaccess_peer.h>
#include <dbusaccess_policy.h>
......@@ -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;
......@@ -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];
};
......@@ -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);
......@@ -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;
......@@ -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;
}
......@@ -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
*/
......@@ -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");
}
......
/*
* 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
......@@ -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 */
......
/*
* Copyright (C) 2020 Jolla Ltd.
* Copyright (C) 2020 Slava Monich <slava.monich@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.
*/
#include "mms_log.h"
#include <dbuslog_server_gio.h>
#include <dbuslog_util.h>
#include <gutil_log.h>
#include <gutil_macros.h>
enum {
DBUSLOG_EVENT_CATEGORY_ENABLED,
DBUSLOG_EVENT_CATEGORY_DISABLED,
DBUSLOG_EVENT_CATEGORY_LEVEL_CHANGED,
DBUSLOG_EVENT_DEFAULT_LEVEL_CHANGED,
DBUSLOG_EVENT_COUNT
};
typedef struct mms_log_priv {
MMSLog log;
GHashTable* map;
gulong event_id[DBUSLOG_EVENT_COUNT];
GLogProc2 default_func;
} MMSLogPriv;
static MMSLogPriv* mms_log_active = NULL;
static
void
mms_log_func(
MMSLogPriv* self,
const GLogModule* log,
int level,
const char* format,
va_list va)
{
va_list va2;
va_copy(va2, va);
dbus_log_server_logv(self->log.server, dbus_log_level_from_gutil(level),
log->name, format, va2);
va_end(va2);
if (self->default_func) {
self->default_func(log, level, format, va);
}
}
static
void
mms_log_hook(
const GLogModule* log,
int level,
const char* format,
va_list va)
{
if (mms_log_active) {
mms_log_func(mms_log_active, log, level, format, va);
}
}
static
void
mms_log_add_category(
MMSLogPriv* self,
GLogModule* module)
{
gulong flags = 0;
GVERBOSE("Adding \"%s\"", module->name);
g_hash_table_replace(self->map, (gpointer)module->name, module);
if (!(module->flags & GLOG_FLAG_DISABLE)) {
flags |= (DBUSLOG_CATEGORY_FLAG_ENABLED |
DBUSLOG_CATEGORY_FLAG_ENABLED_BY_DEFAULT);
}
if (module->flags & GLOG_FLAG_HIDE_NAME) {
flags |= DBUSLOG_CATEGORY_FLAG_HIDE_NAME;
}
dbus_log_server_add_category(self->log.server, module->name,
dbus_log_level_from_gutil(module->level), flags);
}
/*==========================================================================*
* Events
*==========================================================================*/
static
void
mms_log_category_enabled(
DBusLogServer* server,
const char* name,
gpointer user_data)
{
MMSLogPriv* self = user_data;
GLogModule* module = g_hash_table_lookup(self->map, name);
GASSERT(module);
if (module) {
module->flags &= ~GLOG_FLAG_DISABLE;
}
}
static
void
mms_log_category_disabled(
DBusLogServer* server,
const char* name,
gpointer user_data)
{
MMSLogPriv* self = user_data;
GLogModule* module = g_hash_table_lookup(self->map, name);
GASSERT(module);
if (module) {
module->flags |= GLOG_FLAG_DISABLE;
}
}
static
void
mms_log_category_level_changed(
DBusLogServer* server,
const char* name,
DBUSLOG_LEVEL dbus_level,
gpointer user_data)
{
MMSLogPriv* self = user_data;
GLogModule* module = g_hash_table_lookup(self->map, name);
const int level = dbus_log_level_to_gutil(dbus_level);
GASSERT(module);
if (module && level != GLOG_LEVEL_NONE) {
module->level = level;
}
}
static
void
mms_log_default_level_changed(
DBusLogServer* server,
DBUSLOG_LEVEL dbus_level,
gpointer user_data)
{
const int level = dbus_log_level_to_gutil(dbus_level);
if (level != GLOG_LEVEL_NONE) {
gutil_log_default.level = level;
}
}
/*==========================================================================*
* Interface
*==========================================================================*/
MMSLog*
mms_log_new(
GBusType bus,
GLogModule* modules[]) /* NULL terminated */
{
MMSLogPriv* self = g_new0(MMSLogPriv, 1);
GLogModule** ptr = modules;
self->log.server = dbus_log_server_new(bus, NULL, "/");
self->map = g_hash_table_new(g_str_hash, g_str_equal);
while (*ptr) {
mms_log_add_category(self, *ptr++);
}
self->event_id[DBUSLOG_EVENT_CATEGORY_ENABLED] =
dbus_log_server_add_category_enabled_handler(self->log.server,
mms_log_category_enabled, self);
self->event_id[DBUSLOG_EVENT_CATEGORY_DISABLED] =
dbus_log_server_add_category_disabled_handler(self->log.server,
mms_log_category_disabled, self);
self->event_id[DBUSLOG_EVENT_CATEGORY_LEVEL_CHANGED] =
dbus_log_server_add_category_level_handler(self->log.server,
mms_log_category_level_changed, self);
self->event_id[DBUSLOG_EVENT_DEFAULT_LEVEL_CHANGED] =
dbus_log_server_add_default_level_handler(self->log.server,
mms_log_default_level_changed, self);
mms_log_active = self;
self->default_func = gutil_log_func2;
gutil_log_func2 = mms_log_hook;
dbus_log_server_set_default_level(self->log.server,
dbus_log_level_from_gutil(gutil_log_default.level));
return &self->log;
}
void
mms_log_free(
MMSLog* log)
{
MMSLogPriv* self = G_CAST(log,MMSLogPriv,log);
if (mms_log_active == self) {
mms_log_active = NULL;
gutil_log_func2 = self->default_func;
}
dbus_log_server_remove_all_handlers(log->server, self->event_id);
dbus_log_server_unref(log->server);
g_hash_table_destroy(self->map);
g_free(self);
}
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
/*
* Copyright (C) 2020 Jolla Ltd.
* Copyright (C) 2020 Slava Monich <slava.monich@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.
*/
#ifndef JOLLA_MMS_LOG_H
#define JOLLA_MMS_LOG_H
#include <dbuslog_server.h>
#include <gutil_types.h>
#include <gio/gio.h>
typedef struct mms_log {
DBusLogServer* server;
} MMSLog;
MMSLog*
mms_log_new(
GBusType bus,
GLogModule* modules[]); /* NULL terminated */
void
mms_log_free(
MMSLog* log);
#endif /* JOLLA_MMS_LOG_H */
/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
......@@ -5,33 +5,46 @@ Release: 1
License: GPLv2
URL: https://git.sailfishos.org/mer-core/mms-engine
Source0: %{name}-%{version}.tar.bz2
%define glib_version 2.32
%define libsoup_version 2.38
%define libwspcodec_version 2.2
%define libgofono_version 2.0.0
%define libgofonoext_version 1.0.4
%define libglibutil_version 1.0.11
%define libdbusaccess_version 1.0.10
%define libdbuslog_version 1.0.19
Requires: dbus
Requires: ofono
Requires: libsoup >= 2.38
Requires: libwspcodec >= 2.2
Requires: libgofono >= 2.0.0
Requires: libgofonoext >= 1.0.4
Requires: libglibutil >= 1.0.5
Requires: libdbusaccess >= 1.0.10
Requires: glib2 >= %{glib_version}
Requires: libsoup >= %{libsoup_version}
Requires: libwspcodec >= %{libwspcodec_version}
Requires: libgofono >= %{libgofono_version}
Requires: libgofonoext >= %{libgofonoext_version}
Requires: libglibutil >= %{libglibutil_version}
Requires: libdbusaccess >= %{libdbusaccess_version}
Requires: libdbuslogserver-gio >= %{libdbuslog_version}
Requires(post): glib2
Requires(postun): glib2
BuildRequires: systemd
BuildRequires: file-devel
BuildRequires: libjpeg-turbo-devel
BuildRequires: pkgconfig(dconf)
BuildRequires: pkgconfig(libpng)
BuildRequires: pkgconfig(libexif)
BuildRequires: pkgconfig(gmime-2.6)
BuildRequires: pkgconfig(glib-2.0) >= 2.32
BuildRequires: pkgconfig(libsoup-2.4) >= 2.38
BuildRequires: pkgconfig(libwspcodec) >= 2.2
BuildRequires: pkgconfig(libgofono) >= 2.0.0
BuildRequires: pkgconfig(libgofonoext) >= 1.0.4
BuildRequires: pkgconfig(libglibutil) >= 1.0.11
BuildRequires: pkgconfig(libdbusaccess)
BuildRequires: pkgconfig(glib-2.0) >= %{glib_version}
BuildRequires: pkgconfig(libsoup-2.4) >= %{libsoup_version}
BuildRequires: pkgconfig(libwspcodec) >= %{libwspcodec_version}
BuildRequires: pkgconfig(libgofono) >= %{libgofono_version}
BuildRequires: pkgconfig(libgofonoext) >= %{libgofonoext_version}
BuildRequires: pkgconfig(libglibutil) >= %{libglibutil_version}
BuildRequires: pkgconfig(libdbusaccess) >= %{libdbusaccess_version}
BuildRequires: pkgconfig(libdbuslogserver-gio) >= %{libdbuslog_version}
#BuildRequires: pkgconfig(ImageMagick)
BuildRequires: pkgconfig(Qt5Gui)
BuildRequires: systemd
%define src mms-engine
%define exe mms-engine
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment