[Asterisk-cvs] asterisk/channels chan_skinny.c,1.5,1.6

jeremy at lists.digium.com jeremy at lists.digium.com
Sat Sep 13 19:04:28 CDT 2003


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv29526

Modified Files:
	chan_skinny.c 
Log Message:
implement reload


Index: chan_skinny.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_skinny.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- chan_skinny.c	13 Sep 2003 23:30:30 -0000	1.5
+++ chan_skinny.c	14 Sep 2003 00:05:37 -0000	1.6
@@ -526,17 +526,17 @@
 #define SKINNY_ALERT 36
 #define SKINNY_REORDER 37
 #define SKINNY_CALLWAITTONE 45
-
-#define SKINNY_LAMP_OFF 1
-#define SKINNY_LAMP_ON  2
-#define SKINNY_LAMP_WINK 3
-#define SKINNY_LAMP_FLASH 4
-#define SKINNY_LAMP_BLINK 5
-
-#define SKINNY_RING_OFF 1
-#define SKINNY_RING_INSIDE 2
-#define SKINNY_RING_OUTSIDE 3
-#define SKINNY_RING_FEATURE 4
+
+#define SKINNY_LAMP_OFF 1
+#define SKINNY_LAMP_ON  2
+#define SKINNY_LAMP_WINK 3
+#define SKINNY_LAMP_FLASH 4
+#define SKINNY_LAMP_BLINK 5
+
+#define SKINNY_RING_OFF 1
+#define SKINNY_RING_INSIDE 2
+#define SKINNY_RING_OUTSIDE 3
+#define SKINNY_RING_FEATURE 4
 
 #define TYPE_TRUNK		1
 #define TYPE_LINE		2
@@ -559,8 +559,8 @@
 #define SKINNY_CX_CONFERENCE 3
 #define SKINNY_CX_MUTE     4
 #define SKINNY_CX_INACTIVE 4
-
-#if 0
+
+#if 0
 static char *skinny_cxmodes[] = {
     "sendonly",
     "recvonly",
@@ -568,7 +568,7 @@
     "confrnce",
     "inactive"
 };
-#endif
+#endif
 
 /* driver scheduler */
 static struct sched_context *sched;
@@ -581,11 +581,11 @@
 /* Protect the monitoring thread, so only one process can kill or start it, and not
    when it's doing something critical. */
 static ast_mutex_t monlock	   = AST_MUTEX_INITIALIZER;
-/* Protect the network socket */
+/* Protect the network socket */
 static ast_mutex_t netlock	   = AST_MUTEX_INITIALIZER;
