From 6c7ba82edfacdfb3c1fa7e800844d3ab19cd6990 Mon Sep 17 00:00:00 2001 From: MelwareDE Date: Fri, 29 Oct 2010 21:51:03 +0000 Subject: [PATCH] Add 'capi show resources' --- README | 6 +++ chan_capi_cli.c | 112 +++++++++++++++++++++++++++++++++++++++++++--- chan_capi_utils.c | 15 +++++++ chan_capi_utils.h | 13 ++++++ 4 files changed, 139 insertions(+), 7 deletions(-) diff --git a/README b/README index 56e1c7a..cb249d2 100644 --- a/README +++ b/README @@ -138,6 +138,12 @@ capi show channels: capi chatinfo: Show status of CAPI CHAT. +capi ifcstate: + Show state of interfaces. (Diva only, chan_capi + compiled with 'make DIVA_STATUS=1') + +capi show resources: + Show resources in use. CAPI command application ======================================== diff --git a/chan_capi_cli.c b/chan_capi_cli.c index f6de90e..c41441b 100644 --- a/chan_capi_cli.c +++ b/chan_capi_cli.c @@ -28,34 +28,38 @@ /* * usages */ -static char info_usage[] = +static char info_usage[] = "Usage: " CC_MESSAGE_NAME " info\n" " Show info about B channels on controllers.\n"; -static char show_channels_usage[] = +static char show_channels_usage[] = "Usage: " CC_MESSAGE_NAME " show channels\n" " Show info about B channels.\n"; -static char debug_usage[] = +static char show_resources_usage[] = +"Usage: " CC_MESSAGE_NAME " show ressources\n" +" Show info about used by channels resources.\n"; + +static char debug_usage[] = "Usage: " CC_MESSAGE_NAME " debug\n" " Enables dumping of " CC_MESSAGE_BIGNAME " packets for debugging purposes\n"; -static char no_debug_usage[] = +static char no_debug_usage[] = "Usage: " CC_MESSAGE_NAME " no debug\n" " Disables dumping of " CC_MESSAGE_BIGNAME " packets for debugging purposes\n"; -static char qsig_debug_usage[] = +static char qsig_debug_usage[] = "Usage: " CC_MESSAGE_NAME " qsig debug\n" " Enables dumping of QSIG facilities for debugging purposes\n"; -static char qsig_no_debug_usage[] = +static char qsig_no_debug_usage[] = "Usage: " CC_MESSAGE_NAME " qsig no debug\n" " Disables dumping of QSIG facilities for debugging purposes\n"; #ifndef CC_AST_HAS_VERSION_1_6 static #endif -char chatinfo_usage[] = +char chatinfo_usage[] = "Usage: " CC_MESSAGE_NAME " chatinfo\n" " Show info about chat status.\n"; @@ -66,6 +70,7 @@ char chatinfo_usage[] = #define CC_CLI_TEXT_QSIG_DEBUG "Enable QSIG debugging" #define CC_CLI_TEXT_QSIG_NO_DEBUG "Disable QSIG debugging" #define CC_CLI_TEXT_CHATINFO "Show " CC_MESSAGE_BIGNAME " chat info" +#define CC_CLI_TEXT_SHOW_RESOURCES "Show used resources" /* * helper functions to convert conf value to string @@ -226,6 +231,94 @@ static int pbxcli_capi_show_channels(int fd, int argc, char *argv[]) #endif } +/* + * do command capi show resources + */ +#ifdef CC_AST_HAS_VERSION_1_6 +static char *pbxcli_capi_show_resources(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +#else +static int pbxcli_capi_show_ressources(int fd, int argc, char *argv[]) +#endif +{ + int ifc_type; + const struct capi_pvt *i; + int required_args; + int provided_args; + const char* required_channel_name = NULL; + struct { + const struct capi_pvt *head; + void (*lock_proc)(void); + void (*unlock_proc)(void); + } data[2]; + + data[0].head = capi_iflist; + data[0].lock_proc = pbx_capi_lock_interfaces; + data[0].unlock_proc = pbx_capi_unlock_interfaces; + data[1].head = pbx_capi_get_nulliflist(); + data[1].lock_proc = pbx_capi_nulliflist_lock; + data[1].unlock_proc = pbx_capi_nulliflist_unlock; + +#ifdef CC_AST_HAS_VERSION_1_6 + int fd = a->fd; + + if (cmd == CLI_INIT) { + e->command = CC_MESSAGE_NAME " show resources"; + e->usage = show_resources_usage; + return NULL; + } else if (cmd == CLI_GENERATE) + return NULL; + required_args = e->args; + provided_args = a->argc; + if (required_args < provided_args) { + required_channel_name = a->argv[required_args]; + } +#else + required_args = 3; + provided_args = argc; + if (required_args < provided_args) { + required_channel_name = argv[required_args]; + } +#endif + + ast_cli(fd, CC_MESSAGE_BIGNAME " resources in use:\n"); + ast_cli(fd, "%-40s %-6s %-4s %-10s %-9s %-5s %-5s %-6s %-6s\n", + "Line-Name", "Domain", "DTMF", "EchoCancel", "NoiseSupp", "RxAGC", "TxAGC", "RxGain", "TxGain"); + ast_cli(fd, "------------------------------------------------------------------------------------------------------\n"); + + for (ifc_type = 0; ifc_type < sizeof(data)/sizeof(data[0]); ifc_type++) { + data[ifc_type].lock_proc(); + + for (i = data[ifc_type].head; i; i = i->next) { + if ((i->used == 0) || ((i->channeltype != CAPI_CHANNELTYPE_B) && + (i->channeltype != CAPI_CHANNELTYPE_NULL))) + continue; + if (i->data_plci != 0) + continue; + if ((required_channel_name != NULL) && (strcmp(required_channel_name, i->vname) != 0)) + continue; + + ast_cli(fd, "%-40s %-6s %-4s %-10s %-9s %-5s %-5s %-.1f%-3s %-.1f%-3s\n", + i->vname, + (i->channeltype == CAPI_CHANNELTYPE_B) ? "TDM" : "IP", + (i->isdnstate & CAPI_ISDN_STATE_DTMF) ? "Y" : "N", + (i->isdnstate & CAPI_ISDN_STATE_EC) ? "Y" : "N", + (i->divaAudioFlags & 0x0080) ? "Y" : "N", /* Noise supression */ + (i->divaAudioFlags & 0x0008) ? "Y" : "N", /* Rx AGC */ + (i->divaAudioFlags & 0x0004) ? "Y" : "N", /* Tx AGC */ + i->divaDigitalRxGainDB, "dB", + i->divaDigitalTxGainDB, "dB"); + } + + data[ifc_type].unlock_proc(); + } + +#ifdef CC_AST_HAS_VERSION_1_6 + return CLI_SUCCESS; +#else + return RESULT_SUCCESS; +#endif +} + /* * do command capi info */ @@ -426,6 +519,7 @@ static struct ast_cli_entry cc_cli_cmd[] = { #ifdef DIVA_STATUS AST_CLI_DEFINE(pbxcli_capi_ifc_status, CC_CLI_TEXT_IFC_STATUSINFO), #endif + AST_CLI_DEFINE(pbxcli_capi_show_resources, CC_CLI_TEXT_SHOW_RESOURCES), }; #else static struct ast_cli_entry cli_info = @@ -446,6 +540,8 @@ static struct ast_cli_entry cli_chatinfo = static struct ast_cli_entry cli_ifcstate = { { CC_MESSAGE_NAME, "ifcstate", NULL }, pbxcli_capi_ifc_status, CC_CLI_TEXT_IFC_STATUSINFO, diva_status_ifc_state_usage }; #endif +static struct ast_cli_entry cli_show_resources = + { { CC_MESSAGE_NAME, "show", "resources", NULL }, pbxcli_capi_show_resources, CC_CLI_TEXT_SHOW_RESOURCES, show_resources_usage }; #endif @@ -465,6 +561,7 @@ void pbx_capi_cli_register(void) #ifdef DIVA_STATUS ast_cli_register(&cli_ifcstate); #endif + ast_cli_register(&cli_show_resources); #endif } @@ -483,5 +580,6 @@ void pbx_capi_cli_unregister(void) #ifdef DIVA_STATUS ast_cli_unregister(&cli_ifcstate); #endif + ast_cli_unregister(&cli_show_resources); #endif } diff --git a/chan_capi_utils.c b/chan_capi_utils.c index ad27d95..9a14e7e 100644 --- a/chan_capi_utils.c +++ b/chan_capi_utils.c @@ -1631,3 +1631,18 @@ const char* pbx_capi_get_connectedname(struct ast_channel* c) return (name); } +const struct capi_pvt *pbx_capi_get_nulliflist(void) +{ + return nulliflist; +} + +void pbx_capi_nulliflist_lock(void) +{ + cc_mutex_lock(&nullif_lock); +} + +void pbx_capi_nulliflist_unlock(void) +{ + cc_mutex_unlock(&nullif_lock); +} + diff --git a/chan_capi_utils.h b/chan_capi_utils.h index ef6ed4b..910194f 100644 --- a/chan_capi_utils.h +++ b/chan_capi_utils.h @@ -80,4 +80,17 @@ extern MESSAGE_EXCHANGE_ERROR capi_sendf( struct capi_pvt *capii, int waitconf, _cword command, _cdword Id, _cword Number, char * format, ...); +/*! + \brief nulliflist + */ +const struct capi_pvt *pbx_capi_get_nulliflist(void); +/*! + \brief cc_mutex_lock(&nullif_lock) + */ +void pbx_capi_nulliflist_lock(void); +/*! + \brief cc_mutex_unlock(&nullif_lock) + */ +void pbx_capi_nulliflist_unlock(void); + #endif