Issue 9477 - Improve menuselect labels
[asterisk/asterisk.git] / channels / chan_vpb.cc
index d615e60..3cacf03 100644 (file)
@@ -53,6 +53,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/callerid.h"
 #include "asterisk/dsp.h"
 #include "asterisk/features.h"
+#include "asterisk/musiconhold.h"
 }
 
 #include <sys/socket.h>
@@ -104,14 +105,11 @@ static char context[AST_MAX_EXTENSION] = "default";
 
 /* Default language */
 static char language[MAX_LANGUAGE] = "";
-static int usecnt =0;
 
 static int gruntdetect_timeout = 3600000; /* Grunt detect timeout is 1hr. */
 
 static const int prefformat = AST_FORMAT_SLINEAR;
 
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
 /* Protect the interface list (of vpb_pvt's) */
 AST_MUTEX_DEFINE_STATIC(iflock);
 
@@ -338,11 +336,11 @@ static struct vpb_pvt {
 
 } *iflist = NULL;
 
-static struct ast_channel *vpb_new(struct vpb_pvt *i, int state, char *context);
+static struct ast_channel *vpb_new(struct vpb_pvt *i, enum ast_channel_state state, char *context);
 static void *do_chanreads(void *pvt);
-
 static struct ast_channel *vpb_request(const char *type, int format, void *data, int *cause);
-static int vpb_digit(struct ast_channel *ast, char digit);
+static int vpb_digit_begin(struct ast_channel *ast, char digit);
+static int vpb_digit_end(struct ast_channel *ast, char digit);
 static int vpb_call(struct ast_channel *ast, char *dest, int timeout);
 static int vpb_hangup(struct ast_channel *ast);
 static int vpb_answer(struct ast_channel *ast);
@@ -359,9 +357,8 @@ static struct ast_channel_tech vpb_tech = {
        properties: 0,
        requester: vpb_request,
        devicestate: NULL,
-       send_digit: vpb_digit,
-       send_digit_begin: NULL,
-       send_digit_end: NULL,
+       send_digit_begin: vpb_digit_begin,
+       send_digit_end: vpb_digit_end,
        call: vpb_call,
        hangup: vpb_hangup,
        answer: vpb_answer,
@@ -388,9 +385,8 @@ static struct ast_channel_tech vpb_tech_indicate = {
        properties: 0,
        requester: vpb_request,
        devicestate: NULL,
-       send_digit: vpb_digit,
-       send_digit_begin: NULL,
-       send_digit_end: NULL,
+       send_digit_begin: vpb_digit_begin,
+       send_digit_end: vpb_digit_end,
        call: vpb_call,
        hangup: vpb_hangup,
        answer: vpb_answer,
@@ -862,11 +858,11 @@ static inline int monitor_handle_owned(struct vpb_pvt *p, VPB_EVENT *e)
                                vpb_timer_stop(p->ring_timer);
                                vpb_timer_start(p->ring_timer);
                        } else
-                               f.frametype = -1; /* ignore ring on station port. */
+                               f.frametype = AST_FRAME_NULL; /* ignore ring on station port. */
                        break;
 
                case VPB_RING_OFF:
-                       f.frametype = -1;
+                       f.frametype = AST_FRAME_NULL;
                        break;
 
                case VPB_TIMEREXP:
@@ -875,12 +871,12 @@ static inline int monitor_handle_owned(struct vpb_pvt *p, VPB_EVENT *e)
                                p->state = VPB_STATE_PLAYBUSY;
                                vpb_timer_stop(p->busy_timer);
                                vpb_timer_start(p->busy_timer);
-                               f.frametype = -1;
+                               f.frametype = AST_FRAME_NULL;
                        } else if (e->data == p->ringback_timer_id) {
                                playtone(p->handle, &Ringbacktone);
                                vpb_timer_stop(p->ringback_timer);
                                vpb_timer_start(p->ringback_timer);
-                               f.frametype = -1;
+                               f.frametype = AST_FRAME_NULL;
                        } else if (e->data == p->ring_timer_id) {
                                /* We didnt get another ring in time! */
                                if (p->owner->_state != AST_STATE_UP)  {
@@ -889,23 +885,23 @@ static inline int monitor_handle_owned(struct vpb_pvt *p, VPB_EVENT *e)
                                        f.subclass = AST_CONTROL_HANGUP;
                                } else {
                                        vpb_timer_stop(p->ring_timer);
-                                       f.frametype = -1;
+                                       f.frametype = AST_FRAME_NULL;
                                }
                                
                        } else {
-                               f.frametype = -1; /* Ignore. */
+                               f.frametype = AST_FRAME_NULL; /* Ignore. */
                        }
                        break;
 
                case VPB_DTMF_DOWN:
                case VPB_DTMF:
                        if (use_ast_dtmfdet){
-                               f.frametype = -1;
+                               f.frametype = AST_FRAME_NULL;
                        } else if (p->owner->_state == AST_STATE_UP) {
                                        f.frametype = AST_FRAME_DTMF;
                                        f.subclass = e->data;
                        } else
