]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Skinny: Line state
authorMathieu Parent <math.parent@gmail.com>
Wed, 24 Feb 2010 12:05:26 +0000 (12:05 +0000)
committerMathieu Parent <math.parent@gmail.com>
Wed, 24 Feb 2010 12:05:26 +0000 (12:05 +0000)
Avoid the use of TFLAG_WAITING_DEST an replace by a line_state corresponding to the softkey events

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16787 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_skinny/mod_skinny.c
src/mod/endpoints/mod_skinny/mod_skinny.h
src/mod/endpoints/mod_skinny/skinny_protocol.c

index 7cb0118b70a72382bbe9284d75132f51f532c413..48c7572a261d11e33fe8d8d1f378d5cd9172d114 100644 (file)
@@ -238,7 +238,29 @@ switch_bool_t skinny_execute_sql_callback(skinny_profile_t *profile,
 /*****************************************************************************/
 /* CHANNEL FUNCTIONS */
 /*****************************************************************************/
+uint32_t skinny_line_perform_set_state(listener_t *listener, const char *file, const char *func, int line, uint32_t instance, uint32_t state, uint32_t call_id)
+{
+       switch_assert(listener);
+       
+       if(listener->session[instance]) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener->session[instance]), SWITCH_LOG_DEBUG, "Device %s, line %d State Change %d -> %d\n",
+                       listener->device_name, instance, listener->line_state[instance], state);
+       } else {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Device %s, line %d State Change %d -> %d (no session)\n",
+                       listener->device_name, instance, listener->line_state[instance], state);
+       }
+       send_select_soft_keys(listener, instance, call_id, state, 0xffff);
+       listener->line_state[instance] = state;
+       
+       return listener->line_state[instance];
+}
 
