mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 12:16:00 +00:00
media_cache.c: Various CLI improvements
* Use ast_cli_completion_add() to improve performance when large number of cached items are present. * Only complete one URI for commands that only accept a single URI. * Change command documentation to wrap at 80 characters to improve readability. Change-Id: Iedb0a2c3541e49561bc231dca2dcc0ebd8612902
This commit is contained in:
@@ -493,8 +493,7 @@ static char *media_cache_handle_show_all(struct ast_cli_entry *e, int cmd, struc
|
|||||||
e->command = "media cache show all";
|
e->command = "media cache show all";
|
||||||
e->usage =
|
e->usage =
|
||||||
"Usage: media cache show all\n"
|
"Usage: media cache show all\n"
|
||||||
" Display a summary of all current items\n"
|
" Display a summary of all current items in the media cache.\n";
|
||||||
" in the media cache.\n";
|
|
||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -515,27 +514,22 @@ static char *media_cache_handle_show_all(struct ast_cli_entry *e, int cmd, struc
|
|||||||
* \internal
|
* \internal
|
||||||
* \brief CLI tab completion function for URIs
|
* \brief CLI tab completion function for URIs
|
||||||
*/
|
*/
|
||||||
static char *cli_complete_uri(const char *word, int state)
|
static char *cli_complete_uri(const char *word)
|
||||||
{
|
{
|
||||||
struct ast_bucket_file *bucket_file;
|
struct ast_bucket_file *bucket_file;
|
||||||
struct ao2_iterator it_media_items;
|
struct ao2_iterator it_media_items;
|
||||||
int wordlen = strlen(word);
|
int wordlen = strlen(word);
|
||||||
int which = 0;
|
|
||||||
char *result = NULL;
|
|
||||||
|
|
||||||
it_media_items = ao2_iterator_init(media_cache, 0);
|
it_media_items = ao2_iterator_init(media_cache, 0);
|
||||||
while ((bucket_file = ao2_iterator_next(&it_media_items))) {
|
while ((bucket_file = ao2_iterator_next(&it_media_items))) {
|
||||||
if (!strncasecmp(word, ast_sorcery_object_get_id(bucket_file), wordlen)
|
if (!strncasecmp(word, ast_sorcery_object_get_id(bucket_file), wordlen)) {
|
||||||
&& ++which > state) {
|
ast_cli_completion_add(ast_strdup(ast_sorcery_object_get_id(bucket_file)));
|
||||||
result = ast_strdup(ast_sorcery_object_get_id(bucket_file));
|
|
||||||
}
|
}
|
||||||
ao2_ref(bucket_file, -1);
|
ao2_ref(bucket_file, -1);
|
||||||
if (result) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ao2_iterator_destroy(&it_media_items);
|
ao2_iterator_destroy(&it_media_items);
|
||||||
return result;
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *media_cache_handle_show_item(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
static char *media_cache_handle_show_item(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||||
@@ -550,11 +544,10 @@ static char *media_cache_handle_show_item(struct ast_cli_entry *e, int cmd, stru
|
|||||||
e->command = "media cache show";
|
e->command = "media cache show";
|
||||||
e->usage =
|
e->usage =
|
||||||
"Usage: media cache show <uri>\n"
|
"Usage: media cache show <uri>\n"
|
||||||
" Display all information about a particular\n"
|
" Display all information about a particular item in the media cache.\n";
|
||||||
" item in the media cache.\n";
|
|
||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
return cli_complete_uri(a->word, a->n);
|
return a->pos == e->args ? cli_complete_uri(a->word) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a->argc != 4) {
|
if (a->argc != 4) {
|
||||||
@@ -590,14 +583,13 @@ static char *media_cache_handle_delete_item(struct ast_cli_entry *e, int cmd, st
|
|||||||
e->command = "media cache delete";
|
e->command = "media cache delete";
|
||||||
e->usage =
|
e->usage =
|
||||||
"Usage: media cache delete <uri>\n"
|
"Usage: media cache delete <uri>\n"
|
||||||
" Delete an item from the media cache.\n"
|
" Delete an item from the media cache.\n\n"
|
||||||
" Note that this will also remove any local\n"
|
" Note that this will also remove any local storage of the media associated\n"
|
||||||
" storage of the media associated with the URI,\n"
|
" with the URI, and will inform the backend supporting the URI scheme that\n"
|
||||||
" and will inform the backend supporting the URI\n"
|
" it should remove the item.\n";
|
||||||
" scheme that it should remove the item.\n";
|
|
||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
return cli_complete_uri(a->word, a->n);
|
return a->pos == e->args ? cli_complete_uri(a->word) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a->argc != 4) {
|
if (a->argc != 4) {
|
||||||
@@ -622,13 +614,12 @@ static char *media_cache_handle_refresh_item(struct ast_cli_entry *e, int cmd, s
|
|||||||
e->command = "media cache refresh";
|
e->command = "media cache refresh";
|
||||||
e->usage =
|
e->usage =
|
||||||
"Usage: media cache refresh <uri>\n"
|
"Usage: media cache refresh <uri>\n"
|
||||||
" Ask for a refresh of a particular URI.\n"
|
" Ask for a refresh of a particular URI.\n\n"
|
||||||
" If the item does not already exist in the\n"
|
" If the item does not already exist in the media cache, the item will be\n"
|
||||||
" media cache, the item will be populated from\n"
|
" populated from the backend supporting the URI scheme.\n";
|
||||||
" the backend supporting the URI scheme.\n";
|
|
||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
return cli_complete_uri(a->word, a->n);
|
return a->pos == e->args ? cli_complete_uri(a->word) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a->argc != 4) {
|
if (a->argc != 4) {
|
||||||
@@ -651,8 +642,8 @@ static char *media_cache_handle_create_item(struct ast_cli_entry *e, int cmd, st
|
|||||||
e->command = "media cache create";
|
e->command = "media cache create";
|
||||||
e->usage =
|
e->usage =
|
||||||
"Usage: media cache create <uri> <file>\n"
|
"Usage: media cache create <uri> <file>\n"
|
||||||
" Create an item in the media cache by associating\n"
|
" Create an item in the media cache by associating a local media file with\n"
|
||||||
" a local media file with some URI.\n";
|
" some URI.\n";
|
||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user