Skip to content

Commit

Permalink
[mms-engine] Separate network and service inactivity timeouts. JB#42837
Browse files Browse the repository at this point in the history
If "singleDataContext" option is enabled in ofono, it makes sense
to configure mms-engine to use shorter network inactivity timeout
so that data connection gets restored faster. Which shouldn't
affect the general service inactivity timeout.
  • Loading branch information
monich committed Nov 28, 2018
1 parent 67749b0 commit 6ed9ff7
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 133 deletions.
13 changes: 10 additions & 3 deletions mms-engine/main.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2018 Jolla Ltd.
* Copyright (C) 2013-2018 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
Expand Down Expand Up @@ -177,8 +177,11 @@ mms_app_parse_options(
char* retry_secs_help = g_strdup_printf(
"Retry period in seconds [%d]",
opt->global.config.retry_secs);
char* network_idle_secs_help = g_strdup_printf(
"Network inactivity timeout in seconds [%d]",
opt->global.config.network_idle_secs);
char* idle_secs_help = g_strdup_printf(
"Inactivity timeout in seconds [%d]",
"Service inactivity timeout in seconds [%d]",
opt->global.config.idle_secs);
char* description = gutil_log_description(NULL, 0);

Expand All @@ -194,6 +197,9 @@ mms_app_parse_options(
&root_dir, root_dir_help, "DIR" },
{ "retry-secs", 'r', 0, G_OPTION_ARG_INT,
&opt->global.config.retry_secs, retry_secs_help, "SEC" },
{ "network-idle-secs", 'n', 0, G_OPTION_ARG_INT,
&opt->global.config.network_idle_secs,
network_idle_secs_help, "SEC" },
{ "idle-secs", 'i', 0, G_OPTION_ARG_INT,
&opt->global.config.idle_secs, idle_secs_help, "SEC" },
{ "size-limit", 's', 0, G_OPTION_ARG_INT,
Expand Down Expand Up @@ -291,6 +297,7 @@ mms_app_parse_options(
g_free(root_dir_help);
g_free(retry_secs_help);
g_free(idle_secs_help);
g_free(network_idle_secs_help);
g_free(description);

if (!ok) {
Expand Down
74 changes: 39 additions & 35 deletions mms-engine/mms_engine.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2018 Jolla Ltd.
* Copyright (C) 2013-2018 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
Expand Down Expand Up @@ -65,7 +65,7 @@ struct mms_engine {
gboolean stopped;
gboolean stop_requested;
gboolean keep_running;
guint start_timeout_id;
guint idle_timer_id;
gulong proxy_signal_id[MMS_ENGINE_METHOD_COUNT];
};

Expand All @@ -88,7 +88,7 @@ mms_engine_stop_callback(
engine->stopped = TRUE;
if (engine->loop) g_main_loop_quit(engine->loop);
mms_engine_unref(engine);
return FALSE;
return G_SOURCE_REMOVE;
}

static
Expand All @@ -101,36 +101,38 @@ mms_engine_stop_schedule(

static
gboolean
mms_engine_start_timeout_callback(
mms_engine_idle_timer_expired(
gpointer data)
{
MMSEngine* engine = data;
GASSERT(engine->start_timeout_id);
GASSERT(engine->idle_timer_id);
GINFO("Shutting down due to inactivity...");
engine->start_timeout_id = 0;
engine->idle_timer_id = 0;
mms_engine_stop_schedule(engine);
return FALSE;
return G_SOURCE_REMOVE;
}

static
void
mms_engine_start_timeout_cancel(
mms_engine_idle_timer_stop(
MMSEngine* engine)
{
if (engine->start_timeout_id) {
g_source_remove(engine->start_timeout_id);
engine->start_timeout_id = 0;
if (engine->idle_timer_id) {
g_source_remove(engine->idle_timer_id);
engine->idle_timer_id = 0;
}
}

static
void
mms_engine_start_timeout_schedule(
mms_engine_idle_timer_check(
MMSEngine* engine)
{
mms_engine_start_timeout_cancel(engine);
engine->start_timeout_id = g_timeout_add_seconds(engine->config->idle_secs,
mms_engine_start_timeout_callback, engine);
mms_engine_idle_timer_stop(engine);
if (!mms_dispatcher_is_started(engine->dispatcher) && !engine->keep_running) {
engine->idle_timer_id = g_timeout_add_seconds(engine->config->idle_secs,
mms_engine_idle_timer_expired, engine);
}
}

/* org.nemomobile.MmsEngine.sendMessage */
Expand Down Expand Up @@ -186,9 +188,7 @@ mms_engine_handle_send_message(
imsi_to, to_list, cc_list, bcc_list, subject, flags, parts,
info->len, &error);
if (imsi) {
if (mms_dispatcher_start(engine->dispatcher)) {
mms_engine_start_timeout_cancel(engine);
}
mms_dispatcher_start(engine->dispatcher);
org_nemomobile_mms_engine_complete_send_message(proxy, call, imsi);
g_free(imsi);
} else {
Expand All @@ -213,6 +213,7 @@ mms_engine_handle_send_message(
g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
G_DBUS_ERROR_FAILED, "Missing recipient");
}
mms_engine_idle_timer_check(engine);
return TRUE;
}

Expand All @@ -237,9 +238,7 @@ mms_engine_handle_receive_message(
GError* error = NULL;
if (mms_dispatcher_receive_message(engine->dispatcher, id, imsi,
automatic, push, &error)) {
if (mms_dispatcher_start(engine->dispatcher)) {
mms_engine_start_timeout_cancel(engine);
}
mms_dispatcher_start(engine->dispatcher);
org_nemomobile_mms_engine_complete_receive_message(proxy, call);
} else {
g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
Expand All @@ -252,6 +251,7 @@ mms_engine_handle_receive_message(
g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
G_DBUS_ERROR_FAILED, "Invalid parameters");
}
mms_engine_idle_timer_check(engine);
return TRUE;
}

Expand All @@ -274,16 +274,15 @@ mms_engine_handle_send_read_report(
if (mms_dispatcher_send_read_report(engine->dispatcher, id, imsi,
message_id, to, (read_status == 1) ? MMS_READ_STATUS_DELETED :
MMS_READ_STATUS_READ, &error)) {
if (mms_dispatcher_start(engine->dispatcher)) {
mms_engine_start_timeout_cancel(engine);
}
mms_dispatcher_start(engine->dispatcher);
org_nemomobile_mms_engine_complete_send_read_report(proxy, call);
} else {
g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
G_DBUS_ERROR_FAILED, "%s", GERRMSG(error));
g_error_free(error);
}
g_free(id);
mms_engine_idle_timer_check(engine);
return TRUE;
}

Expand All @@ -302,6 +301,7 @@ mms_engine_handle_cancel(
mms_dispatcher_cancel(engine->dispatcher, id);
org_nemomobile_mms_engine_complete_cancel(proxy, call);
g_free(id);
mms_engine_idle_timer_check(engine);
return TRUE;
}

Expand Down Expand Up @@ -335,9 +335,7 @@ mms_engine_handle_push_notify(
GError* err = NULL;
GBytes* msg = g_bytes_new(bytes, len);
if (mms_dispatcher_handle_push(engine->dispatcher, imsi, msg, &err)) {
if (mms_dispatcher_start(engine->dispatcher)) {
mms_engine_start_timeout_cancel(engine);
}
mms_dispatcher_start(engine->dispatcher);
org_nemomobile_mms_engine_complete_push(proxy, call);
} else {
g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
Expand All @@ -346,6 +344,7 @@ mms_engine_handle_push_notify(
}
g_bytes_unref(msg);
}
mms_engine_idle_timer_check(engine);
return TRUE;
}

Expand Down Expand Up @@ -392,6 +391,7 @@ mms_engine_handle_set_log_level(
gutil_log_default.level = level;
}
org_nemomobile_mms_engine_complete_set_log_level(proxy, call);
mms_engine_idle_timer_check(engine);
return TRUE;
}

Expand All @@ -407,6 +407,7 @@ mms_engine_handle_set_log_type(
GDEBUG_("%s", type);
gutil_log_set_type(type, MMS_APP_LOG_PREFIX);
org_nemomobile_mms_engine_complete_set_log_type(proxy, call);
mms_engine_idle_timer_check(engine);
return TRUE;
}

Expand All @@ -433,6 +434,7 @@ mms_engine_handle_get_version(
GDEBUG_("oops");
org_nemomobile_mms_engine_complete_get_version(proxy, call, 0, 0, 0, "");
#endif
mms_engine_idle_timer_check(engine);
return TRUE;
}

Expand All @@ -447,7 +449,7 @@ mms_engine_handle_migrate_settings(
{
char* tmp = NULL;
/* Querying settings will migrate per-SIM settings after upgrading
* from 1.0.21 or older version of mme-engine */
* from 1.0.21 or older version of mms-engine */
GDEBUG_("%s", imsi);
if (!imsi || !imsi[0]) {
imsi = tmp = mms_connman_default_imsi(engine->cm);
Expand All @@ -457,6 +459,7 @@ mms_engine_handle_migrate_settings(
}
org_nemomobile_mms_engine_complete_migrate_settings(proxy, call);
g_free(tmp);
mms_engine_idle_timer_check(engine);
return TRUE;
}

Expand Down Expand Up @@ -570,11 +573,10 @@ mms_engine_run(
engine->loop = loop;
engine->stopped = FALSE;
engine->stop_requested = FALSE;
if (!mms_dispatcher_start(engine->dispatcher) && !engine->keep_running) {
mms_engine_start_timeout_schedule(engine);
}
mms_dispatcher_start(engine->dispatcher);
mms_engine_idle_timer_check(engine);
g_main_loop_run(loop);
mms_engine_start_timeout_cancel(engine);
mms_engine_idle_timer_stop(engine);
engine->loop = NULL;
}

Expand Down Expand Up @@ -627,8 +629,10 @@ mms_engine_delegate_dispatcher_done(
{
MMSEngine* engine = mms_engine_from_dispatcher_delegate(delegate);
GDEBUG("All done");
if (!engine->keep_running || engine->stop_requested) {
if (engine->stop_requested) {
mms_engine_stop_schedule(engine);
} else {
mms_engine_idle_timer_check(engine);
}
}

Expand Down Expand Up @@ -658,7 +662,7 @@ mms_engine_dispose(
GVERBOSE_("%p", mms);
GASSERT(!mms->loop);
mms_engine_unregister(mms);
mms_engine_start_timeout_cancel(mms);
mms_engine_idle_timer_stop(mms);
if (mms->proxy) {
gutil_disconnect_handlers(mms->proxy, mms->proxy_signal_id,
G_N_ELEMENTS(mms->proxy_signal_id));
Expand Down
8 changes: 6 additions & 2 deletions mms-lib/include/mms_dispatcher.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2018 Jolla Ltd.
* Copyright (C) 2013-2018 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
Expand Down Expand Up @@ -47,6 +47,10 @@ mms_dispatcher_set_delegate(
MMSDispatcher* dispatcher,
MMSDispatcherDelegate* delegate);

gboolean
mms_dispatcher_is_started(
MMSDispatcher* dispatcher);

gboolean
mms_dispatcher_is_active(
MMSDispatcher* dispatcher);
Expand Down
14 changes: 8 additions & 6 deletions mms-lib/include/mms_settings.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2014-2018 Jolla Ltd.
* Copyright (C) 2014-2018 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
Expand All @@ -21,7 +21,8 @@
struct mms_config {
const char* root_dir; /* Root directory for storing MMS files */
int retry_secs; /* Retry timeout in seconds */
int idle_secs; /* Idle timeout */
int network_idle_secs; /* Network inactivity timeout */
int idle_secs; /* Service inactivity timeout */
gboolean keep_temp_files; /* Keep temporary files around */
gboolean attic_enabled; /* Keep unrecognized push message in attic */
};
Expand All @@ -31,9 +32,10 @@ typedef struct mms_config_copy {
char* root_dir; /* Allocated copy of root_dir */
} MMSConfigCopy;

#define MMS_CONFIG_DEFAULT_ROOT_DIR "/tmp/mms"
#define MMS_CONFIG_DEFAULT_RETRY_SECS (15)
#define MMS_CONFIG_DEFAULT_IDLE_SECS (20)
#define MMS_CONFIG_DEFAULT_ROOT_DIR "/tmp/mms"
#define MMS_CONFIG_DEFAULT_RETRY_SECS (15)
#define MMS_CONFIG_DEFAULT_NETWORK_IDLE_SECS (10)
#define MMS_CONFIG_DEFAULT_IDLE_SECS (30)

/* Persistent mutable per-SIM settings */
struct mms_settings_sim_data {
Expand Down
18 changes: 15 additions & 3 deletions mms-lib/src/mms_dispatcher.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2018 Jolla Ltd.
* Copyright (C) 2013-2018 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
Expand Down Expand Up @@ -200,9 +200,10 @@ mms_dispatcher_network_idle_check(
{
if (disp->connection && !disp->network_idle_id) {
/* Schedule idle inactivity timeout callback */
const MMSConfig* config = disp->settings->config;
GVERBOSE("Network connection is inactive");
disp->network_idle_id = mms_dispatcher_timeout_callback_schedule(disp,
disp->settings->config->idle_secs, mms_dispatcher_network_idle_run);
config->network_idle_secs, mms_dispatcher_network_idle_run);
}
}

Expand Down Expand Up @@ -309,6 +310,17 @@ mms_dispatcher_is_active(
disp->active_task || !g_queue_is_empty(disp->tasks));
}

/**
* Checks if dispatcher has been started. If it is then delegate may expect
* its done callback invoked at some point later.
*/
gboolean
mms_dispatcher_is_started(
MMSDispatcher* disp)
{
return disp && disp->started;
}

/**
* Task queue sort callback. Defines the order in which tasks are executed.
* Returns 0 if the tasks are equal, a negative value if the first task
Expand Down
5 changes: 3 additions & 2 deletions mms-lib/src/mms_lib_util.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2013-2018 Jolla Ltd.
* Copyright (C) 2013-2018 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
Expand Down Expand Up @@ -66,6 +66,7 @@ mms_lib_default_config(
{
config->root_dir = MMS_CONFIG_DEFAULT_ROOT_DIR;
config->retry_secs = MMS_CONFIG_DEFAULT_RETRY_SECS;
config->network_idle_secs = MMS_CONFIG_DEFAULT_NETWORK_IDLE_SECS;
config->idle_secs = MMS_CONFIG_DEFAULT_IDLE_SECS;
config->keep_temp_files = FALSE;
config->attic_enabled = FALSE;
Expand Down

0 comments on commit 6ed9ff7

Please sign in to comment.