2012-10-06 13:52:09

by Srinivasa Ragavan

[permalink] [raw]
Subject: [PATCH 1/3] client: Add implementation for UpdateInbox

---
client/map.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)

diff --git a/client/map.c b/client/map.c
index 290eaae..c0a5bfc 100644
--- a/client/map.c
+++ b/client/map.c
@@ -1242,6 +1242,60 @@ static DBusMessage *map_list_filter_fields(DBusConnection *connection,
return reply;
}

+static void update_inbox_cb(struct obc_session *session,
+ struct obc_transfer *transfer,
+ GError *err, void *user_data)
+{
+ struct map_data *map = user_data;
+ DBusMessage *reply;
+
+ if (err != NULL) {
+ reply = g_dbus_create_error(map->msg,
+ ERROR_INTERFACE ".Failed",
+ "%s", err->message);
+ goto done;
+ }
+
+ reply = dbus_message_new_method_return(map->msg);
+
+done:
+ g_dbus_send_message(conn, reply);
+ dbus_message_unref(map->msg);
+}
+
+static DBusMessage *map_update_inbox(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ struct map_data *map = user_data;
+ DBusMessage *reply;
+ char contents[2];
+ struct obc_transfer *transfer;
+ GError *err = NULL;
+
+ contents[0] = FILLER_BYTE;
+ contents[1] = '\0';
+
+ transfer = obc_transfer_put("x-bt/MAP-messageUpdate", NULL, NULL,
+ contents,
+ sizeof(contents), &err);
+ if (transfer == NULL)
+ goto fail;
+
+ if (!obc_session_queue(map->session, transfer,
+ update_inbox_cb, map, &err))
+ goto fail;
+
+ map->msg = dbus_message_ref(message);
+
+ return NULL;
+
+fail:
+ reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
+ err->message);
+ g_error_free(err);
+ return reply;
+}
+
static const GDBusMethodTable map_methods[] = {
{ GDBUS_ASYNC_METHOD("SetFolder",
GDBUS_ARGS({ "name", "s" }), NULL,
@@ -1258,6 +1312,10 @@ static const GDBusMethodTable map_methods[] = {
NULL,
GDBUS_ARGS({ "fields", "as" }),
map_list_filter_fields) },
+ { GDBUS_ASYNC_METHOD("UpdateInbox",
+ NULL,
+ NULL,
+ map_update_inbox) },
{ }
};

--
1.7.10.4



2012-10-09 10:16:53

by Srinivasa Ragavan

[permalink] [raw]
Subject: Re: [PATCH 1/3] client: Add implementation for UpdateInbox

Hi Luiz

On Tue, Oct 9, 2012 at 2:44 PM, Luiz Augusto von Dentz
<[email protected]> wrote:
> Hi Srinivasa,
>
> On Sat, Oct 6, 2012 at 3:52 PM, Srinivasa Ragavan
> <[email protected]> wrote:
>> ---
>> client/map.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 58 insertions(+)
>>
>> diff --git a/client/map.c b/client/map.c
>> index 290eaae..c0a5bfc 100644
>> --- a/client/map.c
>> +++ b/client/map.c
>> @@ -1242,6 +1242,60 @@ static DBusMessage *map_list_filter_fields(DBusConnection *connection,
>> return reply;
>> }
>>
>> +static void update_inbox_cb(struct obc_session *session,
>> + struct obc_transfer *transfer,
>> + GError *err, void *user_data)
>> +{
>> + struct map_data *map = user_data;
>> + DBusMessage *reply;
>> +
>> + if (err != NULL) {
>> + reply = g_dbus_create_error(map->msg,
>> + ERROR_INTERFACE ".Failed",
>> + "%s", err->message);
>> + goto done;
>> + }
>> +
>> + reply = dbus_message_new_method_return(map->msg);
>> +
>> +done:
>> + g_dbus_send_message(conn, reply);
>> + dbus_message_unref(map->msg);
>> +}
>> +
>> +static DBusMessage *map_update_inbox(DBusConnection *connection,
>> + DBusMessage *message, void *user_data)
>> +{
>> + struct map_data *map = user_data;
>> + DBusMessage *reply;
>> + char contents[2];
>> + struct obc_transfer *transfer;
>> + GError *err = NULL;
>> +
>> + contents[0] = FILLER_BYTE;
>> + contents[1] = '\0';
>> +
>> + transfer = obc_transfer_put("x-bt/MAP-messageUpdate", NULL, NULL,
>> + contents,
>> + sizeof(contents), &err);
>> + if (transfer == NULL)
>> + goto fail;
>> +
>> + if (!obc_session_queue(map->session, transfer,
>> + update_inbox_cb, map, &err))
>> + goto fail;
>> +
>> + map->msg = dbus_message_ref(message);
>> +
>> + return NULL;
>> +
>> +fail:
>> + reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
>> + err->message);
>> + g_error_free(err);
>> + return reply;
>> +}
>> +
>> static const GDBusMethodTable map_methods[] = {
>> { GDBUS_ASYNC_METHOD("SetFolder",
>> GDBUS_ARGS({ "name", "s" }), NULL,
>> @@ -1258,6 +1312,10 @@ static const GDBusMethodTable map_methods[] = {
>> NULL,
>> GDBUS_ARGS({ "fields", "as" }),
>> map_list_filter_fields) },
>> + { GDBUS_ASYNC_METHOD("UpdateInbox",
>> + NULL,
>> + NULL,
>> + map_update_inbox) },
>> { }
>> };
>>
>> --
>> 1.7.10.4
>
> These patches are now upstream, Ive made some codestyle changes
> because we don't use spaces to align on multilines but checkpatch
> don't seem to catch those are they are no really mandatory on kernel.

I'll be careful from here on. Thx for working it up.

-Srini.

2012-10-09 09:14:08

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH 1/3] client: Add implementation for UpdateInbox

