Commit 24f976a1 authored by Slava Monich's avatar Slava Monich

[mms-lib] Pass "user request" flag to the connection manager.

It's not being used at the moment but we may need it soon.
parent b70fdc33
......@@ -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();
......
......@@ -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 */
......
......@@ -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) {
......@@ -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;
......
......@@ -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;
......@@ -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);
......
......@@ -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 */
......
......@@ -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);
......@@ -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);
}
......
/*
* 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
......@@ -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;
};
......
/*
* 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
......@@ -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);
......@@ -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
......
/*
* 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
......@@ -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)))
......
/*
* 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
......@@ -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;
......
......@@ -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 =
......@@ -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 {
......
/*
* 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
......@@ -180,6 +180,7 @@ mms_task_retrieve_new(
const char* id,
const char* imsi,
const MMSPdu* pdu,
MMS_CONNECTION_TYPE ct,
GError** error);
MMSTask*
......
/*
* 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
......@@ -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);
......@@ -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
......@@ -618,7 +622,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)
{
MMSTaskHttp* http = mms_task_alloc(type ? type : MMS_TYPE_TASK_HTTP,
settings, handler, name, id, imsi);
......@@ -626,6 +631,7 @@ mms_task_http_alloc(
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));
......@@ -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);
}
/*
......
/*
* 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
......@@ -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(
......
/*
* 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
......@@ -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);
}
......
/*
* 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
......@@ -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;
}
......
/*
* 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
......@@ -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);
......@@ -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;
}
......
......@@ -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);
......
/*
* 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
......@@ -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);
......
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