Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mms-lib] Pass "user request" flag to the connection manager.
It's not being used at the moment but we may need it soon.
  • Loading branch information
monich committed Feb 16, 2016
1 parent b70fdc3 commit 24f976a
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 36 deletions.
4 changes: 2 additions & 2 deletions mms-connman-nemo/src/mms_connection_nemo.c
Expand Up @@ -512,13 +512,13 @@ MMSConnection*
mms_connection_nemo_new(
MMSConnMan* cm,
const char* imsi,
gboolean user_request)
MMS_CONNECTION_TYPE type)
{
MMSConnectionNemo* self = g_object_new(MMS_TYPE_CONNECTION_NEMO, NULL);
MMSConnection* conn = &self->connection;

MMS_VERBOSE_("%p %s", self, imsi);
conn->user_connection = user_request;
conn->type = type;
conn->imsi = self->imsi = g_strdup(imsi);
conn->state = MMS_CONNECTION_STATE_OPENING;
self->mm = ofonoext_mm_new();
Expand Down
2 changes: 1 addition & 1 deletion mms-connman-nemo/src/mms_connection_nemo.h
Expand Up @@ -24,7 +24,7 @@ MMSConnection*
mms_connection_nemo_new(
MMSConnMan* cm,
const char* imsi,
gboolean user_request);
MMS_CONNECTION_TYPE type);

#endif /* JOLLA_MMS_CONNECTION_NEMO_H */

Expand Down
4 changes: 2 additions & 2 deletions mms-connman-nemo/src/mms_connman_nemo.c
Expand Up @@ -166,7 +166,7 @@ MMSConnection*
mms_connman_nemo_open_connection(
MMSConnMan* cm,
const char* imsi,
gboolean user_request)
MMS_CONNECTION_TYPE type)
{
MMSConnManNemo* self = MMS_CONNMAN_NEMO(cm);
if (self->conn) {
Expand All @@ -178,7 +178,7 @@ mms_connman_nemo_open_connection(
self->conn = NULL;
}
}
self->conn = mms_connection_nemo_new(cm, imsi, user_request);
self->conn = mms_connection_nemo_new(cm, imsi, type);
g_object_weak_ref(G_OBJECT(self->conn),
mms_connman_nemo_connection_weak_ref_notify, self);
return self->conn;
Expand Down
4 changes: 2 additions & 2 deletions mms-connman-ofono/src/mms_connection_ofono.c
Expand Up @@ -211,7 +211,7 @@ MMSConnection*
mms_connection_ofono_new(
OfonoSimMgr* sim,
OfonoConnCtx* context,
gboolean user_request)
MMS_CONNECTION_TYPE type)
{
MMSConnectionOfono* self = g_object_new(MMS_TYPE_CONNECTION_OFONO, NULL);
MMSConnection* conn = &self->connection;
Expand All @@ -220,7 +220,7 @@ mms_connection_ofono_new(
MMS_ASSERT(sim->present);
MMS_VERBOSE_("%p %s", self, sim->imsi);

conn->user_connection = user_request;
conn->type = type;
conn->imsi = self->imsi = g_strdup(sim->imsi);
self->sim = ofono_simmgr_ref(sim);
self->context = ofono_connctx_ref(context);
Expand Down
2 changes: 1 addition & 1 deletion mms-connman-ofono/src/mms_connection_ofono.h
Expand Up @@ -24,7 +24,7 @@ MMSConnection*
mms_connection_ofono_new(
OfonoSimMgr* sim,
OfonoConnCtx* context,
gboolean user_request);
MMS_CONNECTION_TYPE type);

#endif /* JOLLA_MMS_CONNECTION_OFONO_H */

Expand Down
6 changes: 3 additions & 3 deletions mms-connman-ofono/src/mms_connman_ofono.c
Expand Up @@ -194,7 +194,7 @@ MMSConnection*
mms_connman_ofono_open_connection(
MMSConnMan* cm,
const char* imsi,
gboolean user_request)
MMS_CONNECTION_TYPE type)
{
MMSConnManOfono* self = MMS_CONNMAN_OFONO(cm);
MMSOfonoModem* modem = mms_connman_ofono_modem_for_imsi(self, imsi);
Expand All @@ -205,8 +205,8 @@ mms_connman_ofono_open_connection(
if (modem->conn) {
mms_connection_ref(modem->conn);
} else {
modem->conn = mms_connection_ofono_new(modem->simmgr, ctx,
user_request);
modem->conn =
mms_connection_ofono_new(modem->simmgr, ctx, type);
g_object_weak_ref(G_OBJECT(modem->conn),
mms_connman_ofono_connection_gone, self);
}
Expand Down
4 changes: 2 additions & 2 deletions mms-lib/include/mms_connection.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -44,7 +44,7 @@ struct mms_connection {
const char* mmsc;
const char* mmsproxy;
const char* netif;
gboolean user_connection;
MMS_CONNECTION_TYPE type;
MMS_CONNECTION_STATE state;
};

Expand Down
5 changes: 3 additions & 2 deletions mms-lib/include/mms_connman.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: 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 @@ -28,7 +29,7 @@ typedef struct mms_connman_class {
GObjectClass parent;
char* (*fn_default_imsi)(MMSConnMan* cm);
MMSConnection* (*fn_open_connection)(MMSConnMan* cm, const char* imsi,
gboolean user_request);
MMS_CONNECTION_TYPE type);
} MMSConnManClass;

GType mms_connman_get_type(void);
Expand Down Expand Up @@ -65,7 +66,7 @@ MMSConnection*
mms_connman_open_connection(
MMSConnMan* cm,
const char* imsi,
gboolean user_request);
MMS_CONNECTION_TYPE type);

