gobex: Use GObexDataProducer type instead of (custom) GObexPacketDataFunc

This commit is contained in:
Johan Hedberg 2011-07-05 19:36:41 +03:00 committed by Marcel Holtmann
parent 0a4824ddb1
commit b50f20a501
7 changed files with 16 additions and 22 deletions

View File

@ -39,6 +39,10 @@ typedef enum {
G_OBEX_ERROR_FAILED,
} GObexError;
typedef gssize (*GObexDataProducer) (void *buf, gsize len, gpointer user_data);
typedef gboolean (*GObexDataConsumer) (const void *buf, gsize len,
gpointer user_data);
#define G_OBEX_ERROR g_obex_error_quark()
GQuark g_obex_error_quark(void);

View File

@ -22,6 +22,7 @@
#include <string.h>
#include <errno.h>
#include "gobex-defs.h"
#include "gobex-packet.h"
#define FINAL_BIT 0x80
@ -41,7 +42,7 @@ struct _GObexPacket {
gsize hlen; /* Length of all encoded headers */
GSList *headers;
GObexPacketDataFunc get_body;
GObexDataProducer get_body;
gpointer get_body_data;
};
@ -97,7 +98,7 @@ gboolean g_obex_packet_add_header(GObexPacket *pkt, GObexHeader *header)
return TRUE;
}
gboolean g_obex_packet_add_body(GObexPacket *pkt, GObexPacketDataFunc func,
gboolean g_obex_packet_add_body(GObexPacket *pkt, GObexDataProducer func,
gpointer user_data)
{
if (pkt->get_body != NULL)
@ -280,7 +281,7 @@ static gssize get_body(GObexPacket *pkt, guint8 *buf, gsize len)
if (len < 3)
return -ENOBUFS;
ret = pkt->get_body(pkt, buf + 3, len - 3, pkt->get_body_data);
ret = pkt->get_body(buf + 3, len - 3, pkt->get_body_data);
if (ret < 0)
return ret;

View File

@ -80,15 +80,12 @@
typedef struct _GObexPacket GObexPacket;
typedef gssize (*GObexPacketDataFunc) (GObexPacket *header, void *buf,
gsize len, gpointer user_data);
GObexHeader *g_obex_packet_get_header(GObexPacket *pkt, guint8 id);
guint8 g_obex_packet_get_operation(GObexPacket *pkt, gboolean *final);
GObexHeader *g_obex_packet_find_header(GObexPacket *pkt, guint8 id);
gboolean g_obex_packet_prepend_header(GObexPacket *pkt, GObexHeader *header);
gboolean g_obex_packet_add_header(GObexPacket *pkt, GObexHeader *header);
gboolean g_obex_packet_add_body(GObexPacket *pkt, GObexPacketDataFunc func,
gboolean g_obex_packet_add_body(GObexPacket *pkt, GObexDataProducer func,
gpointer user_data);
gboolean g_obex_packet_set_data(GObexPacket *pkt, const void *data, gsize len,
GObexDataPolicy data_policy);

View File

@ -65,8 +65,7 @@ static void transfer_abort_response(GObex *obex, GError *err, GObexPacket *rsp,
}
static gssize put_get_data(GObexPacket *pkt, void *buf, gsize len,
gpointer user_data)
static gssize put_get_data(void *buf, gsize len, gpointer user_data)
{
struct transfer *transfer = user_data;
GObexPacket *req;

View File

@ -25,10 +25,7 @@
#include <glib.h>
#include <gobex/gobex.h>
typedef gssize (*GObexDataProducer) (void *buf, gsize len, gpointer user_data);
typedef gboolean (*GObexDataConsumer) (const void *buf, gsize len,
gpointer user_data);
#include <gobex/gobex-defs.h>
guint g_obex_put(GObex *obex, const char *type, const char *name,
GObexDataProducer data_func, GObexFunc complete_func,

View File

@ -144,8 +144,7 @@ static void test_decode_encode(void)
g_obex_packet_free(pkt);
}
static gssize get_body_data(GObexPacket *pkt, void *buf, gsize len,
gpointer user_data)
static gssize get_body_data(void *buf, gsize len, gpointer user_data)
{
uint8_t data[] = { 1, 2, 3, 4 };
@ -174,8 +173,7 @@ static void test_encode_on_demand(void)
g_obex_packet_free(pkt);
}
static gssize get_body_data_fail(GObexPacket *pkt, void *buf, gsize len,
gpointer user_data)
static gssize get_body_data_fail(void *buf, gsize len, gpointer user_data)
{
return -1;
}

View File

@ -570,8 +570,7 @@ static void test_send_connect_pkt(void)
test_send_connect(SOCK_SEQPACKET);
}
static gssize get_body_data(GObexPacket *pkt, void *buf, gsize len,
gpointer user_data)
static gssize get_body_data(void *buf, gsize len, gpointer user_data)
{
uint8_t data[] = { 1, 2, 3, 4 };
@ -580,14 +579,13 @@ static gssize get_body_data(GObexPacket *pkt, void *buf, gsize len,
return sizeof(data);
}
static gssize get_body_data_fail(GObexPacket *pkt, void *buf, gsize len,
gpointer user_data)
static gssize get_body_data_fail(void *buf, gsize len, gpointer user_data)
{
g_main_loop_quit(mainloop);
return -1;
}
static void test_send_on_demand(int transport_type, GObexPacketDataFunc func)
static void test_send_on_demand(int transport_type, GObexDataProducer func)
{
struct rcv_buf_info r;
GIOChannel *io;