Hi Srinivasa,

On Sat, Oct 6, 2012 at 3:52 PM, Srinivasa Ragavan
<[email protected]> wrote:
> ---
> client/map.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 58 insertions(+)
>
> diff --git a/client/map.c b/client/map.c
> index 290eaae..c0a5bfc 100644
> --- a/client/map.c
> +++ b/client/map.c
> @@ -1242,6 +1242,60 @@ static DBusMessage *map_list_filter_fields(DBusConnection *connection,
> return reply;
> }
>
> +static void update_inbox_cb(struct obc_session *session,
> + struct obc_transfer *transfer,
> + GError *err, void *user_data)
> +{
> + struct map_data *map = user_data;
> + DBusMessage *reply;
> +
> + if (err != NULL) {
> + reply = g_dbus_create_error(map->msg,
> + ERROR_INTERFACE ".Failed",
> + "%s", err->message);
> + goto done;
> + }
> +
> + reply = dbus_message_new_method_return(map->msg);
> +
> +done:
> + g_dbus_send_message(conn, reply);
> + dbus_message_unref(map->msg);
> +}
> +
> +static DBusMessage *map_update_inbox(DBusConnection *connection,
> + DBusMessage *message, void *user_data)
> +{
> + struct map_data *map = user_data;
> + DBusMessage *reply;
> + char contents[2];
> + struct obc_transfer *transfer;
> + GError *err = NULL;
> +
> + contents[0] = FILLER_BYTE;
> + contents[1] = '\0';
> +
> + transfer = obc_transfer_put("x-bt/MAP-messageUpdate", NULL, NULL,
> + contents,
> + sizeof(contents), &err);
> + if (transfer == NULL)
> + goto fail;
> +
> + if (!obc_session_queue(map->session, transfer,
> + update_inbox_cb, map, &err))
> + goto fail;
> +
> + map->msg = dbus_message_ref(message);
> +
> + return NULL;
> +
> +fail:
> + reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
> + err->message);
> + g_error_free(err);
> + return reply;
> +}
> +
> static const GDBusMethodTable map_methods[] = {
> { GDBUS_ASYNC_METHOD("SetFolder",
> GDBUS_ARGS({ "name", "s" }), NULL,
> @@ -1258,6 +1312,10 @@ static const GDBusMethodTable map_methods[] = {
> NULL,
> GDBUS_ARGS({ "fields", "as" }),
> map_list_filter_fields) },
> + { GDBUS_ASYNC_METHOD("UpdateInbox",
> + NULL,
> + NULL,
> + map_update_inbox) },
> { }
> };
>
> --
> 1.7.10.4

These patches are now upstream, Ive made some codestyle changes
because we don't use spaces to align on multilines but checkpatch
don't seem to catch those are they are no really mandatory on kernel.

--
Luiz Augusto von Dentz

2012-10-06 13:54:23

by Srinivasa Ragavan

[permalink] [raw]
Subject: Re: [PATCH 2/4] client: Add Message.SetProperty and Message.GetProperties implementation.

On Sat, Oct 6, 2012 at 7:22 PM, Srinivasa Ragavan
<[email protected]> wrote:
> ---
> client/map.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 190 insertions(+)
>
Argh, got flushed from my outbox, when I was sending a different
patch. This is already applied. Please ignore this patch.

-Srini.
> diff --git a/client/map.c b/client/map.c
> index e78cd68..fc2d874 100644
> --- a/client/map.c
> +++ b/client/map.c
> @@ -28,6 +28,7 @@
> #include <string.h>
> #include <stdio.h>
> #include <glib.h>
> +#include <glib/gstdio.h>
> #include <gdbus.h>
>
> #include <gobex-apparam.h>
> @@ -78,6 +79,10 @@ static const char * const filter_list[] = {
> #define FILTER_BIT_MAX 15
> #define FILTER_ALL 0xFF
>
> +#define STATUS_READ 0
> +#define STATUS_DELETE 1
> +#define FILLER_BYTE 0x30
> +
> struct map_data {
> struct obc_session *session;
> DBusMessage *msg;
> @@ -104,6 +109,7 @@ struct map_msg {
> uint64_t size;
> char *status;
> uint8_t flags;
> + DBusMessage *msg;
> };
>
> struct map_parser {
> @@ -412,6 +418,183 @@ fail:
> return reply;
> }
>
> +static void set_message_status_cb(struct obc_session *session,
> + struct obc_transfer *transfer,
> + GError *err, void *user_data)
> +{
> + struct map_msg *msg = user_data;
> + DBusMessage *reply;
> +
> + if (err != NULL) {
> + reply = g_dbus_create_error(msg->msg,
> + ERROR_INTERFACE ".Failed",
> + "%s", err->message);
> + goto done;
> + }
> +
> + reply = dbus_message_new_method_return(msg->msg);
> + if (reply == NULL) {
> + reply = g_dbus_create_error(msg->msg,
> + ERROR_INTERFACE ".Failed",
> + "%s", err->message);
> + }
> +
> +done:
> + g_dbus_send_message(conn, reply);
> + dbus_message_unref(msg->msg);
> + msg->msg = NULL;
> +}
> +
> +static DBusMessage *map_msg_set_property(DBusConnection *connection,
> + DBusMessage *message,
> + void *user_data)
> +{
> + struct map_msg *msg = user_data;
> + struct obc_transfer *transfer;
> + char *property;
> + gboolean status;
> + GError *err = NULL;
> + DBusMessage *reply;
> + GObexApparam *apparam;
> + char contents[2];
> + int op;
> + DBusMessageIter args, variant;
> +
> + dbus_message_iter_init(message, &args);
> + if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING)
> + return g_dbus_create_error(message,
> + ERROR_INTERFACE ".InvalidArguments", NULL);
> +
> + dbus_message_iter_get_basic(&args, &property);
> + dbus_message_iter_next(&args);
> + if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_VARIANT)
> + return g_dbus_create_error(message,
> + ERROR_INTERFACE ".InvalidArguments", NULL);
> +
> + dbus_message_iter_recurse(&args, &variant);
> + if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_BOOLEAN)
> + return g_dbus_create_error(message,
> + ERROR_INTERFACE ".InvalidArguments", NULL);
> +
> + dbus_message_iter_get_basic(&variant, &status);
> +
> + /* MAP supports modifying only these two properties. */
> + if (property && strcasecmp(property, "Read") == 0) {
> + op = STATUS_READ;
> + if (status)
> + msg->flags |= MAP_MSG_FLAG_READ;
> + else
> + msg->flags &= ~MAP_MSG_FLAG_READ;
> + } else if (property && strcasecmp(property, "Deleted") == 0)
> + op = STATUS_DELETE;
> + else {
> + return g_dbus_create_error(message,
> + ERROR_INTERFACE ".InvalidArguments", NULL);
> + }
> +
> + contents[0] = FILLER_BYTE;
> + contents[1] = '\0';
> +
> + transfer = obc_transfer_put("x-bt/messageStatus", msg->handle, NULL,
> + contents,
> + sizeof(contents), &err);
> + if (transfer == NULL)
> + goto fail;
> +
> + apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_STATUSINDICATOR,
> + op);
> + apparam = g_obex_apparam_set_uint8(apparam, MAP_AP_STATUSVALUE,
> + status);
> + obc_transfer_set_apparam(transfer, apparam);
> +
> + if (!obc_session_queue(msg->data->session, transfer,
> + set_message_status_cb, msg, &err))
> + goto fail;
> +
> + msg->msg = dbus_message_ref(message);
> + return NULL;
> +
> +fail:
> + reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
> + err->message);
> + g_error_free(err);
> + return reply;
> +}
> +
> +static DBusMessage *map_msg_get_properties(DBusConnection *connection,
> + DBusMessage *message,
> + void *user_data)
> +{
> + struct map_msg *msg = user_data;
> + GError *err = NULL;
> + DBusMessage *reply;
> + DBusMessageIter iter, data_array;
> + gboolean flag;
> +
> + reply = dbus_message_new_method_return(message);
> + if (reply == NULL) {
> + reply = g_dbus_create_error(message,
> + ERROR_INTERFACE ".Failed",
> + NULL);
> + goto done;
> + }
> +
> + dbus_message_iter_init_append(reply, &iter);
> + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
> + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
> + DBUS_TYPE_STRING_AS_STRING
> + DBUS_TYPE_VARIANT_AS_STRING
> + DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
> + &data_array);
> +
> +
> + obex_dbus_dict_append(&data_array, "Subject",
> + DBUS_TYPE_STRING, &msg->subject);
> + obex_dbus_dict_append(&data_array, "Timestamp",
> + DBUS_TYPE_STRING, &msg->timestamp);
> + obex_dbus_dict_append(&data_array, "Sender",
> + DBUS_TYPE_STRING, &msg->sender);
> + obex_dbus_dict_append(&data_array, "SenderAddress",
> + DBUS_TYPE_STRING, &msg->sender_address);
> + obex_dbus_dict_append(&data_array, "ReplyTo",
> + DBUS_TYPE_STRING, &msg->replyto);
> + obex_dbus_dict_append(&data_array, "Recipient",
> + DBUS_TYPE_STRING, &msg->recipient);
> + obex_dbus_dict_append(&data_array, "RecipientAddress",
> + DBUS_TYPE_STRING, &msg->recipient_address);
> + obex_dbus_dict_append(&data_array, "Type",
> + DBUS_TYPE_STRING, &msg->type);
> + obex_dbus_dict_append(&data_array, "Status",
> + DBUS_TYPE_STRING, &msg->status);
> + obex_dbus_dict_append(&data_array, "Size",
> + DBUS_TYPE_UINT64, &msg->size);
> +
> + flag = (msg->flags & MAP_MSG_FLAG_PRIORITY) != 0;
> + obex_dbus_dict_append(&data_array, "Priority",
> + DBUS_TYPE_BOOLEAN, &flag);
> +
> + flag = (msg->flags & MAP_MSG_FLAG_READ) != 0;
> + obex_dbus_dict_append(&data_array, "Read",
> + DBUS_TYPE_BOOLEAN, &flag);
> +
> + flag = (msg->flags & MAP_MSG_FLAG_SENT) != 0;
> + obex_dbus_dict_append(&data_array, "Sent",
> + DBUS_TYPE_BOOLEAN, &flag);
> +
> + flag = (msg->flags & MAP_MSG_FLAG_PROTECTED) != 0;
> + obex_dbus_dict_append(&data_array, "Protected",
> + DBUS_TYPE_BOOLEAN, &flag);
> +
> + dbus_message_iter_close_container(&iter, &data_array);
> +
> +
> +done:
> + if (err)
> + g_error_free(err);
> +
> + return reply;
> +}
> +
> static const GDBusMethodTable map_msg_methods[] = {
> { GDBUS_METHOD("Get",
> GDBUS_ARGS({ "targetfile", "s" },
> @@ -419,6 +602,13 @@ static const GDBusMethodTable map_msg_methods[] = {
> GDBUS_ARGS({ "transfer", "o" },
> { "properties", "a{sv}" }),
> map_msg_get) },
> + { GDBUS_METHOD("GetProperties",
> + NULL,
> + GDBUS_ARGS({ "properties", "a{sv}" }),
> + map_msg_get_properties) },
> + { GDBUS_ASYNC_METHOD("SetProperty",
> + GDBUS_ARGS({ "property", "sv" }), NULL,
> + map_msg_set_property) },
> { }
> };
>
> --
> 1.7.10.4
>

2012-10-06 13:54:09

by Srinivasa Ragavan

[permalink] [raw]
Subject: Re: [PATCH 1/4] client: Update the file offset to the beginning after writing to the file

On Sat, Oct 6, 2012 at 7:22 PM, Srinivasa Ragavan
<[email protected]> wrote:
> When the transfer file is opened in O_RDWR mode, just after the contents are
> written to the file, the file offset has to be set to the beginning of the
> file. If not subsequent read fails. This patch fixes this.

Argh, got flushed from my outbox, when I was sending a different
patch. This is already applied. Please ignore this patch.

-Srini.
> ---
> client/transfer.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/client/transfer.c b/client/transfer.c
> index fbcafc8..cac3884 100644
> --- a/client/transfer.c
> +++ b/client/transfer.c
> @@ -426,6 +426,7 @@ struct obc_transfer *obc_transfer_put(const char *type, const char *name,
> "Writing all contents to file failed");
> goto fail;
> }
> + lseek(transfer->fd, 0, SEEK_SET);
> } else {
> if (!transfer_open(transfer, O_RDONLY, 0, err))
> goto fail;
> --
> 1.7.10.4
>

2012-10-06 13:52:14

by Srinivasa Ragavan

[permalink] [raw]
Subject: [PATCH 3/3] test: Update map-client to include UpdateInbox.

---
test/map-client | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/test/map-client b/test/map-client
index e8c42e3..756ebb8 100755
--- a/test/map-client
+++ b/test/map-client
@@ -51,6 +51,8 @@ def parse_options():
help="Deletes the message from the folder")
parser.add_option("--mark-undeleted", action="store", dest="mark_msg_undeleted",
help="Undeletes the message")
+ parser.add_option("-u", "--update-inbox", action="store_true", dest="update_inbox",
+ help="Checks for new mails")