-/* Protect the session list */
-static ast_mutex_t sessionlock = AST_MUTEX_INITIALIZER;
-/* Protect the device list */
+/* Protect the session list */
+static ast_mutex_t sessionlock = AST_MUTEX_INITIALIZER;
+/* Protect the device list */
 static ast_mutex_t devicelock = AST_MUTEX_INITIALIZER;
 
 /* This is the thread for the monitor which checks for input on the channels
@@ -699,60 +699,60 @@
 	struct skinny_subchannel *sub = l->sub;
 	return sub;
 }
-
-static struct skinny_subchannel *find_subchannel_by_name(char *dest)
-{
-	struct skinny_line *l;
-	struct skinny_device *d;
-	char line[256];
-	char *at;
-	char *device;
-	
-	printf("dest: %s\n", dest);
-
-	strncpy(line, dest, sizeof(line) - 1);
-	at = strchr(line, '@');
-	if (!at) {
-		ast_log(LOG_NOTICE, "Device '%s' has no @ (at) sign!\n", dest);
-		return NULL;
-	}
-	*at = '\0';
-	at++;
-	device = at;
-
-	printf("line: %s\n", line);
-	printf("device: %s\n", device);
-	
-	ast_mutex_lock(&devicelock);
-	d = devices;
-	while(d) {
-		if (!strcasecmp(d->name, device)) {
-			if (skinnydebug) {
-				printf("Found device: %s\n", d->name);
-			}
-			/* Found the device */
-			l = d->lines;
-			while (l) {
-				/* Search for the right line */
-				if (!strcasecmp(l->name, line)) {
-					ast_mutex_unlock(&devicelock);
-					if (skinnydebug) {
-						printf("Found line: %s\n", l->name);
-					}
-					return l->sub;
-				}
-				printf("line cycle\n");
-				l = l->next;
-			}
-		}
-		printf("device cycle\n");
-		d = d->next;
-	}
-	/* Device not found*/
-	ast_mutex_unlock(&devicelock);
-	return NULL;
-}
-
+
+static struct skinny_subchannel *find_subchannel_by_name(char *dest)
+{
+	struct skinny_line *l;
+	struct skinny_device *d;
+	char line[256];
+	char *at;
+	char *device;
+	
+	printf("dest: %s\n", dest);
+
+	strncpy(line, dest, sizeof(line) - 1);
+	at = strchr(line, '@');
+	if (!at) {
+		ast_log(LOG_NOTICE, "Device '%s' has no @ (at) sign!\n", dest);
+		return NULL;
+	}
+	*at = '\0';
+	at++;
+	device = at;
+
+	printf("line: %s\n", line);
+	printf("device: %s\n", device);
+	
+	ast_mutex_lock(&devicelock);
+	d = devices;
+	while(d) {
+		if (!strcasecmp(d->name, device)) {
+			if (skinnydebug) {
+				printf("Found device: %s\n", d->name);
+			}
+			/* Found the device */
+			l = d->lines;
+			while (l) {
+				/* Search for the right line */
+				if (!strcasecmp(l->name, line)) {
+					ast_mutex_unlock(&devicelock);
+					if (skinnydebug) {
+						printf("Found line: %s\n", l->name);
+					}
+					return l->sub;
+				}
+				printf("line cycle\n");
+				l = l->next;
+			}
+		}
+		printf("device cycle\n");
+		d = d->next;
+	}
+	/* Device not found*/
+	ast_mutex_unlock(&devicelock);
+	return NULL;
+}
+
 static int transmit_response(struct skinnysession *s, skinny_req *req)
 {
 	int res = 0;
@@ -1432,52 +1432,52 @@
 
 static int skinny_call(struct ast_channel *ast, char *dest, int timeout)
 {
-	int res = 0;
+	int res = 0;
 	int tone = 0;
 	struct skinny_line *l;
-    struct skinny_subchannel *sub;
+    struct skinny_subchannel *sub;
 	struct skinnysession *session;
-	
-	if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
-		ast_log(LOG_WARNING, "skinny_call called on %s, neither down nor reserved\n", ast->name);
-		return -1;
-	}
-
+	
+	if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
+		ast_log(LOG_WARNING, "skinny_call called on %s, neither down nor reserved\n", ast->name);
+		return -1;
+	}
+
     if (skinnydebug) {
         ast_verbose(VERBOSE_PREFIX_3 "skinny_call(%s)\n", ast->name);
     }
 	
 	sub = ast->pvt->pvt;
-    l = sub->parent;
+    l = sub->parent;
 	session = l->parent->session;
-
-	if (l->dnd) {
-		ast_queue_control(ast, AST_CONTROL_BUSY, 0);
-		return 0;
-	}
-   
+
+	if (l->dnd) {
+		ast_queue_control(ast, AST_CONTROL_BUSY, 0);
+		return 0;
+	}
+   
 	switch (l->hookstate) {
         case SKINNY_OFFHOOK:
             tone = SKINNY_CALLWAITTONE;
             break;
-        case SKINNY_ONHOOK:
-			tone = SKINNY_ALERT;
+        case SKINNY_ONHOOK:
+			tone = SKINNY_ALERT;
 			break;
         default:
             ast_log(LOG_ERROR, "Don't know how to deal with hookstate %d\n", l->hookstate);
             break;
     }
