[Asterisk-cvs] libpri libpri.h, 1.43, 1.44 pri.c, 1.32,
1.33 pri_internal.h, 1.17, 1.18 q921.c, 1.19, 1.20 q931.c,
1.118, 1.119
markster at lists.digium.com
markster at lists.digium.com
Thu Mar 17 09:50:59 CST 2005
- Previous message: [Asterisk-cvs] asterisk/codecs Makefile,1.24.2.1,1.24.2.2
- Next message: [Asterisk-cvs] asterisk/configs enum.conf.sample, 1.3,
1.4 extensions.conf.sample, 1.37, 1.38 iax.conf.sample, 1.42,
1.43 logger.conf.sample, 1.10, 1.11 manager.conf.sample, 1.4,
1.5 meetme.conf.sample, 1.3, 1.4 sip.conf.sample, 1.59,
1.60 zapata.conf.sample, 1.40, 1.41
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /usr/cvsroot/libpri
In directory mongoose.digium.com:/tmp/cvs-serv31800
Modified Files:
libpri.h pri.c pri_internal.h q921.c q931.c
Log Message:
Allow PRI to support callback functions (Diana's patch, placed in public domain)
Index: libpri.h
===================================================================
RCS file: /usr/cvsroot/libpri/libpri.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- libpri.h 2 Mar 2005 16:03:22 -0000 1.43
+++ libpri.h 17 Mar 2005 15:46:23 -0000 1.44
@@ -376,6 +376,9 @@
struct pri;
struct pri_sr;
+#define PRI_IO_FUNCS
+/* Type declaration for callbacks to read or write a HDLC frame as below */
+typedef int (*pri_io_cb)(struct pri *pri, void *buf, int buflen);
/* Create a D-channel on a given file descriptor. The file descriptor must be a
channel operating in HDLC mode with FCS computed by the fd's driver. Also it
@@ -383,6 +386,15 @@
must be one of PRI_NETWORK or PRI_CPE. switchtype should be PRI_SWITCH_* */
extern struct pri *pri_new(int fd, int nodetype, int switchtype);
+/* Create D-channel just as above with user defined I/O callbacks and data */
+extern struct pri *pri_new_cb(int fd, int nodetype, int switchtype, pri_io_cb io_read, pri_io_cb io_write, void *userdata);
+
+/* Retrieve the user data associated with the D channel */
+extern void *pri_get_userdata(struct pri *pri);
+
+/* Set the user data associated with the D channel */
+extern void pri_set_userdata(struct pri *pri, void *userdata);
+
/* Set Network Specific Facility for PRI */
extern void pri_set_nsf(struct pri *pri, int nsf);
Index: pri.c
===================================================================
RCS file: /usr/cvsroot/libpri/pri.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- pri.c 2 Mar 2005 15:56:11 -0000 1.32
+++ pri.c 17 Mar 2005 15:46:23 -0000 1.33
@@ -153,13 +153,38 @@
return -1;
}
-static struct pri *__pri_new(int fd, int node, int switchtype, struct pri *master)
+static int __pri_read(struct pri *pri, void *buf, int buflen)
+{
+ int res = read(pri->fd, buf, buflen);
+ if (res < 0) {
+ if (errno != EAGAIN)
+ pri_error("Read on %d failed: %s\n", pri->fd, strerror(errno));
+ return 0;
+ }
+ return res;
+}
+
+static int __pri_write(struct pri *pri, void *buf, int buflen)
+{
+ int res = write(pri->fd, buf, buflen);
+ if (res < 0) {
+ if (errno != EAGAIN)
+ pri_error("Write to %d failed: %s\n", pri->fd, strerror(errno));
+ return 0;
+ }
+ return res;
+}
+
+static struct pri *__pri_new(int fd, int node, int switchtype, struct pri *master, pri_io_cb rd, pri_io_cb wr, void *userdata)
{
struct pri *p;
p = malloc(sizeof(struct pri));
if (p) {
memset(p, 0, sizeof(struct pri));
p->fd = fd;
+ p->read_func = rd;
+ p->write_func = wr;
+ p->userdata = userdata;
p->localtype = node;
p->switchtype = switchtype;
p->cref = 1;
@@ -180,7 +205,7 @@
p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
p->sapi = Q921_SAPI_GR303_EOC;
p->tei = Q921_TEI_GR303_EOC_OPS;
- p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_EOC_PATH, p);
+ p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_EOC_PATH, p, NULL, NULL, NULL);
if (!p->subchannel) {
free(p);
p = NULL;
@@ -189,7 +214,7 @@
p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
p->sapi = Q921_SAPI_GR303_TMC_CALLPROC;
p->tei = Q921_TEI_GR303_TMC_CALLPROC;
- p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_TMC_SWITCHING, p);
+ p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_TMC_SWITCHING, p, NULL, NULL, NULL);
if (!p->subchannel) {
free(p);
p = NULL;
@@ -210,9 +235,29 @@
return p;
}
-struct pri *pri_new(int fd, int node, int switchtype)
+struct pri *pri_new(int fd, int nodetype, int switchtype)
{
- return __pri_new(fd, node, switchtype, NULL);
+ return __pri_new(fd, nodetype, switchtype, NULL, __pri_read, __pri_write, NULL);
+}
+
+struct pri *pri_new_cb(int fd, int nodetype, int switchtype, pri_io_cb io_read, pri_io_cb io_write, void *userdata)
+{
+ if (!io_read)
+ io_read = __pri_read;
+ if (!io_write)
+ io_write = __pri_write;
+ return __pri_new(fd, nodetype, switchtype, NULL, io_read, io_write, userdata);
+}
+
+void *pri_get_userdata(struct pri *pri)
+{
+ return pri ? pri->userdata : NULL;
+}
+
+void pri_set_userdata(struct pri *pri, void *userdata)
+{
+ if (pri)
+ pri->userdata = userdata;
}
void pri_set_nsf(struct pri *pri, int nsf)
@@ -268,12 +313,7 @@
char buf[1024];
int res;
pri_event *e;
- res = read(pri->fd, buf, sizeof(buf));
- if (res < 0) {
- if (errno != EAGAIN)
- pri_error("Read on %d failed: %s\n", pri->fd, strerror(errno));
- return NULL;
- }
+ res = pri->read_func ? pri->read_func(pri, buf, sizeof(buf)) : 0;
if (!res)
return NULL;
/* Receive the q921 packet */
Index: pri_internal.h
===================================================================
RCS file: /usr/cvsroot/libpri/pri_internal.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- pri_internal.h 2 Mar 2005 15:56:11 -0000 1.17
+++ pri_internal.h 17 Mar 2005 15:46:23 -0000 1.18
@@ -44,6 +44,9 @@
struct pri {
int fd; /* File descriptor for D-Channel */
+ pri_io_cb read_func; /* Read data callback */
+ pri_io_cb write_func; /* Write data callback */
+ void *userdata;
struct pri *subchannel; /* Sub-channel if appropriate */
struct pri *master; /* Master channel if appropriate */
struct pri_sched pri_sched[MAX_SCHED]; /* Scheduled events */
Index: q921.c
===================================================================
RCS file: /usr/cvsroot/libpri/q921.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- q921.c 15 Dec 2004 20:15:28 -0000 1.19
+++ q921.c 17 Mar 2005 15:46:23 -0000 1.20
@@ -83,7 +83,7 @@
if (pri->debug & PRI_DEBUG_Q921_DUMP)
q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1);
/* Write an extra two bytes for the FCS */
- res = write(pri->fd, h, len + 2);
+ res = pri->write_func ? pri->write_func(pri, h, len + 2) : 0;
if (res != (len + 2)) {
pri_error("Short write: %d/%d (%s)\n", res, len + 2, strerror(errno));
return -1;
Index: q931.c
===================================================================
RCS file: /usr/cvsroot/libpri/q931.c,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- q931.c 4 Mar 2005 15:56:37 -0000 1.118
+++ q931.c 17 Mar 2005 15:46:23 -0000 1.119
@@ -1929,10 +1929,10 @@
}
if (len == 3) /* No number information */
return 0;
+ value = 0;
switch(type) {
/* Integer value handling */
case 4: /* Info Digits */
- value = 0;
for(idx = 3; idx < len; ++idx) {
switch(encoding) {
case 0: /* BCD even */
- Previous message: [Asterisk-cvs] asterisk/codecs Makefile,1.24.2.1,1.24.2.2
- Next message: [Asterisk-cvs] asterisk/configs enum.conf.sample, 1.3,
1.4 extensions.conf.sample, 1.37, 1.38 iax.conf.sample, 1.42,
1.43 logger.conf.sample, 1.10, 1.11 manager.conf.sample, 1.4,
1.5 meetme.conf.sample, 1.3, 1.4 sip.conf.sample, 1.59,
1.60 zapata.conf.sample, 1.40, 1.41
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the svn-commits
mailing list