All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage
@ 2013-03-04 20:58 Jefferson Delfes
  2013-03-04 20:58 ` [PATCH BlueZ 1/6] gattrib: remove " Jefferson Delfes
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Jefferson Delfes @ 2013-03-04 20:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

This patch series do a cleanup of glib basic data types usage. Types as
gpointer, guint, gint, gchar and gsize were replaced by standard types without
any extra effort. The only exception was gboolean which needs stdbool.h.
Some variables were mainted as gboolean, because are passed as parameter to
glib functions.

Jefferson Delfes (6):
  gattrib: remove glib basic data types usage
  GATT: remove glib basic data types usage
  attrib: remove glib basic data types usage
  gatttool: remove glib basic data types usage
  attrib: simplify boolean tests
  attrib: removing gboolean usage when possible

 attrib/att-database.h |   6 +-
 attrib/gatt-service.c |  32 ++++-----
 attrib/gatt-service.h |   2 +-
 attrib/gatt.c         | 183 ++++++++++++++++++++++++++------------------------
 attrib/gatt.h         |  48 ++++++-------
 attrib/gattrib.c      | 181 +++++++++++++++++++++++++------------------------
 attrib/gattrib.h      |  44 ++++++------
 attrib/gatttool.c     | 104 ++++++++++++++--------------
 attrib/gatttool.h     |   8 +--
 attrib/interactive.c  |  55 ++++++++-------
 attrib/utils.c        |   7 +-
 11 files changed, 337 insertions(+), 333 deletions(-)

-- 
1.8.1.4


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH BlueZ 1/6] gattrib: remove glib basic data types usage
  2013-03-04 20:58 [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Jefferson Delfes
@ 2013-03-04 20:58 ` Jefferson Delfes
  2013-03-04 20:58 ` [PATCH BlueZ 2/6] GATT: " Jefferson Delfes
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Jefferson Delfes @ 2013-03-04 20:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

---
 attrib/gattrib.c | 93 ++++++++++++++++++++++++++++----------------------------
 attrib/gattrib.h | 36 +++++++++++-----------
 2 files changed, 64 insertions(+), 65 deletions(-)

diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 01c19f9..7cc489a 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -44,43 +44,43 @@
 
 struct _GAttrib {
 	GIOChannel *io;
-	gint refs;
+	int refs;
 	uint8_t *buf;
 	size_t buflen;
-	guint read_watch;
-	guint write_watch;
-	guint timeout_watch;
+	unsigned int read_watch;
+	unsigned int write_watch;
+	unsigned int timeout_watch;
 	GQueue *requests;
 	GQueue *responses;
 	GSList *events;
-	guint next_cmd_id;
+	unsigned int next_cmd_id;
 	GDestroyNotify destroy;
-	gpointer destroy_user_data;
+	void *destroy_user_data;
 	gboolean stale;
 };
 
 struct command {
-	guint id;
-	guint8 opcode;
-	guint8 *pdu;
-	guint16 len;
-	guint8 expected;
+	unsigned int id;
+	uint8_t opcode;
+	uint8_t *pdu;
+	uint16_t len;
+	uint8_t expected;
 	gboolean sent;
 	GAttribResultFunc func;
-	gpointer user_data;
+	void *user_data;
 	GDestroyNotify notify;
 };
 
 struct event {
-	guint id;
-	guint8 expected;
-	guint16 handle;
+	unsigned int id;
+	uint8_t expected;
+	uint16_t handle;
 	GAttribNotifyFunc func;
-	gpointer user_data;
+	void *user_data;
 	GDestroyNotify notify;
 };
 
-static guint8 opcode2expected(guint8 opcode)
+static uint8_t opcode2expected(uint8_t opcode)
 {
 	switch (opcode) {
 	case ATT_OP_MTU_REQ:
@@ -123,7 +123,7 @@ static guint8 opcode2expected(guint8 opcode)
 	return 0;
 }
 
-static gboolean is_response(guint8 opcode)
+static gboolean is_response(uint8_t opcode)
 {
 	switch (opcode) {
 	case ATT_OP_ERROR:
@@ -243,7 +243,7 @@ GIOChannel *g_attrib_get_channel(GAttrib *attrib)
 }
 
 gboolean g_attrib_set_destroy_function(GAttrib *attrib,
-		GDestroyNotify destroy, gpointer user_data)
+					GDestroyNotify destroy, void *user_data)
 {
 	if (attrib == NULL)
 		return FALSE;
@@ -254,7 +254,7 @@ gboolean g_attrib_set_destroy_function(GAttrib *attrib,
 	return TRUE;
 }
 
-static gboolean disconnect_timeout(gpointer data)
+static gboolean disconnect_timeout(void *data)
 {
 	struct _GAttrib *attrib = data;
 	struct command *c;
@@ -284,13 +284,12 @@ done:
 	return FALSE;
 }
 
-static gboolean can_write_data(GIOChannel *io, GIOCondition cond,
-								gpointer data)
+static gboolean can_write_data(GIOChannel *io, GIOCondition cond, void *data)
 {
 	struct _GAttrib *attrib = data;
 	struct command *cmd;
 	GError *gerr = NULL;
-	gsize len;
+	size_t len;
 	GIOStatus iostat;
 	GQueue *queue;
 
@@ -316,8 +315,8 @@ static gboolean can_write_data(GIOChannel *io, GIOCondition cond,
 	if (cmd->sent)
 		return FALSE;
 
-	iostat = g_io_channel_write_chars(io, (gchar *) cmd->pdu, cmd->len,
-								&len, &gerr);
+	iostat = g_io_channel_write_chars(io, (char *) cmd->pdu, cmd->len, &len,
+									&gerr);
 	if (iostat != G_IO_STATUS_NORMAL) {
 		if (gerr) {
 			error("%s", gerr->message);
@@ -343,7 +342,7 @@ static gboolean can_write_data(GIOChannel *io, GIOCondition cond,
 	return FALSE;
 }
 
-static void destroy_sender(gpointer data)
+static void destroy_sender(void *data)
 {
 	struct _GAttrib *attrib = data;
 
@@ -362,9 +361,9 @@ static void wake_up_sender(struct _GAttrib *attrib)
 				can_write_data, attrib, destroy_sender);
 }
 
-static gboolean match_event(struct event *evt, const uint8_t *pdu, gsize len)
+static gboolean match_event(struct event *evt, const uint8_t *pdu, size_t len)
 {
-	guint16 handle;
+	uint16_t handle;
 
 	if (evt->expected == GATTRIB_ALL_EVENTS)
 		return TRUE;
@@ -386,13 +385,13 @@ static gboolean match_event(struct event *evt, const uint8_t *pdu, gsize len)
 	return FALSE;
 }
 
-static gboolean received_data(GIOChannel *io, GIOCondition cond, gpointer data)
+static gboolean received_data(GIOChannel *io, GIOCondition cond, void *data)
 {
 	struct _GAttrib *attrib = data;
 	struct command *cmd = NULL;
 	GSList *l;
 	uint8_t buf[512], status;
-	gsize len;
+	size_t len;
 	GIOStatus iostat;
 	gboolean norequests, noresponses;
 
@@ -406,8 +405,8 @@ static gboolean received_data(GIOChannel *io, GIOCondition cond, gpointer data)
 
 	memset(buf, 0, sizeof(buf));
 
-	iostat = g_io_channel_read_chars(io, (gchar *) buf, sizeof(buf),
-								&len, NULL);
+	iostat = g_io_channel_read_chars(io, (char *) buf, sizeof(buf), &len,
+									NULL);
 	if (iostat != G_IO_STATUS_NORMAL) {
 		status = ATT_ECODE_IO;
 		goto done;
@@ -504,9 +503,9 @@ GAttrib *g_attrib_new(GIOChannel *io)
 	return g_attrib_ref(attrib);
 }
 
-guint g_attrib_send(GAttrib *attrib, guint id, const guint8 *pdu, guint16 len,
-			GAttribResultFunc func, gpointer user_data,
-			GDestroyNotify notify)
+unsigned int g_attrib_send(GAttrib *attrib, unsigned int id, const uint8_t *pdu,
+					uint16_t len, GAttribResultFunc func,
+					void *user_data, GDestroyNotify notify)
 {
 	struct command *c;
 	GQueue *queue;
@@ -558,15 +557,15 @@ guint g_attrib_send(GAttrib *attrib, guint id, const guint8 *pdu, guint16 len,
 	return c->id;
 }
 
-static gint command_cmp_by_id(gconstpointer a, gconstpointer b)
+static int command_cmp_by_id(const void *a, const void *b)
 {
 	const struct command *cmd = a;
-	guint id = GPOINTER_TO_UINT(b);
+	unsigned int id = GPOINTER_TO_UINT(b);
 
 	return cmd->id - id;
 }
 
-gboolean g_attrib_cancel(GAttrib *attrib, guint id)
+gboolean g_attrib_cancel(GAttrib *attrib, unsigned int id)
 {
 	GList *l = NULL;
 	struct command *cmd;
@@ -643,8 +642,8 @@ gboolean g_attrib_cancel_all(GAttrib *attrib)
 	return ret;
 }
 
-gboolean g_attrib_set_debug(GAttrib *attrib,
-		GAttribDebugFunc func, gpointer user_data)
+gboolean g_attrib_set_debug(GAttrib *attrib, GAttribDebugFunc func,
+								void *user_data)
 {
 	return TRUE;
 }
@@ -671,11 +670,11 @@ gboolean g_attrib_set_mtu(GAttrib *attrib, int mtu)
 	return TRUE;
 }
 
-guint g_attrib_register(GAttrib *attrib, guint8 opcode, guint16 handle,
-				GAttribNotifyFunc func, gpointer user_data,
-				GDestroyNotify notify)
+unsigned int g_attrib_register(GAttrib *attrib, uint8_t opcode, uint16_t handle,
+					GAttribNotifyFunc func, void *user_data,
+					GDestroyNotify notify)
 {
-	static guint next_evt_id = 0;
+	static unsigned int next_evt_id = 0;
 	struct event *event;
 
 	event = g_try_new0(struct event, 1);
@@ -694,10 +693,10 @@ guint g_attrib_register(GAttrib *attrib, guint8 opcode, guint16 handle,
 	return event->id;
 }
 
-static gint event_cmp_by_id(gconstpointer a, gconstpointer b)
+static int event_cmp_by_id(const void *a, const void *b)
 {
 	const struct event *evt = a;
-	guint id = GPOINTER_TO_UINT(b);
+	unsigned int id = GPOINTER_TO_UINT(b);
 
 	return evt->id - id;
 }
@@ -714,7 +713,7 @@ gboolean g_attrib_is_encrypted(GAttrib *attrib)
 	return sec_level > BT_IO_SEC_LOW;
 }
 
-gboolean g_attrib_unregister(GAttrib *attrib, guint id)
+gboolean g_attrib_unregister(GAttrib *attrib, unsigned int id)
 {
 	struct event *evt;
 	GSList *l;
diff --git a/attrib/gattrib.h b/attrib/gattrib.h
index 3fe92c7..f0dcdd4 100644
--- a/attrib/gattrib.h
+++ b/attrib/gattrib.h
@@ -35,12 +35,12 @@ extern "C" {
 struct _GAttrib;
 typedef struct _GAttrib GAttrib;
 
-typedef void (*GAttribResultFunc) (guint8 status, const guint8 *pdu,
-					guint16 len, gpointer user_data);
-typedef void (*GAttribDisconnectFunc)(gpointer user_data);
-typedef void (*GAttribDebugFunc)(const char *str, gpointer user_data);
-typedef void (*GAttribNotifyFunc)(const guint8 *pdu, guint16 len,
-							gpointer user_data);
+typedef void (*GAttribResultFunc) (uint8_t status, const uint8_t *pdu,
+						uint16_t len, void *user_data);
+typedef void (*GAttribDisconnectFunc)(void *user_data);
+typedef void (*GAttribDebugFunc)(const char *str, void *user_data);
+typedef void (*GAttribNotifyFunc)(const uint8_t *pdu, uint16_t len,
+							void *user_data);
 
 GAttrib *g_attrib_new(GIOChannel *io);
 GAttrib *g_attrib_ref(GAttrib *attrib);
@@ -48,29 +48,29 @@ void g_attrib_unref(GAttrib *attrib);
 
 GIOChannel *g_attrib_get_channel(GAttrib *attrib);
 
-gboolean g_attrib_set_destroy_function(GAttrib *attrib,
-		GDestroyNotify destroy, gpointer user_data);
+gboolean g_attrib_set_destroy_function(GAttrib *attrib, GDestroyNotify destroy,
+							void *user_data);
 
-guint g_attrib_send(GAttrib *attrib, guint id, const guint8 *pdu, guint16 len,
-			GAttribResultFunc func, gpointer user_data,
-			GDestroyNotify notify);
+unsigned int g_attrib_send(GAttrib *attrib, unsigned int id, const uint8_t *pdu,
+					uint16_t len, GAttribResultFunc func,
+					void *user_data, GDestroyNotify notify);
 
-gboolean g_attrib_cancel(GAttrib *attrib, guint id);
+gboolean g_attrib_cancel(GAttrib *attrib, unsigned int id);
 gboolean g_attrib_cancel_all(GAttrib *attrib);
 
-gboolean g_attrib_set_debug(GAttrib *attrib,
-		GAttribDebugFunc func, gpointer user_data);
+gboolean g_attrib_set_debug(GAttrib *attrib, GAttribDebugFunc func,
+							void *user_data);
 
-guint g_attrib_register(GAttrib *attrib, guint8 opcode, guint16 handle,
-				GAttribNotifyFunc func, gpointer user_data,
-				GDestroyNotify notify);
+unsigned int g_attrib_register(GAttrib *attrib, uint8_t opcode, uint16_t handle,
+					GAttribNotifyFunc func, void *user_data,
+					GDestroyNotify notify);
 
 gboolean g_attrib_is_encrypted(GAttrib *attrib);
 
 uint8_t *g_attrib_get_buffer(GAttrib *attrib, size_t *len);
 gboolean g_attrib_set_mtu(GAttrib *attrib, int mtu);
 
-gboolean g_attrib_unregister(GAttrib *attrib, guint id);
+gboolean g_attrib_unregister(GAttrib *attrib, unsigned int id);
 gboolean g_attrib_unregister_all(GAttrib *attrib);
 
 #ifdef __cplusplus
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH BlueZ 2/6] GATT: remove glib basic data types usage
  2013-03-04 20:58 [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Jefferson Delfes
  2013-03-04 20:58 ` [PATCH BlueZ 1/6] gattrib: remove " Jefferson Delfes
