OSDN Git Service

gobex: Make use of va-args headers in higher level functions
authorJohan Hedberg <johan.hedberg@intel.com>
Sun, 10 Jul 2011 20:09:02 +0000 (23:09 +0300)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 4 Dec 2012 21:22:01 +0000 (22:22 +0100)
gobex/gobex.c
gobex/gobex.h
tools/obex-client-tool.c
unit/test-gobex.c

index f98551e..8cd7f17 100644 (file)
@@ -907,25 +907,21 @@ void g_obex_unref(GObex *obex)
 
 /* Higher level functions */
 
-guint g_obex_connect(GObex *obex, void *target, gsize target_len,
-                               GObexResponseFunc func, gpointer user_data,
-                               GError **err)
+guint g_obex_connect(GObex *obex, GObexResponseFunc func, gpointer user_data,
+                                       GError **err, guint8 first_hdr_id, ...)
 {
        GObexPacket *req;
        struct connect_data data;
+       va_list args;
 
-       req = g_obex_packet_new(G_OBEX_OP_CONNECT, TRUE, G_OBEX_HDR_INVALID);
+       va_start(args, first_hdr_id);
+       req = g_obex_packet_new_valist(G_OBEX_OP_CONNECT, TRUE,
+                                                       first_hdr_id, args);
+       va_end(args);
 
        init_connect_data(obex, &data);
        g_obex_packet_set_data(req, &data, sizeof(data), G_OBEX_DATA_COPY);
 
-       if (target != NULL) {
-               GObexHeader *hdr;
-               hdr = g_obex_header_new_bytes(G_OBEX_HDR_TARGET,
-                                                       target, target_len);
-               g_obex_packet_add_header(req, hdr);
-       }
-
        return g_obex_send_req(obex, req, -1, func, user_data, err);
 }
 
@@ -957,15 +953,13 @@ guint g_obex_mkdir(GObex *obex, const char *path, GObexResponseFunc func,
                                        gpointer user_data, GError **err)
 {
        GObexPacket *req;
-       GObexHeader *hdr;
        struct setpath_data data;
 
-       req = g_obex_packet_new(G_OBEX_OP_SETPATH, TRUE, G_OBEX_HDR_INVALID);
+       req = g_obex_packet_new(G_OBEX_OP_SETPATH, TRUE,
+                                               G_OBEX_HDR_NAME, path,
+                                               G_OBEX_HDR_INVALID);
 
        memset(&data, 0, sizeof(data));
-       hdr = g_obex_header_new_unicode(G_OBEX_HDR_NAME, path);
-       g_obex_packet_add_header(req, hdr);
-
        g_obex_packet_set_data(req, &data, sizeof(data), G_OBEX_DATA_COPY);
 
        return g_obex_send_req(obex, req, -1, func, user_data, err);
@@ -975,12 +969,10 @@ guint g_obex_delete(GObex *obex, const char *name, GObexResponseFunc func,
                                        gpointer user_data, GError **err)
 {
        GObexPacket *req;
-       GObexHeader *hdr;
-
-       req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_INVALID);
 
-       hdr = g_obex_header_new_unicode(G_OBEX_HDR_NAME, name);
-       g_obex_packet_add_header(req, hdr);
+       req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE,
+                                               G_OBEX_HDR_NAME, name,
+                                               G_OBEX_HDR_INVALID);
 
        return g_obex_send_req(obex, req, -1, func, user_data, err);
 }
index 1c0e170..cfe9235 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef __GOBEX_H
 #define __GOBEX_H
 
+#include <stdarg.h>
 #include <glib.h>
 
 #include <gobex/gobex-packet.h>
@@ -65,9 +66,8 @@ void g_obex_unref(GObex *obex);
 
 /* Higher level functions */
 
-guint g_obex_connect(GObex *obex, void *target, gsize target_len,
-                               GObexResponseFunc func, gpointer user_data,
-                               GError **err);
+guint g_obex_connect(GObex *obex, GObexResponseFunc func, gpointer user_data,
+                               GError **err, guint8 first_hdr_id, ...);
 
 guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func,
                                        gpointer user_data, GError **err);
index 9b3279a..a621ec2 100644 (file)
@@ -112,7 +112,7 @@ static void conn_complete(GObex *obex, GError *err, GObexPacket *rsp,
 
 static void cmd_connect(int argc, char **argv)
 {
-       g_obex_connect(obex, NULL, 0, conn_complete, NULL, NULL);
+       g_obex_connect(obex, conn_complete, NULL, NULL, G_OBEX_HDR_INVALID);
 }
 
 struct put_data {
index 005fe3e..bf363f4 100644 (file)
@@ -841,7 +841,7 @@ static void test_connect(void)
 
        timer_id = g_timeout_add_seconds(1, test_timeout, &d);
 
-       g_obex_connect(obex, NULL, 0, req_complete, &d, &d.err);
+       g_obex_connect(obex, req_complete, &d, &d.err, G_OBEX_HDR_INVALID);
        g_assert_no_error(d.err);
 
        g_main_loop_run(d.mainloop);