Skip to content

Commit

Permalink
Merge branch 'progress' into 'master'
Browse files Browse the repository at this point in the history
Transfer progress API

Intended for the Messages app, so that it can show MMS
send/receive progress.

D-Bus interface for the list of transfers goes like this:

<interface name="org.nemomobile.MmsEngine.TransferList">
    <method name="Get">
        <arg name="list" type="ao" direction="out"/>
    </method>
    <signal name="TransferStarted">
        <arg name="path" type="o"/>
    </signal>
    <signal name="TransferFinished">
        <arg name="path" type="o"/>
    </signal>
</interface>

D-Bus interface for individual transfers (identified by path):

<interface name="org.nemomobile.MmsEngine.Transfer">
    <method name="GetAll">
        <arg name="version" type="u" direction="out"/>
        <arg name="bytes_sent" type="u" direction="out"/>
        <arg name="bytes_to_send" type="u" direction="out"/>
        <arg name="bytes_received" type="u" direction="out"/>
        <arg name="bytes_to_receive" type="u" direction="out"/>
    </method>
    <method name="EnableUpdates">
        <!-- 1 - send, 2 - receive, 3 - both -->
        <arg name="flags" type="u" direction="in"/>
        <arg name="cookie" type="u" direction="out"/>
    </method>
    <method name="DisableUpdates">
        <arg name="cookie" type="u" direction="in"/>
    </method>
    <method name="GetInterfaceVersion">
        <arg name="version" type="u" direction="out"/>
    </method>
    <method name="GetSendProgress">
        <arg name="bytes_sent" type="u" direction="out"/>
        <arg name="bytes_to_send" type="u" direction="out"/>
    </method>
    <method name="GetReceiveProgress">
        <arg name="bytes_received" type="u" direction="out"/>
        <arg name="bytes_to_receive" type="u" direction="out"/>
    </method>
    <signal name="SendProgressChanged">
        <arg name="bytes_sent" type="u"/>
        <arg name="bytes_to_send" type="u"/>
    </signal>
    <signal name="ReceiveProgressChanged">
        <arg name="bytes_received" type="u"/>
        <arg name="bytes_to_receive" type="u"/>
    </signal>
    <signal name="Finished"/>
</interface>

Progress signals are not emitted unless there's at least one
D-Bus client expressed an interest by calling EnableUpdates
with appropriate flags. Request for updates can be revoked
with DisableUpdates. This complicates things a bit but I think
it's worth the trouble.

See merge request !9
  • Loading branch information
Slava Monich committed Mar 15, 2016
2 parents e63539b + 99d617c commit 884da77
Show file tree
Hide file tree
Showing 49 changed files with 1,818 additions and 135 deletions.
32 changes: 30 additions & 2 deletions mms-engine/Makefile
Expand Up @@ -4,6 +4,7 @@
.PHONY: mms_lib_debug_lib mms_lib_release_lib
.PHONY: mms_connman_debug_lib mms_connman_release_lib
.PHONY: mms_handler_debug_lib mms_handler_release_lib
.PHONY: mms_transfers_debug_lib mms_transfers_release_lib
.PHONY: mms_settings_debug_lib mms_settings_release_lib

#
Expand Down Expand Up @@ -84,6 +85,16 @@ MMS_HANDLER_BUILD_DIR = $(MMS_HANDLER_DIR)/build
MMS_HANDLER_DEBUG_LIB = $(MMS_HANDLER_BUILD_DIR)/debug/$(MMS_HANDLER_LIB)
MMS_HANDLER_RELEASE_LIB = $(MMS_HANDLER_BUILD_DIR)/release/$(MMS_HANDLER_LIB)

#
# mms-transfer-list-dbus
#

MMS_TRANSFERS_LIB = libmms-transfer-list-dbus.a
MMS_TRANSFERS_DIR = ../mms-transfer-list-dbus
MMS_TRANSFERS_BUILD_DIR = $(MMS_TRANSFERS_DIR)/build
MMS_TRANSFERS_DEBUG_LIB = $(MMS_TRANSFERS_BUILD_DIR)/debug/$(MMS_TRANSFERS_LIB)
MMS_TRANSFERS_RELEASE_LIB = $(MMS_TRANSFERS_BUILD_DIR)/release/$(MMS_TRANSFERS_LIB)