@ 2013-03-04 20:58 ` Jefferson Delfes
  2013-03-04 20:58 ` [PATCH BlueZ 3/6] attrib: " Jefferson Delfes
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Jefferson Delfes @ 2013-03-04 20:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

---
 attrib/gatt.c | 159 ++++++++++++++++++++++++++++++----------------------------
 attrib/gatt.h |  41 +++++++--------
 2 files changed, 103 insertions(+), 97 deletions(-)

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 44d3eb6..9a2d909 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -107,11 +107,11 @@ static void discover_char_free(struct discover_char *dc)
 	g_free(dc);
 }
 
-static guint16 encode_discover_primary(uint16_t start, uint16_t end,
+static uint16_t encode_discover_primary(uint16_t start, uint16_t end,
 				bt_uuid_t *uuid, uint8_t *pdu, size_t len)
 {
 	bt_uuid_t prim;
-	guint16 plen;
+	uint16_t plen;
 
 	bt_uuid16_create(&prim, GATT_PRIM_SVC_UUID);
 
@@ -143,15 +143,15 @@ static guint16 encode_discover_primary(uint16_t start, uint16_t end,
 	return plen;
 }
 
-static void primary_by_uuid_cb(guint8 status, const guint8 *ipdu,
-					guint16 iplen, gpointer user_data)
+static void primary_by_uuid_cb(uint8_t status, const uint8_t *ipdu,
+						uint16_t iplen, void *user_data)
 
 {
 	struct discover_primary *dp = user_data;
 	GSList *ranges, *last;
 	struct att_range *range;
 	uint8_t *buf;
-	guint16 oplen;
+	uint16_t oplen;
 	int err = 0;
 	size_t buflen;
 
@@ -187,8 +187,8 @@ done:
 	discover_primary_free(dp);
 }
 
-static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
-							gpointer user_data)
+static void primary_all_cb(uint8_t status, const uint8_t *ipdu, uint16_t iplen,
+								void *user_data)
 {
 	struct discover_primary *dp = user_data;
 	struct att_data_list *list;
@@ -241,7 +241,7 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
 	if (end != 0xffff) {
 		size_t buflen;
 		uint8_t *buf = g_attrib_get_buffer(dp->attrib, &buflen);
-		guint16 oplen = encode_discover_primary(end + 1, 0xffff, NULL,
+		uint16_t oplen = encode_discover_primary(end + 1, 0xffff, NULL,
 								buf, buflen);
 
 		g_attrib_send(dp->attrib, 0, buf, oplen, primary_all_cb,
@@ -255,14 +255,14 @@ done:
 	discover_primary_free(dp);
 }
 
-guint gatt_discover_primary(GAttrib *attrib, bt_uuid_t *uuid, gatt_cb_t func,
-							gpointer user_data)
+unsigned int gatt_discover_primary(GAttrib *attrib, bt_uuid_t *uuid,
+						gatt_cb_t func, void *user_data)
 {
 	struct discover_primary *dp;
 	size_t buflen;
 	uint8_t *buf = g_attrib_get_buffer(attrib, &buflen);
 	GAttribResultFunc cb;
-	guint16 plen;
+	uint16_t plen;
 
 	plen = encode_discover_primary(0x0001, 0xffff, uuid, buf, buflen);
 	if (plen == 0)
@@ -286,7 +286,7 @@ guint gatt_discover_primary(GAttrib *attrib, bt_uuid_t *uuid, gatt_cb_t func,
 }
 
 static void resolve_included_uuid_cb(uint8_t status, const uint8_t *pdu,
-					uint16_t len, gpointer user_data)
+						uint16_t len, void *user_data)
 {
 	struct included_uuid_query *query = user_data;
 	struct included_discovery *isd = query->isd;
@@ -321,13 +321,13 @@ done:
 	g_free(query);
 }
 
-static guint resolve_included_uuid(struct included_discovery *isd,
-					struct gatt_included *incl)
+static unsigned int resolve_included_uuid(struct included_discovery *isd,
+						struct gatt_included *incl)
 {
 	struct included_uuid_query *query;
 	size_t buflen;
 	uint8_t *buf = g_attrib_get_buffer(isd->attrib, &buflen);
-	guint16 oplen = enc_read_req(incl->range.start, buf, buflen);
+	uint16_t oplen = enc_read_req(incl->range.start, buf, buflen);
 
 	query = g_new0(struct included_uuid_query, 1);
 	query->isd = isd_ref(isd);
@@ -337,7 +337,7 @@ static guint resolve_included_uuid(struct included_discovery *isd,
 				resolve_included_uuid_cb, query, NULL);
 }
 
-static struct gatt_included *included_from_buf(const uint8_t *buf, gsize len)
+static struct gatt_included *included_from_buf(const uint8_t *buf, size_t len)
 {
 	struct gatt_included *incl = g_new0(struct gatt_included, 1);
 
@@ -357,14 +357,15 @@ static struct gatt_included *included_from_buf(const uint8_t *buf, gsize len)
 }
 
 static void find_included_cb(uint8_t status, const uint8_t *pdu, uint16_t len,
-							gpointer user_data);
+							void *user_data);
 
-static guint find_included(struct included_discovery *isd, uint16_t start)
+static unsigned int find_included(struct included_discovery *isd,
+								uint16_t start)
 {
 	bt_uuid_t uuid;
 	size_t buflen;
 	uint8_t *buf = g_attrib_get_buffer(isd->attrib, &buflen);
-	guint16 oplen;
+	uint16_t oplen;
 
 	bt_uuid16_create(&uuid, GATT_INCLUDE_UUID);
 	oplen = enc_read_by_type_req(start, isd->end_handle, &uuid,
@@ -375,7 +376,7 @@ static guint find_included(struct included_discovery *isd, uint16_t start)
 }
 
 static void find_included_cb(uint8_t status, const uint8_t *pdu, uint16_t len,
-							gpointer user_data)
+								void *user_data)
 {
 	struct included_discovery *isd = user_data;
 	uint16_t last_handle = isd->end_handle;
@@ -429,7 +430,7 @@ done:
 }
 
 unsigned int gatt_find_included(GAttrib *attrib, uint16_t start, uint16_t end,
-					gatt_cb_t func, gpointer user_data)
+						gatt_cb_t func, void *user_data)
 {
 	struct included_discovery *isd;
 
@@ -442,15 +443,15 @@ unsigned int gatt_find_included(GAttrib *attrib, uint16_t start, uint16_t end,
 	return find_included(isd, start);
 }
 
-static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
-							gpointer user_data)
+static void char_discovered_cb(uint8_t status, const uint8_t *ipdu,
+						uint16_t iplen, void *user_data)
 {
 	struct discover_char *dc = user_data;
 	struct att_data_list *list;
 	unsigned int i, err = ATT_ECODE_ATTR_NOT_FOUND;
 	size_t buflen;
 	uint8_t *buf;
-	guint16 oplen;
+	uint16_t oplen;
 	bt_uuid_t uuid;
 	uint16_t last = 0;
 
@@ -521,15 +522,15 @@ done:
 	discover_char_free(dc);
 }
 
-guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end,
+unsigned int gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end,
 						bt_uuid_t *uuid, gatt_cb_t func,
-						gpointer user_data)
+						void *user_data)
 {
 	size_t buflen;
 	uint8_t *buf = g_attrib_get_buffer(attrib, &buflen);
 	struct discover_char *dc;
 	bt_uuid_t type_uuid;
-	guint16 plen;
+	uint16_t plen;
 
 	bt_uuid16_create(&type_uuid, GATT_CHARAC_UUID);
 
@@ -551,13 +552,13 @@ guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end,
 								dc, NULL);
 }
 