/**
* While busy flags is on, mms-engine shouldn't exit
Expand Down
8 changes: 7 additions & 1 deletion mms-lib/include/mms_lib_types.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -75,6 +75,12 @@ typedef enum mms_read_status {
MMS_READ_STATUS_DELETED /* Message deleted without reading */
} MMSReadStatus;

/* Connection type */
typedef enum _MMS_CONNECTION_TYPE {
MMS_CONNECTION_TYPE_AUTO, /* Internally requested connection */
MMS_CONNECTION_TYPE_USER /* Connection requested by user */
} MMS_CONNECTION_TYPE;

/* Convenience macros */
#define MMS_CAST(address,type,field) \
((type *)((guint8*)(address) - G_STRUCT_OFFSET(type,field)))
Expand Down
5 changes: 3 additions & 2 deletions mms-lib/src/mms_connman.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: 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 @@ -128,12 +129,12 @@ MMSConnection*
mms_connman_open_connection(
MMSConnMan* cm,
const char* imsi,
gboolean user_request)
MMS_CONNECTION_TYPE type)
{
if (cm) {
MMSConnManClass* klass = MMS_CONNMAN_GET_CLASS(cm);
if (klass->fn_open_connection) {
return klass->fn_open_connection(cm, imsi, user_request);
return klass->fn_open_connection(cm, imsi, type);
}
}
return NULL;
Expand Down
7 changes: 5 additions & 2 deletions mms-lib/src/mms_dispatcher.c
Expand Up @@ -366,7 +366,9 @@ mms_dispatcher_pick_next_task(
mms_dispatcher_close_connection(disp);
if (!disp->connection) {
disp->connection = mms_connman_open_connection(disp->cm,
task->imsi, FALSE);
task->imsi,
(task->state == MMS_TASK_STATE_NEED_USER_CONNECTION) ?
MMS_CONNECTION_TYPE_USER : MMS_CONNECTION_TYPE_AUTO);
if (disp->connection) {
MMS_ASSERT(!disp->connection_changed_id);
disp->connection_changed_id =
Expand Down Expand Up @@ -543,7 +545,8 @@ mms_dispatcher_receive_message(
if (pdu->type == MMS_MESSAGE_TYPE_NOTIFICATION_IND) {
ok = mms_dispatcher_queue_and_unref_task(disp,
mms_task_retrieve_new(disp->settings, disp->handler,
id, imsi, pdu, error));
id, imsi, pdu, automatic ? MMS_CONNECTION_TYPE_AUTO :
MMS_CONNECTION_TYPE_USER, error));
}
mms_message_free(pdu);
} else {
Expand Down
3 changes: 2 additions & 1 deletion mms-lib/src/mms_task.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -180,6 +180,7 @@ mms_task_retrieve_new(
const char* id,
const char* imsi,
const MMSPdu* pdu,
MMS_CONNECTION_TYPE ct,
GError** error);

MMSTask*
Expand Down
15 changes: 11 additions & 4 deletions mms-lib/src/mms_task_http.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -66,6 +66,7 @@ struct mms_task_http_private {
gsize bytes_sent;
guint bytes_received;
MMS_HTTP_STATE transaction_state;
MMS_CONNECTION_TYPE connection_type;
};

G_DEFINE_TYPE(MMSTaskHttp, mms_task_http, MMS_TYPE_TASK);
Expand Down Expand Up @@ -511,7 +512,10 @@ void
mms_task_http_run(
MMSTask* task)
{
mms_task_set_state(task, MMS_TASK_STATE_NEED_CONNECTION);
MMSTaskHttp* http = MMS_TASK_HTTP(task);
mms_task_set_state(task,
(http->priv->connection_type == MMS_CONNECTION_TYPE_USER) ?
MMS_TASK_STATE_NEED_USER_CONNECTION : MMS_TASK_STATE_NEED_CONNECTION);
}

static
Expand Down Expand Up @@ -618,14 +622,16 @@ mms_task_http_alloc(
const char* imsi, /* IMSI associated with the message */
const char* uri, /* NULL to use MMSC URL */
const char* receive_file, /* File to write data to (optional) */
const char* send_file) /* File to read data from (optional) */
const char* send_file, /* File to read data from (optional) */
MMS_CONNECTION_TYPE ct)
{
MMSTaskHttp* http = mms_task_alloc(type ? type : MMS_TYPE_TASK_HTTP,
settings, handler, name, id, imsi);
MMSTaskHttpPrivate* priv = g_new0(MMSTaskHttpPrivate, 1);
http->priv = priv;
priv->uri = g_strdup(uri);
priv->receive_file = receive_file; /* Always static, don't strdup */
priv->connection_type = ct;
if (send_file) {
priv->send_path = mms_task_file(&http->task, send_file);
MMS_ASSERT(g_file_test(priv->send_path, G_FILE_TEST_IS_REGULAR));
Expand All @@ -643,7 +649,8 @@ mms_task_http_alloc_with_parent(
const char* send_file) /* File to read data from (optional) */
{
return mms_task_http_alloc(type, parent->settings, parent->handler,
name, parent->id, parent->imsi, uri, receive_file, send_file);
name, parent->id, parent->imsi, uri, receive_file, send_file,
MMS_CONNECTION_TYPE_AUTO);
}

/*
Expand Down
6 changes: 4 additions & 2 deletions mms-lib/src/mms_task_http.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: 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 @@ -61,7 +62,8 @@ mms_task_http_alloc(
const char* imsi, /* IMSI associated with the message */
const char* uri, /* NULL to use MMSC URL */
const char* receive_file, /* File to write data to (optional) */
const char* send_file); /* File to read data from (optional) */
const char* send_file, /* File to read data from (optional) */
MMS_CONNECTION_TYPE ct);

