GQueue *tx_queue;
- GObexEventFunc ev_func;
- gpointer ev_func_data;
+ GObexRequestFunc req_func;
+ gpointer req_func_data;
+
+ GObexDisconnectFunc disconn_func;
+ gpointer disconn_func_data;
struct pending_pkt *pending_req;
};
return TRUE;
}
-void g_obex_set_event_function(GObex *obex, GObexEventFunc func,
+void g_obex_set_request_function(GObex *obex, GObexRequestFunc func,
+ gpointer user_data)
+{
+ obex->req_func = func;
+ obex->req_func_data = user_data;
+}
+
+void g_obex_set_disconnect_function(GObex *obex, GObexDisconnectFunc func,
gpointer user_data)
{
- obex->ev_func = func;
- obex->ev_func_data = user_data;
+ obex->disconn_func = func;
+ obex->disconn_func_data = user_data;
}
static void parse_connect_data(GObex *obex, GObexPacket *pkt)
static void handle_response(GObex *obex, GError *err, GObexPacket *rsp)
{
struct pending_pkt *p = obex->pending_req;
+ gboolean disconn = err ? TRUE : FALSE;
if (rsp != NULL) {
guint8 op = g_obex_packet_get_operation(p->pkt, NULL);
pending_pkt_free(p);
obex->pending_req = NULL;
- if (g_queue_get_length(obex->tx_queue) > 0)
+ if (!disconn && g_queue_get_length(obex->tx_queue) > 0)
enable_tx(obex);
}
-static void handle_request(GObex *obex, GError *err, GObexPacket *req)
+static void handle_request(GObex *obex, GObexPacket *req)
{
- if (req != NULL) {
- guint8 op = g_obex_packet_get_operation(req, NULL);
- if (op == G_OBEX_OP_CONNECT)
- parse_connect_data(obex, req);
- }
+ if (g_obex_packet_get_operation(req, NULL) == G_OBEX_OP_CONNECT)
+ parse_connect_data(obex, req);
- if (obex->ev_func)
- obex->ev_func(obex, err, req, obex->ev_func_data);
+ if (obex->req_func)
+ obex->req_func(obex, req, obex->req_func_data);
}
static gboolean read_stream(GObex *obex, GError **err)
pkt = g_obex_packet_decode(obex->rx_buf, obex->rx_data, header_offset,
G_OBEX_DATA_REF, &err);
+ if (pkt == NULL)
+ goto failed;
if (obex->pending_req)
- handle_response(obex, err, pkt);
+ handle_response(obex, NULL, pkt);
else
- handle_request(obex, err, pkt);
+ handle_request(obex, pkt);
if (err != NULL)
g_error_free(err);
if (obex->pending_req)
handle_response(obex, err, NULL);
- if (obex->ev_func)
- obex->ev_func(obex, err, NULL, obex->ev_func_data);
+ if (obex->disconn_func)
+ obex->disconn_func(obex, err, obex->disconn_func_data);
g_error_free(err);
typedef struct _GObex GObex;
-typedef void (*GObexEventFunc) (GObex *obex, GError *err, GObexPacket *req,
+typedef void (*GObexRequestFunc) (GObex *obex, GObexPacket *req,
+ gpointer user_data);
+typedef void (*GObexDisconnectFunc) (GObex *obex, GError *err,
gpointer user_data);
typedef void (*GObexResponseFunc) (GObex *obex, GError *err, GObexPacket *rsp,
gpointer user_data);
gboolean g_obex_cancel_req(GObex *obex, guint req_id,
gboolean remove_callback);
-void g_obex_set_event_function(GObex *obex, GObexEventFunc func,
+void g_obex_set_request_function(GObex *obex, GObexRequestFunc func,
+ gpointer user_data);
+void g_obex_set_disconnect_function(GObex *obex, GObexDisconnectFunc func,
gpointer user_data);
GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type);
test_send_on_demand(SOCK_SEQPACKET);
}
-static void handle_connect_event(GObex *obex, GError *err, GObexPacket *pkt,
+static void handle_connect_req(GObex *obex, GObexPacket *req,
gpointer user_data)
{
GError **test_err = user_data;
+ if (g_obex_packet_get_operation(req, NULL) != G_OBEX_OP_CONNECT)
+ g_set_error(test_err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
+ "Unexpected operation");
g_main_loop_quit(mainloop);
- if (err != NULL) {
- *test_err = g_error_copy(err);
- return;
- }
+}
- if (g_obex_packet_get_operation(pkt, NULL) != G_OBEX_OP_CONNECT)
- g_set_error(test_err, TEST_ERROR, TEST_ERROR_UNEXPECTED,
- "Unexpected operation");
+static void handle_connect_err(GObex *obex, GError *err, gpointer user_data)
+{
+ GError **test_err = user_data;
+
+ g_main_loop_quit(mainloop);
+
+ if (err != NULL)
+ *test_err = g_error_copy(err);
+ else
+ *test_err = g_error_new(TEST_ERROR, TEST_ERROR_UNEXPECTED,
+ "Disconnected");
}
static void recv_connect(int transport_type)
create_endpoints(&obex, &io, transport_type);
- g_obex_set_event_function(obex, handle_connect_event, &gerr);
+ g_obex_set_request_function(obex, handle_connect_req, &gerr);
+ g_obex_set_disconnect_function(obex, handle_connect_err, &gerr);
status = g_io_channel_write_chars(io, (gchar *) pkt_connect_req,
sizeof(pkt_connect_req),
recv_connect(SOCK_SEQPACKET);
}
-static void disconn_ev(GObex *obex, GError *err, GObexPacket *req,
- gpointer user_data)
+static void disconn_ev(GObex *obex, GError *err, gpointer user_data)
{
GError **test_err = user_data;
create_endpoints(&obex, &io, SOCK_STREAM);
- g_obex_set_event_function(obex, disconn_ev, &gerr);
+ g_obex_set_disconnect_function(obex, disconn_ev, &gerr);
timer_id = g_timeout_add_seconds(1, test_timeout, &gerr);