Newer
Older
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
/*! \brief Show container contents - CLI command */
static char *handle_cli_astobj2_container_dump(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
const char *name;
struct ao2_reg_container *reg;
switch (cmd) {
case CLI_INIT:
e->command = "astobj2 container dump";
e->usage =
"Usage: astobj2 container dump <name>\n"
" Show contents of the container <name>.\n";
return NULL;
case CLI_GENERATE:
return complete_container_names(a);
}
if (a->argc != 4) {
return CLI_SHOWUSAGE;
}
name = a->argv[3];
reg = ao2_t_find(reg_containers, name, OBJ_SEARCH_KEY, "Find registered container");
if (reg) {
ao2_container_dump(reg->registered, 0, name, (void *) &a->fd, cli_output,
reg->prnt_obj);
ao2_t_ref(reg, -1, "Done with registered container object.");
} else {
ast_cli(a->fd, "Container '%s' not found.\n", name);
}
return CLI_SUCCESS;
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
/*! \brief Show container statistics - CLI command */
static char *handle_cli_astobj2_container_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
const char *name;
struct ao2_reg_container *reg;
switch (cmd) {
case CLI_INIT:
e->command = "astobj2 container stats";
e->usage =
"Usage: astobj2 container stats <name>\n"
" Show statistics about the specified container <name>.\n";
return NULL;
case CLI_GENERATE:
return complete_container_names(a);
}
if (a->argc != 4) {
return CLI_SHOWUSAGE;
}
name = a->argv[3];
reg = ao2_t_find(reg_containers, name, OBJ_SEARCH_KEY, "Find registered container");
if (reg) {
ao2_container_stats(reg->registered, 0, name, (void *) &a->fd, cli_output);
ao2_t_ref(reg, -1, "Done with registered container object.");
} else {
ast_cli(a->fd, "Container '%s' not found.\n", name);
}
return CLI_SUCCESS;
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
/*! \brief Show container check results - CLI command */
static char *handle_cli_astobj2_container_check(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
const char *name;
struct ao2_reg_container *reg;
switch (cmd) {
case CLI_INIT:
e->command = "astobj2 container check";
e->usage =
"Usage: astobj2 container check <name>\n"
" Perform a container integrity check on <name>.\n";
return NULL;
case CLI_GENERATE:
return complete_container_names(a);
}
if (a->argc != 4) {
return CLI_SHOWUSAGE;
}
name = a->argv[3];
reg = ao2_t_find(reg_containers, name, OBJ_SEARCH_KEY, "Find registered container");
if (reg) {
ast_cli(a->fd, "Container check of '%s': %s.\n", name,
ao2_container_check(reg->registered, 0) ? "failed" : "OK");
ao2_t_ref(reg, -1, "Done with registered container object.");
} else {
ast_cli(a->fd, "Container '%s' not found.\n", name);
}
return CLI_SUCCESS;
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
static struct ast_cli_entry cli_astobj2[] = {
AST_CLI_DEFINE(handle_cli_astobj2_container_dump, "Show container contents"),
AST_CLI_DEFINE(handle_cli_astobj2_container_stats, "Show container statistics"),
AST_CLI_DEFINE(handle_cli_astobj2_container_check, "Perform a container integrity check"),
};
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
static void container_cleanup(void)
{
ao2_t_ref(reg_containers, -1, "Releasing container registration container");
reg_containers = NULL;
ast_cli_unregister_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
int container_init(void)
{
George Joseph
committed
#if defined(AO2_DEBUG)
reg_containers = ao2_t_container_alloc_list(AO2_ALLOC_OPT_LOCK_RWLOCK,
AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, ao2_reg_sort_cb, NULL,
"Container registration container.");
if (!reg_containers) {
return -1;
}
ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
ast_register_cleanup(container_cleanup);
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
return 0;
}