Skip to content

Commit

Permalink
[mms-lib] Notify handler when read report sending is finished
Browse files Browse the repository at this point in the history
New method readReportSendStatus has been added to org.nemomobile.MmsHandler
D-Bus interface. It's called when mms-engine is done with sending the read
report, successfully or not. If read report sending fails, the handler has
a chance to retry.
  • Loading branch information
monich committed Mar 12, 2015
1 parent 103a462 commit a27e7f5
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 4 deletions.
23 changes: 23 additions & 0 deletions mms-handler-dbus/spec/org.nemomobile.MmsHandler.xml
Expand Up @@ -251,6 +251,29 @@
<arg direction="in" type="s" name="mmsId"/>
</method>

<!--
===============================================================
Reports completion status of read report send request submitted
by org.nemomobile.MmsEngine.sendReadReport call.
===============================================================
-->
<method name="readReportSendStatus">
<!--
Database record id.
-->
<arg direction="in" type="s" name="recId"/>
<!--
Indicates the result of the operation:
0: Read report has been sent
1: Transient failure (wrong SIM, no coverage, I/O error)
2: Permanent failure (error from the operator)
-->
<arg direction="in" type="i" name="status"/>
</method>

<!--
===============================================================
Expand Down
23 changes: 22 additions & 1 deletion mms-handler-dbus/src/mms_handler_dbus.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2015 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 @@ -444,6 +445,24 @@ mms_handler_dbus_read_report(
return FALSE;
}

/* Done with sending MMS read report */
gboolean
mms_handler_dbus_read_report_send_status(
MMSHandler* handler,
const char* id,
MMS_READ_REPORT_STATUS status)
{
OrgNemomobileMmsHandler* proxy = mms_handler_dbus_connect(handler);
if (id && id[0] && proxy) {
mms_handler_ref(handler);
mms_handler_busy_inc(handler);
org_nemomobile_mms_handler_call_read_report_send_status(proxy, id,
status, NULL, mms_handler_dbus_call_done, handler);
return TRUE;
}
return FALSE;
}

/**
* First stage of deinitialization (release all references).
* May be called more than once in the lifetime of the object.
Expand Down Expand Up @@ -496,6 +515,8 @@ mms_handler_dbus_class_init(
klass->fn_message_sent = mms_handler_dbus_message_sent;
klass->fn_delivery_report = mms_handler_dbus_delivery_report;
klass->fn_read_report = mms_handler_dbus_read_report;
klass->fn_read_report_send_status =
mms_handler_dbus_read_report_send_status;
object_class->dispose = mms_handler_dbus_dispose;
object_class->finalize = mms_handler_dbus_finalize;
}
Expand Down
20 changes: 20 additions & 0 deletions mms-lib/include/mms_handler.h
Expand Up @@ -57,6 +57,14 @@ typedef enum _mms_delivery_status {
/* Read status */
typedef MMSReadStatus MMS_READ_STATUS;

/* Read report status */
typedef enum _mms_read_report_status {
MMS_READ_REPORT_STATUS_INVALID = -1,
MMS_READ_REPORT_STATUS_OK,
MMS_READ_REPORT_STATUS_IO_ERROR,
MMS_READ_REPORT_STATUS_PERMANENT_ERROR
} MMS_READ_REPORT_STATUS;

/* Handler event callback */
typedef void
(*mms_handler_event_fn)(
Expand Down Expand Up @@ -156,6 +164,12 @@ typedef struct mms_handler_class {
const char* recipient, /* Recipient's phone number */
MMS_READ_STATUS rs); /* Read status */

/* Done with sending MMS read report */
gboolean (*fn_read_report_send_status)(
MMSHandler* handler, /* Handler instance */
const char* id, /* Handler record id */
MMS_READ_REPORT_STATUS s); /* Status */

} MMSHandlerClass;

GType mms_handler_get_type(void);
Expand Down Expand Up @@ -231,6 +245,12 @@ mms_handler_read_report(
const char* recipient, /* Recipient's phone number */
MMS_READ_STATUS rs); /* Read status */

gboolean
mms_handler_read_report_send_status(
MMSHandler* handler, /* Handler instance */
const char* id, /* Handler record id */
MMS_READ_REPORT_STATUS status); /* Status */

void
mms_handler_busy_update(
MMSHandler* handler, /* Handler instance */
Expand Down
19 changes: 18 additions & 1 deletion mms-lib/src/mms_handler.c
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013-2014 Jolla Ltd.
* Copyright (C) 2013-2015 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 @@ -262,6 +263,22 @@ mms_handler_read_report(
return FALSE;
}

gboolean
mms_handler_read_report_send_status(
MMSHandler* h,
const char* id,
MMS_READ_REPORT_STATUS status)
{
if (h) {
MMSHandlerClass* klass = MMS_HANDLER_GET_CLASS(h);
if (klass->fn_read_report_send_status) {
return klass->fn_read_report_send_status(h, id, status);
}
MMS_ERR("mms_handler_read_report_send_status not implemented");
}
return FALSE;
}

void
mms_handler_busy_update(
MMSHandler* h,
Expand Down
55 changes: 53 additions & 2 deletions mms-lib/src/mms_task_read.c
Expand Up @@ -16,11 +16,21 @@
#include "mms_task.h"
#include "mms_task_http.h"
#include "mms_file_util.h"
#include "mms_handler.h"
#include "mms_codec.h"
#include "mms_util.h"
#include "mms_log.h"
#include "mms_error.h"

/* Class definition */
typedef MMSTaskHttpClass MMSTaskReadClass;
typedef MMSTaskHttp MMSTaskRead;

G_DEFINE_TYPE(MMSTaskRead, mms_task_read, MMS_TYPE_TASK_HTTP);
#define MMS_TYPE_TASK_READ (mms_task_read_get_type())
#define MMS_TASK_READ(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
MMS_TYPE_TASK_READ, MMSTaskRead))

static
const char*
mms_task_read_encode(
Expand Down Expand Up @@ -58,6 +68,47 @@ mms_task_read_encode(
return result;
}

static
void
mms_task_read_done(
MMSTaskHttp* http,
const char* path,
SoupStatus soup_status)
{
MMSTask* task = &http->task;
MMS_READ_REPORT_STATUS send_status;
if (SOUP_STATUS_IS_INFORMATIONAL(soup_status) ||
SOUP_STATUS_IS_SUCCESSFUL(soup_status)) {
send_status = MMS_READ_REPORT_STATUS_OK;
} else if (SOUP_STATUS_IS_TRANSPORT_ERROR(soup_status)) {
send_status = MMS_READ_REPORT_STATUS_IO_ERROR;
} else {
send_status = MMS_READ_REPORT_STATUS_PERMANENT_ERROR;
}
mms_handler_read_report_send_status(task->handler, task->id, send_status);
}

/**
* Per class initializer
*/
static
void
mms_task_read_class_init(
MMSTaskReadClass* klass)
{
klass->fn_done = mms_task_read_done;
}

/**
* Per instance initializer
*/
static
void
mms_task_read_init(
MMSTaskRead* self)
{
}

/**
* Create MMS read report task
*/
Expand All @@ -75,8 +126,8 @@ mms_task_read_new(
const char* file = mms_task_read_encode(settings->config,
id, msg_id, to, rs, err);
if (file) {
return mms_task_http_alloc(0, settings, handler, "Read",
id, imsi, NULL, NULL, file);
return mms_task_http_alloc(MMS_TYPE_TASK_READ, settings, handler,
"Read", id, imsi, NULL, NULL, file);
}
return NULL;
}
Expand Down

0 comments on commit a27e7f5

Please sign in to comment.