2011-12-21 01:40:59

by Jakub Adamek

[permalink] [raw]
Subject: [RFC obexd 0/4] Extend gobex high level transfer API

The purpose of this patch series is to propose an extension
to the current high level request transfer API.
The motivation for this is that currently profiles that require
parsing of non-body response headers in PUT operations
(such as BIP) can not use the high level transfer API.
The proposed solution is to make the function the API
uses to handle each response packet replaceable at the time
of transfer creation.
A custom handler can process incoming packets and (if desired)
pass them to the default packet handler in order
for it to proceed with the transfer.

Jakub Adamek (4):
gobex: make transfer structure public and opaque
gobex: make default response function public
gobex: add response function parameter to API
gobex: add functions to public transfer API

client/transfer.c | 6 +-
gobex/gobex-transfer.c | 122 ++++++++++++++++++++++++++-----------------
gobex/gobex.h | 16 +++++-
unit/test-gobex-transfer.c | 20 ++++----
4 files changed, 101 insertions(+), 63 deletions(-)

--
1.7.4.1



2011-12-21 01:41:02

by Jakub Adamek

[permalink] [raw]
Subject: [RFC obexd 3/4] gobex: add response function parameter to API

All *_req/*_req_pkt functions now have an additional parameter.
This parameter is the function to be used to handle response packets.
If this parameter is NULL, the default packet reponse function
is used.

Previously, the default response function passed itself as the
callback function to g_obex_send_req (to handle the next packet).
Now this is changed so that the response function supplied
at transfer creation is passed.
---
client/transfer.c | 6 +++---
gobex/gobex-transfer.c | 36 +++++++++++++++++++++++++++++-------
gobex/gobex.h | 8 ++++++--
unit/test-gobex-transfer.c | 20 ++++++++++----------
4 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/client/transfer.c b/client/transfer.c
index c481378..bdefaec 100644
--- a/client/transfer.c
+++ b/client/transfer.c
@@ -548,7 +548,7 @@ int obc_transfer_get(struct obc_transfer *transfer, transfer_callback_t func,
transfer->xfer = g_obex_send_req(obex, req, -1, rsp_cb,
transfer, &err);
else
- transfer->xfer = g_obex_get_req_pkt(obex, req, data_cb,
+ transfer->xfer = g_obex_get_req_pkt(obex, req, NULL, data_cb,
complete_cb, transfer,
&err);

@@ -600,8 +600,8 @@ done:
transfer->params->data,
transfer->params->size);

- transfer->xfer = g_obex_put_req_pkt(obex, req, data_cb, xfer_complete,
- transfer, &err);
+ transfer->xfer = g_obex_put_req_pkt(obex, req, NULL, data_cb,
+ xfer_complete, transfer, &err);
if (transfer->xfer == 0)
return -ENOTCONN;

diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index 2595128..51f0189 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -47,6 +47,7 @@ struct _GObexTransfer {

GObexDataProducer data_producer;
GObexDataConsumer data_consumer;
+ GObexResponseFunc response_func;
GObexFunc complete_func;

gpointer user_data;
@@ -214,7 +215,7 @@ void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
G_OBEX_HDR_INVALID);
}

- transfer->req_id = g_obex_send_req(obex, req, -1, transfer_response,
+ transfer->req_id = g_obex_send_req(obex, req, -1, transfer->response_func,
transfer, &err);
failed:
if (err != NULL) {
@@ -246,6 +247,7 @@ static GObexTransfer *transfer_new(GObex *obex, guint8 opcode,
}

guint g_obex_put_req_pkt(GObex *obex, GObexPacket *req,
+ GObexResponseFunc response_func,
GObexDataProducer data_func, GObexFunc complete_func,
gpointer user_data, GError **err)
{
@@ -256,13 +258,17 @@ guint g_obex_put_req_pkt(GObex *obex, GObexPacket *req,
if (g_obex_packet_get_operation(req, NULL) != G_OBEX_OP_PUT)
return 0;

+ if (response_func == NULL)
+ response_func = transfer_response;
+
transfer = transfer_new(obex, G_OBEX_OP_PUT, complete_func, user_data);
transfer->data_producer = data_func;
+ transfer->response_func = response_func;

g_obex_packet_add_body(req, put_get_data, transfer);

transfer->req_id = g_obex_send_req(obex, req, FIRST_PACKET_TIMEOUT,
- transfer_response, transfer, err);
+ response_func, transfer, err);
if (transfer->req_id == 0) {
transfer_free(transfer);
return 0;
@@ -273,7 +279,8 @@ guint g_obex_put_req_pkt(GObex *obex, GObexPacket *req,
return transfer->id;
}

-guint g_obex_put_req(GObex *obex, GObexDataProducer data_func,
+guint g_obex_put_req(GObex *obex, GObexResponseFunc response_func,
+ GObexDataProducer data_func,
GObexFunc complete_func, gpointer user_data,
GError **err, guint8 first_hdr_id, ...)
{
@@ -283,8 +290,12 @@ guint g_obex_put_req(GObex *obex, GObexDataProducer data_func,

g_obex_debug(G_OBEX_DEBUG_TRANSFER, "obex %p", obex);

+ if (response_func == NULL)
+ response_func = transfer_response;
+
transfer = transfer_new(obex, G_OBEX_OP_PUT, complete_func, user_data);
transfer->data_producer = data_func;
+ transfer->response_func = response_func;

va_start(args, first_hdr_id);
req = g_obex_packet_new_valist(G_OBEX_OP_PUT, FALSE,
@@ -294,7 +305,7 @@ guint g_obex_put_req(GObex *obex, GObexDataProducer data_func,
g_obex_packet_add_body(req, put_get_data, transfer);

transfer->req_id = g_obex_send_req(obex, req, FIRST_PACKET_TIMEOUT,
- transfer_response, transfer, err);
+ response_func, transfer, err);
if (transfer->req_id == 0) {
transfer_free(transfer);
return 0;
@@ -429,6 +440,7 @@ guint g_obex_put_rsp(GObex *obex, GObexPacket *req,
}

guint g_obex_get_req_pkt(GObex *obex, GObexPacket *req,
+ GObexResponseFunc response_func,
GObexDataConsumer data_func, GObexFunc complete_func,
gpointer user_data, GError **err)
{
@@ -439,10 +451,15 @@ guint g_obex_get_req_pkt(GObex *obex, GObexPacket *req,
if (g_obex_packet_get_operation(req, NULL) != G_OBEX_OP_GET)
return 0;

+ if (response_func == NULL)
+ response_func = transfer_response;
+
transfer = transfer_new(obex, G_OBEX_OP_GET, complete_func, user_data);
transfer->data_consumer = data_func;
+ transfer->response_func = response_func;
+
transfer->req_id = g_obex_send_req(obex, req, FIRST_PACKET_TIMEOUT,
- transfer_response, transfer, err);
+ response_func, transfer, err);
if (transfer->req_id == 0) {
transfer_free(transfer);
return 0;
@@ -453,7 +470,8 @@ guint g_obex_get_req_pkt(GObex *obex, GObexPacket *req,
return transfer->id;
}

-guint g_obex_get_req(GObex *obex, GObexDataConsumer data_func,
+guint g_obex_get_req(GObex *obex, GObexResponseFunc response_func,
+ GObexDataConsumer data_func,
GObexFunc complete_func, gpointer user_data,
GError **err, guint8 first_hdr_id, ...)
{
@@ -463,8 +481,12 @@ guint g_obex_get_req(GObex *obex, GObexDataConsumer data_func,

g_obex_debug(G_OBEX_DEBUG_TRANSFER, "obex %p", obex);

+ if (response_func == NULL)
+ response_func = transfer_response;
+
transfer = transfer_new(obex, G_OBEX_OP_GET, complete_func, user_data);
transfer->data_consumer = data_func;
+ transfer->response_func = response_func;

va_start(args, first_hdr_id);
req = g_obex_packet_new_valist(G_OBEX_OP_GET, TRUE,
@@ -472,7 +494,7 @@ guint g_obex_get_req(GObex *obex, GObexDataConsumer data_func,
va_end(args);

transfer->req_id = g_obex_send_req(obex, req, FIRST_PACKET_TIMEOUT,
- transfer_response, transfer, err);
+ response_func, transfer, err);
if (transfer->req_id == 0) {
transfer_free(transfer);
return 0;
diff --git a/gobex/gobex.h b/gobex/gobex.h
index b07e8df..6141e51 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -93,19 +93,23 @@ guint g_obex_move(GObex *obex, const char *name, const char *dest,

/* Transfer related high-level functions */

