[Freeswitch-trunk] [commit] r14020 - in freeswitch/trunk/contrib/mod/endpoints/mod_khomp: include src
FreeSWITCH SVN
jmesquita at freeswitch.org
Sat Jun 27 21:58:27 PDT 2009
Author: jmesquita
Date: Sat Jun 27 23:58:26 2009
New Revision: 14020
Log:
Reverse board lookup and channel lookup using a.
Modified:
freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/khomp_pvt.h
freeswitch/trunk/contrib/mod/endpoints/mod_khomp/src/khomp_pvt.cpp
Modified: freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/khomp_pvt.h
==============================================================================
--- freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/khomp_pvt.h (original)
+++ freeswitch/trunk/contrib/mod/endpoints/mod_khomp/include/khomp_pvt.h Sat Jun 27 23:58:26 2009
@@ -46,6 +46,7 @@
return _pvts[target.device][target.object];
}
+
static KhompPvt * find_channel(char* allocation_string, switch_core_session_t * new_session, switch_call_cause_t * cause);
static void initialize(void)
Modified: freeswitch/trunk/contrib/mod/endpoints/mod_khomp/src/khomp_pvt.cpp
==============================================================================
--- freeswitch/trunk/contrib/mod/endpoints/mod_khomp/src/khomp_pvt.cpp (original)
+++ freeswitch/trunk/contrib/mod/endpoints/mod_khomp/src/khomp_pvt.cpp Sat Jun 27 23:58:26 2009
@@ -5,7 +5,6 @@
KhompPvt * KhompPvt::find_channel(char* allocation_string, switch_core_session_t * new_session, switch_call_cause_t * cause)
{
- /* For now we support only the 'first-free' mode */
char *argv[3] = { 0 };
int argc = 0;
@@ -17,6 +16,8 @@
int channel_high = 0;
bool first_channel_available = true;
+ bool reverse_first_board_available = false;
+ bool reverse_first_channel_available = false;
*cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
@@ -35,6 +36,11 @@
{
board_low = 0;
board_high = Globals::_k3lapi.device_count();
+ // Lets make it reverse...
+ if(*argv[0] == 'a')
+ {
+ reverse_first_board_available = true;
+ }
}
else
{
@@ -45,6 +51,11 @@
if(*argv[1] == 'A' || *argv[1] == 'a')
{
first_channel_available = true;
+ // Lets make it reverse...
+ if(*argv[1] == 'a')
+ {
+ reverse_first_channel_available = true;
+ }
}
else
{
@@ -64,60 +75,202 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel selection: board (%d-%d), channel (%d-%d)!\n", board_low, board_high, channel_low, channel_high);
- for (int board = board_low ; board <= board_high; board++)
+ // TODO: Stop this nonsense of having duplicate code?
+ if(reverse_first_board_available)
{
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking board %d\n", board);
-
- if(pvt != NULL)
- break;
-
- if(first_channel_available)
- {
- channel_low = 0;
- channel_high = Globals::_k3lapi.channel_count(board);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Just to check we are getting on the first_channel\n", board_low, board_high, channel_low, channel_high);
- }
- else
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Doing reverse board lookup.\n");
+ for (int board = board_high-1 ; board >= board_low; board--)
{
- if(channel_low < 0 || channel_high > Globals::_k3lapi.channel_count(board))
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking board %d\n", board);
+
+ if(pvt != NULL)
+ break;
+
+ if(first_channel_available)
{
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid channel selection (%d-%d) !\n", channel_low, channel_high);
- switch_mutex_unlock(_pvts_mutex);
- return NULL;
+ channel_low = 0;
+ channel_high = Globals::_k3lapi.channel_count(board);
+ }
+ else
+ {
+ if(channel_low < 0 || channel_high > Globals::_k3lapi.channel_count(board))
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid channel selection (%d-%d) !\n", channel_low, channel_high);
+ switch_mutex_unlock(_pvts_mutex);
+ return NULL;
+ }
+ }
+ if (reverse_first_channel_available)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Doing a reverse free channel lookup\n", board_low, board_high, channel_low, channel_high);
+ for (int channel = channel_high-1 ; channel >= channel_low ; channel--)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking if (%d-%d) is free\n", board, channel);
+ try
+ {
+ K3L_CHANNEL_CONFIG channelConfig;
+ channelConfig = Globals::_k3lapi.channel_config( board, channel );
+ }
+ catch (...)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception while retrieving channel config for board %d, channel%d!\n", board, channel);
+ switch_mutex_unlock(_pvts_mutex);
+ return NULL;
+ }
+ K3L_CHANNEL_STATUS status;
+ if (k3lGetDeviceStatus( board, channel + ksoChannel, &status, sizeof(status) ) != ksSuccess)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "k3lGetDeviceStatus failed to retrieve channel config for board %d, channel%d!\n", board, channel);
+ switch_mutex_unlock(_pvts_mutex);
+ return NULL;
+ }
+ if(status.CallStatus == kcsFree)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel (%d-%d) is free, let's check if the session is available ...\n", board, channel);
+ pvt = KhompPvt::khompPvt(board, channel);
+ if(pvt != NULL && pvt->session() == NULL)
+ {
+ pvt->session(new_session);
+ break;
+ }
+ pvt = NULL;
+ }
+ }
+ }
+ else
+ {
+ for (int channel = channel_low ; channel <= channel_high ; channel++)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking if (%d-%d) is free\n", board, channel);
+ try
+ {
+ K3L_CHANNEL_CONFIG channelConfig;
+ channelConfig = Globals::_k3lapi.channel_config( board, channel );
+ }
+ catch (...)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception while retrieving channel config for board %d, channel%d!\n", board, channel);
+ switch_mutex_unlock(_pvts_mutex);
+ return NULL;
+ }
+ K3L_CHANNEL_STATUS status;
+ if (k3lGetDeviceStatus( board, channel + ksoChannel, &status, sizeof(status) ) != ksSuccess)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "k3lGetDeviceStatus failed to retrieve channel config for board %d, channel%d!\n", board, channel);
+ switch_mutex_unlock(_pvts_mutex);
+ return NULL;
+ }
+ if(status.CallStatus == kcsFree)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel (%d-%d) is free, let's check if the session is available ...\n", board, channel);
+ pvt = KhompPvt::khompPvt(board, channel);
+ if(pvt != NULL && pvt->session() == NULL)
+ {
+ pvt->session(new_session);
+ break;
+ }
+ pvt = NULL;
+ }
+ }
}
}
+ }
+ else
+ {
- for (int channel = channel_low ; channel <= channel_high ; channel++)
+ for (int board = board_low ; board <= board_high; board++)
{
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking if (%d-%d) is free\n", board, channel);
- try
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking board %d\n", board);
+
+ if(pvt != NULL)
+ break;
+
+ if(first_channel_available)
{
- K3L_CHANNEL_CONFIG channelConfig;
- channelConfig = Globals::_k3lapi.channel_config( board, channel );
+ channel_low = 0;
+ channel_high = Globals::_k3lapi.channel_count(board);
}
- catch (...)
+ else
{
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception while retrieving channel config for board %d, channel%d!\n", board, channel);
- switch_mutex_unlock(_pvts_mutex);
- return NULL;
+ if(channel_low < 0 || channel_high > Globals::_k3lapi.channel_count(board))
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid channel selection (%d-%d) !\n", channel_low, channel_high);
+ switch_mutex_unlock(_pvts_mutex);
+ return NULL;
+ }
}
- K3L_CHANNEL_STATUS status;
- if (k3lGetDeviceStatus( board, channel + ksoChannel, &status, sizeof(status) ) != ksSuccess)
+ if (reverse_first_channel_available)
{
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "k3lGetDeviceStatus failed to retrieve channel config for board %d, channel%d!\n", board, channel);
- switch_mutex_unlock(_pvts_mutex);
- return NULL;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Doing a reverse free channel lookup\n", board_low, board_high, channel_low, channel_high);
+ for (int channel = channel_high-1 ; channel >= channel_low ; channel--)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking if (%d-%d) is free\n", board, channel);
+ try
+ {
+ K3L_CHANNEL_CONFIG channelConfig;
+ channelConfig = Globals::_k3lapi.channel_config( board, channel );
+ }
+ catch (...)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception while retrieving channel config for board %d, channel%d!\n", board, channel);
+ switch_mutex_unlock(_pvts_mutex);
+ return NULL;
+ }
+ K3L_CHANNEL_STATUS status;
+ if (k3lGetDeviceStatus( board, channel + ksoChannel, &status, sizeof(status) ) != ksSuccess)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "k3lGetDeviceStatus failed to retrieve channel config for board %d, channel%d!\n", board, channel);
+ switch_mutex_unlock(_pvts_mutex);
+ return NULL;
+ }
+ if(status.CallStatus == kcsFree)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel (%d-%d) is free, let's check if the session is available ...\n", board, channel);
+ pvt = KhompPvt::khompPvt(board, channel);
+ if(pvt != NULL && pvt->session() == NULL)
+ {
+ pvt->session(new_session);
+ break;
+ }
+ pvt = NULL;
+ }
+ }
}
- if(status.CallStatus == kcsFree)
- {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel (%d-%d) is free, let's check if the session is available ...\n", board, channel);
- pvt = KhompPvt::khompPvt(board, channel);
- if(pvt != NULL && pvt->session() == NULL)
+ else
+ {
+ for (int channel = channel_low ; channel <= channel_high ; channel++)
{
- pvt->session(new_session);
- break;
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking if (%d-%d) is free\n", board, channel);
+ try
+ {
+ K3L_CHANNEL_CONFIG channelConfig;
+ channelConfig = Globals::_k3lapi.channel_config( board, channel );
+ }
+ catch (...)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Exception while retrieving channel config for board %d, channel%d!\n", board, channel);
+ switch_mutex_unlock(_pvts_mutex);
+ return NULL;
+ }
+ K3L_CHANNEL_STATUS status;
+ if (k3lGetDeviceStatus( board, channel + ksoChannel, &status, sizeof(status) ) != ksSuccess)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "k3lGetDeviceStatus failed to retrieve channel config for board %d, channel%d!\n", board, channel);
+ switch_mutex_unlock(_pvts_mutex);
+ return NULL;
+ }
+ if(status.CallStatus == kcsFree)
+ {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel (%d-%d) is free, let's check if the session is available ...\n", board, channel);
+ pvt = KhompPvt::khompPvt(board, channel);
+ if(pvt != NULL && pvt->session() == NULL)
+ {
+ pvt->session(new_session);
+ break;
+ }
+ pvt = NULL;
+ }
}
- pvt = NULL;
}
}
}
More information about the Freeswitch-trunk
mailing list