Rename ISI client and PhoNet netlink APIs

- Add g_ prefix to functions
- Add G-prefix and use CamelCasing in types
This commit is contained in:
Aki Niemi 2009-06-15 11:17:30 +03:00
parent 3a28213072
commit e5f0290ddb
10 changed files with 146 additions and 116 deletions

View File

@ -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 DISTCHECK_CONFIGURE_FLAGS = --disable-datafiles

View File

@ -86,7 +86,7 @@ AM_CONDITIONAL(DATAFILES, test "${enable_datafiles}" != "no")
COMPILER_FLAGS 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 include/Makefile include/version.h src/Makefile
plugins/Makefile drivers/Makefile unit/Makefile plugins/Makefile drivers/Makefile unit/Makefile
doc/Makefile) doc/Makefile)

View File

@ -38,7 +38,7 @@
#include "socket.h" #include "socket.h"
#include "client.h" #include "client.h"
struct isi_client { struct _GIsiClient {
uint8_t resource; uint8_t resource;
/* Requests */ /* Requests */
@ -46,7 +46,7 @@ struct isi_client {
guint source; guint source;
uint8_t prev[256], next[256]; uint8_t prev[256], next[256];
guint timeout[256]; guint timeout[256];
isi_client_cb_t func[256]; GIsiResponseFunc func[256];
void *data[256]; void *data[256];
/* Indications */ /* Indications */
@ -54,27 +54,28 @@ struct isi_client {
int fd; int fd;
guint source; guint source;
uint16_t count; uint16_t count;
isi_ind_cb_t func[256]; GIsiIndicationFunc func[256];
void *data[256]; void *data[256];
} ind; } ind;
}; };
static gboolean isi_callback(GIOChannel *, GIOCondition, gpointer); static gboolean g_isi_callback(GIOChannel *channel, GIOCondition cond,
static gboolean isi_timeout(gpointer); 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; 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 * @param resource Phonet resource ID for the client
* @return NULL on error (see errno), an isi_client pointer on success, * @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; void *ptr;
struct isi_client *cl; GIsiClient *cl;
GIOChannel *channel; GIOChannel *channel;
unsigned i; 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->fd = g_io_channel_unix_get_fd(channel);
cl->source = g_io_add_watch(channel, cl->source = g_io_add_watch(channel,
G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL, G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
isi_callback, cl); g_isi_callback, cl);
g_io_channel_unref(channel); g_io_channel_unref(channel);
return cl; 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. * Destroys an ISI client, cancels all pending transactions and subscriptions.
* @param client client to destroy * @param client client to destroy
*/ */
void isi_client_destroy(struct isi_client *client) void g_isi_client_destroy(GIsiClient *client)
{ {
unsigned id; 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 * Make an ISI request and register a callback to process the response(s) to
* the resulting transaction. * 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 buf pointer to request payload
* @param len request payload byte length * @param len request payload byte length
* @param cb callback to process response(s) * @param cb callback to process response(s)
* @param opaque data for the callback * @param opaque data for the callback
*/ */
struct isi_request *isi_request_make(struct isi_client *cl, GIsiRequest *g_isi_request_make(GIsiClient *cl, const void *__restrict buf,
const void *__restrict buf, size_t len, size_t len, unsigned timeout,
unsigned timeout, GIsiResponseFunc cb, void *opaque)
isi_client_cb_t cb, void *opaque)
{ {
struct iovec iov[2]; struct iovec iov[2];
ssize_t ret; ssize_t ret;
@ -192,10 +192,10 @@ struct isi_request *isi_request_make(struct isi_client *cl,
if (timeout > 0) if (timeout > 0)
cl->timeout[id] = g_timeout_add_seconds(timeout, cl->timeout[id] = g_timeout_add_seconds(timeout,
isi_timeout, cl); g_isi_timeout, cl);
else else
cl->timeout[id] = 0; 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. * timeout.
* @param req request to cancel * @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); GIsiClient *cl = g_isi_cl(req);
uint8_t id = isi_id(req); uint8_t id = g_isi_id(req);
cl->func[id] = NULL; cl->func[id] = NULL;
cl->data[id] = NULL; cl->data[id] = NULL;
@ -229,7 +229,7 @@ void isi_request_cancel(struct isi_request *req)
#define PN_COMMGR 0x10 #define PN_COMMGR 0x10
#define PNS_SUBSCRIBED_RESOURCES_IND 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[] = { uint8_t msg[] = {
0, PNS_SUBSCRIBED_RESOURCES_IND, 1, cl->resource, 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); send(cl->ind.fd, msg, 4, 0);
cl->ind.source = g_io_add_watch(channel, cl->ind.source = g_io_add_watch(channel,
G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL, G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
isi_callback, cl); g_isi_callback, cl);
return 0; return 0;
} }
static void isi_indication_deinit(struct isi_client *client) static void g_isi_indication_deinit(GIsiClient *client)
{ {
uint8_t msg[] = { uint8_t msg[] = {
0, PNS_SUBSCRIBED_RESOURCES_IND, 0, 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 * 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 * is associated with. If the same type was already subscrived, the old
* subscription is overriden. * 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 type indication type
* @param cb callback to process received indications * @param cb callback to process received indications
* @param data data for the callback * @param data data for the callback
* @return 0 on success, a system error code otherwise. * @return 0 on success, a system error code otherwise.
*/ */
int isi_subscribe(struct isi_client *cl, uint8_t type, int g_isi_subscribe(GIsiClient *cl, uint8_t type,
isi_ind_cb_t cb, void *data) GIsiIndicationFunc cb, void *data)
{ {
if (cb == NULL) if (cb == NULL)
return EINVAL; return EINVAL;
if (cl->ind.func[type] == NULL) { if (cl->ind.func[type] == NULL) {
if (cl->ind.count == 0) { if (cl->ind.count == 0) {
int ret = isi_indication_init(cl); int ret = g_isi_indication_init(cl);
if (ret) if (ret)
return ret; return ret;
} }
@ -289,24 +289,24 @@ int isi_subscribe(struct isi_client *cl, uint8_t type,
/** /**
* Unsubscribe from a given indication 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. * @param type indication type.
*/ */
void isi_unsubscribe(struct isi_client *client, uint8_t type) void g_isi_unsubscribe(GIsiClient *client, uint8_t type)
{ {
/* Unsubscribe */ /* Unsubscribe */
if (client->ind.func[type] == NULL) if (client->ind.func[type] == NULL)
return; return;
client->ind.func[type] = NULL; client->ind.func[type] = NULL;
if (--client->ind.count == 0) if (--client->ind.count == 0)
isi_indication_deinit(client); g_isi_indication_deinit(client);
} }
/* Data callback for both responses and indications */ /* 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) gpointer data)
{ {
struct isi_client *cl = data; GIsiClient *cl = data;
int fd = g_io_channel_unix_get_fd(channel); int fd = g_io_channel_unix_get_fd(channel);
bool indication = (fd != cl->fd); bool indication = (fd != cl->fd);
int len; int len;
@ -336,25 +336,25 @@ static gboolean isi_callback(GIOChannel *channel, GIOCondition cond,
return TRUE; /* Bad transaction ID */ return TRUE; /* Bad transaction ID */
if ((cl->func[id])(cl, buf + 1, len - 1, obj, if ((cl->func[id])(cl, buf + 1, len - 1, obj,
cl->data[id])) cl->data[id]))
isi_request_cancel(isi_req(cl, id)); g_isi_request_cancel(g_isi_req(cl, id));
} }
} }
return TRUE; return TRUE;
} }
static gboolean isi_timeout(gpointer data) static gboolean g_isi_timeout(gpointer data)
{ {
struct isi_request *req = data; GIsiRequest *req = data;
struct isi_client *cl = isi_cl(req); GIsiClient *cl = g_isi_cl(req);
uint8_t id = isi_id(req); uint8_t id = g_isi_id(req);
assert(cl->func[id]); assert(cl->func[id]);
(cl->func[id])(cl, NULL, 0, 0, cl->data[id]); (cl->func[id])(cl, NULL, 0, 0, cl->data[id]);
isi_request_cancel(req); g_isi_request_cancel(req);
return FALSE; 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 */ { /* The only possible error at the moment */
return ETIMEDOUT; return ETIMEDOUT;
} }

69
gisi/client.h Normal file
View File

@ -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 <remi.denis-courmont@nokia.com>
*
* 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 <stdint.h>
#include <stdbool.h>
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 */

View File

@ -45,14 +45,14 @@
#include "netlink.h" #include "netlink.h"
struct pn_netlink { struct _GPhonetNetlink {
pn_netlink_cb_t callback; GPhonetNetlinkFunc callback;
void *opaque; void *opaque;
guint watch; guint watch;
}; };
/* Parser Netlink messages */ /* Parser Netlink messages */
static gboolean pn_nl_process(GIOChannel *channel, GIOCondition cond, static gboolean g_pn_nl_process(GIOChannel *channel, GIOCondition cond,
gpointer data) gpointer data)
{ {
struct { struct {
@ -65,7 +65,7 @@ static gboolean pn_nl_process(GIOChannel *channel, GIOCondition cond,
ssize_t ret; ssize_t ret;
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
int fd = g_io_channel_unix_get_fd(channel); 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)) if (cond & (G_IO_NVAL|G_IO_HUP))
return FALSE; return FALSE;
@ -117,7 +117,7 @@ static gboolean pn_nl_process(GIOChannel *channel, GIOCondition cond,
} }
/* Dump current Phonet address table */ /* Dump current Phonet address table */
static int pn_netlink_query(int fd) static int g_pn_netlink_query(int fd)
{ {
struct { struct {
struct nlmsghdr nlh; struct nlmsghdr nlh;
@ -148,10 +148,10 @@ static int pn_netlink_query(int fd)
return 0; 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; GIOChannel *chan;
struct pn_netlink *self; GPhonetNetlink *self;
unsigned group = RTNLGRP_PHONET_IFADDR; unsigned group = RTNLGRP_PHONET_IFADDR;
int fd; 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, if (setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP,
&group, sizeof(group))) &group, sizeof(group)))
goto error; goto error;
pn_netlink_query(fd); g_pn_netlink_query(fd);
chan = g_io_channel_unix_new(fd); chan = g_io_channel_unix_new(fd);
if (chan == NULL) if (chan == NULL)
@ -179,7 +179,7 @@ struct pn_netlink *pn_netlink_start(pn_netlink_cb_t cb, void *opaque)
self->callback = cb; self->callback = cb;
self->opaque = opaque; self->opaque = opaque;
self->watch = g_io_add_watch(chan, G_IO_IN|G_IO_ERR|G_IO_HUP, 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); g_io_channel_unref(chan);
return 0; return 0;
@ -190,7 +190,7 @@ error:
return NULL; return NULL;
} }
void pn_netlink_stop(struct pn_netlink *self) void g_pn_netlink_stop(GPhonetNetlink *self)
{ {
g_source_remove(self->watch); g_source_remove(self->watch);
g_free(self); g_free(self);

View File

@ -21,14 +21,27 @@
* *
*/ */
#ifndef OFONO_PHONET_NETLINK_H
#define OFONO_PHONET_NETLINK_H 1
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
struct pn_netlink; #ifndef __GPHONET_NETLINK_H
typedef void (*pn_netlink_cb_t)(bool, uint8_t, unsigned, void *); #define __GPHONET_NETLINK_H
struct pn_netlink *pn_netlink_start(pn_netlink_cb_t, void *); #ifdef __cplusplus
void pn_netlink_stop(struct pn_netlink *self); extern "C" {
#endif #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 */

View File

@ -21,11 +21,7 @@
* *
*/ */
#ifndef OFONO_PHONET_SOCKET_H
#define OFONO_PHONET_SOCKET_H 1
GIOChannel *phonet_new(uint8_t resource); GIOChannel *phonet_new(uint8_t resource);
size_t phonet_peek_length(GIOChannel *); size_t phonet_peek_length(GIOChannel *io);
ssize_t phonet_read(GIOChannel *, void *restrict, size_t, uint16_t *restrict, ssize_t phonet_read(GIOChannel *io, void *restrict buf, size_t len,
uint8_t *restrict); uint16_t *restrict obj, uint8_t *restrict res);
#endif

View File

@ -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 <remi.denis-courmont@nokia.com>
*
* 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 <stdint.h>
#include <stdbool.h>
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