-guint gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start, uint16_t end,
-					bt_uuid_t *uuid, GAttribResultFunc func,
-					gpointer user_data)
+unsigned int gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start,
+					uint16_t end, bt_uuid_t *uuid,
+					GAttribResultFunc func, void *user_data)
 {
 	size_t buflen;
 	uint8_t *buf = g_attrib_get_buffer(attrib, &buflen);
-	guint16 plen;
+	uint16_t plen;
 
 	plen = enc_read_by_type_req(start, end, uuid, buf, buflen);
 	if (plen == 0)
@@ -569,15 +570,15 @@ guint gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start, uint16_t end,
 struct read_long_data {
 	GAttrib *attrib;
 	GAttribResultFunc func;
-	gpointer user_data;
-	guint8 *buffer;
-	guint16 size;
-	guint16 handle;
-	guint id;
-	gint ref;
+	void *user_data;
+	uint8_t *buffer;
+	uint16_t size;
+	uint16_t handle;
+	unsigned int id;
+	int ref;
 };
 
-static void read_long_destroy(gpointer user_data)
+static void read_long_destroy(void *user_data)
 {
 	struct read_long_data *long_read = user_data;
 
@@ -590,15 +591,15 @@ static void read_long_destroy(gpointer user_data)
 	g_free(long_read);
 }
 
-static void read_blob_helper(guint8 status, const guint8 *rpdu, guint16 rlen,
-							gpointer user_data)
+static void read_blob_helper(uint8_t status, const uint8_t *rpdu, uint16_t rlen,
+								void *user_data)
 {
 	struct read_long_data *long_read = user_data;
 	uint8_t *buf;
 	size_t buflen;
-	guint8 *tmp;
-	guint16 plen;
-	guint id;
+	uint8_t *tmp;
+	uint16_t plen;
+	unsigned int id;
 
 	if (status != 0 || rlen == 1) {
 		status = 0;
@@ -637,14 +638,14 @@ done:
 							long_read->user_data);
 }
 
-static void read_char_helper(guint8 status, const guint8 *rpdu,
-					guint16 rlen, gpointer user_data)
+static void read_char_helper(uint8_t status, const uint8_t *rpdu, uint16_t rlen,
+								void *user_data)
 {
 	struct read_long_data *long_read = user_data;
 	size_t buflen;
 	uint8_t *buf = g_attrib_get_buffer(long_read->attrib, &buflen);
-	guint16 plen;
-	guint id;
+	uint16_t plen;
+	unsigned int id;
 
 	if (status != 0 || rlen < buflen)
 		goto done;
@@ -672,13 +673,13 @@ done:
 	long_read->func(status, rpdu, rlen, long_read->user_data);
 }
 
-guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
-							gpointer user_data)
+unsigned int gatt_read_char(GAttrib *attrib, uint16_t handle,
+					GAttribResultFunc func, void *user_data)
 {
 	uint8_t *buf;
 	size_t buflen;
-	guint16 plen;
-	guint id;
+	uint16_t plen;
+	unsigned int id;
 	struct read_long_data *long_read;
 
 	long_read = g_try_new0(struct read_long_data, 1);
@@ -708,19 +709,19 @@ guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
 struct write_long_data {
 	GAttrib *attrib;
 	GAttribResultFunc func;
-	gpointer user_data;
-	guint16 handle;
+	void *user_data;
+	uint16_t handle;
 	uint16_t offset;
 	uint8_t *value;
 	size_t vlen;
 };
 
-static guint execute_write(GAttrib *attrib, uint8_t flags,
-				GAttribResultFunc func, gpointer user_data)
+static unsigned int execute_write(GAttrib *attrib, uint8_t flags,
+					GAttribResultFunc func, void *user_data)
 {
 	uint8_t *buf;
 	size_t buflen;
-	guint16 plen;
+	uint16_t plen;
 
 	buf = g_attrib_get_buffer(attrib, &buflen);
 	plen = enc_exec_write_req(flags, buf, buflen);
@@ -730,12 +731,13 @@ static guint execute_write(GAttrib *attrib, uint8_t flags,
 	return g_attrib_send(attrib, 0, buf, plen, func, user_data, NULL);
 }
 
-static guint prepare_write(GAttrib *attrib, uint16_t handle, uint16_t offset,
-			uint8_t *value, size_t vlen, GAttribResultFunc func,
-			gpointer user_data);
+static unsigned int prepare_write(GAttrib *attrib, uint16_t handle,
+					uint16_t offset, uint8_t *value,
+					size_t vlen, GAttribResultFunc func,
+					void *user_data);
 
-static void prepare_write_cb(guint8 status, const guint8 *rpdu,
-					guint16 rlen, gpointer user_data)
+static void prepare_write_cb(uint8_t status, const uint8_t *rpdu,
+					uint16_t rlen, void *user_data)
 {
 	struct write_long_data *long_write = user_data;
 
@@ -761,11 +763,12 @@ static void prepare_write_cb(guint8 status, const guint8 *rpdu,
 		long_write->func, long_write);
 }
 
-static guint prepare_write(GAttrib *attrib, uint16_t handle, uint16_t offset,
-			uint8_t *value, size_t vlen, GAttribResultFunc func,
-			gpointer user_data)
+static unsigned int prepare_write(GAttrib *attrib, uint16_t handle,
+					uint16_t offset, uint8_t *value,
+					size_t vlen, GAttribResultFunc func,
+					void *user_data)
 {
-	guint16 plen;
+	uint16_t plen;
 	size_t buflen;
 	uint8_t *buf;
 
@@ -780,12 +783,13 @@ static guint prepare_write(GAttrib *attrib, uint16_t handle, uint16_t offset,
 							user_data, NULL);
 }
 
-guint gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value,
-			size_t vlen, GAttribResultFunc func, gpointer user_data)
+unsigned int gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value,
+					size_t vlen, GAttribResultFunc func,
+					void *user_data)
 {
 	uint8_t *buf;
 	size_t buflen;
-	guint16 plen;
+	uint16_t plen;
 	struct write_long_data *long_write;
 
 	buf = g_attrib_get_buffer(attrib, &buflen);
@@ -820,24 +824,24 @@ guint gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value,
 							func, long_write);
 }
 
-guint gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu, GAttribResultFunc func,
-							gpointer user_data)
+unsigned int gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu,
+					GAttribResultFunc func, void *user_data)
 {
 	uint8_t *buf;
 	size_t buflen;
-	guint16 plen;
+	uint16_t plen;
 
 	buf = g_attrib_get_buffer(attrib, &buflen);
 	plen = enc_mtu_req(mtu, buf, buflen);
 	return g_attrib_send(attrib, 0, buf, plen, func, user_data, NULL);
 }
 
-guint gatt_find_info(GAttrib *attrib, uint16_t start, uint16_t end,
-				GAttribResultFunc func, gpointer user_data)
+unsigned int gatt_find_info(GAttrib *attrib, uint16_t start, uint16_t end,
+					GAttribResultFunc func, void *user_data)
 {
 	uint8_t *buf;
 	size_t buflen;
-	guint16 plen;
+	uint16_t plen;
 
 	buf = g_attrib_get_buffer(attrib, &buflen);
 	plen = enc_find_info_req(start, end, buf, buflen);
@@ -847,12 +851,13 @@ guint gatt_find_info(GAttrib *attrib, uint16_t start, uint16_t end,
 	return g_attrib_send(attrib, 0, buf, plen, func, user_data, NULL);
 }
 
-guint gatt_write_cmd(GAttrib *attrib, uint16_t handle, uint8_t *value, int vlen,
-				GDestroyNotify notify, gpointer user_data)
+unsigned int gatt_write_cmd(GAttrib *attrib, uint16_t handle, uint8_t *value,
+						int vlen, GDestroyNotify notify,
+						void *user_data)
 {
 	uint8_t *buf;
 	size_t buflen;
-	guint16 plen;
+	uint16_t plen;
 
 	buf = g_attrib_get_buffer(attrib, &buflen);
 	plen = enc_write_cmd(handle, value, vlen, buf, buflen);
diff --git a/attrib/gatt.h b/attrib/gatt.h
index 305b4c6..be38400 100644
--- a/attrib/gatt.h
+++ b/attrib/gatt.h
@@ -53,7 +53,7 @@
 #define GATT_CLIENT_CHARAC_CFG_NOTIF_BIT	0x0001
 #define GATT_CLIENT_CHARAC_CFG_IND_BIT		0x0002
 
-typedef void (*gatt_cb_t) (GSList *l, guint8 status, gpointer user_data);
+typedef void (*gatt_cb_t) (GSList *l, uint8_t status, void *user_data);
 
 struct gatt_primary {
 	char uuid[MAX_LEN_UUID_STR + 1];
@@ -74,35 +74,36 @@ struct gatt_char {
 	uint16_t value_handle;
 };
 
-guint gatt_discover_primary(GAttrib *attrib, bt_uuid_t *uuid, gatt_cb_t func,
-							gpointer user_data);
+unsigned int gatt_discover_primary(GAttrib *attrib, bt_uuid_t *uuid,
+					gatt_cb_t func, void *user_data);
 
 unsigned int gatt_find_included(GAttrib *attrib, uint16_t start, uint16_t end,
-					gatt_cb_t func, gpointer user_data);
+					gatt_cb_t func, void *user_data);
 
-guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end,
-					bt_uuid_t *uuid, gatt_cb_t func,
-					gpointer user_data);
+unsigned int gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end,
+						bt_uuid_t *uuid, gatt_cb_t func,
+						void *user_data);
 
-guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
-							gpointer user_data);
+unsigned int gatt_read_char(GAttrib *attrib, uint16_t handle,
+				GAttribResultFunc func, void *user_data);
 
-guint gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value,
+unsigned int gatt_write_char(GAttrib *attrib, uint16_t handle, uint8_t *value,
 					size_t vlen, GAttribResultFunc func,
-					gpointer user_data);
+					void *user_data);
 
-guint gatt_find_info(GAttrib *attrib, uint16_t start, uint16_t end,
-				GAttribResultFunc func, gpointer user_data);
+unsigned int gatt_find_info(GAttrib *attrib, uint16_t start, uint16_t end,
+				GAttribResultFunc func, void *user_data);
 
-guint gatt_write_cmd(GAttrib *attrib, uint16_t handle, uint8_t *value, int vlen,
-				GDestroyNotify notify, gpointer user_data);
+unsigned int gatt_write_cmd(GAttrib *attrib, uint16_t handle, uint8_t *value,
+						int vlen, GDestroyNotify notify,
+						void *user_data);
 
-guint gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start, uint16_t end,
-				bt_uuid_t *uuid, GAttribResultFunc func,
-				gpointer user_data);
+unsigned int gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start,
+				uint16_t end, bt_uuid_t *uuid,
+				GAttribResultFunc func, void *user_data);
 
-guint gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu, GAttribResultFunc func,
-							gpointer user_data);
+unsigned int gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu,
+				GAttribResultFunc func, void *user_data);
 
 gboolean gatt_parse_record(const sdp_record_t *rec,
 					uuid_t *prim_uuid, uint16_t *psm,
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH BlueZ 3/6] attrib: remove glib basic data types usage
  2013-03-04 20:58 [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Jefferson Delfes
  2013-03-04 20:58 ` [PATCH BlueZ 1/6] gattrib: remove " Jefferson Delfes
  2013-03-04 20:58 ` [PATCH BlueZ 2/6] GATT: " Jefferson Delfes
@ 2013-03-04 20:58 ` Jefferson Delfes
  2013-03-04 20:58 ` [PATCH BlueZ 4/6] gatttool: " Jefferson Delfes
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Jefferson Delfes @ 2013-03-04 20:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

---
 attrib/att-database.h | 6 +++---
 attrib/gatt-service.c | 6 +++---
 attrib/utils.c        | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/attrib/att-database.h b/attrib/att-database.h
index 48c50e3..39c1bd8 100644
--- a/attrib/att-database.h
+++ b/attrib/att-database.h
@@ -34,10 +34,10 @@ struct attribute {
 	int read_req;		/* Read requirement */
 	int write_req;		/* Write requirement */
 	uint8_t (*read_cb)(struct attribute *a, struct btd_device *device,
-							gpointer user_data);
+							void *user_data);
 	uint8_t (*write_cb)(struct attribute *a, struct btd_device *device,
-							gpointer user_data);
-	gpointer cb_user_data;
+							void *user_data);
+	void *cb_user_data;
 	size_t len;
 	uint8_t *data;
 };
diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c
index bdb12cd..6f5de22 100644
--- a/attrib/gatt-service.c
+++ b/attrib/gatt-service.c
@@ -168,7 +168,7 @@ static int att_write_req(int authorization, int authentication, uint8_t props)
 	return ATT_NONE;
 }
 