#
# mms-settings-dconf
#
Expand All @@ -108,8 +119,8 @@ WARN = -Wall
BASE_FLAGS = -fPIC $(CFLAGS)
FULL_CFLAGS = $(BASE_FLAGS) -I. -I$(GEN_DIR) -I$(MMS_LIB_DIR)/include \
-I$(MMS_CONNMAN_DIR)/include -I$(MMS_HANDLER_DIR)/include \
-I$(MMS_SETTINGS_DIR)/include -MMD -MP \
$(shell pkg-config --cflags $(PKGS))
-I$(MMS_SETTINGS_DIR)/include -I$(MMS_TRANSFERS_DIR)/include \
-MMD -MP $(shell pkg-config --cflags $(PKGS))

ifndef KEEP_SYMBOLS
KEEP_SYMBOLS = 0
Expand Down Expand Up @@ -137,12 +148,14 @@ LIBS = $(shell pkg-config --libs $(LIB_PKGS)) -lmagic -ljpeg $(RESIZE_LIBS)
DEBUG_LIBS = \
$(MMS_CONNMAN_DEBUG_LIB) \
$(MMS_HANDLER_DEBUG_LIB) \
$(MMS_TRANSFERS_DEBUG_LIB) \
$(MMS_SETTINGS_DEBUG_LIB) \
$(MMS_LIB_DEBUG_LIB) \
$(LIBS)
RELEASE_LIBS = \
$(MMS_CONNMAN_RELEASE_LIB) \
$(MMS_HANDLER_RELEASE_LIB) \
$(MMS_TRANSFERS_RELEASE_LIB) \
$(MMS_SETTINGS_RELEASE_LIB) \
$(MMS_LIB_RELEASE_LIB) \
$(LIBS)
Expand All @@ -168,21 +181,25 @@ DEBUG_DEPS = \
mms_lib_debug_lib \
mms_connman_debug_lib \
mms_handler_debug_lib \
mms_transfers_debug_lib \
mms_settings_debug_lib
RELEASE_DEPS = \
mms_lib_release_lib \
mms_connman_release_lib \
mms_handler_release_lib \
mms_transfers_release_lib \
mms_settings_release_lib
DEBUG_EXE_DEPS = \
$(MMS_LIB_DEBUG_LIB) \
$(MMS_CONNMAN_DEBUG_LIB) \
$(MMS_HANDLER_DEBUG_LIB) \
$(MMS_TRANSFERS_DEBUG_LIB) \
$(MMS_SETTINGS_DEBUG_LIB)
RELEASE_EXE_DEPS = \
$(MMS_LIB_RELEASE_LIB) \
$(MMS_CONNMAN_RELEASE_LIB) \
$(MMS_HANDLER_RELEASE_LIB) \
$(MMS_TRANSFERS_RELEASE_LIB) \
$(MMS_SETTINGS_RELEASE_LIB)
DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d)
ifneq ($(MAKECMDGOALS),clean)
Expand Down Expand Up @@ -214,6 +231,7 @@ cleaner: clean
make -C $(MMS_LIB_DIR) $(SUBMAKE_OPTS) clean
make -C $(MMS_CONNMAN_DIR) $(SUBMAKE_OPTS) clean
make -C $(MMS_HANDLER_DIR) $(SUBMAKE_OPTS) clean
make -C $(MMS_TRANSFERS_DIR) $(SUBMAKE_OPTS) clean
make -C $(MMS_SETTINGS_DIR) $(SUBMAKE_OPTS) clean

$(GEN_DIR):
Expand Down Expand Up @@ -243,6 +261,12 @@ mms_handler_debug_lib:
mms_handler_release_lib:
make -C $(MMS_HANDLER_DIR) $(SUBMAKE_OPTS) release

mms_transfers_debug_lib:
make -C $(MMS_TRANSFERS_DIR) $(SUBMAKE_OPTS) debug

mms_transfers_release_lib:
make -C $(MMS_TRANSFERS_DIR) $(SUBMAKE_OPTS) release

mms_settings_debug_lib:
make -C $(MMS_SETTINGS_DIR) $(SUBMAKE_OPTS) debug

Expand All @@ -261,6 +285,10 @@ $(MMS_HANDLER_DEBUG_LIB): mms_handler_debug_lib

$(MMS_HANDLER_RELEASE_LIB): mms_handler_release_lib

$(MMS_TRANSFERS_DEBUG_LIB): mms_transfers_debug_lib

$(MMS_TRANSFERS_RELEASE_LIB): mms_transfers_release_lib

