added EVENT_NEW_CHANNEL. We change the channel name now when we got the real channel...
authorChristian Richter <christian.richter@beronet.com>
Wed, 24 May 2006 23:21:03 +0000 (23:21 +0000)
committerChristian Richter <christian.richter@beronet.com>
Wed, 24 May 2006 23:21:03 +0000 (23:21 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@30132 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_misdn.c
channels/misdn/isdn_lib.c
channels/misdn/isdn_lib.h
channels/misdn/isdn_msg_parser.c

index 9989f98..6e97289 100644 (file)
@@ -2588,6 +2588,21 @@ static struct ast_channel_tech misdn_tech_wo_bridge = {
 
 static unsigned long glob_channel=0;
 
+static void update_name(struct ast_channel *tmp, int port, int c) 
+{
+       if (c<=0) {
+                       c=glob_channel++;
+                       ast_string_field_build(tmp, name, "%s/%d-u%d",
+                                misdn_type, port, c);
+       } else {
+                        ast_string_field_build(tmp, name, "%s/%d-%d",
+                                misdn_type, port, c);
+       }
+
+       chan_misdn_log(3,port," --> updating channel name to [%s]\n",tmp->name);
+       
+}
+
 static struct ast_channel *misdn_new(struct chan_list *chlist, int state,  char *exten, char *callerid, int format, int port, int c)
 {
        struct ast_channel *tmp;
@@ -2597,16 +2612,8 @@ static struct ast_channel *misdn_new(struct chan_list *chlist, int state,  char
        if (tmp) {
                chan_misdn_log(2, 0, " --> * NEW CHANNEL dad:%s oad:%s\n",exten,callerid);
                
-               
-               if (c<=0) {
-                       c=glob_channel++;
-                       ast_string_field_build(tmp, name, "%s/%d-u%d",
-                                misdn_type, port, c);
-               } else {
-                       ast_string_field_build(tmp, name, "%s/%d-%d",
-                                misdn_type, port, c);
-               }
-               
+               update_name(tmp,port,c);
+       
                tmp->nativeformats = prefformat;
 
                tmp->readformat = format;
@@ -3099,10 +3106,13 @@ cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data)
        
        
        switch (event) {
-
+               
        case EVENT_BCHAN_ACTIVATED:
                break;
                
+       case EVENT_NEW_CHANNEL:
+               update_name(ch->ast,bc->port,bc->channel);
+               break;
                
        case EVENT_NEW_L3ID:
                ch->l3id=bc->l3_id;
@@ -3421,6 +3431,10 @@ cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data)
        case EVENT_SETUP_ACKNOWLEDGE:
        {
                ch->state = MISDN_CALLING_ACKNOWLEDGE;
+
+               if (bc->channel) 
+                       update_name(ch->ast,bc->port,bc->channel);
+               
                if (!ast_strlen_zero(bc->infos_pending)) {
                        /* TX Pending Infos */
                        
index 9cb689c..a969d11 100644 (file)
@@ -370,7 +370,7 @@ void dump_chan_list(struct misdn_stack *stack)
 
 
 
-static int find_free_chan_in_stack(struct misdn_stack *stack, int channel)
+static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchannel *bc, int channel)
 {
        int i;
 
@@ -386,6 +386,8 @@ static int find_free_chan_in_stack(struct misdn_stack *stack, int channel)
                        if (!stack->channels[i]) {
                                cb_log (4, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
                                stack->channels[i] = 1;
+                               bc->channel=i+1;
+                               cb_event(EVENT_NEW_CHANNEL, bc, NULL);
                                return i+1;
                        }
                }
@@ -772,9 +774,9 @@ static int create_process (int midev, struct misdn_bchannel *bc) {
        int free_chan;
   
        if (stack->nt) {
-               free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0);
+               free_chan = find_free_chan_in_stack(stack, bc, bc->channel_preselected?bc->channel:0);
                if (!free_chan) return -1;
-               bc->channel=free_chan;
+               /*bc->channel=free_chan;*/
                
                cb_log(4,stack->port, " -->  found channel: %d\n",free_chan);
     
@@ -805,9 +807,9 @@ static int create_process (int midev, struct misdn_bchannel *bc) {
        } else { 
                if (stack->ptp || bc->te_choose_channel) {
                        /* we know exactly which channels are in use */
-                       free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0);
+                       free_chan = find_free_chan_in_stack(stack, bc, bc->channel_preselected?bc->channel:0);
                        if (!free_chan) return -1;
-                       bc->channel=free_chan;
+                       /*bc->channel=free_chan;*/
                        cb_log(0,stack->port, " -->  found channel: %d\n",free_chan);
                } else {
                        /* other phones could have made a call also on this port (ptmp) */
@@ -1397,7 +1399,7 @@ int handle_event ( struct misdn_bchannel *bc, enum event_e event, iframe_t *frm)
                        
                {
                        if (bc->channel == 0xff) {
-                               bc->channel=find_free_chan_in_stack(stack, 0);
+                               bc->channel=find_free_chan_in_stack(stack, bc,  0);
                                if (!bc->channel) {
                                        cb_log(-1, stack->port, "Any Channel Requested, but we have no more!!\n");
                                        break;
@@ -2877,7 +2879,7 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
        case EVENT_RETRIEVE_ACKNOWLEDGE:
                if (stack->nt) {
                        if (bc->channel <=0 ) { /*  else we have the channel already */
-                               bc->channel = find_free_chan_in_stack(stack, 0);
+                               bc->channel = find_free_chan_in_stack(stack, bc, 0);
                                if (!bc->channel) {
                                        cb_log(-1, stack->port, " No free channel at the moment\n");
                                        
index 26e6187..98c40b0 100644 (file)
@@ -100,6 +100,7 @@ enum event_e {
        EVENT_DTMF_TONE,
        EVENT_NEW_L3ID,
        EVENT_NEW_BC,
+       EVENT_NEW_CHANNEL,
        EVENT_UNKNOWN
 }; 
 
index 2fb43eb..0d5fb9f 100644 (file)
@@ -39,11 +39,14 @@ void set_channel(struct misdn_bchannel *bc, int channel) {
                        cb_log(0,bc->port,"We already have a channel (%d)\n", bc->channel);
                } else {
                        bc->channel = channel;
+                       cb_event(EVENT_NEW_CHANNEL,bc,NULL);
                }
        }
        
-       if (channel > 0 && !bc->nt ) 
+       if (channel > 0 && !bc->nt ) {
                bc->channel = channel;
+               cb_event(EVENT_NEW_CHANNEL,bc,NULL);
+       }
 }
 
 void parse_proceeding (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
@@ -1206,6 +1209,7 @@ char EVENT_CLEAN_INFO[] = "CLEAN_UP";
 char EVENT_DTMF_TONE_INFO[] = "DTMF_TONE";
 char EVENT_NEW_L3ID_INFO[] = "NEW_L3ID";
 char EVENT_NEW_BC_INFO[] = "NEW_BC";
+char EVENT_NEW_CHANNEL_INFO[] = "NEW_CHANNEL";
 char EVENT_BCHAN_DATA_INFO[] = "BCHAN_DATA";
 char EVENT_BCHAN_ACTIVATED_INFO[] = "BCHAN_ACTIVATED";
 char EVENT_TONE_GENERATE_INFO[] = "TONE_GENERATE";
@@ -1220,6 +1224,7 @@ char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt)
        if (event == EVENT_DTMF_TONE) return EVENT_DTMF_TONE_INFO;
        if (event == EVENT_NEW_L3ID) return EVENT_NEW_L3ID_INFO;
        if (event == EVENT_NEW_BC) return EVENT_NEW_BC_INFO;
+       if (event == EVENT_NEW_CHANNEL) return EVENT_NEW_CHANNEL_INFO;
        if (event == EVENT_BCHAN_DATA) return EVENT_BCHAN_DATA_INFO;
        if (event == EVENT_BCHAN_ACTIVATED) return EVENT_BCHAN_ACTIVATED_INFO;
        if (event == EVENT_TONE_GENERATE) return EVENT_TONE_GENERATE_INFO;