-guint g_obex_put_req(GObex *obex, GObexDataProducer data_func,
+guint g_obex_put_req(GObex *obex, GObexResponseFunc response_func,
+ GObexDataProducer data_func,
GObexFunc complete_func, gpointer user_data,
GError **err, guint8 first_hdr_id, ...);

guint g_obex_put_req_pkt(GObex *obex, GObexPacket *req,
+ GObexResponseFunc response_func,
GObexDataProducer data_func, GObexFunc complete_func,
gpointer user_data, GError **err);

-guint g_obex_get_req(GObex *obex, GObexDataConsumer data_func,
+guint g_obex_get_req(GObex *obex, GObexResponseFunc response_func,
+ GObexDataConsumer data_func,
GObexFunc complete_func, gpointer user_data,
GError **err, guint8 first_hdr_id, ...);

guint g_obex_get_req_pkt(GObex *obex, GObexPacket *req,
+ GObexResponseFunc response_func,
GObexDataConsumer data_func, GObexFunc complete_func,
gpointer user_data, GError **err);

diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c
index f677503..3600dc9 100644
--- a/unit/test-gobex-transfer.c
+++ b/unit/test-gobex-transfer.c
@@ -226,7 +226,7 @@ static void test_put_req(void)

timer_id = g_timeout_add_seconds(1, test_timeout, &d);

- g_obex_put_req(obex, provide_data, transfer_complete, &d, &d.err,
+ g_obex_put_req(obex, NULL, provide_data, transfer_complete, &d, &d.err,
G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
G_OBEX_HDR_NAME, "file.txt",
G_OBEX_HDR_INVALID);
@@ -344,7 +344,7 @@ static void test_get_req(void)

timer_id = g_timeout_add_seconds(1, test_timeout, &d);

- g_obex_get_req(obex, rcv_data, transfer_complete, &d, &d.err,
+ g_obex_get_req(obex, NULL, rcv_data, transfer_complete, &d, &d.err,
G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
G_OBEX_HDR_NAME, "file.txt",
G_OBEX_HDR_INVALID);
@@ -387,7 +387,7 @@ static void test_get_req_app(void)

timer_id = g_timeout_add_seconds(1, test_timeout, &d);

- g_obex_get_req(obex, rcv_data, transfer_complete, &d, &d.err,
+ g_obex_get_req(obex, NULL, rcv_data, transfer_complete, &d, &d.err,
G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
G_OBEX_HDR_NAME, "file.txt",
G_OBEX_HDR_APPARAM, hdr_app, sizeof(hdr_app),
@@ -473,7 +473,7 @@ static void test_put_req_random(int sock_type)

timer_id = g_timeout_add_seconds(1, test_timeout, &d);

- g_obex_put_req(obex, provide_random, transfer_complete, &d, &d.err,
+ g_obex_put_req(obex, NULL, provide_random, transfer_complete, &d, &d.err,
G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
G_OBEX_HDR_NAME, "random.bin",
G_OBEX_HDR_INVALID);
@@ -526,7 +526,7 @@ static void test_put_req_eagain(void)

timer_id = g_timeout_add_seconds(1, test_timeout, &d);

- g_obex_put_req(obex, provide_eagain, transfer_complete, &d, &d.err,
+ g_obex_put_req(obex, NULL, provide_eagain, transfer_complete, &d, &d.err,
G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
G_OBEX_HDR_NAME, "file.txt",
G_OBEX_HDR_INVALID);
@@ -677,7 +677,7 @@ static void test_put_req_delay(void)

timer_id = g_timeout_add_seconds(1, test_timeout, &d);

- g_obex_put_req(obex, provide_data, transfer_complete, &d, &d.err,
+ g_obex_put_req(obex, NULL, provide_data, transfer_complete, &d, &d.err,
G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
G_OBEX_HDR_NAME, "file.txt",
G_OBEX_HDR_INVALID);
@@ -847,7 +847,7 @@ static void test_get_req_delay(void)

timer_id = g_timeout_add_seconds(1, test_timeout, &d);

- g_obex_get_req(obex, rcv_data_delay, transfer_complete, &d, &d.err,
+ g_obex_get_req(obex, NULL, rcv_data_delay, transfer_complete, &d, &d.err,
G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
G_OBEX_HDR_NAME, "file.txt",
G_OBEX_HDR_INVALID);
@@ -1030,7 +1030,7 @@ static void conn_complete_get_req(GObex *obex, GError *err, GObexPacket *rsp,
g_main_loop_quit(d->mainloop);
}

- g_obex_get_req(obex, rcv_data, transfer_complete, d, &d->err,
+ g_obex_get_req(obex, NULL, rcv_data, transfer_complete, d, &d->err,
G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
G_OBEX_HDR_NAME, "file.txt",
G_OBEX_HDR_INVALID);
@@ -1136,7 +1136,7 @@ static void conn_complete_put_req(GObex *obex, GError *err, GObexPacket *rsp,
g_main_loop_quit(d->mainloop);
}

- g_obex_put_req(obex, provide_data, transfer_complete, d, &d->err,
+ g_obex_put_req(obex, NULL, provide_data, transfer_complete, d, &d->err,
G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
G_OBEX_HDR_NAME, "file.txt",
G_OBEX_HDR_INVALID);
@@ -1285,7 +1285,7 @@ static void conn_complete_put_req_random(GObex *obex, GError *err,
g_main_loop_quit(d->mainloop);
}

- g_obex_put_req(obex, provide_random, transfer_complete, d, &d->err,
+ g_obex_put_req(obex, NULL, provide_random, transfer_complete, d, &d->err,
G_OBEX_HDR_TYPE, hdr_type, sizeof(hdr_type),
G_OBEX_HDR_NAME, "random.bin",
G_OBEX_HDR_INVALID);
--
1.7.4.1


2011-12-21 01:41:03

by Jakub Adamek

[permalink] [raw]
Subject: [RFC obexd 4/4] gobex: add functions to public transfer API

Two additional functions are added to the public gobex
transfer API and renamed to prevent name collisions. These are:
- g_obex_transfer_get_data - to allow custom packet response
handlers to access user data from the opaque GObexTransfer,
- g_obex_transfer_complete - to allow them to end the transfer
without calling the default packet response function.

Additionally, the default packet response function
is renamed to g_obex_transfer_response.
---
gobex/gobex-transfer.c | 44 ++++++++++++++++++++++++--------------------
gobex/gobex.h | 6 +++++-
2 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index 51f0189..95cc47b 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -53,6 +53,10 @@ struct _GObexTransfer {
gpointer user_data;
};

+gpointer g_obex_transfer_get_data(GObexTransfer *transfer) {
+ return transfer->user_data;
+}
+
static void transfer_free(GObexTransfer *transfer)
{
g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);
@@ -91,7 +95,7 @@ static GObexTransfer *find_transfer(guint id)
return NULL;
}

-static void transfer_complete(GObexTransfer *transfer, GError *err)
+void g_obex_transfer_complete(GObexTransfer *transfer, GError *err)
{
guint id = transfer->id;

@@ -118,7 +122,7 @@ static void transfer_abort_response(GObex *obex, GError *err, GObexPacket *rsp,
err = g_error_new(G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED,
"Operation was aborted");
g_obex_debug(G_OBEX_DEBUG_ERROR, "%s", err->message);
- transfer_complete(transfer, err);
+ g_obex_transfer_complete(transfer, err);
g_error_free(err);
}

@@ -142,7 +146,7 @@ static gssize put_get_data(void *buf, gsize len, gpointer user_data)
transfer_abort_response,
transfer, &err);
if (err != NULL) {
- transfer_complete(transfer, err);
+ g_obex_transfer_complete(transfer, err);
g_error_free(err);
}

@@ -172,7 +176,7 @@ static gboolean handle_get_body(GObexTransfer *transfer, GObexPacket *rsp,
return ret;
}

-void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
+void g_obex_transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
gpointer user_data)
{
GObexTransfer *transfer = user_data;
@@ -184,7 +188,7 @@ void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
transfer->req_id = 0;

if (err != NULL) {
- transfer_complete(transfer, err);
+ g_obex_transfer_complete(transfer, err);
return;
}

@@ -202,7 +206,7 @@ void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
}

if (rspcode == G_OBEX_RSP_SUCCESS) {
- transfer_complete(transfer, NULL);
+ g_obex_transfer_complete(transfer, NULL);
return;
}

@@ -220,7 +224,7 @@ void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
failed:
if (err != NULL) {
g_obex_debug(G_OBEX_DEBUG_ERROR, "%s", err->message);
- transfer_complete(transfer, err);
+ g_obex_transfer_complete(transfer, err);
g_error_free(err);
}
}
@@ -259,7 +263,7 @@ guint g_obex_put_req_pkt(GObex *obex, GObexPacket *req,
return 0;

if (response_func == NULL)
- response_func = transfer_response;
+ response_func = g_obex_transfer_response;

transfer = transfer_new(obex, G_OBEX_OP_PUT, complete_func, user_data);
transfer->data_producer = data_func;
@@ -291,7 +295,7 @@ guint g_obex_put_req(GObex *obex, GObexResponseFunc response_func,
g_obex_debug(G_OBEX_DEBUG_TRANSFER, "obex %p", obex);

if (response_func == NULL)
- response_func = transfer_response;
+ response_func = g_obex_transfer_response;

transfer = transfer_new(obex, G_OBEX_OP_PUT, complete_func, user_data);
transfer->data_producer = data_func;
@@ -329,7 +333,7 @@ static void transfer_abort_req(GObex *obex, GObexPacket *req, gpointer user_data
rsp = g_obex_packet_new(G_OBEX_RSP_SUCCESS, TRUE, G_OBEX_HDR_INVALID);
g_obex_send(obex, rsp, NULL);

- transfer_complete(transfer, err);
+ g_obex_transfer_complete(transfer, err);
g_error_free(err);
}

@@ -376,12 +380,12 @@ static void transfer_put_req_first(GObexTransfer *transfer, GObexPacket *req,

rsp = g_obex_packet_new_valist(rspcode, TRUE, first_hdr_id, args);
if (!g_obex_send(transfer->obex, rsp, &err)) {
- transfer_complete(transfer, err);
+ g_obex_transfer_complete(transfer, err);
g_error_free(err);
}

if (rspcode != G_OBEX_RSP_CONTINUE)
- transfer_complete(transfer, NULL);
+ g_obex_transfer_complete(transfer, NULL);
}

static void transfer_put_req(GObex *obex, GObexPacket *req, gpointer user_data)
@@ -397,12 +401,12 @@ static void transfer_put_req(GObex *obex, GObexPacket *req, gpointer user_data)

rsp = g_obex_packet_new(rspcode, TRUE, G_OBEX_HDR_INVALID);
if (!g_obex_send(obex, rsp, &err)) {
- transfer_complete(transfer, err);
+ g_obex_transfer_complete(transfer, err);
g_error_free(err);
}

if (rspcode != G_OBEX_RSP_CONTINUE)
- transfer_complete(transfer, NULL);
+ g_obex_transfer_complete(transfer, NULL);
}

guint g_obex_put_rsp(GObex *obex, GObexPacket *req,
@@ -452,7 +456,7 @@ guint g_obex_get_req_pkt(GObex *obex, GObexPacket *req,
return 0;

if (response_func == NULL)
- response_func = transfer_response;
+ response_func = g_obex_transfer_response;

transfer = transfer_new(obex, G_OBEX_OP_GET, complete_func, user_data);
transfer->data_consumer = data_func;
@@ -482,7 +486,7 @@ guint g_obex_get_req(GObex *obex, GObexResponseFunc response_func,
g_obex_debug(G_OBEX_DEBUG_TRANSFER, "obex %p", obex);

if (response_func == NULL)
- response_func = transfer_response;
+ response_func = g_obex_transfer_response;

transfer = transfer_new(obex, G_OBEX_OP_GET, complete_func, user_data);
transfer->data_consumer = data_func;
@@ -522,7 +526,7 @@ static gssize get_get_data(void *buf, gsize len, gpointer user_data)
return ret;

if (ret == 0) {
- transfer_complete(transfer, NULL);
+ g_obex_transfer_complete(transfer, NULL);
return ret;
}

@@ -533,7 +537,7 @@ static gssize get_get_data(void *buf, gsize len, gpointer user_data)
err = g_error_new(G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED,
"Data producer function failed");
g_obex_debug(G_OBEX_DEBUG_ERROR, "%s", err->message);
- transfer_complete(transfer, err);
+ g_obex_transfer_complete(transfer, err);
g_error_free(err);

return ret;
@@ -552,7 +556,7 @@ static void transfer_get_req_first(GObexTransfer *transfer,
g_obex_packet_add_body(rsp, get_get_data, transfer);

if (!g_obex_send(transfer->obex, rsp, &err)) {
- transfer_complete(transfer, err);
+ g_obex_transfer_complete(transfer, err);
g_error_free(err);
}
}
@@ -569,7 +573,7 @@ static void transfer_get_req(GObex *obex, GObexPacket *req, gpointer user_data)
g_obex_packet_add_body(rsp, get_get_data, transfer);

if (!g_obex_send(obex, rsp, &err)) {
- transfer_complete(transfer, err);
+ g_obex_transfer_complete(transfer, err);
g_error_free(err);
}
}
diff --git a/gobex/gobex.h b/gobex/gobex.h
index 6141e51..96b0c08 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -124,9 +124,13 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,

gboolean g_obex_cancel_transfer(guint id);

-void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
+void g_obex_transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
gpointer user_data);

+void g_obex_transfer_complete(GObexTransfer *transfer, GError *err);
+
+gpointer g_obex_transfer_get_data(GObexTransfer *transfer);
+
const char *g_obex_strerror(guint8 err_code);

#endif /* __GOBEX_H */
--
1.7.4.1


2011-12-21 01:41:01

by Jakub Adamek

[permalink] [raw]
Subject: [RFC obexd 2/4] gobex: make default response function public

This will allow response functions outside gobex to fall back
to the default behavior if desired.
---
gobex/gobex-transfer.c | 2 +-
gobex/gobex.h | 3 +++
2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index 57eb37b..2595128 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -171,7 +171,7 @@ static gboolean handle_get_body(GObexTransfer *transfer, GObexPacket *rsp,
return ret;
}

-static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
+void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
gpointer user_data)
{
GObexTransfer *transfer = user_data;
diff --git a/gobex/gobex.h b/gobex/gobex.h
index 3403444..b07e8df 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -120,6 +120,9 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,

gboolean g_obex_cancel_transfer(guint id);

+void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
+ gpointer user_data);
+
const char *g_obex_strerror(guint8 err_code);

#endif /* __GOBEX_H */
--
1.7.4.1


2011-12-21 01:41:00

by Jakub Adamek

[permalink] [raw]
Subject: [RFC obexd 1/4] gobex: make transfer structure public and opaque

This renames the structure responsible for storing transfer
information in gobex to _GObexTransfer and typedefs the name
GObexTransfer to it in the main gobex header.
This will let applications using gobex to implement their own
packet response functions.
---
gobex/gobex-transfer.c | 52 ++++++++++++++++++++++++------------------------
gobex/gobex.h | 1 +
2 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index 692d713..57eb37b 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -33,7 +33,7 @@

static GSList *transfers = NULL;

-struct transfer {
+struct _GObexTransfer {
guint id;
guint8 opcode;

@@ -52,7 +52,7 @@ struct transfer {
gpointer user_data;
};

-static void transfer_free(struct transfer *transfer)
+static void transfer_free(GObexTransfer *transfer)
{
g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);

@@ -77,12 +77,12 @@ static void transfer_free(struct transfer *transfer)
g_free(transfer);
}

-static struct transfer *find_transfer(guint id)
+static GObexTransfer *find_transfer(guint id)
{
GSList *l;

for (l = transfers; l != NULL; l = g_slist_next(l)) {
- struct transfer *t = l->data;
+ GObexTransfer *t = l->data;
if (t->id == id)
return t;
}
@@ -90,7 +90,7 @@ static struct transfer *find_transfer(guint id)
return NULL;
}

-static void transfer_complete(struct transfer *transfer, GError *err)
+static void transfer_complete(GObexTransfer *transfer, GError *err)
{
guint id = transfer->id;

@@ -107,7 +107,7 @@ static void transfer_complete(struct transfer *transfer, GError *err)
static void transfer_abort_response(GObex *obex, GError *err, GObexPacket *rsp,
gpointer user_data)
{
- struct transfer *transfer = user_data;
+ GObexTransfer *transfer = user_data;

g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);

@@ -124,7 +124,7 @@ static void transfer_abort_response(GObex *obex, GError *err, GObexPacket *rsp,

static gssize put_get_data(void *buf, gsize len, gpointer user_data)
{
- struct transfer *transfer = user_data;
+ GObexTransfer *transfer = user_data;
GObexPacket *req;
GError *err = NULL;
gssize ret;
@@ -148,7 +148,7 @@ static gssize put_get_data(void *buf, gsize len, gpointer user_data)
return ret;
}

-static gboolean handle_get_body(struct transfer *transfer, GObexPacket *rsp,
+static gboolean handle_get_body(GObexTransfer *transfer, GObexPacket *rsp,
GError **err)
{
GObexHeader *body = g_obex_packet_get_body(rsp);
@@ -174,7 +174,7 @@ static gboolean handle_get_body(struct transfer *transfer, GObexPacket *rsp,
static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
gpointer user_data)
{
- struct transfer *transfer = user_data;
+ GObexTransfer *transfer = user_data;
GObexPacket *req;
gboolean rspcode, final;

@@ -224,15 +224,15 @@ failed:
}
}

-static struct transfer *transfer_new(GObex *obex, guint8 opcode,
+static GObexTransfer *transfer_new(GObex *obex, guint8 opcode,
GObexFunc complete_func, gpointer user_data)
{
static guint next_id = 1;
- struct transfer *transfer;
+ GObexTransfer *transfer;

g_obex_debug(G_OBEX_DEBUG_TRANSFER, "obex %p opcode %u", obex, opcode);

- transfer = g_new0(struct transfer, 1);
+ transfer = g_new0(GObexTransfer, 1);

transfer->id = next_id++;
transfer->opcode = opcode;
@@ -249,7 +249,7 @@ guint g_obex_put_req_pkt(GObex *obex, GObexPacket *req,
GObexDataProducer data_func, GObexFunc complete_func,
gpointer user_data, GError **err)
{
- struct transfer *transfer;
+ GObexTransfer *transfer;

g_obex_debug(G_OBEX_DEBUG_TRANSFER, "obex %p", obex);

@@ -277,7 +277,7 @@ guint g_obex_put_req(GObex *obex, GObexDataProducer data_func,
GObexFunc complete_func, gpointer user_data,
GError **err, guint8 first_hdr_id, ...)
{
- struct transfer *transfer;
+ GObexTransfer *transfer;
GObexPacket *req;
va_list args;

@@ -307,7 +307,7 @@ guint g_obex_put_req(GObex *obex, GObexDataProducer data_func,

static void transfer_abort_req(GObex *obex, GObexPacket *req, gpointer user_data)
{
- struct transfer *transfer = user_data;
+ GObexTransfer *transfer = user_data;
GObexPacket *rsp;
GError *err;

@@ -322,7 +322,7 @@ static void transfer_abort_req(GObex *obex, GObexPacket *req, gpointer user_data
g_error_free(err);
}

-static guint8 put_get_bytes(struct transfer *transfer, GObexPacket *req)
+static guint8 put_get_bytes(GObexTransfer *transfer, GObexPacket *req)
{
GObexHeader *body;
gboolean final;
@@ -352,7 +352,7 @@ static guint8 put_get_bytes(struct transfer *transfer, GObexPacket *req)
return rsp;
}

-static void transfer_put_req_first(struct transfer *transfer, GObexPacket *req,
+static void transfer_put_req_first(GObexTransfer *transfer, GObexPacket *req,
guint8 first_hdr_id, va_list args)
{
GError *err = NULL;
@@ -375,7 +375,7 @@ static void transfer_put_req_first(struct transfer *transfer, GObexPacket *req,

static void transfer_put_req(GObex *obex, GObexPacket *req, gpointer user_data)
{
- struct transfer *transfer = user_data;
+ GObexTransfer *transfer = user_data;
GError *err = NULL;
GObexPacket *rsp;
guint8 rspcode;
@@ -399,7 +399,7 @@ guint g_obex_put_rsp(GObex *obex, GObexPacket *req,
gpointer user_data, GError **err,
guint8 first_hdr_id, ...)
{
- struct transfer *transfer;
+ GObexTransfer *transfer;
va_list args;
guint id;

@@ -432,7 +432,7 @@ guint g_obex_get_req_pkt(GObex *obex, GObexPacket *req,
GObexDataConsumer data_func, GObexFunc complete_func,
gpointer user_data, GError **err)
{
- struct transfer *transfer;
+ GObexTransfer *transfer;

g_obex_debug(G_OBEX_DEBUG_TRANSFER, "obex %p", obex);

@@ -457,7 +457,7 @@ guint g_obex_get_req(GObex *obex, GObexDataConsumer data_func,
GObexFunc complete_func, gpointer user_data,
GError **err, guint8 first_hdr_id, ...)
{
- struct transfer *transfer;
+ GObexTransfer *transfer;
GObexPacket *req;
va_list args;

@@ -485,7 +485,7 @@ guint g_obex_get_req(GObex *obex, GObexDataConsumer data_func,

static gssize get_get_data(void *buf, gsize len, gpointer user_data)
{
- struct transfer *transfer = user_data;
+ GObexTransfer *transfer = user_data;
GObexPacket *req;
GError *err = NULL;
gssize ret;
@@ -517,7 +517,7 @@ static gssize get_get_data(void *buf, gsize len, gpointer user_data)
return ret;
}

-static void transfer_get_req_first(struct transfer *transfer,
+static void transfer_get_req_first(GObexTransfer *transfer,
guint8 first_hdr_id, va_list args)
{
GError *err = NULL;
@@ -537,7 +537,7 @@ static void transfer_get_req_first(struct transfer *transfer,

static void transfer_get_req(GObex *obex, GObexPacket *req, gpointer user_data)
{
- struct transfer *transfer = user_data;
+ GObexTransfer *transfer = user_data;
GError *err = NULL;
GObexPacket *rsp;

@@ -556,7 +556,7 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,
GObexFunc complete_func, gpointer user_data,
GError **err, guint8 first_hdr_id, ...)
{
- struct transfer *transfer;
+ GObexTransfer *transfer;
va_list args;
guint id;

@@ -587,7 +587,7 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,

gboolean g_obex_cancel_transfer(guint id)
{
- struct transfer *transfer = NULL;
+ GObexTransfer *transfer = NULL;

g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", id);

diff --git a/gobex/gobex.h b/gobex/gobex.h
index 81981ea..3403444 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -34,6 +34,7 @@ typedef enum {
} GObexTransportType;

typedef struct _GObex GObex;
+typedef struct _GObexTransfer GObexTransfer;

typedef void (*GObexFunc) (GObex *obex, GError *err, gpointer user_data);
typedef void (*GObexRequestFunc) (GObex *obex, GObexPacket *req,
--
1.7.4.1