$(MMS_SETTINGS_DEBUG_LIB): mms_settings_debug_lib

$(MMS_SETTINGS_RELEASE_LIB): mms_settings_release_lib
Expand Down
4 changes: 4 additions & 0 deletions mms-engine/mms-engine.pro
Expand Up @@ -23,12 +23,14 @@ DBUS_INTERFACE_DIR = $$_PRO_FILE_PWD_
MMS_LIB_DIR = $$_PRO_FILE_PWD_/../mms-lib
MMS_HANDLER_DIR = $$_PRO_FILE_PWD_/../mms-handler-dbus
MMS_SETTINGS_DIR = $$_PRO_FILE_PWD_/../mms-settings-dconf
MMS_TRANSFER_LIST_DIR = $$_PRO_FILE_PWD_/../mms-transfer-list-dbus
MMS_CONNMAN_DIR = $$_PRO_FILE_PWD_/../$$MMS_CONNMAN

INCLUDEPATH += $$MMS_LIB_DIR/include
INCLUDEPATH += $$MMS_HANDLER_DIR/include
INCLUDEPATH += $$MMS_SETTINGS_DIR/include
INCLUDEPATH += $$MMS_CONNMAN_DIR/include
INCLUDEPATH += $$MMS_TRANSFER_LIST_DIR/include

SOURCES += \
main.c \
Expand All @@ -47,12 +49,14 @@ CONFIG(debug, debug|release) {
DESTDIR = $$_PRO_FILE_PWD_/build/debug
LIBS += $$MMS_CONNMAN_DIR/build/debug/lib$${MMS_CONNMAN}.a
LIBS += $$MMS_HANDLER_DIR/build/debug/libmms-handler-dbus.a
LIBS += $$MMS_TRANSFER_LIST_DIR/build/debug/libmms-transfer-list-dbus.a
LIBS += $$MMS_LIB_DIR/build/debug/libmms-lib.a
LIBS += $$MMS_SETTINGS_DIR/build/debug/libmms-settings-dconf.a
} else {
DESTDIR = $$_PRO_FILE_PWD_/build/release
LIBS += $$MMS_CONNMAN_DIR/build/release/lib$${MMS_CONNMAN}.a
LIBS += $$MMS_HANDLER_DIR/build/release/libmms-handler-dbus.a
LIBS += $$MMS_TRANSFER_LIST_DIR/build/release/libmms-transfer-list-dbus.a
LIBS += $$MMS_LIB_DIR/build/release/libmms-lib.a
LIBS += $$MMS_SETTINGS_DIR/build/release/libmms-settings-dconf.a
}
Expand Down
5 changes: 4 additions & 1 deletion mms-engine/mms_engine.c
Expand Up @@ -19,6 +19,7 @@
#include "mms_lib_util.h"
#include "mms_handler_dbus.h"
#include "mms_settings_dconf.h"
#include "mms_transfer_list_dbus.h"
#include "mms_log.h"

