2012-05-21 09:07:02

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 00/12] client: Polishing D-Bus API

From: Mikel Astiz <[email protected]>

This patchset includes a first set of D-Bus changes as part of a bigger API rewrite in obex-client. The original API proposal started around 6 months ago ([1]) and it has later been discussed and modified several times.

This first series proposes some minor refactoring of the existing APIs. The most relevant part, regarding the removal of the agent, is left for a later discussion.

[1] http://marc.info/?l=linux-bluetooth&m=132189357404237&w=2

Mikel Astiz (12):
client-doc: Wrap OPP into specific session type
client: Use constant instead of NULL variable
client: Wrap OPP into specific session type
client-test: Update to wrapped OPP session type
client-doc: Replace SendFiles with SendFile
client: Replace SendFiles with SendFile
client-test: Replace SendFiles with SendFile
client-doc: Move GetCapabilities to session API
client: Move GetCapabilities to session API
client-doc: Replace parameter dict with conventional ones
client: Replace parameter dict with conventional ones
client-test: Replace CreateSession parameter dict

client/manager.c | 406 ++---------------------------------------
client/opp.c | 205 +++++++++++++++++++++-
client/session.c | 68 +++++++
doc/client-api.txt | 69 ++++---
test/exchange-business-cards | 9 +-
test/ftp-client | 3 +-
test/get-capabilities | 15 +-
test/list-folders | 2 +-
test/map-client | 3 +-
test/pbap-client | 2 +-
test/pull-business-card | 8 +-
test/send-files | 85 ++--------
12 files changed, 370 insertions(+), 505 deletions(-)

--
1.7.7.6



2012-05-23 10:36:44

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH obexd v0 00/12] client: Polishing D-Bus API

Hi Mikel,

On Mon, May 21, 2012 at 12:07 PM, Mikel Astiz <[email protected]> wrote:
> From: Mikel Astiz <[email protected]>
>
> This patchset includes a first set of D-Bus changes as part of a bigger API rewrite in obex-client. The original API proposal started around 6 months ago ([1]) and it has later been discussed and modified several times.
>
> This first series proposes some minor refactoring of the existing APIs. The most relevant part, regarding the removal of the agent, is left for a later discussion.
>
> [1] http://marc.info/?l=linux-bluetooth&m=132189357404237&w=2
>
> Mikel Astiz (12):
> ?client-doc: Wrap OPP into specific session type
> ?client: Use constant instead of NULL variable
> ?client: Wrap OPP into specific session type
> ?client-test: Update to wrapped OPP session type
> ?client-doc: Replace SendFiles with SendFile
> ?client: Replace SendFiles with SendFile
> ?client-test: Replace SendFiles with SendFile
> ?client-doc: Move GetCapabilities to session API
> ?client: Move GetCapabilities to session API
> ?client-doc: Replace parameter dict with conventional ones
> ?client: Replace parameter dict with conventional ones
> ?client-test: Replace CreateSession parameter dict
>
> ?client/manager.c ? ? ? ? ? ? | ?406 ++---------------------------------------
> ?client/opp.c ? ? ? ? ? ? ? ? | ?205 +++++++++++++++++++++-
> ?client/session.c ? ? ? ? ? ? | ? 68 +++++++
> ?doc/client-api.txt ? ? ? ? ? | ? 69 ++++---
> ?test/exchange-business-cards | ? ?9 +-
> ?test/ftp-client ? ? ? ? ? ? ?| ? ?3 +-
> ?test/get-capabilities ? ? ? ?| ? 15 +-
> ?test/list-folders ? ? ? ? ? ?| ? ?2 +-
> ?test/map-client ? ? ? ? ? ? ?| ? ?3 +-
> ?test/pbap-client ? ? ? ? ? ? | ? ?2 +-
> ?test/pull-business-card ? ? ?| ? ?8 +-
> ?test/send-files ? ? ? ? ? ? ?| ? 85 ++--------
> ?12 files changed, 370 insertions(+), 505 deletions(-)
>
> --
> 1.7.7.6

All 12 patches pushed upstream, thanks.


--
Luiz Augusto von Dentz

2012-05-21 12:39:53

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH obexd v0 05/12] client-doc: Replace SendFiles with SendFile

Hi Mikel,

On Mon, May 21, 2012 at 2:40 PM, Mikel Astiz <[email protected]> wrote:
> In addition, this change does make some sense on its own, since it
> maps better to the OBEX spec. IIRC SendFiles was there to avoid
> creating one session per transfer, but this is no longer a problem
> once OPP is wrapped in a session type. It also allows to have a
> asynchronous call, so the client can wait until the transfer is
> finished.

I don't think the client should be waiting it to finish, it is a bad
API because it can take forever to transfer the file and eventually
the message will timeout while the transfer is still ongoing, besides
it takes away the possibility to cancel the transfer or watch its
progress.

> So I can merge both changes but I would rather keep them separated, so
> we can have more consistent APIs after each step.

Hmm, but I would have the changes to the same API at least in the same set.

--
Luiz Augusto von Dentz

2012-05-21 11:40:27

by Mikel Astiz

[permalink] [raw]
Subject: Re: [PATCH obexd v0 05/12] client-doc: Replace SendFiles with SendFile

Hi Luiz,

On Mon, May 21, 2012 at 11:33 AM, Luiz Augusto von Dentz
<[email protected]> wrote:
> Hi Mikel,
>
> On Mon, May 21, 2012 at 12:07 PM, Mikel Astiz <[email protected]> wrote:
>> From: Mikel Astiz <[email protected]>
>>
>> Now that OPP sessions exist, sending multiple files can be achieved with
>> consecutive calls to SendFile. Note that within a session the pending
>> operations will be queued and sequentially executed.
>> ---
>> ?doc/client-api.txt | ? ?4 ++--
>> ?1 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/doc/client-api.txt b/doc/client-api.txt
>> index 32caa17..de726a8 100644
>> --- a/doc/client-api.txt
>> +++ b/doc/client-api.txt
>> @@ -65,9 +65,9 @@ Service ? ? ? ? ? ? ? org.openobex.client
>> ?Interface ? ? ?org.openobex.ObjectPush
>> ?Object path ? ?[variable prefix]/{session0,session1,...}
>>
>> -Methods ? ? ? ? ? ? ? ?void SendFiles(array{string} files)
>> +Methods ? ? ? ? ? ? ? ?void SendFile(string sourcefile)
>>
>> - ? ? ? ? ? ? ? ? ? ? ? Send one or multiple local files to the remote device.
>> + ? ? ? ? ? ? ? ? ? ? ? Send one local file to the remote device.
>>
>> ? ? ? ? ? ? ? ?void PullBusinessCard(string targetfile)
>>
>> --
>> 1.7.7.6
>
> Perhaps it is a good idea to return the transfer object here, so the
> application can track the progress and cancel it which is the whole
> point of not having multiple files so we can do this properly.

It is a good idea indeed, but I was planning to do this in a later
patch along with the rest of the API, for example PullBusinessCard.
Most of the D-Bus interfaces will need such a transition in fact.

