Diff between c45162aaec3e52df28e06f48399f1dbb9f1ffff4 and b8cd1913e6261b166eab6a388c387487eda19f25

Changed Files

File Additions Deletions Status
gobex/gobex.c +37 -0 modified
gobex/gobex.h +8 -0 modified
unit/test-gobex.c +13 -0 modified

Full Patch

diff --git a/gobex/gobex.c b/gobex/gobex.c
index 8ae23b8..ef0feef 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 cdc7f77..3910367 100644
--- a/gobex/gobex.h
+++ b/gobex/gobex.h
@@ -25,7 +25,15 @@
 #include <stdint.h>
 #include <glib.h>
 
+#include <gobex/obex.h>
+
 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 1f5c8b9..a1fabf2 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;