#include <gutil_misc.h>
Expand Down Expand Up @@ -472,6 +473,7 @@ mms_engine_new(
MMSEngine* mms = g_object_new(MMS_TYPE_ENGINE, NULL);
MMSHandler* handler = mms_handler_dbus_new();
MMSSettings* settings = mms_settings_dconf_new(config);
MMSTransferList* txlist = mms_transfer_list_dbus_new();

if (flags & MMS_ENGINE_FLAG_OVERRIDE_USER_AGENT) {
settings->flags |= MMS_SETTINGS_FLAG_OVERRIDE_USER_AGENT;
Expand All @@ -494,8 +496,9 @@ mms_engine_new(
settings->sim_defaults.data.max_pixels = override->max_pixels;
}

mms->dispatcher = mms_dispatcher_new(settings, cm, handler);
mms->dispatcher = mms_dispatcher_new(settings, cm, handler, txlist);
mms_handler_unref(handler);
mms_transfer_list_unref(txlist);
mms_dispatcher_set_delegate(mms->dispatcher,
&mms->dispatcher_delegate);

Expand Down
1 change: 1 addition & 0 deletions mms-lib/Makefile
Expand Up @@ -49,6 +49,7 @@ SRC = \
mms_task_read.c \
mms_task_retrieve.c \
mms_task_send.c \
mms_transfer_list.c \
mms_util.c

ifeq ($(MMS_RESIZE),Qt)
Expand Down
6 changes: 4 additions & 2 deletions mms-lib/include/mms_dispatcher.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 @@ -30,7 +31,8 @@ MMSDispatcher*
mms_dispatcher_new(
MMSSettings* settings,
MMSConnMan* cm,
MMSHandler* handler);
MMSHandler* handler,
MMSTransferList* transfers);

MMSDispatcher*
mms_dispatcher_ref(
Expand Down
3 changes: 2 additions & 1 deletion mms-lib/include/mms_lib_log.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 All @@ -21,6 +21,7 @@
#define MMS_LIB_LOG_MODULES(log) \
log(mms_dispatcher_log)\
log(mms_settings_log)\
log(mms_transfer_list_log)\
log(mms_handler_log)\
log(mms_message_log)\
log(mms_attachment_log)\
Expand Down
1 change: 1 addition & 0 deletions mms-lib/include/mms_lib_types.h
Expand Up @@ -60,6 +60,7 @@ typedef struct mms_handler MMSHandler;
typedef struct mms_connman MMSConnMan;
typedef struct mms_dispatcher MMSDispatcher;
typedef struct mms_connection MMSConnection;
typedef struct mms_transfer_list MMSTransferList;
typedef struct mms_message MMSPdu;
typedef struct _mms_message MMSMessage;
typedef struct _mms_attachment MMSAttachment;
Expand Down
98 changes: 98 additions & 0 deletions mms-lib/include/mms_transfer_list.h
@@ -0,0 +1,98 @@
/*
* Copyright (C) 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
* 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_TRANSFER_LIST_H
#define JOLLA_MMS_TRANSFER_LIST_H

#include "mms_message.h"

/* Instance */
struct mms_transfer_list {
GObject object;
};

/* Class */
typedef struct mms_transfer_list_class {
GObjectClass parent;
void (*fn_transfer_started)(
MMSTransferList* list, /* Instance */
char* id, /* Message ID */
char* type); /* Transfer type */
void (*fn_transfer_finished)(
MMSTransferList* list, /* Instance */
char* id, /* Message ID */
char* type); /* Transfer type */
void (*fn_send_progress)(
MMSTransferList* list, /* Instance */
char* id, /* Message ID */
char* type, /* Transfer type */
guint bytes_sent, /* Bytes sent so far */
guint bytes_total); /* Total bytes to send */
void (*fn_receive_progress)(
MMSTransferList* list, /* Instance */
char* id, /* Message ID */
char* type, /* Transfer type */
guint bytes_received, /* Bytes received so far */
guint bytes_total); /* Total bytes to receive*/
} MMSTransferListClass;

GType mms_transfer_list_get_type(void);
#define MMS_TYPE_TRANSFER_LIST (mms_transfer_list_get_type())

MMSTransferList*
mms_transfer_list_ref(
MMSTransferList* list);

void
mms_transfer_list_unref(
MMSTransferList* list);

void
mms_transfer_list_transfer_started(
MMSTransferList* list, /* Instance */
char* id, /* Message ID */
char* type); /* Transfer type */

void
mms_transfer_list_transfer_finished(
MMSTransferList* list, /* Instance */
char* id, /* Message ID */
char* type); /* Transfer type */

void
mms_transfer_list_transfer_send_progress(
MMSTransferList* list, /* Instance */
char* id, /* Message ID */
char* type, /* Transfer type */
guint bytes_sent, /* Bytes sent so far */
guint bytes_total); /* Total bytes to send */

void
mms_transfer_list_transfer_receive_progress(
MMSTransferList* list, /* Instance */
char* id, /* Message ID */
char* type, /* Transfer type */
guint bytes_received, /* Bytes received so far */
guint bytes_total); /* Total bytes to receive*/

#endif /* JOLLA_MMS_TRANSFER_LIST_H */

/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
4 changes: 3 additions & 1 deletion mms-lib/mms-lib.pro
Expand Up @@ -50,6 +50,7 @@ SOURCES += \
src/mms_task_read.c \
src/mms_task_retrieve.c \
src/mms_task_send.c \
src/mms_transfer_list.c \
src/mms_util.c

HEADERS += \
Expand All @@ -72,4 +73,5 @@ HEADERS += \
include/mms_lib_util.h \
include/mms_log.h \
include/mms_message.h \
include/mms_settings.h
include/mms_settings.h \
include/mms_transfer_list.h

0 comments on commit 884da77

Please sign in to comment.