In addition, this change does make some sense on its own, since it
maps better to the OBEX spec. IIRC SendFiles was there to avoid
creating one session per transfer, but this is no longer a problem
once OPP is wrapped in a session type. It also allows to have a
asynchronous call, so the client can wait until the transfer is
finished.

So I can merge both changes but I would rather keep them separated, so
we can have more consistent APIs after each step.

Cheers,
Mikel

2012-05-21 09:33:34

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH obexd v0 05/12] client-doc: Replace SendFiles with SendFile

Hi Mikel,

On Mon, May 21, 2012 at 12:07 PM, Mikel Astiz <[email protected]> wrote:
> From: Mikel Astiz <[email protected]>
>
> Now that OPP sessions exist, sending multiple files can be achieved with
> consecutive calls to SendFile. Note that within a session the pending
> operations will be queued and sequentially executed.
> ---
> ?doc/client-api.txt | ? ?4 ++--
> ?1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/doc/client-api.txt b/doc/client-api.txt
> index 32caa17..de726a8 100644
> --- a/doc/client-api.txt
> +++ b/doc/client-api.txt
> @@ -65,9 +65,9 @@ Service ? ? ? ? ? ? ? org.openobex.client
> ?Interface ? ? ?org.openobex.ObjectPush
> ?Object path ? ?[variable prefix]/{session0,session1,...}
>
> -Methods ? ? ? ? ? ? ? ?void SendFiles(array{string} files)
> +Methods ? ? ? ? ? ? ? ?void SendFile(string sourcefile)
>
> - ? ? ? ? ? ? ? ? ? ? ? Send one or multiple local files to the remote device.
> + ? ? ? ? ? ? ? ? ? ? ? Send one local file to the remote device.
>
> ? ? ? ? ? ? ? ?void PullBusinessCard(string targetfile)
>
> --
> 1.7.7.6

Perhaps it is a good idea to return the transfer object here, so the
application can track the progress and cancel it which is the whole
point of not having multiple files so we can do this properly.


--
Luiz Augusto von Dentz

2012-05-21 09:07:06

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 04/12] client-test: Update to wrapped OPP session type

From: Mikel Astiz <[email protected]>

---
test/exchange-business-cards | 10 ++++-
test/get-capabilities | 16 ++++----
test/pull-business-card | 9 ++++-
test/send-files | 85 ++++++-----------------------------------
4 files changed, 37 insertions(+), 83 deletions(-)

diff --git a/test/exchange-business-cards b/test/exchange-business-cards
index 4b0c7ed..548ad2d 100755
--- a/test/exchange-business-cards
+++ b/test/exchange-business-cards
@@ -11,5 +11,11 @@ if (len(sys.argv) < 4):
print "Usage: %s <device> <clientfile> <file>" % (sys.argv[0])
sys.exit(1)

-client.ExchangeBusinessCards({ "Destination": sys.argv[1] },
- sys.argv[2], sys.argv[3])
+print "Creating Session"
+session_path = client.CreateSession({"Destination": sys.argv[1],
+ "Target": "OPP"})
+opp = dbus.Interface(bus.get_object("org.openobex.client",
+ session_path),
+ "org.openobex.ObjectPush")
+
+opp.ExchangeBusinessCards(sys.argv[2], sys.argv[3])
diff --git a/test/get-capabilities b/test/get-capabilities
index c835bd9..29120f1 100755
--- a/test/get-capabilities
+++ b/test/get-capabilities
@@ -7,14 +7,14 @@ bus = dbus.SessionBus()
client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
"org.openobex.Client")

-if (len(sys.argv) < 2):
- print "Usage: %s <device> [target]" % (sys.argv[0])
+if (len(sys.argv) < 3):
+ print "Usage: %s <device> <target>" % (sys.argv[0])
sys.exit(1)

-if (len(sys.argv) == 3):
- dict = {"Destination": sys.argv[1],
- "Target": sys.argv[2]}
-else:
- dict = {"Destination": sys.argv[1]}
+print "Creating Session"
+session_path = client.CreateSession({"Destination": sys.argv[1],
+ "Target": sys.argv[2]})
+session = dbus.Interface(bus.get_object("org.openobex.client", session_path),
+ "org.openobex.Session")

-print client.GetCapabilities(dict)
+print session.GetCapabilities()
diff --git a/test/pull-business-card b/test/pull-business-card
index b13968d..5912155 100755
--- a/test/pull-business-card
+++ b/test/pull-business-card
@@ -28,7 +28,14 @@ if __name__ == '__main__':
print "Usage: %s <device> <file>" % (sys.argv[0])
sys.exit(1)

- client.PullBusinessCard({ "Destination": sys.argv[1] }, sys.argv[2],
+ print "Creating Session"
+ session_path = client.CreateSession({"Destination": sys.argv[1],
+ "Target": "OPP"})
+ opp = dbus.Interface(bus.get_object("org.openobex.client",
+ session_path),
+ "org.openobex.ObjectPush")
+
+ opp.PullBusinessCard(sys.argv[2],
reply_handler=success, error_handler=failure)

mainloop.run()
diff --git a/test/send-files b/test/send-files
index 52f9c04..504a066 100755
--- a/test/send-files
+++ b/test/send-files
@@ -1,82 +1,23 @@
#!/usr/bin/python

-import gobject
-
import os
import sys
-import time
import dbus
-import dbus.service
-import dbus.mainloop.glib
-
-class Agent(dbus.service.Object):
- def __init__(self, conn=None, obj_path=None):
- dbus.service.Object.__init__(self, conn, obj_path)
-
- @dbus.service.method("org.openobex.Agent",
- in_signature="o", out_signature="s")
- def Request(self, path):
- print "Transfer Request"
- self.transfer = dbus.Interface(bus.get_object("org.openobex.client",
- path), "org.openobex.Transfer")
- properties = self.transfer.GetProperties()
- for key in properties.keys():
- print " %s = %s" % (key, properties[key])
- self.start = True
- return ""
-
- @dbus.service.method("org.openobex.Agent",
- in_signature="ot", out_signature="")
- def Progress(self, path, transferred):
- if (self.start):
- print "Transfer Started"
- properties = self.transfer.GetProperties()
- self.transfer_size = properties['Size']
- self.start_time = time.time()
- self.start = False
- else:
- speed = transferred / abs((time.time() - self.start_time) * 1000)
- progress = "(" + str(transferred) + "/" + str(self.transfer_size) + " bytes) @ " + str(int(speed)) + " kB/s"
- out = "\rTransfer progress " + progress
- sys.stdout.write(out)
- sys.stdout.flush()
- return
-
- @dbus.service.method("org.openobex.Agent",
- in_signature="o", out_signature="")
- def Complete(self, path):
- print "\nTransfer finished"
- return
-
- @dbus.service.method("org.openobex.Agent",
- in_signature="os", out_signature="")
- def Error(self, path, error):
- print "\nTransfer finished with an error: %s" % (error)
- return
-
- @dbus.service.method("org.openobex.Agent",
- in_signature="", out_signature="")
- def Release(self):
- mainloop.quit()
- return
-
-if __name__ == '__main__':
- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-
- bus = dbus.SessionBus()
- client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
- "org.openobex.Client")

