From e5f0290ddb17f368cf21bc0262a531e67486c409 Mon Sep 17 00:00:00 2001 From: Aki Niemi Date: Mon, 15 Jun 2009 11:17:30 +0300 Subject: [PATCH] Rename ISI client and PhoNet netlink APIs - Add g_ prefix to functions - Add G-prefix and use CamelCasing in types --- Makefile.am | 2 +- configure.ac | 2 +- {isi => gisi}/Makefile.am | 0 {isi => gisi}/client.c | 86 +++++++++++++++++++-------------------- gisi/client.h | 69 +++++++++++++++++++++++++++++++ {isi => gisi}/netlink.c | 20 ++++----- {isi => gisi}/netlink.h | 25 +++++++++--- {isi => gisi}/socket.c | 0 {isi => gisi}/socket.h | 10 ++--- isi/client.h | 48 ---------------------- 10 files changed, 146 insertions(+), 116 deletions(-) rename {isi => gisi}/Makefile.am (100%) rename {isi => gisi}/client.c (79%) create mode 100644 gisi/client.h rename {isi => gisi}/netlink.c (91%) rename {isi => gisi}/netlink.h (67%) rename {isi => gisi}/socket.c (100%) rename {isi => gisi}/socket.h (80%) delete mode 100644 isi/client.h diff --git a/Makefile.am b/Makefile.am index 8b63f166..4081601f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = gdbus gatchat isi include plugins drivers unit src doc +SUBDIRS = gdbus gatchat gisi include plugins drivers unit src doc DISTCHECK_CONFIGURE_FLAGS = --disable-datafiles diff --git a/configure.ac b/configure.ac index 720e8226..92fb82f8 100644 --- a/configure.ac +++ b/configure.ac @@ -86,7 +86,7 @@ AM_CONDITIONAL(DATAFILES, test "${enable_datafiles}" != "no") COMPILER_FLAGS -AC_OUTPUT(Makefile gdbus/Makefile gatchat/Makefile isi/Makefile +AC_OUTPUT(Makefile gdbus/Makefile gatchat/Makefile gisi/Makefile include/Makefile include/version.h src/Makefile plugins/Makefile drivers/Makefile unit/Makefile doc/Makefile) diff --git a/isi/Makefile.am b/gisi/Makefile.am similarity index 100% rename from isi/Makefile.am rename to gisi/Makefile.am diff --git a/isi/client.c b/gisi/client.c similarity index 79% rename from isi/client.c rename to gisi/client.c index f8f01711..24b89ecd 100644 --- a/isi/client.c +++ b/gisi/client.c @@ -38,7 +38,7 @@ #include "socket.h" #include "client.h" -struct isi_client { +struct _GIsiClient { uint8_t resource; /* Requests */ @@ -46,7 +46,7 @@ struct isi_client { guint source; uint8_t prev[256], next[256]; guint timeout[256]; - isi_client_cb_t func[256]; + GIsiResponseFunc func[256]; void *data[256]; /* Indications */ @@ -54,27 +54,28 @@ struct isi_client { int fd; guint source; uint16_t count; - isi_ind_cb_t func[256]; + GIsiIndicationFunc func[256]; void *data[256]; } ind; }; -static gboolean isi_callback(GIOChannel *, GIOCondition, gpointer); -static gboolean isi_timeout(gpointer); +static gboolean g_isi_callback(GIOChannel *channel, GIOCondition cond, + gpointer data); +static gboolean g_isi_timeout(gpointer data); -static inline struct isi_request *isi_req(struct isi_client *cl, uint8_t id) +static inline GIsiRequest *g_isi_req(GIsiClient *cl, uint8_t id) { - return (struct isi_request *)(((uint8_t *)(void *)cl) + id); + return (GIsiRequest *)(((uint8_t *)(void *)cl) + id); } -static inline uint8_t isi_id(void *ptr) +static inline uint8_t g_isi_id(void *ptr) { return ((uintptr_t)ptr) & 255; } -static inline struct isi_client *isi_cl(void *ptr) +static inline GIsiClient *g_isi_cl(void *ptr) { - return (struct isi_client *)(((uintptr_t)ptr) & ~255); + return (GIsiClient *)(((uintptr_t)ptr) & ~255); } /** @@ -82,10 +83,10 @@ static inline struct isi_client *isi_cl(void *ptr) * @param resource Phonet resource ID for the client * @return NULL on error (see errno), an isi_client pointer on success, */ -struct isi_client *isi_client_create(uint8_t resource) +GIsiClient *g_isi_client_create(uint8_t resource) { void *ptr; - struct isi_client *cl; + GIsiClient *cl; GIOChannel *channel; unsigned i; @@ -118,7 +119,7 @@ struct isi_client *isi_client_create(uint8_t resource) cl->fd = g_io_channel_unix_get_fd(channel); cl->source = g_io_add_watch(channel, G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL, - isi_callback, cl); + g_isi_callback, cl); g_io_channel_unref(channel); return cl; } @@ -127,7 +128,7 @@ struct isi_client *isi_client_create(uint8_t resource) * Destroys an ISI client, cancels all pending transactions and subscriptions. * @param client client to destroy */ -void isi_client_destroy(struct isi_client *client) +void g_isi_client_destroy(GIsiClient *client) { unsigned id; @@ -143,16 +144,15 @@ void isi_client_destroy(struct isi_client *client) /** * Make an ISI request and register a callback to process the response(s) to * the resulting transaction. - * @param cl ISI client (from isi_client_create()) + * @param cl ISI client (from g_isi_client_create()) * @param buf pointer to request payload * @param len request payload byte length * @param cb callback to process response(s) * @param opaque data for the callback */ -struct isi_request *isi_request_make(struct isi_client *cl, - const void *__restrict buf, size_t len, - unsigned timeout, - isi_client_cb_t cb, void *opaque) +GIsiRequest *g_isi_request_make(GIsiClient *cl, const void *__restrict buf, + size_t len, unsigned timeout, + GIsiResponseFunc cb, void *opaque) { struct iovec iov[2]; ssize_t ret; @@ -192,10 +192,10 @@ struct isi_request *isi_request_make(struct isi_client *cl, if (timeout > 0) cl->timeout[id] = g_timeout_add_seconds(timeout, - isi_timeout, cl); + g_isi_timeout, cl); else cl->timeout[id] = 0; - return isi_req(cl, id); + return g_isi_req(cl, id); } /** @@ -203,10 +203,10 @@ struct isi_request *isi_request_make(struct isi_client *cl, * timeout. * @param req request to cancel */ -void isi_request_cancel(struct isi_request *req) +void g_isi_request_cancel(GIsiRequest *req) { - struct isi_client *cl = isi_cl(req); - uint8_t id = isi_id(req); + GIsiClient *cl = g_isi_cl(req); + uint8_t id = g_isi_id(req); cl->func[id] = NULL; cl->data[id] = NULL; @@ -229,7 +229,7 @@ void isi_request_cancel(struct isi_request *req) #define PN_COMMGR 0x10 #define PNS_SUBSCRIBED_RESOURCES_IND 0x10 -static int isi_indication_init(struct isi_client *cl) +static int g_isi_indication_init(GIsiClient *cl) { uint8_t msg[] = { 0, PNS_SUBSCRIBED_RESOURCES_IND, 1, cl->resource, @@ -243,11 +243,11 @@ static int isi_indication_init(struct isi_client *cl) send(cl->ind.fd, msg, 4, 0); cl->ind.source = g_io_add_watch(channel, G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL, - isi_callback, cl); + g_isi_callback, cl); return 0; } -static void isi_indication_deinit(struct isi_client *client) +static void g_isi_indication_deinit(GIsiClient *client) { uint8_t msg[] = { 0, PNS_SUBSCRIBED_RESOURCES_IND, 0, @@ -262,21 +262,21 @@ static void isi_indication_deinit(struct isi_client *client) * Subscribe to a given indication type for the resource that an ISI client * is associated with. If the same type was already subscrived, the old * subscription is overriden. - * @param cl ISI client (fomr isi_client_create()) + * @param cl ISI client (fomr g_isi_client_create()) * @param type indication type * @param cb callback to process received indications * @param data data for the callback * @return 0 on success, a system error code otherwise. */ -int isi_subscribe(struct isi_client *cl, uint8_t type, - isi_ind_cb_t cb, void *data) +int g_isi_subscribe(GIsiClient *cl, uint8_t type, + GIsiIndicationFunc cb, void *data) { if (cb == NULL) return EINVAL; if (cl->ind.func[type] == NULL) { if (cl->ind.count == 0) { - int ret = isi_indication_init(cl); + int ret = g_isi_indication_init(cl); if (ret) return ret; } @@ -289,24 +289,24 @@ int isi_subscribe(struct isi_client *cl, uint8_t type, /** * Unsubscribe from a given indication type. - * @param client ISI client (from isi_client_create()) + * @param client ISI client (from g_isi_client_create()) * @param type indication type. */ -void isi_unsubscribe(struct isi_client *client, uint8_t type) +void g_isi_unsubscribe(GIsiClient *client, uint8_t type) { /* Unsubscribe */ if (client->ind.func[type] == NULL) return; client->ind.func[type] = NULL; if (--client->ind.count == 0) - isi_indication_deinit(client); + g_isi_indication_deinit(client); } /* Data callback for both responses and indications */ -static gboolean isi_callback(GIOChannel *channel, GIOCondition cond, +static gboolean g_isi_callback(GIOChannel *channel, GIOCondition cond, gpointer data) { - struct isi_client *cl = data; + GIsiClient *cl = data; int fd = g_io_channel_unix_get_fd(channel); bool indication = (fd != cl->fd); int len; @@ -336,25 +336,25 @@ static gboolean isi_callback(GIOChannel *channel, GIOCondition cond, return TRUE; /* Bad transaction ID */ if ((cl->func[id])(cl, buf + 1, len - 1, obj, cl->data[id])) - isi_request_cancel(isi_req(cl, id)); + g_isi_request_cancel(g_isi_req(cl, id)); } } return TRUE; } -static gboolean isi_timeout(gpointer data) +static gboolean g_isi_timeout(gpointer data) { - struct isi_request *req = data; - struct isi_client *cl = isi_cl(req); - uint8_t id = isi_id(req); + GIsiRequest *req = data; + GIsiClient *cl = g_isi_cl(req); + uint8_t id = g_isi_id(req); assert(cl->func[id]); (cl->func[id])(cl, NULL, 0, 0, cl->data[id]); - isi_request_cancel(req); + g_isi_request_cancel(req); return FALSE; } -int isi_client_error(const struct isi_client *client) +int g_isi_client_error(const GIsiClient *client) { /* The only possible error at the moment */ return ETIMEDOUT; } diff --git a/gisi/client.h b/gisi/client.h new file mode 100644 index 00000000..b8cde37f --- /dev/null +++ b/gisi/client.h @@ -0,0 +1,69 @@ +/* + * This file is part of oFono - Open Source Telephony + * + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: Rémi Denis-Courmont + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + * + */ + +#ifndef __GISI_CLIENT_H +#define __GISI_CLIENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +struct _GIsiClient; +typedef struct _GIsiClient GIsiClient; + +struct _GIsiRequest; +typedef struct _GIsiRequest GIsiRequest; + +typedef bool (*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); + +GIsiClient *g_isi_client_create(uint8_t resource); + +void g_isi_client_destroy(GIsiClient *client); + +int g_isi_client_error(const GIsiClient *client); + +GIsiRequest *g_isi_request_make(GIsiClient *client, const void *data, + size_t len, unsigned timeout, + GIsiResponseFunc func, void *opaque); + +void g_isi_request_cancel(GIsiRequest *req); + +int g_isi_subscribe(GIsiClient *client, uint8_t type, + GIsiIndicationFunc func, void *opaque); + +void g_isi_unsubscribe(GIsiClient *client, uint8_t type); + +#ifdef __cplusplus +} +#endif + +#endif /* __GISI_CLIENT_H */ diff --git a/isi/netlink.c b/gisi/netlink.c similarity index 91% rename from isi/netlink.c rename to gisi/netlink.c index 3bb61db6..efe1109e 100644 --- a/isi/netlink.c +++ b/gisi/netlink.c @@ -45,14 +45,14 @@ #include "netlink.h" -struct pn_netlink { - pn_netlink_cb_t callback; +struct _GPhonetNetlink { + GPhonetNetlinkFunc callback; void *opaque; guint watch; }; /* Parser Netlink messages */ -static gboolean pn_nl_process(GIOChannel *channel, GIOCondition cond, +static gboolean g_pn_nl_process(GIOChannel *channel, GIOCondition cond, gpointer data) { struct { @@ -65,7 +65,7 @@ static gboolean pn_nl_process(GIOChannel *channel, GIOCondition cond, ssize_t ret; struct nlmsghdr *nlh; int fd = g_io_channel_unix_get_fd(channel); - struct pn_netlink *self = data; + GPhonetNetlink *self = data; if (cond & (G_IO_NVAL|G_IO_HUP)) return FALSE; @@ -117,7 +117,7 @@ static gboolean pn_nl_process(GIOChannel *channel, GIOCondition cond, } /* Dump current Phonet address table */ -static int pn_netlink_query(int fd) +static int g_pn_netlink_query(int fd) { struct { struct nlmsghdr nlh; @@ -148,10 +148,10 @@ static int pn_netlink_query(int fd) return 0; } -struct pn_netlink *pn_netlink_start(pn_netlink_cb_t cb, void *opaque) +GPhonetNetlink *g_pn_netlink_start(GPhonetNetlinkFunc cb, void *opaque) { GIOChannel *chan; - struct pn_netlink *self; + GPhonetNetlink *self; unsigned group = RTNLGRP_PHONET_IFADDR; int fd; @@ -167,7 +167,7 @@ struct pn_netlink *pn_netlink_start(pn_netlink_cb_t cb, void *opaque) if (setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &group, sizeof(group))) goto error; - pn_netlink_query(fd); + g_pn_netlink_query(fd); chan = g_io_channel_unix_new(fd); if (chan == NULL) @@ -179,7 +179,7 @@ struct pn_netlink *pn_netlink_start(pn_netlink_cb_t cb, void *opaque) self->callback = cb; self->opaque = opaque; self->watch = g_io_add_watch(chan, G_IO_IN|G_IO_ERR|G_IO_HUP, - pn_nl_process, self); + g_pn_nl_process, self); g_io_channel_unref(chan); return 0; @@ -190,7 +190,7 @@ error: return NULL; } -void pn_netlink_stop(struct pn_netlink *self) +void g_pn_netlink_stop(GPhonetNetlink *self) { g_source_remove(self->watch); g_free(self); diff --git a/isi/netlink.h b/gisi/netlink.h similarity index 67% rename from isi/netlink.h rename to gisi/netlink.h index d34c5e8c..8ea0607a 100644 --- a/isi/netlink.h +++ b/gisi/netlink.h @@ -21,14 +21,27 @@ * */ -#ifndef OFONO_PHONET_NETLINK_H -#define OFONO_PHONET_NETLINK_H 1 #include #include -struct pn_netlink; -typedef void (*pn_netlink_cb_t)(bool, uint8_t, unsigned, void *); +#ifndef __GPHONET_NETLINK_H +#define __GPHONET_NETLINK_H -struct pn_netlink *pn_netlink_start(pn_netlink_cb_t, void *); -void pn_netlink_stop(struct pn_netlink *self); +#ifdef __cplusplus +extern "C" { #endif + +struct _GPhonetNetlink; +typedef struct _GPhonetNetlink GPhonetNetlink; + +typedef void (*GPhonetNetlinkFunc)(bool up, uint8_t addr, unsigned idx, + void *data); + +GPhonetNetlink *g_pn_netlink_start(GPhonetNetlinkFunc func, void *data); +void g_pn_netlink_stop(GPhonetNetlink *self); + +#ifdef __cplusplus +} +#endif + +#endif /* __GPHONET_NETLINK_H */ diff --git a/isi/socket.c b/gisi/socket.c similarity index 100% rename from isi/socket.c rename to gisi/socket.c diff --git a/isi/socket.h b/gisi/socket.h similarity index 80% rename from isi/socket.h rename to gisi/socket.h index 206154e5..b95a4d78 100644 --- a/isi/socket.h +++ b/gisi/socket.h @@ -21,11 +21,7 @@ * */ -#ifndef OFONO_PHONET_SOCKET_H -#define OFONO_PHONET_SOCKET_H 1 - GIOChannel *phonet_new(uint8_t resource); -size_t phonet_peek_length(GIOChannel *); -ssize_t phonet_read(GIOChannel *, void *restrict, size_t, uint16_t *restrict, - uint8_t *restrict); -#endif +size_t phonet_peek_length(GIOChannel *io); +ssize_t phonet_read(GIOChannel *io, void *restrict buf, size_t len, + uint16_t *restrict obj, uint8_t *restrict res); diff --git a/isi/client.h b/isi/client.h deleted file mode 100644 index 0632fdc4..00000000 --- a/isi/client.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of oFono - Open Source Telephony - * - * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). - * - * Contact: Rémi Denis-Courmont - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA - * - */ - -#ifndef OFONO_PHONET_CLIENT_H -#define OFONO_PHONET_CLIENT_H 1 -#include -#include - -struct isi_client; -struct isi_client *isi_client_create(uint8_t resource); -void isi_client_destroy(struct isi_client *client); -int isi_client_error(const struct isi_client *client); - -typedef bool (*isi_client_cb_t)(struct isi_client *client, - const void *restrict data, size_t len, - uint16_t object, void *opaque); -struct isi_request; -struct isi_request *isi_request_make(struct isi_client *, const void *, size_t, - unsigned timeout, isi_client_cb_t, void *); -void isi_request_cancel(struct isi_request *req); - -typedef void (*isi_ind_cb_t) (struct isi_client *client, - const void *restrict data, size_t len, - uint16_t object, void *opaque); -int isi_subscribe(struct isi_client *client, uint8_t type, - isi_ind_cb_t, void *); -void isi_unsubscribe(struct isi_client *client, uint8_t type); -#endif