-static gint find_callback(gconstpointer a, gconstpointer b)
+static int find_callback(const void *a, const void *b)
 {
 	const struct attrib_cb *cb = a;
 	unsigned int event = GPOINTER_TO_UINT(b);
@@ -199,7 +199,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
 	/* TODO: static characteristic values are not supported, therefore a
 	 * callback must be always provided if a read/write property is set */
 	if (read_req != ATT_NOT_PERMITTED) {
-		gpointer reqs = GUINT_TO_POINTER(ATTRIB_READ);
+		void *reqs = GUINT_TO_POINTER(ATTRIB_READ);
 
 		if (!g_slist_find_custom(info->callbacks, reqs,
 							find_callback)) {
@@ -209,7 +209,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
 	}
 
 	if (write_req != ATT_NOT_PERMITTED) {
-		gpointer reqs = GUINT_TO_POINTER(ATTRIB_WRITE);
+		void *reqs = GUINT_TO_POINTER(ATTRIB_WRITE);
 
 		if (!g_slist_find_custom(info->callbacks, reqs,
 							find_callback)) {
diff --git a/attrib/utils.c b/attrib/utils.c
index f9813d1..e410a35 100644
--- a/attrib/utils.c
+++ b/attrib/utils.c
@@ -40,9 +40,9 @@
 #include "gatt.h"
 #include "gatttool.h"
 
-GIOChannel *gatt_connect(const gchar *src, const gchar *dst,
-				const gchar *dst_type, const gchar *sec_level,
-				int psm, int mtu, BtIOConnect connect_cb)
+GIOChannel *gatt_connect(const char *src, const char *dst, const char *dst_type,
+						const char *sec_level, int psm,
+						int mtu, BtIOConnect connect_cb)
 {
 	GIOChannel *chan;
 	bdaddr_t sba, dba;
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH BlueZ 4/6] gatttool: remove glib basic data types usage
  2013-03-04 20:58 [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Jefferson Delfes
                   ` (2 preceding siblings ...)
  2013-03-04 20:58 ` [PATCH BlueZ 3/6] attrib: " Jefferson Delfes
@ 2013-03-04 20:58 ` Jefferson Delfes
  2013-03-04 20:58 ` [PATCH BlueZ 5/6] attrib: simplify boolean tests Jefferson Delfes
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Jefferson Delfes @ 2013-03-04 20:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

---
 attrib/gatttool.c    | 61 ++++++++++++++++++++++++++--------------------------
 attrib/gatttool.h    |  8 +++----
 attrib/interactive.c | 54 ++++++++++++++++++++++------------------------
 3 files changed, 60 insertions(+), 63 deletions(-)

diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 29e3261..62a7c11 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -42,11 +42,11 @@
 #include "gatt.h"
 #include "gatttool.h"
 
-static gchar *opt_src = NULL;
-static gchar *opt_dst = NULL;
-static gchar *opt_dst_type = NULL;
-static gchar *opt_value = NULL;
-static gchar *opt_sec_level = NULL;
+static char *opt_src = NULL;
+static char *opt_dst = NULL;
+static char *opt_dst_type = NULL;
+static char *opt_value = NULL;
+static char *opt_sec_level = NULL;
 static bt_uuid_t *opt_uuid = NULL;
 static int opt_start = 0x0001;
 static int opt_end = 0xffff;
@@ -71,7 +71,7 @@ struct characteristic_data {
 	uint16_t end;
 };
 
-static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
+static void events_handler(const uint8_t *pdu, uint16_t len, void *user_data)
 {
 	GAttrib *attrib = user_data;
 	uint8_t *opdu;
@@ -107,7 +107,7 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
 		g_attrib_send(attrib, 0, opdu, olen, NULL, NULL, NULL);
 }
 
-static gboolean listen_start(gpointer user_data)
+static gboolean listen_start(void *user_data)
 {
 	GAttrib *attrib = user_data;
 
@@ -119,7 +119,7 @@ static gboolean listen_start(gpointer user_data)
 	return FALSE;
 }
 
-static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
+static void connect_cb(GIOChannel *io, GError *err, void *user_data)
 {
 	GAttrib *attrib;
 
@@ -137,7 +137,7 @@ static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
 	operation(attrib);
 }
 
-static void primary_all_cb(GSList *services, guint8 status, gpointer user_data)
+static void primary_all_cb(GSList *services, uint8_t status, void *user_data)
 {
 	GSList *l;
 
@@ -157,8 +157,7 @@ done:
 	g_main_loop_quit(event_loop);
 }
 
-static void primary_by_uuid_cb(GSList *ranges, guint8 status,
-							gpointer user_data)
+static void primary_by_uuid_cb(GSList *ranges, uint8_t status, void *user_data)
 {
 	GSList *l;
 
@@ -178,7 +177,7 @@ done:
 	g_main_loop_quit(event_loop);
 }
 
-static gboolean primary(gpointer user_data)
+static gboolean primary(void *user_data)
 {
 	GAttrib *attrib = user_data;
 
@@ -191,8 +190,8 @@ static gboolean primary(gpointer user_data)
 	return FALSE;
 }
 
-static void char_discovered_cb(GSList *characteristics, guint8 status,
-							gpointer user_data)
+static void char_discovered_cb(GSList *characteristics, uint8_t status,
+								void *user_data)
 {
 	GSList *l;
 
@@ -214,7 +213,7 @@ done:
 	g_main_loop_quit(event_loop);
 }
 
-static gboolean characteristics(gpointer user_data)
+static gboolean characteristics(void *user_data)
 {
 	GAttrib *attrib = user_data;
 
@@ -224,8 +223,8 @@ static gboolean characteristics(gpointer user_data)
 	return FALSE;
 }
 
-static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
-							gpointer user_data)
+static void char_read_cb(uint8_t status, const uint8_t *pdu, uint16_t plen,
+								void *user_data)
 {
 	uint8_t value[plen];
 	ssize_t vlen;
@@ -252,8 +251,8 @@ done:
 		g_main_loop_quit(event_loop);
 }
 
-static void char_read_by_uuid_cb(guint8 status, const guint8 *pdu,
-					guint16 plen, gpointer user_data)
+static void char_read_by_uuid_cb(uint8_t status, const uint8_t *pdu,
+						uint16_t plen, void *user_data)
 {
 	struct characteristic_data *char_data = user_data;
 	struct att_data_list *list;
@@ -293,7 +292,7 @@ done:
 	g_main_loop_quit(event_loop);
 }
 
-static gboolean characteristics_read(gpointer user_data)
+static gboolean characteristics_read(void *user_data)
 {
 	GAttrib *attrib = user_data;
 
@@ -322,7 +321,7 @@ static gboolean characteristics_read(gpointer user_data)
 	return FALSE;
 }
 
-static void mainloop_quit(gpointer user_data)
+static void mainloop_quit(void *user_data)
 {
 	uint8_t *value = user_data;
 
@@ -330,7 +329,7 @@ static void mainloop_quit(gpointer user_data)
 	g_main_loop_quit(event_loop);
 }
 
-static gboolean characteristics_write(gpointer user_data)
+static gboolean characteristics_write(void *user_data)
 {
 	GAttrib *attrib = user_data;
 	uint8_t *value;
@@ -361,8 +360,8 @@ error:
 	return FALSE;
 }
 
-static void char_write_req_cb(guint8 status, const guint8 *pdu, guint16 plen,
-							gpointer user_data)
+static void char_write_req_cb(uint8_t status, const uint8_t *pdu, uint16_t plen,
+								void *user_data)
 {
 	if (status != 0) {
 		g_printerr("Characteristic Write Request failed: "
@@ -382,7 +381,7 @@ done:
 		g_main_loop_quit(event_loop);
 }
 
-static gboolean characteristics_write_req(gpointer user_data)
+static gboolean characteristics_write_req(void *user_data)
 {
 	GAttrib *attrib = user_data;
 	uint8_t *value;
@@ -414,11 +413,11 @@ error:
 	return FALSE;
 }
 
-static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
-							gpointer user_data)
+static void char_desc_cb(uint8_t status, const uint8_t *pdu, uint16_t plen,
+								void *user_data)
 {
 	struct att_data_list *list;
-	guint8 format;
+	uint8_t format;
 	int i;
 
 	if (status != 0) {
@@ -456,7 +455,7 @@ done:
 		g_main_loop_quit(event_loop);
 }
 
-static gboolean characteristics_desc(gpointer user_data)
+static gboolean characteristics_desc(void *user_data)
 {
 	GAttrib *attrib = user_data;
 
@@ -466,7 +465,7 @@ static gboolean characteristics_desc(gpointer user_data)
 }
 
 static gboolean parse_uuid(const char *key, const char *value,
-				gpointer user_data, GError **error)
+						void *user_data, GError **error)
 {
 	if (!value)
 		return FALSE;
@@ -596,7 +595,7 @@ int main(int argc, char *argv[])
 	else if (opt_char_desc)
 		operation = characteristics_desc;
 	else {
-		gchar *help = g_option_context_get_help(context, TRUE, NULL);
+		char *help = g_option_context_get_help(context, TRUE, NULL);
 		g_print("%s\n", help);
 		g_free(help);
 		got_error = TRUE;
diff --git a/attrib/gatttool.h b/attrib/gatttool.h
index 260480d..6aa1611 100644
--- a/attrib/gatttool.h
+++ b/attrib/gatttool.h
@@ -21,9 +21,9 @@
  *
  */
 
-int interactive(const gchar *src, const gchar *dst, const gchar *dst_type,
+int interactive(const char *src, const char *dst, const char *dst_type,
 								int psm);
-GIOChannel *gatt_connect(const gchar *src, const gchar *dst,
-			const gchar *dst_type, const gchar *sec_level,
-			int psm, int mtu, BtIOConnect connect_cb);
+GIOChannel *gatt_connect(const char *src, const char *dst, const char *dst_type,
+					const char *sec_level, int psm,
+					int mtu, BtIOConnect connect_cb);
 size_t gatt_attr_data_from_string(const char *str, uint8_t **data);
diff --git a/attrib/interactive.c b/attrib/interactive.c
index a99ad0a..1dccfe5 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -46,10 +46,10 @@ static GAttrib *attrib = NULL;
 static GMainLoop *event_loop;
 static GString *prompt;
 
-static gchar *opt_src = NULL;
-static gchar *opt_dst = NULL;
-static gchar *opt_dst_type = NULL;
-static gchar *opt_sec_level = NULL;
+static char *opt_src = NULL;
+static char *opt_dst = NULL;
+static char *opt_dst_type = NULL;
+static char *opt_sec_level = NULL;
 static int opt_psm = 0;
 static int opt_mtu = 0;
 static int start;
@@ -105,7 +105,7 @@ static void set_state(enum state st)
 	rl_redisplay();
 }
 
-static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
+static void events_handler(const uint8_t *pdu, uint16_t len, void *user_data)
 {
 	uint8_t *opdu;
 	uint16_t handle, i, olen;
@@ -142,7 +142,7 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
 		g_attrib_send(attrib, 0, opdu, olen, NULL, NULL, NULL);
 }
 
-static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
+static void connect_cb(GIOChannel *io, GError *err, void *user_data)
 {
 	if (err) {
 		printf("connect error: %s\n", err->message);
@@ -174,7 +174,7 @@ static void disconnect_io()
 	set_state(STATE_DISCONNECTED);
 }
 
-static void primary_all_cb(GSList *services, guint8 status, gpointer user_data)
+static void primary_all_cb(GSList *services, uint8_t status, void *user_data)
 {
 	GSList *l;
 
@@ -194,8 +194,7 @@ static void primary_all_cb(GSList *services, guint8 status, gpointer user_data)
 	rl_forced_update_display();
 }
 
-static void primary_by_uuid_cb(GSList *ranges, guint8 status,
-							gpointer user_data)
+static void primary_by_uuid_cb(GSList *ranges, uint8_t status, void *user_data)
 {
 	GSList *l;
 
@@ -215,7 +214,7 @@ static void primary_by_uuid_cb(GSList *ranges, guint8 status,
 	rl_forced_update_display();
 }
 
-static void included_cb(GSList *includes, guint8 status, gpointer user_data)
+static void included_cb(GSList *includes, uint8_t status, void *user_data)
 {
 	GSList *l;
 
@@ -243,7 +242,7 @@ done:
 	rl_forced_update_display();
 }
 
-static void char_cb(GSList *characteristics, guint8 status, gpointer user_data)
+static void char_cb(GSList *characteristics, uint8_t status, void *user_data)
 {
 	GSList *l;
 
@@ -266,11 +265,11 @@ static void char_cb(GSList *characteristics, guint8 status, gpointer user_data)
 	rl_forced_update_display();
 }
 
-static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
-							gpointer user_data)
+static void char_desc_cb(uint8_t status, const uint8_t *pdu, uint16_t plen,
+								void *user_data)
 {
 	struct att_data_list *list;
-	guint8 format;
+	uint8_t format;
 	uint16_t handle = 0xffff;
 	int i;
 
@@ -310,8 +309,8 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
 		rl_forced_update_display();
 }
 
-static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
-							gpointer user_data)
+static void char_read_cb(uint8_t status, const uint8_t *pdu, uint16_t plen,
+							void *user_data)
 {
 	uint8_t value[plen];
 	ssize_t vlen;
@@ -337,8 +336,8 @@ static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
 	rl_forced_update_display();
 }
 
-static void char_read_by_uuid_cb(guint8 status, const guint8 *pdu,
-					guint16 plen, gpointer user_data)
+static void char_read_by_uuid_cb(uint8_t status, const uint8_t *pdu,
+						uint16_t plen, void *user_data)
 {
 	struct characteristic_data *char_data = user_data;
 	struct att_data_list *list;
@@ -386,7 +385,7 @@ static void cmd_exit(int argcp, char **argvp)
 }
 
 static gboolean channel_watcher(GIOChannel *chan, GIOCondition cond,
-				gpointer user_data)
+								void *user_data)
 {
 	disconnect_io();
 
@@ -633,8 +632,8 @@ static void cmd_read_uuid(int argcp, char **argvp)
 					char_read_by_uuid_cb, char_data);
 }
 
-static void char_write_req_cb(guint8 status, const guint8 *pdu, guint16 plen,
-							gpointer user_data)
+static void char_write_req_cb(uint8_t status, const uint8_t *pdu, uint16_t plen,
+								void *user_data)
 {
 	if (status != 0) {
 		printf("Characteristic Write Request failed: "
@@ -728,8 +727,8 @@ static void cmd_sec_level(int argcp, char **argvp)
 	}
 }
 
-static void exchange_mtu_cb(guint8 status, const guint8 *pdu, guint16 plen,
-							gpointer user_data)
+static void exchange_mtu_cb(uint8_t status, const uint8_t *pdu, uint16_t plen,
+								void *user_data)
 {
 	uint16_t mtu;
 
@@ -837,7 +836,7 @@ static void cmd_help(int argcp, char **argvp)
 
 static void parse_line(char *line_read)
 {
-	gchar **argvp;
+	char **argvp;
 	int argcp;
 	int i;
 
@@ -869,7 +868,7 @@ static void parse_line(char *line_read)
 }
 
 static gboolean prompt_read(GIOChannel *chan, GIOCondition cond,
-							gpointer user_data)
+								void *user_data)
 {
 	if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
 		g_io_channel_unref(chan);
@@ -908,11 +907,10 @@ static char **commands_completion(const char *text, int start, int end)
 		return NULL;
 }
 
-int interactive(const gchar *src, const gchar *dst,
-		const gchar *dst_type, int psm)
+int interactive(const char *src, const char *dst, const char *dst_type, int psm)
 {
 	GIOChannel *pchan;
-	gint events;
+	int events;
 
 	opt_sec_level = g_strdup("low");
 
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH BlueZ 5/6] attrib: simplify boolean tests
  2013-03-04 20:58 [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Jefferson Delfes
                   ` (3 preceding siblings ...)
  2013-03-04 20:58 ` [PATCH BlueZ 4/6] gatttool: " Jefferson Delfes
@ 2013-03-04 20:58 ` Jefferson Delfes
  2013-03-04 20:58 ` [PATCH BlueZ 6/6] attrib: removing gboolean usage when possible Jefferson Delfes
  2013-03-25 12:29 ` [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Johan Hedberg
  6 siblings, 0 replies; 9+ messages in thread
From: Jefferson Delfes @ 2013-03-04 20:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

Remove unnecessary TRUE/FALSE in boolean tests.
---
 attrib/gatt.c     | 4 ++--
 attrib/gattrib.c  | 6 +++---
 attrib/gatttool.c | 8 ++++----
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 9a2d909..3f1a469 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -86,7 +86,7 @@ static struct included_discovery *isd_ref(struct included_discovery *isd)
 
 static void isd_unref(struct included_discovery *isd)
 {
-	if (g_atomic_int_dec_and_test(&isd->refs) == FALSE)
+	if (!g_atomic_int_dec_and_test(&isd->refs))
 		return;
 
 	if (isd->err)
@@ -582,7 +582,7 @@ static void read_long_destroy(void *user_data)
 {
 	struct read_long_data *long_read = user_data;
 
-	if (g_atomic_int_dec_and_test(&long_read->ref) == FALSE)
+	if (!g_atomic_int_dec_and_test(&long_read->ref))
 		return;
 
 	if (long_read->buffer != NULL)
diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 7cc489a..33df293 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -228,7 +228,7 @@ void g_attrib_unref(GAttrib *attrib)
 
 	DBG("%p: ref=%d", attrib, attrib->refs);
 
-	if (ret == FALSE)
+	if (!ret)
 		return;
 
 	attrib_destroy(attrib);
@@ -368,7 +368,7 @@ static gboolean match_event(struct event *evt, const uint8_t *pdu, size_t len)
 	if (evt->expected == GATTRIB_ALL_EVENTS)
 		return TRUE;
 
-	if (is_response(pdu[0]) == FALSE && evt->expected == GATTRIB_ALL_REQS)
+	if (!is_response(pdu[0]) && evt->expected == GATTRIB_ALL_REQS)
 		return TRUE;
 
 	if (evt->expected == pdu[0] && evt->handle == GATTRIB_ALL_HANDLES)
@@ -419,7 +419,7 @@ static gboolean received_data(GIOChannel *io, GIOCondition cond, void *data)
 			evt->func(buf, len, evt->user_data);
 	}
 
-	if (is_response(buf[0]) == FALSE)
+	if (!is_response(buf[0]))
 		return TRUE;
 
 	if (attrib->timeout_watch > 0) {
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 62a7c11..5f4388d 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -247,7 +247,7 @@ static void char_read_cb(uint8_t status, const uint8_t *pdu, uint16_t plen,
 	g_print("\n");
 
 done:
-	if (opt_listen == FALSE)
+	if (!opt_listen)
 		g_main_loop_quit(event_loop);
 }
 
@@ -377,7 +377,7 @@ static void char_write_req_cb(uint8_t status, const uint8_t *pdu, uint16_t plen,
 	g_print("Characteristic value was written successfully\n");
 
 done:
-	if (opt_listen == FALSE)
+	if (!opt_listen)
 		g_main_loop_quit(event_loop);
 }
 
@@ -451,7 +451,7 @@ static void char_desc_cb(uint8_t status, const uint8_t *pdu, uint16_t plen,
 	att_data_list_free(list);
 
 done:
-	if (opt_listen == FALSE)
+	if (!opt_listen)
 		g_main_loop_quit(event_loop);
 }
 
@@ -572,7 +572,7 @@ int main(int argc, char *argv[])
 	g_option_context_add_group(context, char_rw_group);
 	g_option_group_add_entries(char_rw_group, char_rw_options);
 
-	if (g_option_context_parse(context, &argc, &argv, &gerr) == FALSE) {
+	if (!g_option_context_parse(context, &argc, &argv, &gerr)) {
 		g_printerr("%s\n", gerr->message);
 		g_error_free(gerr);
 	}
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH BlueZ 6/6] attrib: removing gboolean usage when possible
  2013-03-04 20:58 [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Jefferson Delfes
                   ` (4 preceding siblings ...)
  2013-03-04 20:58 ` [PATCH BlueZ 5/6] attrib: simplify boolean tests Jefferson Delfes
@ 2013-03-04 20:58 ` Jefferson Delfes
  2013-03-25 12:29 ` [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Johan Hedberg
  6 siblings, 0 replies; 9+ messages in thread
From: Jefferson Delfes @ 2013-03-04 20:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jefferson Delfes

---
 attrib/gatt-service.c | 26 +++++++-------
 attrib/gatt-service.h |  2 +-
 attrib/gatt.c         | 20 +++++------
 attrib/gatt.h         |  7 ++--
 attrib/gattrib.c      | 96 +++++++++++++++++++++++++--------------------------
 attrib/gattrib.h      | 16 ++++-----
 attrib/gatttool.c     | 37 ++++++++++----------
 attrib/interactive.c  |  1 +
 attrib/utils.c        |  1 +
 9 files changed, 104 insertions(+), 102 deletions(-)

diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c
index 6f5de22..905d697 100644
--- a/attrib/gatt-service.c
+++ b/attrib/gatt-service.c
@@ -176,8 +176,8 @@ static int find_callback(const void *a, const void *b)
 	return cb->event - event;
 }
 
-static gboolean add_characteristic(struct btd_adapter *adapter,
-				uint16_t *handle, struct gatt_info *info)
+static bool add_characteristic(struct btd_adapter *adapter, uint16_t *handle,
+							struct gatt_info *info)
 {
 	int read_req, write_req;
 	uint16_t h = *handle;
@@ -188,7 +188,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
 
 	if (!info->uuid.value.u16 || !info->props) {
 		error("Characteristic UUID or properties are missing");
-		return FALSE;
+		return false;
 	}
 
 	read_req = att_read_req(info->authorization, info->authentication,
@@ -204,7 +204,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
 		if (!g_slist_find_custom(info->callbacks, reqs,
 							find_callback)) {
 			error("Callback for read required");
-			return FALSE;
+			return false;
 		}
 	}
 
@@ -214,7 +214,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
 		if (!g_slist_find_custom(info->callbacks, reqs,
 							find_callback)) {
 			error("Callback for write required");
-			return FALSE;
+			return false;
 		}
 	}
 
@@ -225,13 +225,13 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
 	att_put_u16(info->uuid.value.u16, &atval[3]);
 	if (attrib_db_add(adapter, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED,
 						atval, sizeof(atval)) == NULL)
-		return FALSE;
+		return false;
 
 	/* characteristic value */
 	a = attrib_db_add(adapter, h++, &info->uuid, read_req, write_req,
 								NULL, 0);
 	if (a == NULL)
-		return FALSE;
+		return false;
 
 	for (l = info->callbacks; l != NULL; l = l->next) {
 		struct attrib_cb *cb = l->data;
@@ -261,7 +261,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
 		a = attrib_db_add(adapter, h++, &bt_uuid, ATT_NONE,
 				ATT_AUTHENTICATION, cfg_val, sizeof(cfg_val));
 		if (a == NULL)
-			return FALSE;
+			return false;
 
 		if (info->ccc_handle != NULL)
 			*info->ccc_handle = a->handle;
@@ -269,7 +269,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
 
 	*handle = h;
 
-	return TRUE;
+	return true;
 }
 
 static void free_gatt_info(void *data)
@@ -290,7 +290,7 @@ static void service_attr_del(struct btd_adapter *adapter, uint16_t start_handle,
 			error("Can't delete handle 0x%04x", handle);
 }
 
-gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
+bool gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
 				bt_uuid_t *svc_uuid, gatt_option opt1, ...)
 {
 	char uuidstr[MAX_LEN_UUID_STR];
@@ -303,7 +303,7 @@ gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
 
 	if (svc_uuid->type != BT_UUID16 && svc_uuid->type != BT_UUID128) {
 		error("Invalid service uuid: %s", uuidstr);
-		return FALSE;
+		return false;
 	}
 
 	va_start(args, opt1);
@@ -344,9 +344,9 @@ gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
 	g_assert(h - start_handle == (uint16_t) size);
 	g_slist_free_full(chrs, free_gatt_info);
 
-	return TRUE;
+	return true;
 
 fail:
 	g_slist_free_full(chrs, free_gatt_info);
-	return FALSE;
+	return false;
 }
diff --git a/attrib/gatt-service.h b/attrib/gatt-service.h
index b810e2e..ad3469d 100644
--- a/attrib/gatt-service.h
+++ b/attrib/gatt-service.h
@@ -47,5 +47,5 @@ typedef enum {
 	ATTRIB_WRITE,
 } attrib_event_t;
 
-gboolean gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
+bool gatt_service_add(struct btd_adapter *adapter, uint16_t uuid,
 					bt_uuid_t *svc_uuid, gatt_option opt1, ...);
diff --git a/attrib/gatt.c b/attrib/gatt.c
index 3f1a469..8b05c43 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -28,6 +28,7 @@
 
 #include <stdint.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <glib.h>
 #include <bluetooth/sdp.h>
 #include <bluetooth/sdp_lib.h>
@@ -884,7 +885,7 @@ static sdp_data_t *proto_seq_find(sdp_list_t *proto_list)
 	return NULL;
 }
 
-static gboolean parse_proto_params(sdp_list_t *proto_list, uint16_t *psm,
+static bool parse_proto_params(sdp_list_t *proto_list, uint16_t *psm,
 						uint16_t *start, uint16_t *end)
 {
 	sdp_data_t *seq1, *seq2;
@@ -895,11 +896,11 @@ static gboolean parse_proto_params(sdp_list_t *proto_list, uint16_t *psm,
 	/* Getting start and end handle */
 	seq1 = proto_seq_find(proto_list);
 	if (!seq1 || seq1->dtd != SDP_UINT16)
-		return FALSE;
+		return false;
 
 	seq2 = seq1->next;
 	if (!seq2 || seq2->dtd != SDP_UINT16)
-		return FALSE;
+		return false;
 
 	if (start)
 		*start = seq1->val.uint16;
@@ -907,25 +908,24 @@ static gboolean parse_proto_params(sdp_list_t *proto_list, uint16_t *psm,
 	if (end)
 		*end = seq2->val.uint16;
 
-	return TRUE;
+	return true;
 }
 
-gboolean gatt_parse_record(const sdp_record_t *rec,
-					uuid_t *prim_uuid, uint16_t *psm,
-					uint16_t *start, uint16_t *end)
+bool gatt_parse_record(const sdp_record_t *rec, uuid_t *prim_uuid,
+				uint16_t *psm, uint16_t *start, uint16_t *end)
 {
 	sdp_list_t *list;
 	uuid_t uuid;
-	gboolean ret;
+	bool ret;
 
 	if (sdp_get_service_classes(rec, &list) < 0)
-		return FALSE;
+		return false;
 
 	memcpy(&uuid, list->data, sizeof(uuid));
 	sdp_list_free(list, free);
 
 	if (sdp_get_access_protos(rec, &list) < 0)
-		return FALSE;
+		return false;
 
 	ret = parse_proto_params(list, psm, start, end);
 
diff --git a/attrib/gatt.h b/attrib/gatt.h
index be38400..88a5cca 100644
--- a/attrib/gatt.h
+++ b/attrib/gatt.h
@@ -57,7 +57,7 @@ typedef void (*gatt_cb_t) (GSList *l, uint8_t status, void *user_data);
 
 struct gatt_primary {
 	char uuid[MAX_LEN_UUID_STR + 1];
-	gboolean changed;
+	bool changed;
 	struct att_range range;
 };
 
@@ -105,6 +105,5 @@ unsigned int gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start,
 unsigned int gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu,
 				GAttribResultFunc func, void *user_data);
 
-gboolean gatt_parse_record(const sdp_record_t *rec,
-					uuid_t *prim_uuid, uint16_t *psm,
-					uint16_t *start, uint16_t *end);
+bool gatt_parse_record(const sdp_record_t *rec, uuid_t *prim_uuid,
+				uint16_t *psm, uint16_t *start, uint16_t *end);
diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 33df293..8307bb8 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -31,6 +31,7 @@
 #include <glib.h>
 
 #include <stdio.h>
+#include <stdbool.h>
 
 #include <bluetooth/bluetooth.h>
 #include <btio/btio.h>
@@ -56,7 +57,7 @@ struct _GAttrib {
 	unsigned int next_cmd_id;
 	GDestroyNotify destroy;
 	void *destroy_user_data;
-	gboolean stale;
+	bool stale;
 };
 
 struct command {
@@ -65,7 +66,7 @@ struct command {
 	uint8_t *pdu;
 	uint16_t len;
 	uint8_t expected;
-	gboolean sent;
+	bool sent;
 	GAttribResultFunc func;
 	void *user_data;
 	GDestroyNotify notify;
@@ -123,7 +124,7 @@ static uint8_t opcode2expected(uint8_t opcode)
 	return 0;
 }
 
-static gboolean is_response(uint8_t opcode)
+static bool is_response(uint8_t opcode)
 {
 	switch (opcode) {
 	case ATT_OP_ERROR:
@@ -139,10 +140,10 @@ static gboolean is_response(uint8_t opcode)
 	case ATT_OP_PREP_WRITE_RESP:
 	case ATT_OP_EXEC_WRITE_RESP:
 	case ATT_OP_HANDLE_CNF:
-		return TRUE;
+		return true;
 	}
 
-	return FALSE;
+	return false;
 }
 
 GAttrib *g_attrib_ref(GAttrib *attrib)
@@ -219,7 +220,7 @@ static void attrib_destroy(GAttrib *attrib)
 
 void g_attrib_unref(GAttrib *attrib)
 {
-	gboolean ret;
+	bool ret;
 
 	if (!attrib)
 		return;
@@ -242,16 +243,16 @@ GIOChannel *g_attrib_get_channel(GAttrib *attrib)
 	return attrib->io;
 }
 
-gboolean g_attrib_set_destroy_function(GAttrib *attrib,
-					GDestroyNotify destroy, void *user_data)
+bool g_attrib_set_destroy_function(GAttrib *attrib, GDestroyNotify destroy,
+								void *user_data)
 {
 	if (attrib == NULL)
-		return FALSE;
+		return false;
 
 	attrib->destroy = destroy;
 	attrib->destroy_user_data = user_data;
 
-	return TRUE;
+	return true;
 }
 
 static gboolean disconnect_timeout(void *data)
@@ -277,7 +278,7 @@ static gboolean disconnect_timeout(void *data)
 	}
 
 done:
-	attrib->stale = TRUE;
+	attrib->stale = true;
 
 	g_attrib_unref(attrib);
 
@@ -333,7 +334,7 @@ static gboolean can_write_data(GIOChannel *io, GIOCondition cond, void *data)
 		return TRUE;
 	}
 
-	cmd->sent = TRUE;
+	cmd->sent = true;
 
 	if (attrib->timeout_watch == 0)
 		attrib->timeout_watch = g_timeout_add_seconds(GATT_TIMEOUT,
@@ -361,28 +362,28 @@ static void wake_up_sender(struct _GAttrib *attrib)
 				can_write_data, attrib, destroy_sender);
 }
 
-static gboolean match_event(struct event *evt, const uint8_t *pdu, size_t len)
+static bool match_event(struct event *evt, const uint8_t *pdu, size_t len)
 {
 	uint16_t handle;
 
 	if (evt->expected == GATTRIB_ALL_EVENTS)
-		return TRUE;
+		return true;
 
 	if (!is_response(pdu[0]) && evt->expected == GATTRIB_ALL_REQS)
-		return TRUE;
+		return true;
 
 	if (evt->expected == pdu[0] && evt->handle == GATTRIB_ALL_HANDLES)
-		return TRUE;
+		return true;
 
 	if (len < 3)
-		return FALSE;
+		return false;
 
 	handle = att_get_u16(&pdu[1]);
 
 	if (evt->expected == pdu[0] && evt->handle == handle)
-		return TRUE;
+		return true;
 
-	return FALSE;
+	return false;
 }
 
 static gboolean received_data(GIOChannel *io, GIOCondition cond, void *data)
@@ -393,7 +394,7 @@ static gboolean received_data(GIOChannel *io, GIOCondition cond, void *data)
 	uint8_t buf[512], status;
 	size_t len;
 	GIOStatus iostat;
-	gboolean norequests, noresponses;
+	bool norequests, noresponses;
 
 	if (attrib->stale)
 		return FALSE;
@@ -565,14 +566,14 @@ static int command_cmp_by_id(const void *a, const void *b)
 	return cmd->id - id;
 }
 
-gboolean g_attrib_cancel(GAttrib *attrib, unsigned int id)
+bool g_attrib_cancel(GAttrib *attrib, unsigned int id)
 {
 	GList *l = NULL;
 	struct command *cmd;
 	GQueue *queue;
 
 	if (attrib == NULL)
-		return FALSE;
+		return false;
 
 	queue = attrib->requests;
 	if (queue)
@@ -581,13 +582,13 @@ gboolean g_attrib_cancel(GAttrib *attrib, unsigned int id)
 	if (l == NULL) {
 		queue = attrib->responses;
 		if (!queue)
-			return FALSE;
+			return false;
 		l = g_queue_find_custom(queue, GUINT_TO_POINTER(id),
 					command_cmp_by_id);
 	}
 
 	if (l == NULL)
-		return FALSE;
+		return false;
 
 	cmd = l->data;
 
@@ -598,16 +599,16 @@ gboolean g_attrib_cancel(GAttrib *attrib, unsigned int id)
 		command_destroy(cmd);
 	}
 
-	return TRUE;
+	return true;
 }
 
-static gboolean cancel_all_per_queue(GQueue *queue)
+static bool cancel_all_per_queue(GQueue *queue)
 {
 	struct command *c, *head = NULL;
-	gboolean first = TRUE;
+	bool first = true;
 
 	if (queue == NULL)
-		return FALSE;
+		return false;
 
 	while ((c = g_queue_pop_head(queue))) {
 		if (first && c->sent) {
@@ -617,7 +618,7 @@ static gboolean cancel_all_per_queue(GQueue *queue)
 			continue;
 		}
 
-		first = FALSE;
+		first = false;
 		command_destroy(c);
 	}
 
@@ -626,15 +627,15 @@ static gboolean cancel_all_per_queue(GQueue *queue)
 		g_queue_push_head(queue, head);
 	}
 
-	return TRUE;
+	return true;
 }
 
-gboolean g_attrib_cancel_all(GAttrib *attrib)
+bool g_attrib_cancel_all(GAttrib *attrib)
 {
-	gboolean ret;
+	bool ret;
 
 	if (attrib == NULL)
-		return FALSE;
+		return false;
 
 	ret = cancel_all_per_queue(attrib->requests);
 	ret = cancel_all_per_queue(attrib->responses) && ret;
@@ -642,10 +643,9 @@ gboolean g_attrib_cancel_all(GAttrib *attrib)
 	return ret;
 }
 
-gboolean g_attrib_set_debug(GAttrib *attrib, GAttribDebugFunc func,
-								void *user_data)
+bool g_attrib_set_debug(GAttrib *attrib, GAttribDebugFunc func, void *user_data)
 {
-	return TRUE;
+	return true;
 }
 
 uint8_t *g_attrib_get_buffer(GAttrib *attrib, size_t *len)
@@ -658,16 +658,16 @@ uint8_t *g_attrib_get_buffer(GAttrib *attrib, size_t *len)
 	return attrib->buf;
 }
 
-gboolean g_attrib_set_mtu(GAttrib *attrib, int mtu)
+bool g_attrib_set_mtu(GAttrib *attrib, int mtu)
 {
 	if (mtu < ATT_DEFAULT_LE_MTU)
-		return FALSE;
+		return false;
 
 	attrib->buf = g_realloc(attrib->buf, mtu);
 
 	attrib->buflen = mtu;
 
-	return TRUE;
+	return true;
 }
 
 unsigned int g_attrib_register(GAttrib *attrib, uint8_t opcode, uint16_t handle,
@@ -701,32 +701,32 @@ static int event_cmp_by_id(const void *a, const void *b)
 	return evt->id - id;
 }
 
-gboolean g_attrib_is_encrypted(GAttrib *attrib)
+bool g_attrib_is_encrypted(GAttrib *attrib)
 {
 	BtIOSecLevel sec_level;
 
 	if (!bt_io_get(attrib->io, NULL,
 			BT_IO_OPT_SEC_LEVEL, &sec_level,
 			BT_IO_OPT_INVALID))
-		return FALSE;
+		return false;
 
 	return sec_level > BT_IO_SEC_LOW;
 }
 
-gboolean g_attrib_unregister(GAttrib *attrib, unsigned int id)
+bool g_attrib_unregister(GAttrib *attrib, unsigned int id)
 {
 	struct event *evt;
 	GSList *l;
 
 	if (id == 0) {
 		warn("%s: invalid id", __FUNCTION__);
-		return FALSE;
+		return false;
 	}
 
 	l = g_slist_find_custom(attrib->events, GUINT_TO_POINTER(id),
 							event_cmp_by_id);
 	if (l == NULL)
-		return FALSE;
+		return false;
 
 	evt = l->data;
 
@@ -737,15 +737,15 @@ gboolean g_attrib_unregister(GAttrib *attrib, unsigned int id)
 
 	g_free(evt);
 
-	return TRUE;
+	return true;
 }
 
-gboolean g_attrib_unregister_all(GAttrib *attrib)
+bool g_attrib_unregister_all(GAttrib *attrib)
 {
 	GSList *l;
 
 	if (attrib->events == NULL)
-		return FALSE;
+		return false;
 
 	for (l = attrib->events; l; l = l->next) {
 		struct event *evt = l->data;
@@ -759,5 +759,5 @@ gboolean g_attrib_unregister_all(GAttrib *attrib)
 	g_slist_free(attrib->events);
 	attrib->events = NULL;
 
-	return TRUE;
+	return true;
 }
diff --git a/attrib/gattrib.h b/attrib/gattrib.h
index f0dcdd4..72f4a50 100644
--- a/attrib/gattrib.h
+++ b/attrib/gattrib.h
@@ -48,30 +48,30 @@ void g_attrib_unref(GAttrib *attrib);
 
 GIOChannel *g_attrib_get_channel(GAttrib *attrib);
 
-gboolean g_attrib_set_destroy_function(GAttrib *attrib, GDestroyNotify destroy,
+bool g_attrib_set_destroy_function(GAttrib *attrib, GDestroyNotify destroy,
 							void *user_data);
 
 unsigned int g_attrib_send(GAttrib *attrib, unsigned int id, const uint8_t *pdu,
 					uint16_t len, GAttribResultFunc func,
 					void *user_data, GDestroyNotify notify);
 
-gboolean g_attrib_cancel(GAttrib *attrib, unsigned int id);
-gboolean g_attrib_cancel_all(GAttrib *attrib);
+bool g_attrib_cancel(GAttrib *attrib, unsigned int id);
+bool g_attrib_cancel_all(GAttrib *attrib);
 
-gboolean g_attrib_set_debug(GAttrib *attrib, GAttribDebugFunc func,
+bool g_attrib_set_debug(GAttrib *attrib, GAttribDebugFunc func,
 							void *user_data);
 
 unsigned int g_attrib_register(GAttrib *attrib, uint8_t opcode, uint16_t handle,
 					GAttribNotifyFunc func, void *user_data,
 					GDestroyNotify notify);
 
-gboolean g_attrib_is_encrypted(GAttrib *attrib);
+bool g_attrib_is_encrypted(GAttrib *attrib);
 
 uint8_t *g_attrib_get_buffer(GAttrib *attrib, size_t *len);
-gboolean g_attrib_set_mtu(GAttrib *attrib, int mtu);
+bool g_attrib_set_mtu(GAttrib *attrib, int mtu);
 
-gboolean g_attrib_unregister(GAttrib *attrib, unsigned int id);
-gboolean g_attrib_unregister_all(GAttrib *attrib);
+bool g_attrib_unregister(GAttrib *attrib, unsigned int id);
+bool g_attrib_unregister_all(GAttrib *attrib);
 
 #ifdef __cplusplus
 }
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 5f4388d..fc72b38 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -29,6 +29,7 @@
 #include <errno.h>
 #include <glib.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <unistd.h>
 
 #include <bluetooth/bluetooth.h>
@@ -53,16 +54,16 @@ static int opt_end = 0xffff;
 static int opt_handle = -1;
 static int opt_mtu = 0;
 static int opt_psm = 0;
-static gboolean opt_primary = FALSE;
-static gboolean opt_characteristics = FALSE;
-static gboolean opt_char_read = FALSE;
-static gboolean opt_listen = FALSE;
-static gboolean opt_char_desc = FALSE;
-static gboolean opt_char_write = FALSE;
-static gboolean opt_char_write_req = FALSE;
-static gboolean opt_interactive = FALSE;
+static bool opt_primary = false;
+static bool opt_characteristics = false;
+static bool opt_char_read = false;
+static bool opt_listen = false;
+static bool opt_char_desc = false;
+static bool opt_char_write = false;
+static bool opt_char_write_req = false;
+static bool opt_interactive = false;
 static GMainLoop *event_loop;
-static gboolean got_error = FALSE;
+static bool got_error = false;
 static GSourceFunc operation;
 
 struct characteristic_data {
@@ -125,7 +126,7 @@ static void connect_cb(GIOChannel *io, GError *err, void *user_data)
 
 	if (err) {
 		g_printerr("%s\n", err->message);
-		got_error = TRUE;
+		got_error = true;
 		g_main_loop_quit(event_loop);
 	}
 
@@ -464,20 +465,20 @@ static gboolean characteristics_desc(void *user_data)
 	return FALSE;
 }
 
-static gboolean parse_uuid(const char *key, const char *value,
-						void *user_data, GError **error)
+static bool parse_uuid(const char *key, const char *value, void *user_data,
+								GError **error)
 {
 	if (!value)
-		return FALSE;
+		return false;
 
 	opt_uuid = g_try_malloc(sizeof(bt_uuid_t));
 	if (opt_uuid == NULL)
-		return FALSE;
+		return false;
 
 	if (bt_string_to_uuid(opt_uuid, value) < 0)
-		return FALSE;
+		return false;
 
-	return TRUE;
+	return true;
 }
 
 static GOptionEntry primary_char_options[] = {
@@ -598,14 +599,14 @@ int main(int argc, char *argv[])
 		char *help = g_option_context_get_help(context, TRUE, NULL);
 		g_print("%s\n", help);
 		g_free(help);
-		got_error = TRUE;
+		got_error = true;
 		goto done;
 	}
 
 	chan = gatt_connect(opt_src, opt_dst, opt_dst_type, opt_sec_level,
 					opt_psm, opt_mtu, connect_cb);
 	if (chan == NULL) {
-		got_error = TRUE;
+		got_error = true;
 		goto done;
 	}
 
diff --git a/attrib/interactive.c b/attrib/interactive.c
index 1dccfe5..c394d5e 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -27,6 +27,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <errno.h>
 #include <stdio.h>
 #include <glib.h>
diff --git a/attrib/utils.c b/attrib/utils.c
index e410a35..a8af7f2 100644
--- a/attrib/utils.c
+++ b/attrib/utils.c
@@ -26,6 +26,7 @@
 #endif
 
 #include <stdlib.h>
+#include <stdbool.h>
 #include <glib.h>
 
 #include <bluetooth/bluetooth.h>
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage
  2013-03-04 20:58 [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Jefferson Delfes
                   ` (5 preceding siblings ...)
  2013-03-04 20:58 ` [PATCH BlueZ 6/6] attrib: removing gboolean usage when possible Jefferson Delfes
@ 2013-03-25 12:29 ` Johan Hedberg
  2013-03-25 14:50   ` Jefferson Delfes
  6 siblings, 1 reply; 9+ messages in thread
From: Johan Hedberg @ 2013-03-25 12:29 UTC (permalink / raw)
  To: Jefferson Delfes; +Cc: linux-bluetooth

Hi Jefferson,

On Mon, Mar 04, 2013, Jefferson Delfes wrote:
> This patch series do a cleanup of glib basic data types usage. Types as
> gpointer, guint, gint, gchar and gsize were replaced by standard types without
> any extra effort. The only exception was gboolean which needs stdbool.h.
> Some variables were mainted as gboolean, because are passed as parameter to
> glib functions.

For code directly interacting with GLib APIs I thought the convention is
to use the same data types as in the APIs (meaning the GLib ones). Have
you seen major differences to this principle somewhere in the source
tree?

Johan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage
  2013-03-25 12:29 ` [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Johan Hedberg
@ 2013-03-25 14:50   ` Jefferson Delfes
  0 siblings, 0 replies; 9+ messages in thread
From: Jefferson Delfes @ 2013-03-25 14:50 UTC (permalink / raw)
  To: Jefferson Delfes, linux-bluetooth

Hi Johan.

Maybe there are too many changes here hehehe.
I will split it better trying to change only vars that aren't passed
to GLib, so I'll send to maillist again.

Thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-03-25 14:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-04 20:58 [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Jefferson Delfes
2013-03-04 20:58 ` [PATCH BlueZ 1/6] gattrib: remove " Jefferson Delfes
2013-03-04 20:58 ` [PATCH BlueZ 2/6] GATT: " Jefferson Delfes
2013-03-04 20:58 ` [PATCH BlueZ 3/6] attrib: " Jefferson Delfes
2013-03-04 20:58 ` [PATCH BlueZ 4/6] gatttool: " Jefferson Delfes
2013-03-04 20:58 ` [PATCH BlueZ 5/6] attrib: simplify boolean tests Jefferson Delfes
2013-03-04 20:58 ` [PATCH BlueZ 6/6] attrib: removing gboolean usage when possible Jefferson Delfes
2013-03-25 12:29 ` [PATCH BlueZ 0/6] attrib: Remove glib basic data types usage Johan Hedberg
2013-03-25 14:50   ` Jefferson Delfes

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.