- if (len(sys.argv) < 3):
- print "Usage: %s <device> <file> [file*]" % (sys.argv[0])
- sys.exit(1)
+bus = dbus.SessionBus()
+client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
+ "org.openobex.Client")

- path = "/test/agent"
- agent = Agent(bus, path)
+if (len(sys.argv) < 3):
+ print "Usage: %s <device> <file> [file*]" % (sys.argv[0])
+ sys.exit(1)

- mainloop = gobject.MainLoop()
- files = [os.path.realpath(f) for f in sys.argv[2:]]
+files = [os.path.realpath(f) for f in sys.argv[2:]]

- client.SendFiles({ "Destination": sys.argv[1] }, files, path)
+print "Creating Session"
+session_path = client.CreateSession({"Destination": sys.argv[1],
+ "Target": "OPP"})
+opp = dbus.Interface(bus.get_object("org.openobex.client", session_path),
+ "org.openobex.ObjectPush")

- mainloop.run()
+opp.SendFiles(files)
--
1.7.7.6


2012-05-21 09:07:11

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 09/12] client: Move GetCapabilities to session API

From: Mikel Astiz <[email protected]>

---
client/manager.c | 121 ------------------------------------------------------
client/session.c | 68 ++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 121 deletions(-)

diff --git a/client/manager.c b/client/manager.c
index 4078211..94bcbdf 100644
--- a/client/manager.c
+++ b/client/manager.c
@@ -221,133 +221,12 @@ static DBusMessage *remove_session(DBusConnection *connection,
return dbus_message_new_method_return(message);
}

-static void capabilities_complete_callback(struct obc_session *session,
- struct obc_transfer *transfer,
- GError *err, void *user_data)
-{
- struct send_data *data = user_data;
- char *contents;
- size_t size;
- int perr;
-
- if (err != NULL) {
- DBusMessage *error = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "%s", err->message);
- g_dbus_send_message(data->connection, error);
- goto done;
- }
-
- perr = obc_transfer_get_contents(transfer, &contents, &size);
- if (perr < 0) {
- DBusMessage *error = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "Error reading contents: %s",
- strerror(-perr));
- g_dbus_send_message(data->connection, error);
- goto done;
- }
-
- g_dbus_send_reply(data->connection, data->message,
- DBUS_TYPE_STRING, &contents,
- DBUS_TYPE_INVALID);
- g_free(contents);
-
-done:
-
- shutdown_session(session);
- dbus_message_unref(data->message);
- dbus_connection_unref(data->connection);
- g_free(data);
-}
-
-static void capability_obc_session_callback(struct obc_session *session,
- struct obc_transfer *transfer,
- GError *err, void *user_data)
-{
- struct send_data *data = user_data;
- struct obc_transfer *pull;
- DBusMessage *reply;
- GError *gerr = NULL;
-
- if (err != NULL)
- goto fail;
-
- pull = obc_transfer_get("x-obex/capability", NULL, NULL, &gerr);
- if (pull == NULL)
- goto fail;
-
- if (!obc_session_queue(session, pull, capabilities_complete_callback,
- data, &gerr))
- goto fail;
-
- return;
-
-fail:
- if (err == NULL)
- err = gerr;
-
- reply = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "%s", err->message);
- g_dbus_send_message(data->connection, reply);
- shutdown_session(session);
- dbus_message_unref(data->message);
- dbus_connection_unref(data->connection);
- g_clear_error(&gerr);
- g_free(data);
-}
-
-static DBusMessage *get_capabilities(DBusConnection *connection,
- DBusMessage *message, void *user_data)
-{
- DBusMessageIter iter, dict;
- struct obc_session *session;
- struct send_data *data;
- const char *source = NULL, *dest = NULL, *target = NULL;
- uint8_t channel = 0;
-
- dbus_message_iter_init(message, &iter);
- dbus_message_iter_recurse(&iter, &dict);
-
- parse_device_dict(&dict, &source, &dest, &target, &channel);
- if ((dest == NULL) || (target == NULL))
- return g_dbus_create_error(message,
- "org.openobex.Error.InvalidArguments", NULL);
-
- data = g_try_malloc0(sizeof(*data));
- if (data == NULL)
- return g_dbus_create_error(message,
- "org.openobex.Error.NoMemory", NULL);
-
- data->connection = dbus_connection_ref(connection);
- data->message = dbus_message_ref(message);
-
- session = obc_session_create(source, dest, target, channel,
- dbus_message_get_sender(message),
- capability_obc_session_callback, data);
- if (session != NULL) {
- sessions = g_slist_append(sessions, session);
- return NULL;
- }
-
- dbus_message_unref(data->message);
- dbus_connection_unref(data->connection);
- g_free(data);
-
- return g_dbus_create_error(message, "org.openobex.Error.Failed", NULL);
-}
-
static const GDBusMethodTable client_methods[] = {
{ GDBUS_ASYNC_METHOD("CreateSession",
GDBUS_ARGS({ "devices", "a{sv}" }),
GDBUS_ARGS({ "session", "o" }), create_session) },
{ GDBUS_ASYNC_METHOD("RemoveSession",
GDBUS_ARGS({ "session", "o" }), NULL, remove_session) },
- { GDBUS_ASYNC_METHOD("GetCapabilities",
- GDBUS_ARGS({ "device", "a{sv}" }),
- GDBUS_ARGS({ "capabilities", "s" }),
- get_capabilities) },
{ }
};

diff --git a/client/session.c b/client/session.c
index d4ec55d..1c5e452 100644
--- a/client/session.c
+++ b/client/session.c
@@ -648,6 +648,71 @@ static DBusMessage *session_get_properties(DBusConnection *connection,
return reply;
}

