Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merged Retrieve and Upload into a single task
This makes even more sense in context of implementing MMS
send which will require a task that both sends (M-Send.req)
and receives (M-Send.conf) data.
  • Loading branch information
monich committed Feb 24, 2014
1 parent 9498ec3 commit f5bb834
Show file tree
Hide file tree
Showing 21 changed files with 799 additions and 775 deletions.
4 changes: 2 additions & 2 deletions mms-lib/Makefile
Expand Up @@ -18,8 +18,8 @@ all: debug release
SRC = mms_codec.c mms_connection.c mms_connman.c mms_dispatcher.c \
mms_error.c mms_handler.c mms_lib_util.c mms_file_util.c mms_log.c \
mms_message.c mms_task.c mms_task_ack.c mms_task_decode.c \
mms_task_notification.c mms_task_notifyresp.c mms_task_publish.c \
mms_task_read.c mms_task_retrieve.c mms_task_upload.c mms_util.c
mms_task_http.c mms_task_notification.c mms_task_notifyresp.c \
mms_task_publish.c mms_task_read.c mms_task_retrieve.c mms_util.c

#
# Directories
Expand Down
3 changes: 1 addition & 2 deletions mms-lib/include/mms_lib_log.h
Expand Up @@ -21,12 +21,11 @@
log(mms_dispatcher_log)\
log(mms_handler_log)\
log(mms_message_log)\
log(mms_util_log)\
log(mms_task_log)\
log(mms_task_http_log)\
log(mms_task_decode_log)\
log(mms_task_notification_log)\
log(mms_task_retrieve_log)\
log(mms_task_upload_log)\
log(mms_task_publish_log)\
log(mms_connman_log)\
log(mms_connection_log)
Expand Down
3 changes: 2 additions & 1 deletion mms-lib/mms-lib.pro
Expand Up @@ -27,19 +27,20 @@ SOURCES += \
src/mms_task.c \
src/mms_task_ack.c \
src/mms_task_decode.c \
src/mms_task_http.c \
src/mms_task_notification.c \
src/mms_task_notifyresp.c \
src/mms_task_publish.c \
src/mms_task_read.c \
src/mms_task_retrieve.c \
src/mms_task_upload.c \
src/mms_util.c

HEADERS += \
src/mms_codec.h \
src/mms_error.h \
src/mms_file_util.h \
src/mms_task.h \
src/mms_task_http.h \
src/mms_util.h \

HEADERS += \
Expand Down
12 changes: 7 additions & 5 deletions mms-lib/src/mms_file_util.c
Expand Up @@ -23,12 +23,14 @@ void
mms_remove_file_and_dir(
const char* file)
{
char* dir = g_path_get_dirname(file);
unlink(file);
if (rmdir(dir) == 0) {
MMS_VERBOSE("Deleted %s", dir);
if (file) {
char* dir = g_path_get_dirname(file);
unlink(file);
if (rmdir(dir) == 0) {
MMS_VERBOSE("Deleted %s", dir);
}
g_free(dir);
}
g_free(dir);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions mms-lib/src/mms_task.c
Expand Up @@ -134,15 +134,22 @@ mms_task_finalize(
G_OBJECT_CLASS(mms_task_parent_class)->finalize(object);
}

static
void
mms_task_class_init(
mms_task_init_class(
MMSTaskClass* klass)
{
klass->fn_cancel = mms_task_cancel_cb;
G_OBJECT_CLASS(klass)->finalize = mms_task_finalize;
}

static
void
mms_task_class_init(
MMSTaskClass* klass)
{
mms_task_init_class(klass);
}

static
void
mms_task_init(
Expand Down
13 changes: 4 additions & 9 deletions mms-lib/src/mms_task.h
Expand Up @@ -87,6 +87,10 @@ GType mms_task_get_type(void);
#define MMS_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \
MMS_TYPE_TASK, MMSTaskClass))

void
mms_task_init_class(
MMSTaskClass* klass);

void*
mms_task_alloc(
GType type,
Expand Down Expand Up @@ -175,15 +179,6 @@ mms_task_decode_new(
const char* transaction_id,
const char* file);

MMSTask*
mms_task_upload_new(
const MMSConfig* config,
MMSHandler* handler,
const char* name,
const char* id,
const char* imsi,
const char* file);

MMSTask*
mms_task_notifyresp_new(
const MMSConfig* config,
Expand Down
35 changes: 16 additions & 19 deletions mms-lib/src/mms_task_ack.c
Expand Up @@ -13,51 +13,48 @@
*/

#include "mms_task.h"
#include "mms_log.h"
#include "mms_codec.h"
#include "mms_task_http.h"
#include "mms_file_util.h"
#include "mms_codec.h"

static
char*
mms_task_ack_create_pdu_file(
const char*
mms_task_ack_encode(
const MMSConfig* config,
const char* id,
const char* transaction_id)
{
char* path = NULL;
const char* result = NULL;
const char* file = MMS_ACKNOWLEDGE_IND_FILE;
char* dir = mms_message_dir(config, id);
int fd = mms_create_file(dir, MMS_ACKNOWLEDGE_IND_FILE, &path, NULL);
int fd = mms_create_file(dir, file, NULL, NULL);
if (fd >= 0) {
MMSPdu* pdu = g_new0(MMSPdu, 1);
pdu->type = MMS_MESSAGE_TYPE_ACKNOWLEDGE_IND;
pdu->version = MMS_VERSION;
pdu->transaction_id = g_strdup(transaction_id);
pdu->ai.report = config->send_dr;
if (!mms_message_encode(pdu, fd)) {
g_free(path);
path = NULL;
}
if (mms_message_encode(pdu, fd)) result = file;
mms_message_free(pdu);
close(fd);
}
g_free(dir);
return path;
return result;
}

/* Create MMS delivery acknowledgement task */
MMSTask*
mms_task_ack_new(
const MMSConfig* cfg,
MMSHandler* h,
const MMSConfig* config,
MMSHandler* handler,
const char* id,
const char* imsi,
const char* transaction_id)
const char* tx_id)
{
char* path = mms_task_ack_create_pdu_file(cfg, id, transaction_id);
if (path) {
MMSTask* task = mms_task_upload_new(cfg, h, "Ack", id, imsi, path);
g_free(path);
return task;
const char* file = mms_task_ack_encode(config, id, tx_id);
if (file) {
return mms_task_http_alloc(0, config, handler, "Ack",
id, imsi, NULL, NULL, file);
}
return NULL;
}
Expand Down
1 change: 1 addition & 0 deletions mms-lib/src/mms_task_decode.c
Expand Up @@ -244,6 +244,7 @@ void
mms_task_decode_class_init(
MMSTaskDecodeClass* klass)
{
mms_task_init_class(MMS_TASK_CLASS(mms_task_decode_parent_class));
klass->fn_run = mms_task_decode_run;
G_OBJECT_CLASS(klass)->finalize = mms_task_decode_finalize;
}
Expand Down

0 comments on commit f5bb834

Please sign in to comment.