void*
mms_task_http_alloc_with_parent(
Expand Down
4 changes: 2 additions & 2 deletions mms-lib/src/mms_task_notification.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -121,7 +121,7 @@ mms_task_notification_done(
/* Schedule the download task */
if (!mms_task_queue_and_unref(task->delegate,
mms_task_retrieve_new(task->settings, task->handler,
task->id, task->imsi, ind->pdu, NULL))) {
task->id, task->imsi, ind->pdu, FALSE, NULL))) {
mms_handler_message_receive_state_changed(task->handler, id,
MMS_RECEIVE_STATE_DOWNLOAD_ERROR);
}
Expand Down
4 changes: 2 additions & 2 deletions mms-lib/src/mms_task_read.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -127,7 +127,7 @@ mms_task_read_new(
id, msg_id, to, rs, err);
if (file) {
return mms_task_http_alloc(MMS_TYPE_TASK_READ, settings, handler,
"Read", id, imsi, NULL, NULL, file);
"Read", id, imsi, NULL, NULL, file, MMS_CONNECTION_TYPE_AUTO);
}
return NULL;
}
Expand Down
7 changes: 4 additions & 3 deletions mms-lib/src/mms_task_retrieve.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -119,6 +119,7 @@ mms_task_retrieve_new(
const char* id,
const char* imsi,
const MMSPdu* pdu,
MMS_CONNECTION_TYPE ct,
GError** error)
{
const time_t now = time(NULL);
Expand All @@ -127,8 +128,8 @@ mms_task_retrieve_new(
MMS_ASSERT(pdu->transaction_id);
if (pdu->ni.expiry > now) {
MMSTaskRetrieve* retrieve = mms_task_http_alloc(
MMS_TYPE_TASK_RETRIEVE, settings, handler, "Retrieve",
id, imsi, pdu->ni.location, MMS_RETRIEVE_CONF_FILE, NULL);
MMS_TYPE_TASK_RETRIEVE, settings, handler, "Retrieve", id, imsi,
pdu->ni.location, MMS_RETRIEVE_CONF_FILE, NULL, ct);
if (retrieve->http.task.deadline > pdu->ni.expiry) {
retrieve->http.task.deadline = pdu->ni.expiry;
}
Expand Down
1 change: 1 addition & 0 deletions mms-lib/test/common/test_connection.c
Expand Up @@ -83,6 +83,7 @@ mms_connection_test_new(
test->mmsc = g_strdup_printf("http://127.0.0.1:%hu", port);
}
}
test->type = MMS_CONNECTION_TYPE_AUTO;
test->state = MMS_CONNECTION_STATE_OPENING;
mms_connection_test_set_state(test, test->netif ?
MMS_CONNECTION_STATE_OPEN : MMS_CONNECTION_STATE_FAILED);
Expand Down
5 changes: 3 additions & 2 deletions mms-lib/test/common/test_connman.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: 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 @@ -103,7 +104,7 @@ MMSConnection*
mms_connman_test_open_connection(
MMSConnMan* cm,
const char* imsi,
gboolean user_request)
MMS_CONNECTION_TYPE type)
{
MMSConnManTest* test = MMS_CONNMAN_TEST(cm);
mms_connman_test_close_connection(cm);
Expand Down

0 comments on commit 24f976a

Please sign in to comment.