+static void capabilities_complete_callback(struct obc_session *session,
+ struct obc_transfer *transfer,
+ GError *err, void *user_data)
+{
+ DBusMessage *message = user_data;
+ char *contents;
+ size_t size;
+ int perr;
+
+ if (err != NULL) {
+ DBusMessage *error = g_dbus_create_error(message,
+ "org.openobex.Error.Failed",
+ "%s", err->message);
+ g_dbus_send_message(session->conn, error);
+ goto done;
+ }
+
+ perr = obc_transfer_get_contents(transfer, &contents, &size);
+ if (perr < 0) {
+ DBusMessage *error = g_dbus_create_error(message,
+ "org.openobex.Error.Failed",
+ "Error reading contents: %s",
+ strerror(-perr));
+ g_dbus_send_message(session->conn, error);
+ goto done;
+ }
+
+ g_dbus_send_reply(session->conn, message,
+ DBUS_TYPE_STRING, &contents,
+ DBUS_TYPE_INVALID);
+ g_free(contents);
+
+done:
+ dbus_message_unref(message);
+}
+
+static DBusMessage *get_capabilities(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ struct obc_session *session = user_data;
+ struct obc_transfer *pull;
+ DBusMessage *reply;
+ GError *gerr = NULL;
+
+ pull = obc_transfer_get("x-obex/capability", NULL, NULL, &gerr);
+ if (pull == NULL)
+ goto fail;
+
+ if (!obc_session_queue(session, pull, capabilities_complete_callback,
+ message, &gerr))
+ goto fail;
+
+ dbus_message_ref(message);
+
+ return NULL;
+
+fail:
+ reply = g_dbus_create_error(message,
+ "org.openobex.Error.Failed",
+ "%s", gerr->message);
+ g_error_free(gerr);
+ return reply;
+
+}
+
static const GDBusMethodTable session_methods[] = {
{ GDBUS_METHOD("GetProperties",
NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
@@ -658,6 +723,9 @@ static const GDBusMethodTable session_methods[] = {
{ GDBUS_METHOD("ReleaseAgent",
GDBUS_ARGS({ "agent", "o" }), NULL,
release_agent) },
+ { GDBUS_ASYNC_METHOD("GetCapabilities",
+ NULL, GDBUS_ARGS({ "capabilities", "s" }),
+ get_capabilities) },
{ }
};

--
1.7.7.6


2012-05-21 09:07:09

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 07/12] client-test: Replace SendFiles with SendFile

From: Mikel Astiz <[email protected]>

The test script still accepts several files in the argument list and
internally uses a loop to individually send them with SendFile.
---
test/send-files | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/test/send-files b/test/send-files
index 504a066..aa4862f 100755
--- a/test/send-files
+++ b/test/send-files
@@ -20,4 +20,5 @@ session_path = client.CreateSession({"Destination": sys.argv[1],
opp = dbus.Interface(bus.get_object("org.openobex.client", session_path),
"org.openobex.ObjectPush")

-opp.SendFiles(files)
+for f in files:
+ opp.SendFile(f)
--
1.7.7.6


2012-05-21 09:07:08

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 06/12] client: Replace SendFiles with SendFile

From: Mikel Astiz <[email protected]>

The function is now asynchronous, since it will return only when the
transfer has been finished.
---
client/opp.c | 66 ++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/client/opp.c b/client/opp.c
index 424ae8d..67b01a9 100644
--- a/client/opp.c
+++ b/client/opp.c
@@ -45,48 +45,60 @@ struct opp_data {

static DBusConnection *conn = NULL;

-static DBusMessage *opp_send_files(DBusConnection *connection,
+static void send_file_callback(struct obc_session *session,
+ struct obc_transfer *transfer,
+ GError *err, void *user_data)
+{
+ DBusMessage *msg = user_data;
+ DBusMessage *reply;
+
+ if (err != NULL)
+ reply = g_dbus_create_error(msg,
+ ERROR_INF ".Failed", "%s", err->message);
+ else
+ reply = dbus_message_new_method_return(msg);
+
+ g_dbus_send_message(conn, reply);
+ dbus_message_unref(msg);
+}
+
+static DBusMessage *opp_send_file(DBusConnection *connection,
DBusMessage *message, void *user_data)
{
struct opp_data *opp = user_data;
- DBusMessageIter iter, array;
+ struct obc_transfer *transfer;
DBusMessage *reply;
+ char *filename;
+ char *basename;
GError *err = NULL;

- dbus_message_iter_init(message, &iter);
- dbus_message_iter_recurse(&iter, &array);
-
- while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
- char *filename;
- char *basename;
- struct obc_transfer *transfer;
-
- dbus_message_iter_get_basic(&array, &filename);
- basename = g_path_get_basename(filename);
+ if (dbus_message_get_args(message, NULL,
+ DBUS_TYPE_STRING, &filename,
+ DBUS_TYPE_INVALID) == FALSE)
+ return g_dbus_create_error(message,
+ ERROR_INF ".InvalidArguments", NULL);

- transfer = obc_transfer_put(NULL, basename, filename, NULL, 0,
- &err);
+ basename = g_path_get_basename(filename);

- g_free(basename);
+ transfer = obc_transfer_put(NULL, basename, filename, NULL, 0, &err);

- if (transfer == NULL)
- goto fail;
+ g_free(basename);

- if (!obc_session_queue(opp->session, transfer, NULL, NULL,
- &err))
- goto fail;
+ if (transfer == NULL)
+ goto fail;

- dbus_message_iter_next(&array);
- }
+ if (!obc_session_queue(opp->session, transfer, send_file_callback,
+ message, &err))
+ goto fail;

- return dbus_message_new_method_return(message);
+ dbus_message_ref(message);
+ return NULL;

fail:
reply = g_dbus_create_error(message,
ERROR_INF ".Failed", "%s", err->message);
g_error_free(err);
return reply;
-
}

static void pull_complete_callback(struct obc_session *session,
@@ -153,10 +165,10 @@ static DBusMessage *opp_exchange_business_cards(DBusConnection *connection,
}

static const GDBusMethodTable opp_methods[] = {
- { GDBUS_METHOD("SendFiles",
- GDBUS_ARGS({ "files", "as" }),
+ { GDBUS_ASYNC_METHOD("SendFile",
+ GDBUS_ARGS({ "sourcefile", "s" }),
NULL,
- opp_send_files) },
+ opp_send_file) },
{ GDBUS_ASYNC_METHOD("PullBusinessCard",
GDBUS_ARGS({ "targetfile", "s" }),
NULL,
--
1.7.7.6


2012-05-21 09:07:14

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 12/12] client-test: Replace CreateSession parameter dict

From: Mikel Astiz <[email protected]>

---
test/exchange-business-cards | 3 +--
test/ftp-client | 3 +--
test/get-capabilities | 3 +--
test/list-folders | 2 +-
test/map-client | 3 +--
test/pbap-client | 2 +-
test/pull-business-card | 3 +--
test/send-files | 3 +--
8 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/test/exchange-business-cards b/test/exchange-business-cards
index 548ad2d..4abe426 100755
--- a/test/exchange-business-cards
+++ b/test/exchange-business-cards
@@ -12,8 +12,7 @@ if (len(sys.argv) < 4):
sys.exit(1)

print "Creating Session"
-session_path = client.CreateSession({"Destination": sys.argv[1],
- "Target": "OPP"})
+session_path = client.CreateSession(sys.argv[1], { "Target": "OPP" })
opp = dbus.Interface(bus.get_object("org.openobex.client",
session_path),
"org.openobex.ObjectPush")
diff --git a/test/ftp-client b/test/ftp-client
index 9bc038d..825f591 100755
--- a/test/ftp-client
+++ b/test/ftp-client
@@ -135,8 +135,7 @@ if __name__ == '__main__':
client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
"org.openobex.Client")

- session_path = client.CreateSession({ "Destination": options.device,
- "Target": "ftp"})
+ session_path = client.CreateSession(options.device, { "Target": "ftp" })

session = dbus.Interface(bus.get_object("org.openobex.client", session_path),
"org.openobex.Session")
diff --git a/test/get-capabilities b/test/get-capabilities
index 29120f1..09e2d24 100755
--- a/test/get-capabilities
+++ b/test/get-capabilities
@@ -12,8 +12,7 @@ if (len(sys.argv) < 3):
sys.exit(1)

print "Creating Session"
-session_path = client.CreateSession({"Destination": sys.argv[1],
- "Target": sys.argv[2]})
+session_path = client.CreateSession(sys.argv[1], { "Target": sys.argv[2] })
session = dbus.Interface(bus.get_object("org.openobex.client", session_path),
"org.openobex.Session")

diff --git a/test/list-folders b/test/list-folders
index c7eec10..7239d6d 100755
--- a/test/list-folders
+++ b/test/list-folders
@@ -9,7 +9,7 @@ def list_folder(folder):
client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
"org.openobex.Client")

- session_path = client.CreateSession({ "Destination": sys.argv[1], "Target": "ftp"})
+ session_path = client.CreateSession(sys.argv[1], { "Target": "ftp" })

ftp = dbus.Interface(bus.get_object("org.openobex.client", session_path),
"org.openobex.FileTransfer")
diff --git a/test/map-client b/test/map-client
index 5c7c447..cf006b6 100755
--- a/test/map-client
+++ b/test/map-client
@@ -41,8 +41,7 @@ if __name__ == '__main__':
client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
"org.openobex.Client")

- session_path = client.CreateSession({ "Destination": options.device,
- "Target": "map"})
+ session_path = client.CreateSession( options.device, { "Target": "map" })

session = dbus.Interface(bus.get_object("org.openobex.client", session_path),
"org.openobex.Session")
diff --git a/test/pbap-client b/test/pbap-client
index 7456c01..ecca14f 100755
--- a/test/pbap-client
+++ b/test/pbap-client
@@ -9,7 +9,7 @@ client = dbus.Interface(bus.get_object("org.openobex.client", "/"),
"org.openobex.Client")

print "Creating Session"
-session_path = client.CreateSession({"Destination": sys.argv[1], "Target": "PBAP"})
+session_path = client.CreateSession(sys.argv[1], { "Target": "PBAP" })
pbap = dbus.Interface(bus.get_object("org.openobex.client", session_path),
"org.openobex.PhonebookAccess")
session = dbus.Interface(bus.get_object("org.openobex.client", session_path),
diff --git a/test/pull-business-card b/test/pull-business-card
index 5912155..6f9267b 100755
--- a/test/pull-business-card
+++ b/test/pull-business-card
@@ -29,8 +29,7 @@ if __name__ == '__main__':
sys.exit(1)

print "Creating Session"
- session_path = client.CreateSession({"Destination": sys.argv[1],
- "Target": "OPP"})
+ session_path = client.CreateSession(sys.argv[1], { "Target": "OPP" })
opp = dbus.Interface(bus.get_object("org.openobex.client",
session_path),
"org.openobex.ObjectPush")
diff --git a/test/send-files b/test/send-files
index aa4862f..5310c06 100755
--- a/test/send-files
+++ b/test/send-files
@@ -15,8 +15,7 @@ if (len(sys.argv) < 3):
files = [os.path.realpath(f) for f in sys.argv[2:]]

print "Creating Session"
-session_path = client.CreateSession({"Destination": sys.argv[1],
- "Target": "OPP"})
+session_path = client.CreateSession(sys.argv[1], { "Target": "OPP" })
opp = dbus.Interface(bus.get_object("org.openobex.client", session_path),
"org.openobex.ObjectPush")

--
1.7.7.6


2012-05-21 09:07:05

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 03/12] client: Wrap OPP into specific session type

From: Mikel Astiz <[email protected]>

---
client/manager.c | 270 ++----------------------------------------------------
client/opp.c | 193 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 201 insertions(+), 262 deletions(-)

diff --git a/client/manager.c b/client/manager.c
index 3005fe8..4078211 100644
--- a/client/manager.c
+++ b/client/manager.c
@@ -53,10 +53,6 @@
struct send_data {
DBusConnection *connection;
DBusMessage *message;
- gchar *sender;
- gchar *agent;
- char *filename;
- GPtrArray *files;
};

static GSList *sessions = NULL;
@@ -84,7 +80,7 @@ static void create_callback(struct obc_session *session,
GError *err, void *user_data)
{
struct send_data *data = user_data;
- unsigned int i;
+ const char *path;

if (err != NULL) {
DBusMessage *error = g_dbus_create_error(data->message,
@@ -95,48 +91,16 @@ static void create_callback(struct obc_session *session,
goto done;
}

- if (obc_session_get_target(session) != NULL) {
- const char *path;

- path = obc_session_register(session, unregister_session);
+ path = obc_session_register(session, unregister_session);

- g_dbus_send_reply(data->connection, data->message,
+ g_dbus_send_reply(data->connection, data->message,
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
- goto done;
- }
-
- g_dbus_send_reply(data->connection, data->message, DBUS_TYPE_INVALID);
-
- obc_session_set_agent(session, data->sender, data->agent);
-
- for (i = 0; i < data->files->len; i++) {
- const gchar *filename = g_ptr_array_index(data->files, i);
- gchar *basename = g_path_get_basename(filename);
- struct obc_transfer *transfer;
-
- transfer = obc_transfer_put(NULL, basename, filename, NULL, 0,
- NULL);
-
- g_free(basename);
- if (transfer == NULL)
- break;
-
- if (!obc_session_queue(session, transfer, NULL, NULL, NULL))
- break;
- }
-
- /* No need to keep a reference for SendFiles */
- sessions = g_slist_remove(sessions, session);
- obc_session_unref(session);

done:
- if (data->files)
- g_ptr_array_free(data->files, TRUE);
dbus_message_unref(data->message);
dbus_connection_unref(data->connection);
- g_free(data->sender);
- g_free(data->agent);
g_free(data);
}

@@ -175,205 +139,6 @@ static int parse_device_dict(DBusMessageIter *iter,
return 0;
}

-static DBusMessage *send_files(DBusConnection *connection,
- DBusMessage *message, void *user_data)
-{
- DBusMessageIter iter, array;
- struct obc_session *session;
- GPtrArray *files;
- struct send_data *data;
- const char *agent, *source = NULL, *dest = NULL, *target = NULL;
- const char *sender;
- uint8_t channel = 0;
-
- dbus_message_iter_init(message, &iter);
- dbus_message_iter_recurse(&iter, &array);
-
- parse_device_dict(&array, &source, &dest, &target, &channel);
- if (dest == NULL)
- return g_dbus_create_error(message,
- "org.openobex.Error.InvalidArguments", NULL);
-
- dbus_message_iter_next(&iter);
- dbus_message_iter_recurse(&iter, &array);
-
- files = g_ptr_array_new();
- if (files == NULL)
- return g_dbus_create_error(message,
- "org.openobex.Error.NoMemory", NULL);
-
- while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
- char *value;
-
- dbus_message_iter_get_basic(&array, &value);
- g_ptr_array_add(files, value);
-
- dbus_message_iter_next(&array);
- }
-
- dbus_message_iter_next(&iter);
- dbus_message_iter_get_basic(&iter, &agent);
-
- if (files->len == 0) {
- g_ptr_array_free(files, TRUE);
- return g_dbus_create_error(message,
- "org.openobex.Error.InvalidArguments", NULL);
- }
-
- sender = dbus_message_get_sender(message);
-
- data = g_try_malloc0(sizeof(*data));
- if (data == NULL) {
- g_ptr_array_free(files, TRUE);
- return g_dbus_create_error(message,
- "org.openobex.Error.NoMemory", NULL);
- }
-
- data->connection = dbus_connection_ref(connection);
- data->message = dbus_message_ref(message);
- data->sender = g_strdup(sender);
- data->agent = g_strdup(agent);
- data->files = files;
-
- session = obc_session_create(source, dest, "OPP", channel, sender,
- create_callback, data);
- if (session != NULL) {
- sessions = g_slist_append(sessions, session);
- return NULL;
- }
-
- g_ptr_array_free(data->files, TRUE);
- dbus_message_unref(data->message);
- dbus_connection_unref(data->connection);
- g_free(data->sender);
- g_free(data->agent);
- g_free(data);
-
- return g_dbus_create_error(message, "org.openobex.Error.Failed", NULL);
-}
-
-static void pull_complete_callback(struct obc_session *session,
- struct obc_transfer *transfer,
- GError *err, void *user_data)
-{
- struct send_data *data = user_data;
-
- if (err != NULL) {
- DBusMessage *error = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "%s", err->message);
- g_dbus_send_message(data->connection, error);
- goto done;
- }
-
- g_dbus_send_reply(data->connection, data->message, DBUS_TYPE_INVALID);
-
-done:
- shutdown_session(session);
- dbus_message_unref(data->message);
- dbus_connection_unref(data->connection);
- g_free(data->filename);
- g_free(data->sender);
- g_free(data);
-}
-
-static void pull_obc_session_callback(struct obc_session *session,
- struct obc_transfer *transfer,
- GError *err, void *user_data)
-{
- struct send_data *data = user_data;
- struct obc_transfer *pull;
- DBusMessage *reply;
- GError *gerr = NULL;
-
- if (err != NULL)
- goto fail;
-
- pull = obc_transfer_get("text/x-vcard", NULL, data->filename, &gerr);
- if (pull == NULL)
- goto fail;
-
- if (!obc_session_queue(session, pull, pull_complete_callback, data,
- &gerr))
- goto fail;
-
- return;
-
-fail:
- if (err == NULL)
- err = gerr;
-
- reply = g_dbus_create_error(data->message,
- "org.openobex.Error.Failed",
- "%s", err->message);
- g_dbus_send_message(data->connection, reply);
- shutdown_session(session);
- dbus_message_unref(data->message);
- dbus_connection_unref(data->connection);
- g_clear_error(&gerr);
- g_free(data->filename);
- g_free(data->sender);
- g_free(data);
-}
-
-static DBusMessage *pull_business_card(DBusConnection *connection,
- DBusMessage *message, void *user_data)
-{
- DBusMessageIter iter, dict;
- struct obc_session *session;
- struct send_data *data;
- const char *source = NULL, *dest = NULL, *target = NULL;
- const char *name = NULL;
- uint8_t channel = 0;
-
- dbus_message_iter_init(message, &iter);
- dbus_message_iter_recurse(&iter, &dict);
-
- parse_device_dict(&dict, &source, &dest, &target, &channel);
- if (dest == NULL)
- return g_dbus_create_error(message,
- "org.openobex.Error.InvalidArguments", NULL);
-
- dbus_message_iter_next(&iter);
-
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return g_dbus_create_error(message,
- "org.openobex.Error.InvalidArguments", NULL);
-
- dbus_message_iter_get_basic(&iter, &name);
-
- data = g_try_malloc0(sizeof(*data));
- if (data == NULL)
- return g_dbus_create_error(message,
- "org.openobex.Error.NoMemory", NULL);
-
- data->connection = dbus_connection_ref(connection);
- data->message = dbus_message_ref(message);
- data->sender = g_strdup(dbus_message_get_sender(message));
- data->filename = g_strdup(name);
-
- session = obc_session_create(source, dest, "OPP", channel, data->sender,
- pull_obc_session_callback, data);
- if (session != NULL) {
- sessions = g_slist_append(sessions, session);
- return NULL;
- }
-
- dbus_message_unref(data->message);
- dbus_connection_unref(data->connection);
- g_free(data->sender);
- g_free(data->filename);
- g_free(data);
-
- return g_dbus_create_error(message, "org.openobex.Error.Failed", NULL);
-}
-
-static DBusMessage *exchange_business_cards(DBusConnection *connection,
- DBusMessage *message, void *user_data)
-{
- return g_dbus_create_error(message, "org.openobex.Error.Failed", NULL);
-}
-
static struct obc_session *find_session(const char *path)
{
GSList *l;
@@ -412,10 +177,10 @@ static DBusMessage *create_session(DBusConnection *connection,

data->connection = dbus_connection_ref(connection);
data->message = dbus_message_ref(message);
- data->sender = g_strdup(dbus_message_get_sender(message));

- session = obc_session_create(source, dest, target, channel, data->sender,
- create_callback, data);
+ session = obc_session_create(source, dest, target, channel,
+ dbus_message_get_sender(message),
+ create_callback, data);
if (session != NULL) {
sessions = g_slist_append(sessions, session);
return NULL;
@@ -423,7 +188,6 @@ static DBusMessage *create_session(DBusConnection *connection,

dbus_message_unref(data->message);
dbus_connection_unref(data->connection);
- g_free(data->sender);
g_free(data);

return g_dbus_create_error(message, "org.openobex.Error.Failed", NULL);
@@ -494,7 +258,6 @@ done:
shutdown_session(session);
dbus_message_unref(data->message);
dbus_connection_unref(data->connection);
- g_free(data->sender);
g_free(data);
}

@@ -532,7 +295,6 @@ fail:
dbus_message_unref(data->message);
dbus_connection_unref(data->connection);
g_clear_error(&gerr);
- g_free(data->sender);
g_free(data);
}

@@ -549,7 +311,7 @@ static DBusMessage *get_capabilities(DBusConnection *connection,
dbus_message_iter_recurse(&iter, &dict);

parse_device_dict(&dict, &source, &dest, &target, &channel);
- if (dest == NULL)
+ if ((dest == NULL) || (target == NULL))
return g_dbus_create_error(message,
"org.openobex.Error.InvalidArguments", NULL);

@@ -560,12 +322,9 @@ static DBusMessage *get_capabilities(DBusConnection *connection,

data->connection = dbus_connection_ref(connection);
data->message = dbus_message_ref(message);
- data->sender = g_strdup(dbus_message_get_sender(message));
-
- if (!target)
- target = "OPP";

- session = obc_session_create(source, dest, target, channel, data->sender,
+ session = obc_session_create(source, dest, target, channel,
+ dbus_message_get_sender(message),
capability_obc_session_callback, data);
if (session != NULL) {
sessions = g_slist_append(sessions, session);
@@ -574,23 +333,12 @@ static DBusMessage *get_capabilities(DBusConnection *connection,

dbus_message_unref(data->message);
dbus_connection_unref(data->connection);
- g_free(data->sender);
g_free(data);

return g_dbus_create_error(message, "org.openobex.Error.Failed", NULL);
}

static const GDBusMethodTable client_methods[] = {
- { GDBUS_ASYNC_METHOD("SendFiles",
- GDBUS_ARGS({ "device", "a{sv}" }, { "files", "as" },
- { "agent", "o" }), NULL, send_files) },
- { GDBUS_ASYNC_METHOD("PullBusinessCard",
- GDBUS_ARGS({ "device", "a{sv}" }, { "file", "s" }), NULL,
- pull_business_card) },
- { GDBUS_ASYNC_METHOD("ExchangeBusinessCards",
- GDBUS_ARGS({ "device", "a{sv}" },
- { "clientfile", "s" }, { "file", "s" }),
- NULL, exchange_business_cards) },
{ GDBUS_ASYNC_METHOD("CreateSession",
GDBUS_ARGS({ "devices", "a{sv}" }),
GDBUS_ARGS({ "session", "o" }), create_session) },
diff --git a/client/opp.c b/client/opp.c
index efbf3e9..424ae8d 100644
--- a/client/opp.c
+++ b/client/opp.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif

+#include <errno.h>
#include <gdbus.h>

#include "log.h"
@@ -35,22 +36,212 @@
#include "opp.h"

#define OPP_UUID "00001105-0000-1000-8000-00805f9b34fb"
+#define OPP_INTERFACE "org.openobex.ObjectPush"
+#define ERROR_INF OPP_INTERFACE ".Error"
+
+struct opp_data {
+ struct obc_session *session;
+};
+
+static DBusConnection *conn = NULL;
+
+static DBusMessage *opp_send_files(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ struct opp_data *opp = user_data;
+ DBusMessageIter iter, array;
+ DBusMessage *reply;
+ GError *err = NULL;
+
+ dbus_message_iter_init(message, &iter);
+ dbus_message_iter_recurse(&iter, &array);
+
+ while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
+ char *filename;
+ char *basename;
+ struct obc_transfer *transfer;
+
+ dbus_message_iter_get_basic(&array, &filename);
+ basename = g_path_get_basename(filename);
+
+ transfer = obc_transfer_put(NULL, basename, filename, NULL, 0,
+ &err);
+
+ g_free(basename);
+
+ if (transfer == NULL)
+ goto fail;
+
+ if (!obc_session_queue(opp->session, transfer, NULL, NULL,
+ &err))
+ goto fail;
+
+ dbus_message_iter_next(&array);
+ }
+
+ return dbus_message_new_method_return(message);
+
+fail:
+ reply = g_dbus_create_error(message,
+ ERROR_INF ".Failed", "%s", err->message);
+ g_error_free(err);
+ return reply;
+
+}
+
+static void pull_complete_callback(struct obc_session *session,
+ struct obc_transfer *transfer,
+ GError *err, void *user_data)
+{
+ DBusMessage *message = user_data;
+
+ if (err != NULL) {
+ DBusMessage *error = g_dbus_create_error(message,
+ "org.openobex.Error.Failed",
+ "%s", err->message);
+ g_dbus_send_message(conn, error);
+ goto done;
+ }
+
+ g_dbus_send_reply(conn, message, DBUS_TYPE_INVALID);
+
+done:
+ dbus_message_unref(message);
+}
+
+static DBusMessage *opp_pull_business_card(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ struct opp_data *opp = user_data;
+ struct obc_transfer *pull;
+ DBusMessageIter iter;
+ DBusMessage *reply;
+ const char *filename = NULL;
+ GError *err = NULL;
+
+ dbus_message_iter_init(message, &iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return g_dbus_create_error(message,
+ ERROR_INF ".InvalidArguments", NULL);
+
+ dbus_message_iter_get_basic(&iter, &filename);
+
+ pull = obc_transfer_get("text/x-vcard", NULL, filename, &err);
+ if (pull == NULL)
+ goto fail;
+
+ if (!obc_session_queue(opp->session, pull, pull_complete_callback,
+ message, &err))
+ goto fail;
+
+ dbus_message_ref(message);
+
+ return NULL;
+
+fail:
+ reply = g_dbus_create_error(message,
+ ERROR_INF ".Failed", "%s", err->message);
+ g_error_free(err);
+ return reply;
+}
+
+static DBusMessage *opp_exchange_business_cards(DBusConnection *connection,
+ DBusMessage *message, void *user_data)
+{
+ return g_dbus_create_error(message, "org.openobex.Error.Failed", NULL);
+}
+
+static const GDBusMethodTable opp_methods[] = {
+ { GDBUS_METHOD("SendFiles",
+ GDBUS_ARGS({ "files", "as" }),
+ NULL,
+ opp_send_files) },
+ { GDBUS_ASYNC_METHOD("PullBusinessCard",
+ GDBUS_ARGS({ "targetfile", "s" }),
+ NULL,
+ opp_pull_business_card) },
+ { GDBUS_ASYNC_METHOD("ExchangeBusinessCards",
+ GDBUS_ARGS({ "clientfile", "s" }, { "targetfile", "s" }),
+ NULL,
+ opp_exchange_business_cards) },
+ { }
+};
+
+static void opp_free(void *data)
+{
+ struct opp_data *opp = data;
+
+ obc_session_unref(opp->session);
+ g_free(opp);
+}
+
+static int opp_probe(struct obc_session *session)
+{
+ struct opp_data *opp;
+ const char *path;
+
+ path = obc_session_get_path(session);
+
+ DBG("%s", path);
+
+ opp = g_try_new0(struct opp_data, 1);
+ if (!opp)
+ return -ENOMEM;
+
+ opp->session = obc_session_ref(session);
+
+ if (!g_dbus_register_interface(conn, path, OPP_INTERFACE, opp_methods,
+ NULL, NULL, opp, opp_free)) {
+ opp_free(opp);
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+static void opp_remove(struct obc_session *session)
+{
+ const char *path = obc_session_get_path(session);
+
+ DBG("%s", path);
+
+ g_dbus_unregister_interface(conn, path, OPP_INTERFACE);
+}

static struct obc_driver opp = {
.service = "OPP",
.uuid = OPP_UUID,
+ .probe = opp_probe,
+ .remove = opp_remove
};

int opp_init(void)
{
+ int err;
+
DBG("");

- return obc_driver_register(&opp);
+ conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
+ if (!conn)
+ return -EIO;
+
+ err = obc_driver_register(&opp);
+ if (err < 0) {
+ dbus_connection_unref(conn);
+ conn = NULL;
+ return err;
+ }
+
+ return 0;
}

void opp_exit(void)
{
DBG("");

+ dbus_connection_unref(conn);
+ conn = NULL;
+
obc_driver_unregister(&opp);
}
--
1.7.7.6


2012-05-21 09:07:03

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 01/12] client-doc: Wrap OPP into specific session type

From: Mikel Astiz <[email protected]>

This modification makes the OPP API more consistent with the rest of the
supported target types, and also it allows to perform several operations
on the same session.
---
doc/client-api.txt | 42 +++++++++++++++++++++++-------------------
1 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/doc/client-api.txt b/doc/client-api.txt
index 7dd83d9..32caa17 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -11,25 +11,7 @@ Service org.openobex.client
Interface org.openobex.Client
Object path /

-Methods void SendFiles(dict device, array{string} files, object agent)
-
- Send one or multiple local files to the specified
- device. The device is configured via properties. At
- least the Destination property should be specified.
-
- void PullBusinessCard(dict device, string file)
-
- Request the business card from a remote device and
- store it in the local file.
-
- void ExchangeBusinessCards(dict device, string clientfile,
- string file)
-
- Push the client's business card to the remote device
- and then retrieve the remote business card and store
- it in a local file.
-
- object CreateSession(dict device)
+Methods object CreateSession(dict device)

Create a new OBEX session. The device is configured
via properties like in SendFiles.
@@ -76,6 +58,28 @@ Properties string Source [readonly]

byte Channel [readonly]

+Object Push hierarchy
+=====================
+
+Service org.openobex.client
+Interface org.openobex.ObjectPush
+Object path [variable prefix]/{session0,session1,...}
+
+Methods void SendFiles(array{string} files)
+
+ Send one or multiple local files to the remote device.
+
+ void PullBusinessCard(string targetfile)
+
+ Request the business card from a remote device and
+ store it in the local file.
+
+ void ExchangeBusinessCards(string clientfile, string targetfile)
+
+ Push the client's business card to the remote device
+ and then retrieve the remote business card and store
+ it in a local file.
+
File Transfer hierarchy
=======================

--
1.7.7.6


2012-05-21 09:07:10

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 08/12] client-doc: Move GetCapabilities to session API

From: Mikel Astiz <[email protected]>

---
doc/client-api.txt | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/doc/client-api.txt b/doc/client-api.txt
index de726a8..a467d40 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -20,10 +20,6 @@ Methods object CreateSession(dict device)

Unregister session and abort pending transfers.

- string GetCapabilities(dict device)
-
- Get remote device capabilities.
-
Properties string Target

string Source
@@ -52,6 +48,10 @@ Methods dict GetProperties()

Release a previously assigned OBEX agent.

+ string GetCapabilities()
+
+ Get remote device capabilities.
+
Properties string Source [readonly]

string Destination [readonly]
--
1.7.7.6


2012-05-21 09:07:12

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 10/12] client-doc: Replace parameter dict with conventional ones

From: Mikel Astiz <[email protected]>

Required arguments are passed as formal parameters in the D-Bus API, and
an additional dictionary is used to pass target-specific parameters.
This will allow future extensions without breaking the method signature.
---
doc/client-api.txt | 25 ++++++++++++++++---------
1 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/doc/client-api.txt b/doc/client-api.txt
index a467d40..cfb4ec9 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -11,22 +11,29 @@ Service org.openobex.client
Interface org.openobex.Client
Object path /

-Methods object CreateSession(dict device)
+Methods object CreateSession(string destination, dict args)

- Create a new OBEX session. The device is configured
- via properties like in SendFiles.
+ Create a new OBEX session for the given remote address.

- void RemoveSession(object session)
+ The last parameter is a dictionary to hold optional or
+ type-specific parameters. Typical parameters that can
+ be set in this dictionary include the following:

- Unregister session and abort pending transfers.
+ string "Target" : type of session to be created
+ string "Source" : local address to be used
+ byte "Channel"

-Properties string Target
+ The currently supported targets are the following:

- string Source
+ "FTP"
+ "MAP"
+ "OPP"
+ "PBAP"
+ "SYNC"

- string Destination
+ void RemoveSession(object session)

- byte Channel
+ Unregister session and abort pending transfers.

Session hierarchy
=================
--
1.7.7.6


2012-05-21 09:07:13

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 11/12] client: Replace parameter dict with conventional ones

From: Mikel Astiz <[email protected]>

---
client/manager.c | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/client/manager.c b/client/manager.c
index 94bcbdf..9bb1465 100644
--- a/client/manager.c
+++ b/client/manager.c
@@ -105,8 +105,7 @@ done:
}

static int parse_device_dict(DBusMessageIter *iter,
- const char **source, const char **dest, const char **target,
- uint8_t *channel)
+ const char **source, const char **target, uint8_t *channel)
{
while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_DICT_ENTRY) {
DBusMessageIter entry, value;
@@ -122,8 +121,6 @@ static int parse_device_dict(DBusMessageIter *iter,
case DBUS_TYPE_STRING:
if (g_str_equal(key, "Source") == TRUE)
dbus_message_iter_get_basic(&value, source);
- else if (g_str_equal(key, "Destination") == TRUE)
- dbus_message_iter_get_basic(&value, dest);
else if (g_str_equal(key, "Target") == TRUE)
dbus_message_iter_get_basic(&value, target);
break;
@@ -163,9 +160,20 @@ static DBusMessage *create_session(DBusConnection *connection,
uint8_t channel = 0;

dbus_message_iter_init(message, &iter);
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return g_dbus_create_error(message,
+ "org.openobex.Error.InvalidArguments", NULL);
+
+ dbus_message_iter_get_basic(&iter, &dest);
+ dbus_message_iter_next(&iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+ return g_dbus_create_error(message,
+ "org.openobex.Error.InvalidArguments", NULL);
+
dbus_message_iter_recurse(&iter, &dict);

- parse_device_dict(&dict, &source, &dest, &target, &channel);
+ parse_device_dict(&dict, &source, &target, &channel);
if (dest == NULL || target == NULL)
return g_dbus_create_error(message,
"org.openobex.Error.InvalidArguments", NULL);
@@ -223,7 +231,7 @@ static DBusMessage *remove_session(DBusConnection *connection,

static const GDBusMethodTable client_methods[] = {
{ GDBUS_ASYNC_METHOD("CreateSession",
- GDBUS_ARGS({ "devices", "a{sv}" }),
+ GDBUS_ARGS({ "destination", "s" }, { "args", "a{sv}" }),
GDBUS_ARGS({ "session", "o" }), create_session) },
{ GDBUS_ASYNC_METHOD("RemoveSession",
GDBUS_ARGS({ "session", "o" }), NULL, remove_session) },
--
1.7.7.6


2012-05-21 09:07:07

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 05/12] client-doc: Replace SendFiles with SendFile

From: Mikel Astiz <[email protected]>

Now that OPP sessions exist, sending multiple files can be achieved with
consecutive calls to SendFile. Note that within a session the pending
operations will be queued and sequentially executed.
---
doc/client-api.txt | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/client-api.txt b/doc/client-api.txt
index 32caa17..de726a8 100644
--- a/doc/client-api.txt
+++ b/doc/client-api.txt
@@ -65,9 +65,9 @@ Service org.openobex.client
Interface org.openobex.ObjectPush
Object path [variable prefix]/{session0,session1,...}

-Methods void SendFiles(array{string} files)
+Methods void SendFile(string sourcefile)

- Send one or multiple local files to the remote device.
+ Send one local file to the remote device.

void PullBusinessCard(string targetfile)

--
1.7.7.6


2012-05-21 09:07:04

by Mikel Astiz

[permalink] [raw]
Subject: [PATCH obexd v0 02/12] client: Use constant instead of NULL variable

From: Mikel Astiz <[email protected]>

The filename will always be NULL for capability-requesting sessions, so
it doesn't make much sense to use such field.
---
client/manager.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/client/manager.c b/client/manager.c
index 3dd0220..3005fe8 100644
--- a/client/manager.c
+++ b/client/manager.c
@@ -510,8 +510,7 @@ static void capability_obc_session_callback(struct obc_session *session,
if (err != NULL)
goto fail;

- pull = obc_transfer_get("x-obex/capability", NULL, data->filename,
- &gerr);
+ pull = obc_transfer_get("x-obex/capability", NULL, NULL, &gerr);
if (pull == NULL)
goto fail;

--
1.7.7.6