-
-	transmit_lamp_indication(session, l->instance, SKINNY_LAMP_BLINK);
-	transmit_ringer_mode(session, SKINNY_RING_INSIDE);
-	transmit_tone(session, tone);
-	transmit_callstate(session, l->instance, SKINNY_RINGIN, sub->callid);
-
-// Set the prompt
-// Select the active softkeys
-
-	ast_setstate(ast, AST_STATE_RINGING);
-	ast_queue_control(ast, AST_CONTROL_RINGING, 0);
+
+	transmit_lamp_indication(session, l->instance, SKINNY_LAMP_BLINK);
+	transmit_ringer_mode(session, SKINNY_RING_INSIDE);
+	transmit_tone(session, tone);
+	transmit_callstate(session, l->instance, SKINNY_RINGIN, sub->callid);
+
+// Set the prompt
+// Select the active softkeys
+
+	ast_setstate(ast, AST_STATE_RINGING);
+	ast_queue_control(ast, AST_CONTROL_RINGING, 0);
 
 	sub->outgoing = 1;
 //    sub->cxmode = SKINNY_CX_RECVONLY;
@@ -1485,10 +1485,10 @@
         if (!sub->rtp) {
             start_rtp(sub);
         } else {
-			/* do we need to anything if there already is an RTP allocated? */
+			/* do we need to anything if there already is an RTP allocated? */
 //           transmit_modify_request(sub);
         }
-
+
 #if 0
         if (sub->next->owner && sub->next->callid) {
             /* try to prevent a callwait from disturbing the other connection */
@@ -1502,8 +1502,8 @@
             sub->next->cxmode = SKINNY_CX_SENDRECV;
 //           transmit_modify_request(sub->next);
         }