return parser.parse_args()

@@ -145,6 +147,9 @@ class MapClient:
msg = dbus.Interface(obj, "org.bluez.obex.Message")
msg.SetProperty (prop, flag);

+ def update_inbox(self):
+ self.map.UpdateInbox()
+

if __name__ == '__main__':

@@ -196,5 +201,7 @@ if __name__ == '__main__':
if options.mark_msg_undeleted is not None:
map_client.set_message_property(options.mark_msg_undeleted, "Deleted", False)

+ if options.update_inbox:
+ map_client.update_inbox()

mainloop.run()
--
1.7.10.4


2012-10-06 13:52:12

by Srinivasa Ragavan

[permalink] [raw]
Subject: [PATCH 2/3] client-doc: Add documentation for UpdateInbox

---
doc/client-api.txt | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/doc/client-api.txt b/doc/client-api.txt
index e680427..1222ff3 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -460,6 +460,11 @@ Methods void SetFolder(string name)

Message protected flag

+ void UpdateInbox(void)
+
+ Requests the MSE to update its inbox.
+
+
Filter: uint16 Offset:

Offset of the first item, default is 0
--
1.7.10.4


2012-10-06 13:52:10

by Srinivasa Ragavan

[permalink] [raw]
Subject: [PATCH 1/4] client: Update the file offset to the beginning after writing to the file