+uint32_t skinny_line_get_state(listener_t *listener, uint32_t instance)
+{
+       switch_assert(listener);
+
+       return listener->line_state[instance];
+}
 switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force)
 {
        int ms;
index ff920fc308ba66cc8b251bc5417cf06f49c3f9c9..9169cd2b07fc7dccc9652d87e5ab9c3822f861fe 100644 (file)
@@ -112,6 +112,7 @@ struct listener {
        skinny_profile_t *profile;
        char device_name[16];
        switch_core_session_t *session[SKINNY_MAX_LINES];
+       uint32_t line_state[SKINNY_MAX_LINES]; /* See enum skinny_key_set */
 
        switch_socket_t *sock;
        switch_memory_pool_t *pool;
@@ -145,9 +146,7 @@ typedef enum {
        TFLAG_BREAK = (1 << 8),
        
        TFLAG_READING = (1 << 9),
-       TFLAG_WRITING = (1 << 10),
-       
-       TFLAG_WAITING_DEST = (1 << 11)
+       TFLAG_WRITING = (1 << 10)
 } TFLAGS;
 
 typedef enum {
@@ -204,6 +203,11 @@ switch_status_t keepalive_listener(listener_t *listener, void *pvt);
 /*****************************************************************************/
 /* CHANNEL FUNCTIONS */
 /*****************************************************************************/
+uint32_t skinny_line_perform_set_state(listener_t *listener, const char *file, const char *func, int line, uint32_t instance, uint32_t state, uint32_t call_id);
+#define  skinny_line_set_state(listener, instance, state, call_id)  skinny_line_perform_set_state(listener, __FILE__, __SWITCH_FUNC__, __LINE__, instance, state, call_id)
+
+uint32_t skinny_line_get_state(listener_t *listener, uint32_t instance);
+
 switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force);
 void tech_init(private_t *tech_pvt, switch_core_session_t *session);
 switch_status_t channel_on_init(switch_core_session_t *session);
index 64aa5c1f1c594c48571ecac33cb5d37318e938f6..08ef0550d83ee8ae905e99e17e89e50ee06a62e1 100644 (file)
@@ -308,8 +308,6 @@ switch_status_t skinny_pick_up(listener_t *listener, uint32_t line)
 
        tech_init(tech_pvt, session);
 
-       switch_set_flag_locked(tech_pvt, TFLAG_WAITING_DEST);
-
        set_ringer(listener, SKINNY_RING_OFF, SKINNY_RING_FOREVER, 0);
        set_speaker_mode(listener, SKINNY_SPEAKER_ON);
        set_lamp(listener, SKINNY_BUTTON_LINE, tech_pvt->line, SKINNY_LAMP_ON);
@@ -317,8 +315,7 @@ switch_status_t skinny_pick_up(listener_t *listener, uint32_t line)
                SKINNY_OFF_HOOK,
                tech_pvt->line,
                tech_pvt->call_id);
-       send_select_soft_keys(listener, tech_pvt->line, tech_pvt->call_id,
-               SKINNY_KEY_SET_OFF_HOOK, 0xffff);
+       skinny_line_set_state(listener, tech_pvt->line, SKINNY_KEY_SET_OFF_HOOK, tech_pvt->call_id);
        display_prompt_status(listener,
                0,
                "\200\000",
@@ -368,11 +365,7 @@ switch_status_t skinny_answer(switch_core_session_t *session)
                SKINNY_CONNECTED,
                tech_pvt->line,
                tech_pvt->call_id);
-       send_select_soft_keys(listener,
-               tech_pvt->line,
-               tech_pvt->call_id,
-               SKINNY_KEY_SET_CONNECTED,
-               0xffff);
+       skinny_line_set_state(listener, tech_pvt->line, SKINNY_KEY_SET_CONNECTED, tech_pvt->call_id);
        display_prompt_status(listener,
                0,
                "\200\030",
@@ -1474,21 +1467,20 @@ switch_status_t skinny_handle_keypad_button_message(listener_t *listener, skinny
 
                /* TODO check call_id and line */
 
-               if(switch_test_flag(tech_pvt, TFLAG_WAITING_DEST)) {
+               if((skinny_line_get_state(listener, tech_pvt->line) == SKINNY_KEY_SET_OFF_HOOK)
+                               || (skinny_line_get_state(listener, tech_pvt->line) == SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT)) {
                        char name[128];
                        switch_channel_t *channel;
                        char *cid_name = "TODO-soft_key_event"; /* TODO */
                        char *cid_num = "00000"; /* TODO */
                        if(strlen(tech_pvt->dest) == 0) {/* first digit */
                                stop_tone(listener, tech_pvt->line, tech_pvt->call_id);
-                               send_select_soft_keys(listener, tech_pvt->line, tech_pvt->call_id,
-                                       SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT, 0xffff);
+                               skinny_line_set_state(listener, tech_pvt->line, SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT, tech_pvt->call_id);
                        }
                        
                        tech_pvt->dest[strlen(tech_pvt->dest)] = digit;
                        
                        if(strlen(tech_pvt->dest) >= 4) { /* TODO Number is complete */
-                               switch_clear_flag_locked(tech_pvt, TFLAG_WAITING_DEST);
                                if (!(tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(listener->session[line]),
                                                                                                                                                  NULL, listener->profile->dialplan, cid_name, cid_num, listener->remote_ip, NULL, NULL, NULL, "skinny" /* modname */, listener->profile->context, tech_pvt->dest)) != 0) {
                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener->session[line]), SWITCH_LOG_CRIT, "Error Creating Session caller profile\n");
@@ -1510,11 +1502,7 @@ switch_status_t skinny_handle_keypad_button_message(listener_t *listener, skinny
                                        goto error;
                                }
 
-                               send_select_soft_keys(listener,
-                                       tech_pvt->line,
-                                       tech_pvt->call_id,
-                                       SKINNY_KEY_SET_CONNECTED,
-                                       0xffff);
+                               skinny_line_set_state(listener, tech_pvt->line, SKINNY_KEY_SET_CONNECTED, tech_pvt->call_id);
                                send_dialed_number(listener, tech_pvt->dest, tech_pvt->line, tech_pvt->call_id);
                                skinny_answer(listener->session[line]);