]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
SKinny: handle hold corner cases
authorMathieu Parent <math.parent@gmail.com>
Fri, 9 Apr 2010 16:02:14 +0000 (18:02 +0200)
committerMathieu Parent <math.parent@gmail.com>
Fri, 9 Apr 2010 16:02:14 +0000 (18:02 +0200)
- try to re-use existing OffHook session
- hold active lines before: newcall, resume
- allow endcall on: offHook, afterFirstDigit
- allow newcall on: connected, ringin

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

index 7b5be3529f4be20b88373e07864f4c70ed1f6319..391923d5e95fb2a66a65c8717be59875ffeda1bf 100644 (file)
@@ -221,7 +221,7 @@ char * skinny_profile_find_session_uuid(skinny_profile_t *profile, listener_t *l
                        "SELECT channel_uuid, line_instance "
                                "FROM skinny_active_lines "
                                "WHERE %s AND %s AND %s "
-                               "ORDER BY channel_uuid DESC",
+                               "ORDER BY call_state, channel_uuid", /* off hook first */
                        device_condition, line_instance_condition, call_id_condition
                        ))) {
                skinny_execute_sql_callback(profile, profile->sql_mutex, sql,
@@ -365,7 +365,9 @@ struct skinny_line_get_state_helper {
 int skinny_line_get_state_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
        struct skinny_line_get_state_helper *helper = pArg;
-       helper->call_state = atoi(argv[0]);
+       if (helper->call_state == -1) {
+               helper->call_state = atoi(argv[0]);
+       }
        return 0;
 }
 
@@ -391,10 +393,12 @@ uint32_t skinny_line_get_state(listener_t *listener, uint32_t line_instance, uin
        }
        switch_assert(call_id_condition);
 
+       helper.call_state = -1;
        if ((sql = switch_mprintf(
                        "SELECT call_state FROM skinny_active_lines "
                        "WHERE device_name='%s' AND device_instance=%d "
-                       "AND %s AND %s",
+                       "AND %s AND %s "
+                       "ORDER BY call_state, channel_uuid", /* off hook first */
                        listener->device_name, listener->device_instance,
                        line_instance_condition, call_id_condition
                        ))) {
index 0dab0fe47a9c919e1de1239e0ecdf6bde7d21499..94c61eb1dd7e28e813528b30399a943a773d70ba 100644 (file)
@@ -451,7 +451,6 @@ switch_status_t skinny_create_ingoing_session(listener_t *listener, uint32_t *li
                *session = nsession;
                return SWITCH_STATUS_SUCCESS;
            }
-           skinny_session_hold_line(nsession, listener, *line_instance_p);
            switch_core_session_rwunlock(nsession);
        }
        *line_instance_p = line_instance;
@@ -459,6 +458,8 @@ switch_status_t skinny_create_ingoing_session(listener_t *listener, uint32_t *li
            *line_instance_p = 1;
        }
 
+    skinny_hold_active_calls(listener);
+    
        skinny_line_get(listener, *line_instance_p, &button);
 
        if (!button || !button->shortname) {
@@ -819,6 +820,7 @@ switch_status_t skinny_session_unhold_line(switch_core_session_t *session, liste
        channel = switch_core_session_get_channel(session);
        tech_pvt = switch_core_session_get_private(session);
 
+    skinny_hold_active_calls(listener);
        send_set_ringer(listener, SKINNY_RING_OFF, SKINNY_RING_FOREVER, 0, tech_pvt->call_id);
        send_set_speaker_mode(listener, SKINNY_SPEAKER_ON);
        send_select_soft_keys(listener, line_instance, tech_pvt->call_id, SKINNY_KEY_SET_RING_OUT, 0xffff);
@@ -854,6 +856,65 @@ switch_status_t skinny_session_stop_media(switch_core_session_t *session, listen
        return SWITCH_STATUS_SUCCESS;
 }
 
+struct skinny_hold_active_calls_helper {
+       listener_t *listener;
+};
+
+int skinny_hold_active_calls_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+       struct skinny_hold_active_calls_helper *helper = pArg;
+       switch_core_session_t *session;
+
+       /* char *device_name = argv[0]; */
+       /* uint32_t device_instance = atoi(argv[1]); */
+       /* uint32_t position = atoi(argv[2]); */
+       uint32_t line_instance = atoi(argv[3]);
+       /* char *label = argv[4]; */
+       /* char *value = argv[5]; */
+       /* char *caller_name = argv[6]; */
+       /* uint32_t ring_on_idle = atoi(argv[7]); */
+       /* uint32_t ring_on_active = atoi(argv[8]); */
+       /* uint32_t busy_trigger = atoi(argv[9]); */
+       /* char *forward_all = argv[10]; */
+       /* char *forward_busy = argv[11]; */
+       /* char *forward_noanswer = argv[12]; */
+       /* uint32_t noanswer_duration = atoi(argv[13]); */
+       /* char *channel_uuid = argv[14]; */
+       uint32_t call_id = atoi(argv[15]);
+       /* uint32_t call_state = atoi(argv[16]); */
+       
+    session = skinny_profile_find_session(helper->listener->profile, helper->listener, &line_instance, call_id);
+
+    if(session) {
+        skinny_session_hold_line(session, helper->listener, line_instance);
+               switch_core_session_rwunlock(session);
+    }
+
+       return 0;
+}
+
+switch_status_t skinny_hold_active_calls(listener_t *listener)
+{
+       struct skinny_hold_active_calls_helper helper = {0};
+       char *sql;
+       
+       helper.listener = listener;
+       
+       if ((sql = switch_mprintf(
+                       "SELECT skinny_lines.*, channel_uuid, call_id, call_state "
+                       "FROM skinny_active_lines "
+                       "INNER JOIN skinny_lines "
+                               "ON skinny_active_lines.device_name = skinny_lines.device_name "
+                               "AND skinny_active_lines.device_instance = skinny_lines.device_instance "
+                               "AND skinny_active_lines.line_instance = skinny_lines.line_instance "
+                       "WHERE skinny_lines.device_name='%s' AND skinny_lines.device_instance=%d AND call_state=%d",
+                       listener->device_name, listener->device_instance, SKINNY_CONNECTED))) {
+               skinny_execute_sql_callback(listener->profile, listener->profile->sql_mutex, sql, skinny_hold_active_calls_callback, &helper);
+               switch_safe_free(sql);
+       }
+       
+       return SWITCH_STATUS_SUCCESS;
+}
 /*****************************************************************************/
 /* SKINNY BUTTONS */
 /*****************************************************************************/
@@ -1900,14 +1961,18 @@ switch_status_t skinny_handle_soft_key_set_request(listener_t *listener, skinny_
        message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_ON_HOOK].soft_key_template_index[1] = SOFTKEY_REDIAL;
        
        message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_OFF_HOOK].soft_key_template_index[1] = SOFTKEY_REDIAL;
+       message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_OFF_HOOK].soft_key_template_index[2] = SOFTKEY_ENDCALL;
 
        message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT].soft_key_template_index[0] = SOFTKEY_BACKSPACE;
