From a97a97147d8523cd54be8cd6ddbf16e321b2b133 Mon Sep 17 00:00:00 2001 From: Pekka Pessi Date: Thu, 27 May 2010 19:12:45 +0300 Subject: [PATCH] Eliminated bool, true and false from gisi --- gisi/client.c | 10 ++----- gisi/client.h | 17 ++++++------ gisi/iter.c | 73 +++++++++++++++++++++++++------------------------- gisi/iter.h | 23 ++++++++-------- gisi/netlink.c | 1 - gisi/netlink.h | 1 - gisi/pipe.c | 45 +++++++++++++++---------------- gisi/server.h | 7 +++-- gisi/verify.c | 13 +++++---- 9 files changed, 88 insertions(+), 102 deletions(-) diff --git a/gisi/client.c b/gisi/client.c index fa40f0c7..640484d6 100644 --- a/gisi/client.c +++ b/gisi/client.c @@ -570,14 +570,8 @@ static void g_isi_dispatch_response(GIsiClient *client, uint16_t obj, req = *(GIsiRequest **)ret; - if (req->func) { - bool handled; - - handled = req->func(client, msg + 1, len - 1, obj, req->data); - if (!handled) - return; - } - g_isi_request_cancel(req); + if (!req->func || req->func(client, msg + 1, len - 1, obj, req->data)) + g_isi_request_cancel(req); } /* Data callback for both responses and indications */ diff --git a/gisi/client.h b/gisi/client.h index 1962f5c9..7046f31e 100644 --- a/gisi/client.h +++ b/gisi/client.h @@ -27,7 +27,6 @@ extern "C" { #endif #include -#include #include struct _GIsiClient; @@ -36,16 +35,16 @@ typedef struct _GIsiClient GIsiClient; struct _GIsiRequest; typedef struct _GIsiRequest GIsiRequest; -typedef void (*GIsiVerifyFunc)(GIsiClient *client, bool alive, +typedef void (*GIsiVerifyFunc)(GIsiClient *client, gboolean alive, uint16_t object, void *opaque); -typedef bool (*GIsiResponseFunc)(GIsiClient *client, - const void *restrict data, size_t len, - uint16_t object, void *opaque); +typedef gboolean (*GIsiResponseFunc)(GIsiClient *client, + const void *restrict data, size_t len, + uint16_t object, void *opaque); typedef void (*GIsiIndicationFunc) (GIsiClient *client, - const void *restrict data, size_t len, - uint16_t object, void *opaque); + const void *restrict data, size_t len, + uint16_t object, void *opaque); GIsiClient *g_isi_client_create(GIsiModem *modem, uint8_t resource); @@ -70,8 +69,8 @@ GIsiRequest *g_isi_request_make(GIsiClient *client, const void *data, GIsiResponseFunc func, void *opaque); struct iovec; GIsiRequest *g_isi_request_vmake(GIsiClient *client, const struct iovec *iov, - size_t iovlen, unsigned timeout, - GIsiResponseFunc func, void *opaque); + size_t iovlen, unsigned timeout, + GIsiResponseFunc func, void *opaque); void g_isi_request_cancel(GIsiRequest *req); diff --git a/gisi/iter.c b/gisi/iter.c index 152b2365..7b3191b9 100644 --- a/gisi/iter.c +++ b/gisi/iter.c @@ -25,7 +25,6 @@ #include #endif -#include #include #include #include @@ -49,7 +48,7 @@ static inline void bcd_to_mccmnc(const uint8_t *restrict bcd, } void g_isi_sb_iter_init_full(GIsiSubBlockIter *iter, const void *restrict data, - size_t len, size_t used, bool longhdr, + size_t len, size_t used, gboolean longhdr, uint16_t sub_blocks) { if (!data) @@ -69,25 +68,25 @@ void g_isi_sb_iter_init(GIsiSubBlockIter *iter, const void *restrict data, iter->start = (uint8_t *)data + used; iter->end = iter->start + len; - iter->longhdr = false; + iter->longhdr = FALSE; iter->sub_blocks = len > used ? iter->start[-1] : 0; } -bool g_isi_sb_iter_is_valid(const GIsiSubBlockIter *iter) +gboolean g_isi_sb_iter_is_valid(const GIsiSubBlockIter *iter) { if (!iter) - return false; + return FALSE; if (iter->sub_blocks == 0) - return false; + return FALSE; if (iter->start + (iter->longhdr ? 4 : 2) > iter->end) - return false; + return FALSE; if (iter->start + g_isi_sb_iter_get_len(iter) > iter->end) - return false; + return FALSE; - return true; + return TRUE; } int g_isi_sb_iter_get_id(const GIsiSubBlockIter *iter) @@ -104,103 +103,103 @@ size_t g_isi_sb_iter_get_len(const GIsiSubBlockIter *iter) return iter->start[1]; } -bool g_isi_sb_iter_get_data(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_data(const GIsiSubBlockIter *restrict iter, void **data, unsigned pos) { if ((size_t)pos > g_isi_sb_iter_get_len(iter) || iter->start + pos > iter->end) - return false; + return FALSE; *data = (void *)iter->start + pos; - return true; + return TRUE; } -bool g_isi_sb_iter_get_byte(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_byte(const GIsiSubBlockIter *restrict iter, uint8_t *byte, unsigned pos) { if ((size_t)pos > g_isi_sb_iter_get_len(iter) || iter->start + pos > iter->end) - return false; + return FALSE; *byte = iter->start[pos]; - return true; + return TRUE; } -bool g_isi_sb_iter_get_word(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_word(const GIsiSubBlockIter *restrict iter, uint16_t *word, unsigned pos) { uint16_t val; if (pos + 1 > g_isi_sb_iter_get_len(iter)) - return false; + return FALSE; memcpy(&val, iter->start + pos, sizeof(uint16_t)); *word = ntohs(val); - return true; + return TRUE; } -bool g_isi_sb_iter_get_dword(const GIsiSubBlockIter *restrict iter, - uint32_t *dword, unsigned pos) +gboolean g_isi_sb_iter_get_dword(const GIsiSubBlockIter *restrict iter, + uint32_t *dword, unsigned pos) { uint32_t val; if (pos + 3 > g_isi_sb_iter_get_len(iter)) - return false; + return FALSE; memcpy(&val, iter->start + pos, sizeof(uint32_t)); *dword = ntohl(val); - return true; + return TRUE; } -bool g_isi_sb_iter_get_oper_code(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_oper_code(const GIsiSubBlockIter *restrict iter, char *mcc, char *mnc, unsigned pos) { if (pos + 2 > g_isi_sb_iter_get_len(iter)) - return false; + return FALSE; bcd_to_mccmnc(iter->start + pos, mcc, mnc); - return true; + return TRUE; } -bool g_isi_sb_iter_get_alpha_tag(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_alpha_tag(const GIsiSubBlockIter *restrict iter, char **utf8, size_t len, unsigned pos) { uint8_t *ucs2 = NULL; if (pos > g_isi_sb_iter_get_len(iter)) - return false; + return FALSE; if (!utf8 || len == 0 || pos + len > g_isi_sb_iter_get_len(iter)) - return false; + return FALSE; ucs2 = iter->start + pos; if (ucs2 + len > iter->end) - return false; + return FALSE; *utf8 = g_convert((const char *)ucs2, len, "UTF-8//TRANSLIT", "UCS-2BE", NULL, NULL, NULL); return *utf8 != NULL; } -bool g_isi_sb_iter_get_latin_tag(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_latin_tag(const GIsiSubBlockIter *restrict iter, char **latin, size_t len, unsigned pos) { uint8_t *str = NULL; if (pos > g_isi_sb_iter_get_len(iter)) - return false; + return FALSE; if (!latin || len == 0 || pos + len > g_isi_sb_iter_get_len(iter)) - return false; + return FALSE; str = iter->start + pos; if (str + len > iter->end) - return false; + return FALSE; *latin = g_strndup((char *)str, len); return *latin != NULL; } -bool g_isi_sb_iter_next(GIsiSubBlockIter *iter) +gboolean g_isi_sb_iter_next(GIsiSubBlockIter *iter) { uint8_t len = g_isi_sb_iter_get_len(iter); @@ -208,13 +207,13 @@ bool g_isi_sb_iter_next(GIsiSubBlockIter *iter) len = iter->longhdr ? 4 : 2; if (iter->sub_blocks == 0) - return false; + return FALSE; if (iter->start + len > iter->end) - return false; + return FALSE; iter->start += len; iter->sub_blocks--; - return true; + return TRUE; } diff --git a/gisi/iter.h b/gisi/iter.h index 86489009..8418331a 100644 --- a/gisi/iter.h +++ b/gisi/iter.h @@ -29,7 +29,6 @@ extern "C" { #endif #include -#include struct _GIsiSubBlockIter { uint8_t *start; @@ -46,28 +45,28 @@ void g_isi_sb_iter_init(GIsiSubBlockIter *iter, void g_isi_sb_iter_init_full(GIsiSubBlockIter *iter, const void *restrict data, size_t len, size_t used, - bool longhdr, + gboolean longhdr, uint16_t sub_blocks); -bool g_isi_sb_iter_is_valid(const GIsiSubBlockIter *iter); +gboolean g_isi_sb_iter_is_valid(const GIsiSubBlockIter *iter); -bool g_isi_sb_iter_next(GIsiSubBlockIter *iter); +gboolean g_isi_sb_iter_next(GIsiSubBlockIter *iter); int g_isi_sb_iter_get_id(const GIsiSubBlockIter *iter); size_t g_isi_sb_iter_get_len(const GIsiSubBlockIter *iter); -bool g_isi_sb_iter_get_data(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_data(const GIsiSubBlockIter *restrict iter, void **data, unsigned pos); -bool g_isi_sb_iter_get_byte(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_byte(const GIsiSubBlockIter *restrict iter, uint8_t *byte, unsigned pos); -bool g_isi_sb_iter_get_word(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_word(const GIsiSubBlockIter *restrict iter, uint16_t *word, unsigned pos); -bool g_isi_sb_iter_get_dword(const GIsiSubBlockIter *restrict iter, - uint32_t *dword, unsigned pos); -bool g_isi_sb_iter_get_oper_code(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_dword(const GIsiSubBlockIter *restrict iter, + uint32_t *dword, unsigned pos); +gboolean g_isi_sb_iter_get_oper_code(const GIsiSubBlockIter *restrict iter, char *mcc, char *mnc, unsigned pos); -bool g_isi_sb_iter_get_alpha_tag(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_alpha_tag(const GIsiSubBlockIter *restrict iter, char **utf8, size_t len, unsigned pos); -bool g_isi_sb_iter_get_latin_tag(const GIsiSubBlockIter *restrict iter, +gboolean g_isi_sb_iter_get_latin_tag(const GIsiSubBlockIter *restrict iter, char **ascii, size_t len, unsigned pos); #ifdef __cplusplus diff --git a/gisi/netlink.c b/gisi/netlink.c index 06d4863d..7ef8ec0c 100644 --- a/gisi/netlink.c +++ b/gisi/netlink.c @@ -25,7 +25,6 @@ #include #endif -#include #include #include #include diff --git a/gisi/netlink.h b/gisi/netlink.h index 5b58fa48..816cd74e 100644 --- a/gisi/netlink.h +++ b/gisi/netlink.h @@ -21,7 +21,6 @@ * */ -#include #include #include diff --git a/gisi/pipe.c b/gisi/pipe.c index 0e7698d2..55852b18 100644 --- a/gisi/pipe.c +++ b/gisi/pipe.c @@ -26,7 +26,6 @@ #endif #include -#include #include #include #include "client.h" @@ -125,8 +124,8 @@ struct _GIsiPipe { void *opaque; int error; uint8_t handle; - bool enabled; - bool enabling; + gboolean enabled; + gboolean enabling; }; static int g_isi_pipe_error(uint8_t code) @@ -163,16 +162,16 @@ static void g_isi_pipe_handle_error(GIsiPipe *pipe, uint8_t code) pipe->error_handler(pipe); } -static bool g_isi_pipe_created(GIsiClient *client, - const void *restrict data, size_t len, - uint16_t object, void *opaque) +static gboolean g_isi_pipe_created(GIsiClient *client, + const void *restrict data, size_t len, + uint16_t object, void *opaque) { GIsiPipe *pipe = opaque; const isi_pipe_resp_t *resp = data; if (len < 5 || resp->cmd != PNS_PIPE_CREATE_RESP) - return false; + return FALSE; if (resp->pipe_handle != PN_PIPE_INVALID_HANDLE) { pipe->handle = resp->pipe_handle; @@ -182,7 +181,7 @@ static bool g_isi_pipe_created(GIsiClient *client, pipe->handler(pipe); } else g_isi_pipe_handle_error(pipe, resp->error_code); - return true; + return TRUE; } /** @@ -220,8 +219,8 @@ GIsiPipe *g_isi_pipe_create(GIsiModem *modem, void (*created)(GIsiPipe *), pipe->handler = created; pipe->error_handler = NULL; pipe->error = 0; - pipe->enabling = false; - pipe->enabled = false; + pipe->enabling = FALSE; + pipe->enabled = FALSE; pipe->handle = PN_PIPE_INVALID_HANDLE; if (pipe->client == NULL || @@ -250,22 +249,22 @@ g_isi_pipe_check_resp(const GIsiPipe *pipe, uint8_t cmd, return resp; } -static bool g_isi_pipe_enabled(GIsiClient *client, - const void *restrict data, size_t len, - uint16_t object, void *opaque) +static gboolean g_isi_pipe_enabled(GIsiClient *client, + const void *restrict data, size_t len, + uint16_t object, void *opaque) { GIsiPipe *pipe = opaque; const isi_pipe_resp_t *resp; resp = g_isi_pipe_check_resp(pipe, PNS_PIPE_ENABLE_RESP, data, len); if (!resp) - return false; + return FALSE; g_isi_pipe_handle_error(pipe, resp->error_code); - pipe->enabling = false; + pipe->enabling = FALSE; if (!pipe->error) - pipe->enabled = true; - return true; + pipe->enabled = TRUE; + return TRUE; } static GIsiRequest *g_isi_pipe_enable(GIsiPipe *pipe) @@ -295,26 +294,26 @@ int g_isi_pipe_start(GIsiPipe *pipe) if (pipe->handle != PN_PIPE_INVALID_HANDLE) g_isi_pipe_enable(pipe); else - pipe->enabling = true; + pipe->enabling = TRUE; return 0; } /* Not very useful, it will never have time to trigger */ -static bool g_isi_pipe_removed(GIsiClient *client, - const void *restrict data, size_t len, - uint16_t object, void *opaque) +static gboolean g_isi_pipe_removed(GIsiClient *client, + const void *restrict data, size_t len, + uint16_t object, void *opaque) { GIsiPipe *pipe = opaque; const isi_pipe_resp_t *resp; resp = g_isi_pipe_check_resp(pipe, PNS_PIPE_REMOVE_RESP, data, len); if (!resp) - return false; + return FALSE; pipe->handle = PN_PIPE_INVALID_HANDLE; pipe->error = -EPIPE; - return true; + return TRUE; } diff --git a/gisi/server.h b/gisi/server.h index 080573fe..d1be88e6 100644 --- a/gisi/server.h +++ b/gisi/server.h @@ -27,7 +27,6 @@ extern "C" { #endif #include -#include #include struct _GIsiServer; @@ -36,9 +35,9 @@ typedef struct _GIsiServer GIsiServer; struct _GIsiIncoming; typedef struct _GIsiIncoming GIsiIncoming; -typedef bool (*GIsiRequestFunc)(GIsiServer *server, - const void *restrict data, size_t len, - GIsiIncoming *, void *opaque); +typedef gboolean (*GIsiRequestFunc)(GIsiServer *server, + const void *restrict data, size_t len, + GIsiIncoming *, void *opaque); GIsiServer *g_isi_server_create(GIsiModem *modem, uint8_t resource, uint8_t major, uint8_t minor); diff --git a/gisi/verify.c b/gisi/verify.c index ebedfbe8..7ba0cdc5 100644 --- a/gisi/verify.c +++ b/gisi/verify.c @@ -26,7 +26,6 @@ #endif #include -#include #include #include "client.h" @@ -43,14 +42,14 @@ struct verify_data { void *data; }; -static bool verify_cb(GIsiClient *client, const void *restrict data, - size_t len, uint16_t object, void *opaque) +static gboolean verify_cb(GIsiClient *client, const void *restrict data, + size_t len, uint16_t object, void *opaque) { const uint8_t *msg = data; struct verify_data *vd = opaque; GIsiVerifyFunc func = vd->func; - bool alive = false; + gboolean alive = FALSE; if (!msg) goto out; @@ -60,18 +59,18 @@ static bool verify_cb(GIsiClient *client, const void *restrict data, if (msg[1] == COMM_ISI_VERSION_GET_RESP && len >= 4) { g_isi_version_set(client, msg[2], msg[3]); - alive = true; + alive = TRUE; goto out; } if (msg[1] != COMM_ISA_ENTITY_NOT_REACHABLE_RESP) - alive = true; + alive = TRUE; out: if (func) func(client, alive, object, vd->data); g_free(vd); - return true; + return TRUE; } /**