[asterisk-commits] tzafrir: branch tzafrir/dahdi_name r190903 - /team/tzafrir/dahdi_name/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 28 12:29:54 CDT 2009


Author: tzafrir
Date: Tue Apr 28 12:29:50 2009
New Revision: 190903

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=190903
Log:
Allow defining DAHDI channels by name

Modified:
    team/tzafrir/dahdi_name/channels/chan_dahdi.c

Modified: team/tzafrir/dahdi_name/channels/chan_dahdi.c
URL: http://svn.digium.com/svn-view/asterisk/team/tzafrir/dahdi_name/channels/chan_dahdi.c?view=diff&rev=190903&r1=190902&r2=190903
==============================================================================
--- team/tzafrir/dahdi_name/channels/chan_dahdi.c (original)
+++ team/tzafrir/dahdi_name/channels/chan_dahdi.c Tue Apr 28 12:29:50 2009
@@ -1062,6 +1062,13 @@
 	 */
 	struct ast_variable *vars;
 	int channel;					/*!< Channel Number or CRV */
+	/*!
+	 * \brief The name of the file containing the device file
+	 * \note If empty, the channel number is used. Has a different meaning 
+	 *       in the channel than in config: in config it is a pattern.
+	 * \fixme make it a stringfield?
+	 */
+	char dev_file_name[AST_MAX_EXTENSION];
 	int span;					/*!< Span number */
 	time_t guardtime;				/*!< Must wait this much time before using for new call */
 	int cid_signalling;				/*!< CID signalling type bell202 or v23 */
@@ -9940,6 +9947,21 @@
 	return sigtype;
 }
 
+static void get_device_filename(int channel, 
+		const struct dahdi_chan_conf *conf, char* fn) {
+	if (!conf->chan.dev_file_name[0]) {
+		/* If file name is not used, just use a plain number */
+		snprintf(fn, 80, "%d", channel);
+		return;
+	}
+	/* replace patter in the file name with the exact name */
+	/* \todo: think of a useful pattern and implement it. For now we have: */
+	snprintf(fn, 80, "/dev/dahdi/%s_%d",
+			conf->chan.dev_file_name, channel);
+	return;
+
+}
+
 static struct dahdi_pvt *mkintf(int channel, const struct dahdi_chan_conf *conf, struct dahdi_pri *pri, int reloading)
 {
 	/* Make a dahdi_pvt structure for this interface (or CRV if "pri" is specified) */
@@ -10001,7 +10023,7 @@
 		if (!here) {
 			if ((channel != CHAN_PSEUDO) && !pri) {
 				int count = 0;
-				snprintf(fn, sizeof(fn), "%d", channel);
+				get_device_filename(channel, conf, fn);
 				/* Open non-blocking */
 				tmp->subs[SUB_REAL].dfd = dahdi_open(fn);
 				while (tmp->subs[SUB_REAL].dfd < 0 && reloading == 2 && count < 1000) { /* the kernel may not call dahdi_release fast enough for the open flagbit to be cleared in time */
@@ -10017,6 +10039,8 @@
 				}
 				memset(&p, 0, sizeof(p));
 				res = ioctl(tmp->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &p);
+				ast_log(LOG_NOTICE, "setting channel %d (%s)to %d\n", channel, fn, p.channo);
+				tmp->channel = p.channo;
 				if (res < 0) {
 					ast_log(LOG_ERROR, "Unable to get parameters: %s\n", strerror(errno));
 					destroy_dahdi_pvt(&tmp);
@@ -10032,6 +10056,7 @@
 				tmp->law = p.curlaw;
 				tmp->span = p.spanno;
 				span = p.spanno - 1;
+				ast_copy_string(tmp->dev_file_name, fn, sizeof(tmp->dev_file_name));
 			} else {
 				if (channel == CHAN_PSEUDO)
 					chan_sig = 0;
@@ -10414,7 +10439,6 @@
 		tmp->dtmfrelax = conf->chan.dtmfrelax;
 		tmp->callwaiting = tmp->permcallwaiting;
 		tmp->hidecallerid = tmp->permhidecallerid;
-		tmp->channel = channel;
 		tmp->stripmsd = conf->chan.stripmsd;
 		tmp->use_callerid = conf->chan.use_callerid;
 		tmp->cid_signalling = conf->chan.cid_signalling;
@@ -14872,6 +14896,7 @@
 #endif
 			ast_cli(a->fd, "Channel: %d\n", tmp->channel);
 			ast_cli(a->fd, "File Descriptor: %d\n", tmp->subs[SUB_REAL].dfd);
+			ast_cli(a->fd, "File Name: %s\n", tmp->dev_file_name);
 			ast_cli(a->fd, "Span: %d\n", tmp->span);
 			ast_cli(a->fd, "Extension: %s\n", tmp->exten);
 			ast_cli(a->fd, "Dialing: %s\n", tmp->dialing ? "yes" : "no");
@@ -16489,6 +16514,8 @@
 			confp->chan.callwaiting = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "callwaitingcallerid")) {
 			confp->chan.callwaitingcallerid = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "dev_pattern")) {
+			ast_copy_string(confp->chan.dev_file_name, v->value, sizeof(confp->chan.dev_file_name));
 		} else if (!strcasecmp(v->name, "context")) {
 			ast_copy_string(confp->chan.context, v->value, sizeof(confp->chan.context));
 		} else if (!strcasecmp(v->name, "language")) {




More information about the asterisk-commits mailing list