From 4b21faa82d105314c1b325b8ae0293f99b36ad2d Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Thu, 22 Jul 2010 17:59:57 +0000 Subject: [PATCH] Add pri_new_bri_cb() API - Create BRI D-channel with user defined I/O callbacks and data There currently exists a pri_new_cb() API call that allows you to create a PRI with user-defined I/O read and write callbacks, and option userdata. Add the same capability for BRI interfaces by adding a pri_new_bri_cb() API function. (closes issue #16477) Reported by: nic_bellamy Patches: pri_new_bri_cb_api.patch uploaded by nic bellamy (license 299) (with minor cosmetic changes) git-svn-id: https://origsvn.digium.com/svn/libpri/branches/1.4@1836 2fbb986a-6c06-0410-b554-c9c1f0a7f128 --- libpri.h | 3 +++ pri.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/libpri.h b/libpri.h index ba942dd..d8ea12f 100644 --- a/libpri.h +++ b/libpri.h @@ -1308,6 +1308,9 @@ struct pri *pri_new_bri(int fd, int ptpmode, int nodetype, int switchtype); /* Create D-channel just as above with user defined I/O callbacks and data */ struct pri *pri_new_cb(int fd, int nodetype, int switchtype, pri_io_cb io_read, pri_io_cb io_write, void *userdata); +/* Create BRI D-channel just as above with user defined I/O callbacks and data */ +struct pri *pri_new_bri_cb(int fd, int ptpmode, 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 */ void *pri_get_userdata(struct pri *pri); diff --git a/pri.c b/pri.c index d46740a..53aee0e 100644 --- a/pri.c +++ b/pri.c @@ -457,6 +457,21 @@ struct pri *pri_new_cb(int fd, int nodetype, int switchtype, pri_io_cb io_read, return __pri_new_tei(fd, nodetype, switchtype, NULL, io_read, io_write, userdata, Q921_TEI_PRI, 0); } +struct pri *pri_new_bri_cb(int fd, int ptpmode, 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; + } + if (ptpmode) { + return __pri_new_tei(fd, nodetype, switchtype, NULL, io_read, io_write, userdata, Q921_TEI_PRI, 1); + } else { + return __pri_new_tei(fd, nodetype, switchtype, NULL, io_read, io_write, userdata, Q921_TEI_GROUP, 1); + } +} + void *pri_get_userdata(struct pri *pri) { return pri ? pri->userdata : NULL;