diff options
author | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2013-08-14 09:27:51 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-08-20 11:05:30 +0200 |
commit | a3594b1032554feee39844f01c7c709d1bca9545 (patch) | |
tree | 844d8332e9271c04eff89515f1a2226c68ec7213 | |
parent | dfced76294726f33dacdc9d3670b76c10ac12f8a (diff) | |
download | neard-a3594b1032554feee39844f01c7c709d1bca9545.tar.gz neard-a3594b1032554feee39844f01c7c709d1bca9545.tar.bz2 neard-a3594b1032554feee39844f01c7c709d1bca9545.zip |
plugins: Use stdbool instead gboolean or near_bool_t
This patch has been created via coccinelle:
// Rule set 1
f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
,...)
@r2@
type T;
identifier f;
parameter list[n] ps;
identifier i;
@@
T f(ps, near_bool_t i, ...);
@@
identifier r2.f;
expression list [r.n] es;
@@
f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
,...)
@@
typedef bool;
@@
- near_bool_t
+ bool
// Rule set 2
// This is not a beautiful script but it does the job.
// Improvemtents are welcome.
// Fix all assigments but do not convert yet the type
@@
gboolean x;
@@
x =
(
- TRUE
+ true
|
- FALSE
+ false
)
// Figure out which function signature will to be fixed...
// when we have the defitition
@r@
identifier f;
parameter list[n] ps;
identifier i;
@@
f(ps, gboolean i, ...) { ... }
// ... and now convert all call sites
@@
identifier r.f;
expression list [r.n] es;
@@
f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
,...)
// Figure out which function signature will to be fixed...
// when we have the declaration only
@r2@
type T;
identifier f;
parameter list[n] ps;
identifier i;
@@
T f(ps, gboolean i, ...);
// ... and now convert all call sites
@@
identifier r2.f;
expression list [r.n] es;
@@
f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
,...)
// A handfull of the GLib hooks we can't change. Let's remember
// all ther positions.
// 1. timeouts
@k1@
identifier f;
position p;
typedef gpointer;
identifier ptr;
@@
static gboolean@p f(gpointer ptr);
@k2@
identifier f;
position p;
identifier ptr;
@@
static gboolean@p f(gpointer ptr) { ... }
// hash map iterator functions
@k3@
identifier f;
position p;
identifier p1, p2, p3;
@@
static gboolean@p f(gpointer p1, gpointer p2, gpointer p3) { ... }
// 2. GIOChannel
@k4@
identifier f;
position p;
typedef GIOChannel, GIOCondition;
identifier ptr;
identifier ch, cn;
@@
static gboolean@p f(GIOChannel *ch, GIOCondition cn, gpointer ptr);
@k5@
identifier f;
position p;
identifier ptr;
identifier ch, cn;
@@
static gboolean@p f(GIOChannel *ch, GIOCondition cn, gpointer ptr) { ... }
// 3. GSourceFuncs
@k6@
identifier f;
position p;
typedef GSource;
identifier src;
@@
static gboolean@p f(GSource *src, ...) { ... }
// gdbus functions
@k7@
identifier f;
position p;
typedef DBusConnection;
identifier con;
@@
static gboolean@p f(DBusConnection *con, ...) { ... }
// Now convert all gboolean which are are not used for interactin
// with GLib
// Note here happens the magic!
@@
typedef bool;
position p != {k1.p,k2.p,k3.p,k4.p,k5.p,k6.p,k7.p};
@@
- gboolean@p
+ bool
// Update all return types
@@
identifier f;
@@
bool f(...) {
<...
- return TRUE;
+ return true;
...>
}
@@
identifier f;
@@
bool f(...) {
<...
- return FALSE;
+ return false;
...>
}
// Rule set 3
@@
expression E;
symbol TRUE;
symbol FALSE;
@@
(
E
- == TRUE
|
- TRUE == E
+ E
|
- E != TRUE
+ !E
|
- TRUE != E
+ !E
|
- E == FALSE
+ !E
|
- FALSE == E
+ !E
|
E
- != FALSE
|
- FALSE != E
+ E
)
-rw-r--r-- | plugins/handover.c | 70 | ||||
-rw-r--r-- | plugins/llcp-validation.c | 26 | ||||
-rw-r--r-- | plugins/mifare.c | 2 | ||||
-rw-r--r-- | plugins/npp.c | 6 | ||||
-rw-r--r-- | plugins/p2p.c | 8 | ||||
-rw-r--r-- | plugins/p2p.h | 4 | ||||
-rw-r--r-- | plugins/snep-validation.c | 20 | ||||
-rw-r--r-- | plugins/snep.c | 14 |
8 files changed, 75 insertions, 75 deletions
diff --git a/plugins/handover.c b/plugins/handover.c index d4a8f89..8eee61f 100644 --- a/plugins/handover.c +++ b/plugins/handover.c @@ -73,8 +73,8 @@ struct hr_ndef { near_tag_io_cb cb; int extra_ndef_count; int block_free_size; - near_bool_t cfg_record_state; - near_bool_t in_extra_read; + bool cfg_record_state; + bool in_extra_read; }; struct hr_push_client { @@ -152,18 +152,18 @@ fail: return err; } -static near_bool_t handover_recv_error(void) +static bool handover_recv_error(void) { near_error("%s", strerror(errno)); if (errno == EAGAIN) - return TRUE; + return true; - return FALSE; + return false; } /* Add extra records right after the end of the "Hr" ndef record */ -static near_bool_t handover_read_cfg_records(int client_fd, +static bool handover_read_cfg_records(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb) { @@ -176,15 +176,15 @@ static near_bool_t handover_read_cfg_records(int client_fd, ndef = g_hash_table_lookup(hr_ndef_hash, GINT_TO_POINTER(client_fd)); if (ndef == NULL) { near_error("hr_ndef should exist"); - return FALSE; + return false; } - if (ndef->in_extra_read == TRUE) { + if (ndef->in_extra_read) { /* Next prepare read to complete the Hr */ new_ndef = g_try_realloc(ndef->ndef, ndef->cur_record_len + NDEF_HR_MSG_MIN_LENGTH); if (new_ndef == NULL) - return FALSE; + return false; ndef->ndef = new_ndef; @@ -207,14 +207,14 @@ static near_bool_t handover_read_cfg_records(int client_fd, new_ndef = g_try_realloc(ndef->ndef, ndef->cur_record_len + ndef_size); if (new_ndef == NULL) - return FALSE; + return false; ndef->ndef = new_ndef; ndef->cur_record_len += ndef_size; - ndef->in_extra_read = FALSE; + ndef->in_extra_read = false; - return TRUE; + return true; } /* Read remaining bytes */ @@ -228,12 +228,12 @@ static near_bool_t handover_read_cfg_records(int client_fd, /* Is the NDEF read complete ? */ if (ndef->missing_bytes) - return TRUE; /* more bytes to come... */ + return true; /* more bytes to come... */ if (ndef->extra_ndef_count > 0) ndef->extra_ndef_count--; - ndef->in_extra_read = TRUE; + ndef->in_extra_read = true; if (ndef->extra_ndef_count == 0) { /* All the bytes are read so now, parse the frame */ @@ -241,21 +241,21 @@ static near_bool_t handover_read_cfg_records(int client_fd, if (err > 0) { /* clean memory */ handover_close(client_fd, 0); - return TRUE; + return true; } - return FALSE; + return false; } /* Process the next NDEF */ - return TRUE; + return true; fail: near_error("Handover read NDEFs failed"); - return FALSE; + return false; } -static near_bool_t handover_read_hr(int client_fd, +static bool handover_read_hr(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb) { int bytes_recv; @@ -266,7 +266,7 @@ static near_bool_t handover_read_hr(int client_fd, ndef = g_hash_table_lookup(hr_ndef_hash, GINT_TO_POINTER(client_fd)); if (ndef == NULL) - return FALSE; + return false; /* Read remaining bytes */ bytes_recv = recv(client_fd, ndef->ndef + ndef->cur_ptr, @@ -279,7 +279,7 @@ static near_bool_t handover_read_hr(int client_fd, /* Is the ndef "Hr" read complete or should we loop */ if (ndef->missing_bytes) - return TRUE; + return true; /* * The first NDEF frame is read. We now should determine how many @@ -296,23 +296,23 @@ static near_bool_t handover_read_hr(int client_fd, ndef->extra_ndef_count = extra_ndefs; /* End of Handover message - now process extra records */ - ndef->in_extra_read = TRUE; - ndef->cfg_record_state = TRUE; + ndef->in_extra_read = true; + ndef->cfg_record_state = true; /* But, if there's no ac record, we jump to the parsing */ if (ndef->extra_ndef_count == 0) { handover_ndef_parse(client_fd, ndef); - return FALSE; + return false; } - return TRUE; + return true; fail: near_error("Handover read failed"); - return FALSE; + return false; } -static near_bool_t handover_read_initialize(int client_fd, +static bool handover_read_initialize(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb) { int bytes_recv; @@ -336,7 +336,7 @@ static near_bool_t handover_read_initialize(int client_fd, ndef->adapter_idx = adapter_idx; ndef->target_idx = target_idx; ndef->cb = cb; - ndef->cfg_record_state = FALSE; + ndef->cfg_record_state = false; g_hash_table_insert(hr_ndef_hash, GINT_TO_POINTER(client_fd), ndef); @@ -356,7 +356,7 @@ static near_bool_t handover_read_initialize(int client_fd, if (ndef->cur_record_len == NDEF_HR_MSG_MIN_LENGTH) { handover_ndef_parse(client_fd, ndef); - return FALSE; + return false; } DBG("Handover frame size is %d", ndef->cur_ptr); @@ -366,19 +366,19 @@ static near_bool_t handover_read_initialize(int client_fd, if (ndef->ndef == NULL) goto fail; - return TRUE; + return true; fail: free_hr_ndef(ndef); - return FALSE; + return false; } /* * This function is a "dispatcher", to read Hr/Hs messages, * and/or additional NDEF messages */ -static near_bool_t handover_read(int client_fd, +static bool handover_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb) { @@ -391,7 +391,7 @@ static near_bool_t handover_read(int client_fd, target_idx, cb); } - if (ndef->cfg_record_state == TRUE) { + if (ndef->cfg_record_state) { return handover_read_cfg_records(client_fd, adapter_idx, target_idx, cb); } @@ -417,7 +417,7 @@ static void free_hr_push_client(struct hr_push_client *client, int status) static gboolean handover_push_event(GIOChannel *channel, GIOCondition condition, gpointer data) { - near_bool_t ret; + bool ret; struct hr_push_client *client = (struct hr_push_client *) data; DBG("condition 0x%x", condition); @@ -434,7 +434,7 @@ static gboolean handover_push_event(GIOChannel *channel, client->adapter_idx, client->target_idx, client->cb); - if (ret == FALSE) + if (!ret) free_hr_push_client(client, 0); return ret; diff --git a/plugins/llcp-validation.c b/plugins/llcp-validation.c index 5df727e..4040133 100644 --- a/plugins/llcp-validation.c +++ b/plugins/llcp-validation.c @@ -60,7 +60,7 @@ struct sdu { uint8_t *data; }; -typedef near_bool_t (*near_incoming_cb) (struct co_cl_client_data *co_client); +typedef bool (*near_incoming_cb) (struct co_cl_client_data *co_client); static GHashTable *llcp_client_hash = NULL; @@ -139,7 +139,7 @@ static gboolean llcp_common_delay_cb(gpointer user_data) * If this is the first SDU, we start a 2 secs timer, and be ready for * another SDU */ -static near_bool_t llcp_add_incoming_sdu(struct co_cl_client_data *clt, int len) +static bool llcp_add_incoming_sdu(struct co_cl_client_data *clt, int len) { struct sdu *i_sdu; @@ -162,11 +162,11 @@ static near_bool_t llcp_add_incoming_sdu(struct co_cl_client_data *clt, int len) if (clt->buf_count == 1) g_timeout_add(ECHO_DELAY, llcp_common_delay_cb, clt); - return TRUE; + return true; out_error: g_free(i_sdu); - return FALSE; + return false; } /* @@ -174,7 +174,7 @@ out_error: * acceppt more than 2 SDUs, so we discard subsequent SDU. * * */ -static near_bool_t llcp_cl_data_recv(struct co_cl_client_data *cl_client) +static bool llcp_cl_data_recv(struct co_cl_client_data *cl_client) { socklen_t addr_len; int len; @@ -188,7 +188,7 @@ static near_bool_t llcp_cl_data_recv(struct co_cl_client_data *cl_client) if (len < 0) { near_error("Could not read data %d %s", len, strerror(errno)); - return FALSE; + return false; } /* Two SDUs max, reject the others */ @@ -197,13 +197,13 @@ static near_bool_t llcp_cl_data_recv(struct co_cl_client_data *cl_client) else near_warn("No more than 2 SDU..ignored"); - return TRUE; + return true; } /* * Connection oriented mode. We get the SDU and add it to the list. */ -static near_bool_t llcp_co_data_recv(struct co_cl_client_data *co_client) +static bool llcp_co_data_recv(struct co_cl_client_data *co_client) { int len; @@ -212,14 +212,14 @@ static near_bool_t llcp_co_data_recv(struct co_cl_client_data *co_client) len = recv(co_client->fd, co_client->miu_buffer, co_client->miu_len, 0); if (len < 0) { near_error("Could not read data %d %s", len, strerror(errno)); - return FALSE; + return false; } return llcp_add_incoming_sdu(co_client, len); } /* Common function to initialize client connection data */ -static near_bool_t llcp_common_read(int client_fd, uint32_t adapter_idx, +static bool llcp_common_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb, near_incoming_cb llcp_read_bytes, const int sock_type) @@ -266,7 +266,7 @@ error: DBG("Memory allocation failed"); g_free(cx_client); - return FALSE; + return false; } /* clean on close */ @@ -279,7 +279,7 @@ static void llcp_validation_close(int client_fd, int err) } /* Connection Oriented: Wrapper for read function */ -static near_bool_t llcp_validation_read_co(int client_fd, uint32_t adapter_idx, +static bool llcp_validation_read_co(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb) { @@ -289,7 +289,7 @@ static near_bool_t llcp_validation_read_co(int client_fd, uint32_t adapter_idx, } /* Connection less: Wrapper for read function */ -static near_bool_t llcp_validation_read_cl(int client_fd, uint32_t adapter_idx, +static bool llcp_validation_read_cl(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb) { diff --git a/plugins/mifare.c b/plugins/mifare.c index 86259b8..4cb7450 100644 --- a/plugins/mifare.c +++ b/plugins/mifare.c @@ -430,7 +430,7 @@ static int mifare_read_sector(void *cookie, uint8_t *pmem, /* memory to fill */ uint16_t memsize, /* remaining free size */ uint8_t sector_id, /* sector to read */ - near_bool_t trailer, /* Add trailer or not */ + bool trailer, /* Add trailer or not */ near_recv next_func) { struct mifare_cookie *mf_ck = cookie; diff --git a/plugins/npp.c b/plugins/npp.c index 3763e69..55c391b 100644 --- a/plugins/npp.c +++ b/plugins/npp.c @@ -54,7 +54,7 @@ struct p2p_npp_frame { struct p2p_npp_ndef_entry ndefs[]; } __attribute__((packed)); -static near_bool_t npp_read(int client_fd, +static bool npp_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb) { @@ -124,7 +124,7 @@ static near_bool_t npp_read(int client_fd, err = near_tag_add_data(adapter_idx, target_idx, ndefs, total_ndef_length); if (err < 0) - return FALSE; + return false; device = near_device_get_device(adapter_idx, target_idx); if (device == NULL) { @@ -140,7 +140,7 @@ static near_bool_t npp_read(int client_fd, g_free(ndefs); - return FALSE; + return false; } struct near_p2p_driver npp_driver = { diff --git a/plugins/p2p.c b/plugins/p2p.c index 44791fe..2026223 100644 --- a/plugins/p2p.c +++ b/plugins/p2p.c @@ -129,7 +129,7 @@ static gboolean p2p_client_event(GIOChannel *channel, GIOCondition condition, gpointer user_data) { struct p2p_data *client_data = user_data; - near_bool_t more; + bool more; DBG("condition 0x%x", condition); @@ -359,7 +359,7 @@ out: return FALSE; } -static gboolean check_nval(GIOChannel *io) +static bool check_nval(GIOChannel *io) { struct pollfd fds; @@ -368,9 +368,9 @@ static gboolean check_nval(GIOChannel *io) fds.events = POLLNVAL; if (poll(&fds, 1, 0) > 0 && (fds.revents & POLLNVAL)) - return TRUE; + return true; - return FALSE; + return false; } static gboolean p2p_connect_event(GIOChannel *channel, GIOCondition condition, diff --git a/plugins/p2p.h b/plugins/p2p.h index 7a7c359..243e7b5 100644 --- a/plugins/p2p.h +++ b/plugins/p2p.h @@ -33,9 +33,9 @@ struct near_p2p_driver { const char *name; const char *service_name; const char *fallback_service_name; - near_bool_t single_connection; + bool single_connection; int sock_type; - near_bool_t (*read)(int client_fd, + bool (*read)(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_device_io_cb cb); int (*push)(int client_fd, uint32_t adapter_idx, uint32_t target_idx, diff --git a/plugins/snep-validation.c b/plugins/snep-validation.c index 158a5ff..1128a32 100644 --- a/plugins/snep-validation.c +++ b/plugins/snep-validation.c @@ -59,7 +59,7 @@ static void free_snep_validation_client(gpointer data) * The validation server shall accept PUT and GET requests. A PUT request shall * cause the server to store the ndef message transmitted with the request. * */ -static near_bool_t snep_validation_server_req_put(int client_fd, void *data) +static bool snep_validation_server_req_put(int client_fd, void *data) { struct p2p_snep_data *snep_data = data; GList *records; @@ -105,12 +105,12 @@ static near_bool_t snep_validation_server_req_put(int client_fd, void *data) near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_SUCCESS); - return TRUE; + return true; error: near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_REJECT); - return TRUE; + return true; } /* @@ -119,7 +119,7 @@ error: * cause the server to return a previously stored NDEF message of the same NDEF * message type and identifier as transmitted with the request. * */ -static near_bool_t snep_validation_server_req_get(int client_fd, void *data) +static bool snep_validation_server_req_get(int client_fd, void *data) { struct p2p_snep_data *snep_data = data; struct near_ndef_record *recd, *rec_store; @@ -168,10 +168,10 @@ static near_bool_t snep_validation_server_req_get(int client_fd, void *data) rec_store = iter->data; /* Same mime type and same id ?*/ - if (near_ndef_record_cmp_id(recd, rec_store) == FALSE) + if (!near_ndef_record_cmp_id(recd, rec_store)) continue; - if (near_ndef_record_cmp_mime(recd, rec_store) == FALSE) + if (!near_ndef_record_cmp_mime(recd, rec_store)) continue; /* Found a record, check the length */ @@ -194,22 +194,22 @@ static near_bool_t snep_validation_server_req_get(int client_fd, void *data) } else near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_EXCESS); - return TRUE; + return true; } done: /* If not found */ near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_NOT_FOUND); - return TRUE; + return true; error: /* Not found */ near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_REJECT); - return FALSE; + return false; } /* This function is a wrapper to push post processing read functions */ -static near_bool_t snep_validation_read(int client_fd, uint32_t adapter_idx, +static bool snep_validation_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb) { diff --git a/plugins/snep.c b/plugins/snep.c index 4b58451..d10f6e2 100644 --- a/plugins/snep.c +++ b/plugins/snep.c @@ -49,7 +49,7 @@ * * TODO: check the nfc_data (simple NDEF or complete frame ?) * */ -static near_bool_t snep_default_server_req_put(int client_fd, void *data) +static bool snep_default_server_req_put(int client_fd, void *data) { struct p2p_snep_data *snep_data = data; struct near_device *device; @@ -65,12 +65,12 @@ static near_bool_t snep_default_server_req_put(int client_fd, void *data) snep_data->target_idx, snep_data->nfc_data, snep_data->nfc_data_length) < 0) - return FALSE; + return false; device = near_device_get_device(snep_data->adapter_idx, snep_data->target_idx); if (device == NULL) - return FALSE; + return false; records = near_ndef_parse_msg(snep_data->nfc_data, snep_data->nfc_data_length, NULL); @@ -80,7 +80,7 @@ static near_bool_t snep_default_server_req_put(int client_fd, void *data) snep_data->nfc_data_length = 0; snep_data->nfc_data = NULL; - return TRUE; + return true; } /* @@ -90,7 +90,7 @@ static near_bool_t snep_default_server_req_put(int client_fd, void *data) * !!! We check if the incoming NDEF looks like a handover frame, * because of Android 4.1.1 ... * */ -static near_bool_t snep_default_server_req_get(int client_fd, void *data) +static bool snep_default_server_req_get(int client_fd, void *data) { struct p2p_snep_data *snep_data = data; @@ -111,11 +111,11 @@ static near_bool_t snep_default_server_req_get(int client_fd, void *data) NEAR_SNEP_ACC_LENGTH_SIZE); } - return TRUE; + return true; } /* This function is a wrapper to push post processing read functions */ -static near_bool_t snep_default_read(int client_fd, uint32_t adapter_idx, +static bool snep_default_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb) { |