-                               f.frametype = -1;
+                               f.frametype = AST_FRAME_NULL;
                        break;
 
                case VPB_TONEDETECT:
@@ -949,11 +945,11 @@ static inline int monitor_handle_owned(struct vpb_pvt *p, VPB_EVENT *e)
                                        f.subclass = AST_CONTROL_HANGUP;
                                } else {
                                        p->lastgrunt = ast_tvnow();
-                                       f.frametype = -1;
+                                       f.frametype = AST_FRAME_NULL;
                                }
                        } 
                        else {
-                               f.frametype = -1;
+                               f.frametype = AST_FRAME_NULL;
                        }
                        break;
 
@@ -969,7 +965,7 @@ static inline int monitor_handle_owned(struct vpb_pvt *p, VPB_EVENT *e)
                                f.subclass = AST_CONTROL_HANGUP;
                        #else
                        ast_log(LOG_NOTICE,"%s: Got call progress callback but blind dialing \n", p->dev); 
-                       f.frametype = -1;
+                       f.frametype = AST_FRAME_NULL;
                        #endif
                        break;
 
@@ -982,14 +978,14 @@ static inline int monitor_handle_owned(struct vpb_pvt *p, VPB_EVENT *e)
                                if (p->owner->_state == AST_STATE_UP) 
                                        f.subclass = AST_CONTROL_HANGUP;
                                else
-                                       f.frametype = -1;
+                                       f.frametype = AST_FRAME_NULL;
                        }
                        break;
                case VPB_LOOP_ONHOOK:
                        if (p->owner->_state == AST_STATE_UP)
                                f.subclass = AST_CONTROL_HANGUP;
                        else
-                               f.frametype = -1;
+                               f.frametype = AST_FRAME_NULL;
                        break;
                case VPB_STATION_ONHOOK:
                        f.subclass = AST_CONTROL_HANGUP;
@@ -1008,22 +1004,22 @@ static inline int monitor_handle_owned(struct vpb_pvt *p, VPB_EVENT *e)
                                if (option_verbose > 1) 
                                        ast_verbose(VERBOSE_PREFIX_2 "%s: Dialend\n", p->dev);
                        } else {
-                               f.frametype = -1;
+                               f.frametype = AST_FRAME_NULL;
                        }
                        break;
 
                case VPB_PLAY_UNDERFLOW:
-                       f.frametype = -1;
+                       f.frametype = AST_FRAME_NULL;
                        vpb_reset_play_fifo_alarm(p->handle);
                        break;
 
                case VPB_RECORD_OVERFLOW:
-                       f.frametype = -1;
+                       f.frametype = AST_FRAME_NULL;
                        vpb_reset_record_fifo_alarm(p->handle);
                        break;
 
                default:
-                       f.frametype = -1;
+                       f.frametype = AST_FRAME_NULL;
                        break;
        }
 
@@ -1777,7 +1773,12 @@ static int vpb_indicate(struct ast_channel *ast, int condition, const void *data
                                vpb_timer_start(p->busy_timer);
                        }
                        break;
-
+               case AST_CONTROL_HOLD:
+                       ast_moh_start(ast, (const char *) data, NULL);
+                       break;
+               case AST_CONTROL_UNHOLD:
+                       ast_moh_stop(ast);
+                       break;
                default:
                        res = 0;
                        break;