When the transfer file is opened in O_RDWR mode, just after the contents are
written to the file, the file offset has to be set to the beginning of the
file. If not subsequent read fails. This patch fixes this.
---
client/transfer.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/client/transfer.c b/client/transfer.c
index fbcafc8..cac3884 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -426,6 +426,7 @@ struct obc_transfer *obc_transfer_put(const char *type, const char *name,
"Writing all contents to file failed");
goto fail;
}
+ lseek(transfer->fd, 0, SEEK_SET);
} else {
if (!transfer_open(transfer, O_RDONLY, 0, err))
goto fail;
--
1.7.10.4


2012-10-06 13:52:11

by Srinivasa Ragavan

[permalink] [raw]
Subject: [PATCH 2/4] client: Add Message.SetProperty and Message.GetProperties implementation.

---
client/map.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 190 insertions(+)

diff --git a/client/map.c b/client/map.c
index e78cd68..fc2d874 100644
--- a/client/map.c
+++ b/client/map.c
@@ -28,6 +28,7 @@
#include <string.h>
#include <stdio.h>
#include <glib.h>
+#include <glib/gstdio.h>
#include <gdbus.h>

#include <gobex-apparam.h>
@@ -78,6 +79,10 @@ static const char * const filter_list[] = {
#define FILTER_BIT_MAX 15
#define FILTER_ALL 0xFF

+#define STATUS_READ 0
+#define STATUS_DELETE 1
+#define FILLER_BYTE 0x30
+
struct map_data {
struct obc_session *session;
DBusMessage *msg;
@@ -104,6 +109,7 @@ struct map_msg {
uint64_t size;
char *status;
uint8_t flags;
+ DBusMessage *msg;
};

struct map_parser {
@@ -412,6 +418,183 @@ fail:
return reply;
}

+static void set_message_status_cb(struct obc_session *session,
+ struct obc_transfer *transfer,
+ GError *err, void *user_data)
+{
+ struct map_msg *msg = user_data;
+ DBusMessage *reply;
+
+ if (err != NULL) {
+ reply = g_dbus_create_error(msg->msg,
+ ERROR_INTERFACE ".Failed",
+ "%s", err->message);
+ goto done;
+ }
+
+ reply = dbus_message_new_method_return(msg->msg);
+ if (reply == NULL) {
+ reply = g_dbus_create_error(msg->msg,
+ ERROR_INTERFACE ".Failed",
+ "%s", err->message);
+ }
+
+done:
+ g_dbus_send_message(conn, reply);
+ dbus_message_unref(msg->msg);
+ msg->msg = NULL;
+}
+
+static DBusMessage *map_msg_set_property(DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ struct map_msg *msg = user_data;
+ struct obc_transfer *transfer;
+ char *property;
+ gboolean status;
+ GError *err = NULL;
+ DBusMessage *reply;
+ GObexApparam *apparam;
+ char contents[2];
+ int op;
+ DBusMessageIter args, variant;
+
+ dbus_message_iter_init(message, &args);
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING)
+ return g_dbus_create_error(message,
+ ERROR_INTERFACE ".InvalidArguments", NULL);
+
+ dbus_message_iter_get_basic(&args, &property);
+ dbus_message_iter_next(&args);
+ if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_VARIANT)
+ return g_dbus_create_error(message,
+ ERROR_INTERFACE ".InvalidArguments", NULL);
+
+ dbus_message_iter_recurse(&args, &variant);
+ if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_BOOLEAN)
+ return g_dbus_create_error(message,
+ ERROR_INTERFACE ".InvalidArguments", NULL);
+
+ dbus_message_iter_get_basic(&variant, &status);
+
+ /* MAP supports modifying only these two properties. */
+ if (property && strcasecmp(property, "Read") == 0) {
+ op = STATUS_READ;
+ if (status)
+ msg->flags |= MAP_MSG_FLAG_READ;
+ else
+ msg->flags &= ~MAP_MSG_FLAG_READ;
+ } else if (property && strcasecmp(property, "Deleted") == 0)
+ op = STATUS_DELETE;
+ else {
+ return g_dbus_create_error(message,
+ ERROR_INTERFACE ".InvalidArguments", NULL);
+ }
+
+ contents[0] = FILLER_BYTE;
+ contents[1] = '\0';
+
+ transfer = obc_transfer_put("x-bt/messageStatus", msg->handle, NULL,
+ contents,
+ sizeof(contents), &err);
+ if (transfer == NULL)
+ goto fail;
+
+ apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_STATUSINDICATOR,
+ op);
+ apparam = g_obex_apparam_set_uint8(apparam, MAP_AP_STATUSVALUE,
+ status);
+ obc_transfer_set_apparam(transfer, apparam);
+
+ if (!obc_session_queue(msg->data->session, transfer,
+ set_message_status_cb, msg, &err))
+ goto fail;
+
+ msg->msg = dbus_message_ref(message);
+ return NULL;
+
+fail:
+ reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
+ err->message);
+ g_error_free(err);
+ return reply;
+}
+
+static DBusMessage *map_msg_get_properties(DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ struct map_msg *msg = user_data;
+ GError *err = NULL;
+ DBusMessage *reply;
+ DBusMessageIter iter, data_array;
+ gboolean flag;
+
+ reply = dbus_message_new_method_return(message);
+ if (reply == NULL) {
+ reply = g_dbus_create_error(message,
+ ERROR_INTERFACE ".Failed",
+ NULL);
+ goto done;
+ }
+
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+ DBUS_TYPE_STRING_AS_STRING
+ DBUS_TYPE_VARIANT_AS_STRING
+ DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+ &data_array);
+
+
+ obex_dbus_dict_append(&data_array, "Subject",
+ DBUS_TYPE_STRING, &msg->subject);
+ obex_dbus_dict_append(&data_array, "Timestamp",
+ DBUS_TYPE_STRING, &msg->timestamp);
+ obex_dbus_dict_append(&data_array, "Sender",
+ DBUS_TYPE_STRING, &msg->sender);
+ obex_dbus_dict_append(&data_array, "SenderAddress",
+ DBUS_TYPE_STRING, &msg->sender_address);
+ obex_dbus_dict_append(&data_array, "ReplyTo",
+ DBUS_TYPE_STRING, &msg->replyto);
+ obex_dbus_dict_append(&data_array, "Recipient",
+ DBUS_TYPE_STRING, &msg->recipient);
+ obex_dbus_dict_append(&data_array, "RecipientAddress",
+ DBUS_TYPE_STRING, &msg->recipient_address);
+ obex_dbus_dict_append(&data_array, "Type",
+ DBUS_TYPE_STRING, &msg->type);
+ obex_dbus_dict_append(&data_array, "Status",
+ DBUS_TYPE_STRING, &msg->status);
+ obex_dbus_dict_append(&data_array, "Size",
+ DBUS_TYPE_UINT64, &msg->size);
+
+ flag = (msg->flags & MAP_MSG_FLAG_PRIORITY) != 0;
+ obex_dbus_dict_append(&data_array, "Priority",
+ DBUS_TYPE_BOOLEAN, &flag);
+
+ flag = (msg->flags & MAP_MSG_FLAG_READ) != 0;
+ obex_dbus_dict_append(&data_array, "Read",
+ DBUS_TYPE_BOOLEAN, &flag);
+
+ flag = (msg->flags & MAP_MSG_FLAG_SENT) != 0;
+ obex_dbus_dict_append(&data_array, "Sent",
+ DBUS_TYPE_BOOLEAN, &flag);
+
+ flag = (msg->flags & MAP_MSG_FLAG_PROTECTED) != 0;
+ obex_dbus_dict_append(&data_array, "Protected",
+ DBUS_TYPE_BOOLEAN, &flag);
+
+ dbus_message_iter_close_container(&iter, &data_array);
+
+
+done:
+ if (err)
+ g_error_free(err);
+
+ return reply;
+}
+
static const GDBusMethodTable map_msg_methods[] = {
{ GDBUS_METHOD("Get",
GDBUS_ARGS({ "targetfile", "s" },
@@ -419,6 +602,13 @@ static const GDBusMethodTable map_msg_methods[] = {
GDBUS_ARGS({ "transfer", "o" },
{ "properties", "a{sv}" }),
map_msg_get) },
+ { GDBUS_METHOD("GetProperties",
+ NULL,
+ GDBUS_ARGS({ "properties", "a{sv}" }),
+ map_msg_get_properties) },
+ { GDBUS_ASYNC_METHOD("SetProperty",
+ GDBUS_ARGS({ "property", "sv" }), NULL,
+ map_msg_set_property) },
{ }
};

--
1.7.10.4


2012-10-04 20:55:03

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH 1/4] client: Update the file offset to the beginning after writing to the file

Hi Srinivasa,

On Thu, Oct 4, 2012 at 5:22 PM, Srinivasa Ragavan
<[email protected]> wrote:
> When the transfer file is opened in O_RDWR mode, just after the contents are
> written to the file, the file offset has to be set to the beginning of the
> file. If not subsequent read fails. This patch fixes this.
> ---
> client/transfer.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/client/transfer.c b/client/transfer.c
> index fbcafc8..cac3884 100644
> --- a/client/transfer.c
> +++ b/client/transfer.c
> @@ -426,6 +426,7 @@ struct obc_transfer *obc_transfer_put(const char *type, const char *name,
> "Writing all contents to file failed");
> goto fail;
> }
> + lseek(transfer->fd, 0, SEEK_SET);
> } else {
> if (!transfer_open(transfer, O_RDONLY, 0, err))
> goto fail;
> --
> 1.7.10.4

All 4 patches are now upstream, thanks.


--
Luiz Augusto von Dentz