-#endif
-
+#endif
+
 	} else {
 		ast_log(LOG_NOTICE, "Don't know how to dial on trunks yet\n");
 		res = -1;
@@ -1693,7 +1693,7 @@
 	case AST_CONTROL_RINGING:
 		transmit_tone(s, SKINNY_ALERT);
 		transmit_callstate(s, l->instance, SKINNY_PROGRESS, sub->callid);
-		break;
+		break;
 	case AST_CONTROL_BUSY:
 		transmit_tone(s, SKINNY_BUSYTONE);
 		transmit_callstate(s, l->instance, SKINNY_BUSY, sub->callid);
@@ -1801,12 +1801,12 @@
 	time_t timer;
 	struct tm *cmtime;
 	pthread_t t;
-	
-	if ( (!s->device) && (req->e != REGISTER_MESSAGE && req->e != ALARM_MESSAGE)) {
-		ast_log(LOG_WARNING, "Client sent message #%d without first registering.\n", req->e);
-		free(req);
-		return 0;
-	}
+	
+	if ( (!s->device) && (req->e != REGISTER_MESSAGE && req->e != ALARM_MESSAGE)) {
+		ast_log(LOG_WARNING, "Client sent message #%d without first registering.\n", req->e);
+		free(req);
+		return 0;
+	}
 
 		
 	switch(req->e)	{
@@ -2049,14 +2049,14 @@
 		}
 		sub->parent->hookstate = SKINNY_OFFHOOK;
 		
-			if (sub->outgoing) {
-				transmit_callstate(s, s->device->lines->instance, SKINNY_OFFHOOK, sub->callid);
-				transmit_tone(s, SKINNY_SILENCE);
-				ast_setstate(sub->owner, AST_STATE_UP);
+			if (sub->outgoing) {
+				transmit_callstate(s, s->device->lines->instance, SKINNY_OFFHOOK, sub->callid);
+				transmit_tone(s, SKINNY_SILENCE);
+				ast_setstate(sub->owner, AST_STATE_UP);
 				// select soft keys
 			} else { 	
-				if (!sub->owner) {	
-
+				if (!sub->owner) {	
+
 					transmit_callstate(s, s->device->lines->instance, SKINNY_OFFHOOK, sub->callid);
 					transmit_tone(s, SKINNY_DIALTONE);
 					c = skinny_new(sub, AST_STATE_DOWN);			
@@ -2072,7 +2072,7 @@
 				
 				} else {
 					ast_log(LOG_DEBUG, "Current sub [%s] already has owner\n", sub->owner->name);
-				}
+				}
 			}
 		break;
 	case ONHOOK_MESSAGE:
@@ -2232,21 +2232,21 @@
  
 	res = ast_select(s->fd + 1, &fds, NULL, NULL, NULL);  
  
-	if (res < 0) {
-		ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
+	if (res < 0) {
+		ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
  	} else if (res > 0) {
 		memset(s->inbuf,0,sizeof(s->inbuf));
-		res = read(s->fd, s->inbuf, 4);
-		if (res != 4) {
-			ast_log(LOG_WARNING, "Skinny Client sent less data than expected.\n");
-			return -1;
-		}
-		dlen = *(int *)s->inbuf;
-		res = read(s->fd, s->inbuf+4, dlen+4);
-		ast_mutex_unlock(&s->lock);
-		if (res != (dlen+4)) {
-			ast_log(LOG_WARNING, "Skinny Client sent less data than expected.\n");
-			return -1;
+		res = read(s->fd, s->inbuf, 4);
+		if (res != 4) {
+			ast_log(LOG_WARNING, "Skinny Client sent less data than expected.\n");
+			return -1;
+		}
+		dlen = *(int *)s->inbuf;
+		res = read(s->fd, s->inbuf+4, dlen+4);
+		ast_mutex_unlock(&s->lock);
+		if (res != (dlen+4)) {
+			ast_log(LOG_WARNING, "Skinny Client sent less data than expected.\n");
+			return -1;
 		} 
  
 	}  
@@ -2267,7 +2267,7 @@
 	memcpy(req, s->inbuf, *(int*)(s->inbuf)+8); // +8
 	if (req->e < 0) {
 		ast_log(LOG_ERROR, "Event Message is NULL from socket %d, This is bad\n", s->fd);
-		free(req);
+		free(req);
 		return NULL;
 	}
 	return req;
@@ -2422,9 +2422,9 @@
 	int oldformat;
 	struct skinny_subchannel *sub;
 	struct ast_channel *tmpc = NULL;
-	char tmp[256];
-	char *dest = data;
-
+	char tmp[256];
+	char *dest = data;
+
 	oldformat = format;
 	format &= capability;
 	if (!format) {
@@ -2432,11 +2432,11 @@
 		return NULL;
 	}
 	
-	strncpy(tmp, dest, sizeof(tmp) - 1);
-	if (!strlen(tmp)) {
-		ast_log(LOG_NOTICE, "Skinny channels require a device\n");
-		return NULL;
-	}
+	strncpy(tmp, dest, sizeof(tmp) - 1);
+	if (!strlen(tmp)) {
+		ast_log(LOG_NOTICE, "Skinny channels require a device\n");
+		return NULL;
+	}
 	
 	sub = find_subchannel_by_name(tmp);  
 	if (!sub) {
@@ -2600,7 +2600,46 @@
 
 	return 0;
 }
+
+void delete_devices(void)
+{
+	struct skinny_device *d, *dlast;
+	struct skinny_line *l, *llast;
+	struct skinny_subchannel *sub, *slast;
+	
+	ast_mutex_lock(&devicelock);
+	
+	/* Delete all devices */
+	for (d=devices;d;) {
+		
+		/* Delete all lines for this device */
+		for (l=d->lines;l;) {
+			/* Delete all subchannels for this line */
+			for (sub=l->sub;sub;) {
+				slast = sub;
+				sub = sub->next;
+				free(slast);
+			}
+			llast = l;
+			l = l->next;
+			free(llast);
+		}
+		dlast = d;
+		d = d->next;
+		free(dlast);
+	}
+	devices=NULL;
+	ast_mutex_unlock(&devicelock);
+}
 
+int reload(void)
+{
+	delete_devices();
+	reload_config();
+	restart_monitor();
+	return 0;
+}
+
 
 int load_module()
 {




More information about the svn-commits mailing list