From b8cd1913e6261b166eab6a388c387487eda19f25 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 21 Jun 2011 00:29:26 +0300 Subject: [PATCH] gobex: Add request stubs --- gobex/gobex.c | 37 +++++++++++++++++++++++++++++++++++++ gobex/gobex.h | 8 ++++++++ unit/test-gobex.c | 13 +++++++++++++ 3 files changed, 58 insertions(+) diff --git a/gobex/gobex.c b/gobex/gobex.c index 8ae23b8aa..ef0feef70 100644 --- a/gobex/gobex.c +++ b/gobex/gobex.c @@ -21,11 +21,44 @@ #include "gobex.h" +struct _GObexRequest { + uint8_t opcode; + GSList *headers; +}; + struct _GObex { gint ref_count; GIOChannel *io; + + GQueue *req_queue; }; +GObexRequest *g_obex_request_new(uint8_t opcode) +{ + GObexRequest *req; + + req = g_new0(GObexRequest, 1); + + req->opcode = opcode; + + return req; +} + +void g_obex_request_free(GObexRequest *req) +{ + g_free(req); +} + +gboolean g_obex_send(GObex *obex, GObexRequest *req) +{ + if (obex == NULL || req == NULL) + return FALSE; + + g_queue_push_tail(obex->req_queue, req); + + return TRUE; +} + GObex *g_obex_new(GIOChannel *io) { GObex *obex; @@ -37,6 +70,7 @@ GObex *g_obex_new(GIOChannel *io) obex->io = io; obex->ref_count = 1; + obex->req_queue = g_queue_new(); return obex; } @@ -60,6 +94,9 @@ void g_obex_unref(GObex *obex) if (!last_ref) return; + g_queue_foreach(obex->req_queue, (GFunc) g_obex_request_free, NULL); + g_queue_free(obex->req_queue); + g_io_channel_unref(obex->io); g_free(obex); diff --git a/gobex/gobex.h b/gobex/gobex.h index cdc7f77eb..3910367e4 100644 --- a/gobex/gobex.h +++ b/gobex/gobex.h @@ -25,7 +25,15 @@ #include #include +#include + typedef struct _GObex GObex; +typedef struct _GObexRequest GObexRequest; + +GObexRequest *g_obex_request_new(uint8_t opcode); +void g_obex_request_free(GObexRequest *req); + +gboolean g_obex_send(GObex *obex, GObexRequest *req); GObex *g_obex_new(GIOChannel *io); diff --git a/unit/test-gobex.c b/unit/test-gobex.c index 1f5c8b9b6..a1fabf268 100644 --- a/unit/test-gobex.c +++ b/unit/test-gobex.c @@ -33,6 +33,17 @@ static GObex *create_gobex(int fd) return g_obex_new(io); } +static void test_req(void) +{ + GObexRequest *req; + + req = g_obex_request_new(G_OBEX_OP_PUT); + + g_assert(req != NULL); + + g_obex_request_free(req); +} + static void test_ref_unref(void) { GObex *obex; @@ -75,6 +86,8 @@ int main(int argc, char *argv[]) g_test_add_func("/gobex/basic", test_basic); g_test_add_func("/gobex/ref_unref", test_ref_unref); + g_test_add_func("/gobex/test_req", test_req); + g_test_run(); return 0; -- 2.47.3