+       message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_DIGITS_AFTER_DIALING_FIRST_DIGIT].soft_key_template_index[2] = SOFTKEY_ENDCALL;
 
        message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_CONNECTED].soft_key_template_index[0] = SOFTKEY_ENDCALL;
        message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_CONNECTED].soft_key_template_index[1] = SOFTKEY_HOLD;
+       message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_CONNECTED].soft_key_template_index[2] = SOFTKEY_NEWCALL;
        
        message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_RING_IN].soft_key_template_index[0] = SOFTKEY_ANSWER;
        message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_RING_IN].soft_key_template_index[1] = SOFTKEY_ENDCALL;
+       message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_RING_IN].soft_key_template_index[2] = SOFTKEY_NEWCALL;
 
        message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_ON_HOLD].soft_key_template_index[0] = SOFTKEY_NEWCALL;
        message->data.soft_key_set.soft_key_set[SKINNY_KEY_SET_ON_HOLD].soft_key_template_index[1] = SOFTKEY_RESUME;
index 74a24a05907847e2a7fda6ed3b42e25141eb697b..31997388564c4396908e72d3660ddd03e91c37bb 100644 (file)
@@ -631,6 +631,7 @@ switch_status_t skinny_session_start_media(switch_core_session_t *session, liste
 switch_status_t skinny_session_hold_line(switch_core_session_t *session, listener_t *listener, uint32_t line_instance);
 switch_status_t skinny_session_unhold_line(switch_core_session_t *session, listener_t *listener, uint32_t line_instance);
 switch_status_t skinny_session_stop_media(switch_core_session_t *session, listener_t *listener, uint32_t line_instance);
+switch_status_t skinny_hold_active_calls(listener_t *listener);
 
 void skinny_line_get(listener_t *listener, uint32_t instance, struct line_stat_res_message **button);
 void skinny_speed_dial_get(listener_t *listener, uint32_t instance, struct speed_dial_stat_res_message **button);