提交 900c50fd authored 作者: Mathieu Parent's avatar Mathieu Parent

Skinny: Corrections

- Construct call_id based on simple increment per profile
- close RTP only if needed
- now hanging up while there is no other leg works
- better steps: create_session -> process_dest -> answer

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16789 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 834a28ff
...@@ -381,13 +381,19 @@ switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force) ...@@ -381,13 +381,19 @@ switch_status_t skinny_tech_set_codec(private_t *tech_pvt, int force)
return status; return status;
} }
void tech_init(private_t *tech_pvt, switch_core_session_t *session) void tech_init(private_t *tech_pvt, switch_core_session_t *session, listener_t *listener, uint32_t line)
{ {
switch_assert(tech_pvt);
switch_assert(session);
switch_assert(listener);
tech_pvt->read_frame.data = tech_pvt->databuf; tech_pvt->read_frame.data = tech_pvt->databuf;
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
tech_pvt->call_id = 12345; /* TODO */ tech_pvt->call_id = listener->profile->next_call_id++;
tech_pvt->listener = listener;
tech_pvt->line = line;
switch_core_session_set_private(session, tech_pvt); switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session; tech_pvt->session = session;
} }
...@@ -508,6 +514,8 @@ switch_status_t channel_on_hangup(switch_core_session_t *session) ...@@ -508,6 +514,8 @@ switch_status_t channel_on_hangup(switch_core_session_t *session)
stop_tone(listener, tech_pvt->line, tech_pvt->call_id); stop_tone(listener, tech_pvt->line, tech_pvt->call_id);
set_lamp(listener, SKINNY_BUTTON_LINE, tech_pvt->line, SKINNY_LAMP_OFF); set_lamp(listener, SKINNY_BUTTON_LINE, tech_pvt->line, SKINNY_LAMP_OFF);
clear_prompt_status(listener, tech_pvt->line, tech_pvt->call_id); clear_prompt_status(listener, tech_pvt->line, tech_pvt->call_id);
if( skinny_line_get_state(tech_pvt->listener, tech_pvt->line) == SKINNY_KEY_SET_CONNECTED ) {
close_receive_channel(listener, close_receive_channel(listener,
tech_pvt->call_id, /* uint32_t conference_id, */ tech_pvt->call_id, /* uint32_t conference_id, */
tech_pvt->party_id, /* uint32_t pass_thru_party_id, */ tech_pvt->party_id, /* uint32_t pass_thru_party_id, */
...@@ -518,6 +526,13 @@ switch_status_t channel_on_hangup(switch_core_session_t *session) ...@@ -518,6 +526,13 @@ switch_status_t channel_on_hangup(switch_core_session_t *session)
tech_pvt->party_id, /* uint32_t pass_thru_party_id, */ tech_pvt->party_id, /* uint32_t pass_thru_party_id, */
tech_pvt->call_id /* uint32_t conference_id2, */ tech_pvt->call_id /* uint32_t conference_id2, */
); );
switch_mutex_lock(globals.calls_mutex);
globals.calls--;
if (globals.calls < 0) {
globals.calls = 0;
}
switch_mutex_unlock(globals.calls_mutex);
}
send_call_state(listener, send_call_state(listener,
SKINNY_ON_HOOK, SKINNY_ON_HOOK,
tech_pvt->line, tech_pvt->line,
...@@ -527,14 +542,6 @@ switch_status_t channel_on_hangup(switch_core_session_t *session) ...@@ -527,14 +542,6 @@ switch_status_t channel_on_hangup(switch_core_session_t *session)
set_speaker_mode(listener, SKINNY_SPEAKER_OFF); set_speaker_mode(listener, SKINNY_SPEAKER_OFF);
set_ringer(listener, SKINNY_RING_OFF, SKINNY_RING_FOREVER, 0); set_ringer(listener, SKINNY_RING_OFF, SKINNY_RING_FOREVER, 0);
switch_mutex_lock(globals.calls_mutex);
globals.calls--;
if (globals.calls < 0) {
globals.calls = 0;
}
switch_mutex_unlock(globals.calls_mutex);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -551,12 +558,12 @@ switch_status_t channel_kill_channel(switch_core_session_t *session, int sig) ...@@ -551,12 +558,12 @@ switch_status_t channel_kill_channel(switch_core_session_t *session, int sig)
switch (sig) { switch (sig) {
case SWITCH_SIG_KILL: case SWITCH_SIG_KILL:
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
break; break;
case SWITCH_SIG_BREAK: case SWITCH_SIG_BREAK:
switch_set_flag_locked(tech_pvt, TFLAG_BREAK); if (switch_rtp_ready(tech_pvt->rtp_session)) {
switch_rtp_break(tech_pvt->rtp_session);
}
break; break;
default: default:
break; break;
...@@ -748,6 +755,8 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi ...@@ -748,6 +755,8 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi
char *profile_name, *dest; char *profile_name, *dest;
skinny_profile_t *profile = NULL; skinny_profile_t *profile = NULL;
listener_t *listener = NULL;
uint32_t line = 0;
char name[128]; char name[128];
switch_channel_t *channel; switch_channel_t *channel;
switch_caller_profile_t *caller_profile; switch_caller_profile_t *caller_profile;
...@@ -767,8 +776,6 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi ...@@ -767,8 +776,6 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi
goto error; goto error;
} }
tech_init(tech_pvt, nsession);
if(!(profile_name = switch_core_session_strdup(nsession, outbound_profile->destination_number))) { if(!(profile_name = switch_core_session_strdup(nsession, outbound_profile->destination_number))) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Error Creating Session Info\n"); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Error Creating Session Info\n");
goto error; goto error;
...@@ -794,31 +801,33 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi ...@@ -794,31 +801,33 @@ switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, swi
switch_channel_set_name(channel, name); switch_channel_set_name(channel, name);
caller_profile = switch_caller_profile_clone(nsession, outbound_profile); if ((skinny_profile_find_listener(profile, dest, &listener, &line) != SWITCH_STATUS_SUCCESS)) {
switch_channel_set_caller_profile(channel, caller_profile);
tech_pvt->caller_profile = caller_profile;
switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
if ((skinny_profile_find_listener(profile, dest, &tech_pvt->listener, &tech_pvt->line) != SWITCH_STATUS_SUCCESS)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Problem while retrieving listener and line for destination %s in profile %s\n", dest, profile_name); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Problem while retrieving listener and line for destination %s in profile %s\n", dest, profile_name);
cause = SWITCH_CAUSE_UNALLOCATED_NUMBER; cause = SWITCH_CAUSE_UNALLOCATED_NUMBER;
goto error; goto error;
} }
if (!tech_pvt->listener) { if (!listener) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid destination or phone not registred %s in profile %s\n", dest, profile_name); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid destination or phone not registred %s in profile %s\n", dest, profile_name);
cause = SWITCH_CAUSE_UNALLOCATED_NUMBER; cause = SWITCH_CAUSE_UNALLOCATED_NUMBER;
goto error; goto error;
} }
if (tech_pvt->line == 0) { if (line == 0) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid destination or phone not registred %s in profile %s\n", dest, profile_name); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Invalid destination or phone not registred %s in profile %s\n", dest, profile_name);
cause = SWITCH_CAUSE_UNALLOCATED_NUMBER; cause = SWITCH_CAUSE_UNALLOCATED_NUMBER;
goto error; goto error;
} }
tech_init(tech_pvt, nsession, listener, line);
caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
switch_channel_set_caller_profile(channel, caller_profile);
tech_pvt->caller_profile = caller_profile;
switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
if(tech_pvt->listener->session[tech_pvt->line]) { /* Line is busy */ if(tech_pvt->listener->session[tech_pvt->line]) { /* Line is busy */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Device line is busy %s in profile %s\n", dest, profile_name); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Device line is busy %s in profile %s\n", dest, profile_name);
cause = SWITCH_CAUSE_USER_BUSY; cause = SWITCH_CAUSE_USER_BUSY;
...@@ -1424,8 +1433,6 @@ static switch_status_t load_skinny_config(void) ...@@ -1424,8 +1433,6 @@ static switch_status_t load_skinny_config(void)
skinny_execute_sql_callback(profile, profile->listener_mutex, "DELETE FROM skinny_devices", NULL, NULL); skinny_execute_sql_callback(profile, profile->listener_mutex, "DELETE FROM skinny_devices", NULL, NULL);
skinny_execute_sql_callback(profile, profile->listener_mutex, "DELETE FROM skinny_buttons", NULL, NULL); skinny_execute_sql_callback(profile, profile->listener_mutex, "DELETE FROM skinny_buttons", NULL, NULL);
switch_core_hash_init(&profile->session_hash, module_pool);
switch_core_hash_insert(globals.profile_hash, profile->name, profile); switch_core_hash_insert(globals.profile_hash, profile->name, profile);
profile = NULL; profile = NULL;
} else { } else {
......
...@@ -92,9 +92,8 @@ struct skinny_profile { ...@@ -92,9 +92,8 @@ struct skinny_profile {
switch_mutex_t *sock_mutex; switch_mutex_t *sock_mutex;
struct listener *listeners; struct listener *listeners;
uint8_t listener_ready; uint8_t listener_ready;
/* sessions */ /* call id */
switch_hash_t *session_hash; uint32_t next_call_id;
switch_mutex_t *sessions_mutex;
}; };
typedef struct skinny_profile skinny_profile_t; typedef struct skinny_profile skinny_profile_t;
...@@ -143,7 +142,6 @@ typedef enum { ...@@ -143,7 +142,6 @@ typedef enum {
TFLAG_HANGUP = (1 << 5), TFLAG_HANGUP = (1 << 5),
TFLAG_LINEAR = (1 << 6), TFLAG_LINEAR = (1 << 6),
TFLAG_CODEC = (1 << 7), TFLAG_CODEC = (1 << 7),
TFLAG_BREAK = (1 << 8),
TFLAG_READING = (1 << 9), TFLAG_READING = (1 << 9),
TFLAG_WRITING = (1 << 10) TFLAG_WRITING = (1 << 10)
...@@ -209,7 +207,7 @@ uint32_t skinny_line_perform_set_state(listener_t *listener, const char *file, c ...@@ -209,7 +207,7 @@ uint32_t skinny_line_perform_set_state(listener_t *listener, const char *file, c
uint32_t skinny_line_get_state(listener_t *listener, uint32_t instance); 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); 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); void tech_init(private_t *tech_pvt, switch_core_session_t *session, listener_t *listener, uint32_t line);
switch_status_t channel_on_init(switch_core_session_t *session); switch_status_t channel_on_init(switch_core_session_t *session);
switch_status_t channel_on_hangup(switch_core_session_t *session); switch_status_t channel_on_hangup(switch_core_session_t *session);
switch_status_t channel_on_destroy(switch_core_session_t *session); switch_status_t channel_on_destroy(switch_core_session_t *session);
......
...@@ -73,7 +73,7 @@ struct keypad_button_message { ...@@ -73,7 +73,7 @@ struct keypad_button_message {
struct stimulus_message { struct stimulus_message {
uint32_t instance_type; /* See enum skinny_button_definition */ uint32_t instance_type; /* See enum skinny_button_definition */
uint32_t instance; uint32_t instance;
uint32_t call_reference; /* uint32_t call_reference; */
}; };
/* OffHookMessage */ /* OffHookMessage */
...@@ -665,6 +665,10 @@ switch_status_t skinny_device_event(listener_t *listener, switch_event_t **ev, s ...@@ -665,6 +665,10 @@ switch_status_t skinny_device_event(listener_t *listener, switch_event_t **ev, s
switch_status_t skinny_send_call_info(switch_core_session_t *session); switch_status_t skinny_send_call_info(switch_core_session_t *session);
switch_status_t skinny_create_session(listener_t *listener, uint32_t line, uint32_t to_state);
switch_status_t skinny_process_dest(listener_t *listener, uint32_t line);
switch_status_t skinny_answer(switch_core_session_t *session);
switch_status_t skinny_perform_send_reply(listener_t *listener, const char *file, const char *func, int line, skinny_message_t *reply); switch_status_t skinny_perform_send_reply(listener_t *listener, const char *file, const char *func, int line, skinny_message_t *reply);
#define skinny_send_reply(listener, reply) skinny_perform_send_reply(listener, __FILE__, __SWITCH_FUNC__, __LINE__, reply) #define skinny_send_reply(listener, reply) skinny_perform_send_reply(listener, __FILE__, __SWITCH_FUNC__, __LINE__, reply)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论