@@ -1825,7 +1826,12 @@ static int vpb_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
        return 0;
 }
 
-static int vpb_digit(struct ast_channel *ast, char digit)
+static int vpb_digit_begin(struct ast_channel *ast, char digit)
+{
+       /* XXX Modify this callback to let Asterisk control the length of DTMF */
+       return 0;
+}
+static int vpb_digit_end(struct ast_channel *ast, char digit)
 {
        struct vpb_pvt *p = (struct vpb_pvt *)ast->tech_pvt;
        char s[2];
@@ -2086,11 +2092,6 @@ static int vpb_hangup(struct ast_channel *ast)
                p->vad = NULL;
        }
 
-       ast_mutex_lock(&usecnt_lock); {
-               usecnt--;
-       } ast_mutex_unlock(&usecnt_lock);
-       ast_update_use_count();
-
        if (option_verbose > 1)
                ast_verbose(VERBOSE_PREFIX_2 "%s: Hangup complete\n", ast->name);
 
@@ -2612,7 +2613,7 @@ static void *do_chanreads(void *pvt)
        return NULL;
 }
 
-static struct ast_channel *vpb_new(struct vpb_pvt *me, int state, char *context)
+static struct ast_channel *vpb_new(struct vpb_pvt *me, enum ast_channel_state state, char *context)
 {
        struct ast_channel *tmp; 
        char cid_num[256];
@@ -2625,7 +2626,7 @@ static struct ast_channel *vpb_new(struct vpb_pvt *me, int state, char *context)
        if (option_verbose > 3)
                ast_verbose("%s: New call for context [%s]\n",me->dev,context);
            
-       tmp = ast_channel_alloc(1);
+       tmp = ast_channel_alloc(1, state, 0, 0, "", me->exten, me->context, 0, me->dev);
        if (tmp) {
                if (use_ast_ind == 1){
                        tmp->tech = &vpb_tech_indicate;
@@ -2634,8 +2635,6 @@ static struct ast_channel *vpb_new(struct vpb_pvt *me, int state, char *context)
                        tmp->tech = &vpb_tech;
                }
 
-               ast_string_field_set(tmp, name, me->dev);
-               
                tmp->callgroup = me->callgroup;
                tmp->pickupgroup = me->pickupgroup;
               
@@ -2646,7 +2645,6 @@ static struct ast_channel *vpb_new(struct vpb_pvt *me, int state, char *context)
                tmp->nativeformats = prefformat;
                tmp->rawreadformat = AST_FORMAT_SLINEAR;
                tmp->rawwriteformat =  AST_FORMAT_SLINEAR;
-               ast_setstate(tmp, state);
                if (state == AST_STATE_RING) {
                        tmp->rings = 1;
                        cid_name[0] = '\0';
@@ -2677,10 +2675,6 @@ static struct ast_channel *vpb_new(struct vpb_pvt *me, int state, char *context)
                me->lastgrunt  = ast_tvnow(); /* Assume at least one grunt tone seen now. */
                me->lastplay  = ast_tvnow(); /* Assume at least one grunt tone seen now. */
 
-               ast_mutex_lock(&usecnt_lock);
-               usecnt++;
-               ast_mutex_unlock(&usecnt_lock);
-               ast_update_use_count();
                if (state != AST_STATE_DOWN) {
                        if ((me->mode != MODE_FXO)&&(state != AST_STATE_UP)){
                                vpb_answer(tmp);
@@ -2863,7 +2857,7 @@ int load_module()
        /* We *must* have a config file otherwise stop immediately */
        if (!cfg) {
                ast_log(LOG_ERROR, "Unable to load config %s\n", config);
-               return -1;
+               return AST_MODULE_LOAD_DECLINE;
        }  
 
        vpb_seterrormode(VPB_ERROR_CODE);
@@ -3055,4 +3049,8 @@ const char *key()
 #endif
 /**/
 
-
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "VoiceTronix API driver",
+               .load = load_module,
+               .unload = unload_module,
+               .reload = reload,
+              );