Asterisk - The Open Source Telephony Project
18.5.0
|
Skeleton application. More...
#include "asterisk.h"
#include <math.h>
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
#include "asterisk/config.h"
#include "asterisk/config_options.h"
#include "asterisk/say.h"
#include "asterisk/astobj2.h"
#include "asterisk/acl.h"
#include "asterisk/netsock2.h"
#include "asterisk/strings.h"
#include "asterisk/cli.h"
Go to the source code of this file.
Data Structures | |
struct | skel_config |
A container that holds all config-related information. More... | |
struct | skel_current_game |
Information about a currently running set of games. More... | |
struct | skel_global_config |
A structure to hold global configuration-related options. More... | |
struct | skel_level |
Object to hold level config information. More... | |
struct | skel_level_state |
A structure to maintain level state across reloads. More... | |
Macros | |
#define | LEVEL_BUCKETS 1 |
#define | SKEL_FORMAT "%-15.15s %-15.15s %-15.15s\n" |
#define | SKEL_FORMAT "%-15.15s %-11.11s %-12.12s %-8.8s %-8.8s %-12.12s\n" |
#define | SKEL_FORMAT1 "%-15.15s %-15u %-15u\n" |
#define | SKEL_FORMAT1 "%-15.15s %-11u %-12u %-8u %-8u %-8f\n" |
Enumerations | |
enum | option_args { OPTION_ARG_NUMGAMES, OPTION_ARG_ARRAY_SIZE } |
enum | option_flags { OPTION_CHEAT = (1 << 0), OPTION_NUMGAMES = (1 << 1), OPTION_WAIT = (1 << 0), OPTION_PATTERNS_DISABLED = (1 << 0) } |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static | AO2_GLOBAL_OBJ_STATIC (globals) |
A global object container that will contain the skel_config that gets swapped out on reloads. More... | |
static int | app_exec (struct ast_channel *chan, const char *data) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
CONFIG_INFO_STANDARD (cfg_info, globals, skel_config_alloc,.files=ACO_FILES(&app_skel_conf),) | |
Register information about the configs being processed by this module. More... | |
static int | custom_bitfield_handler (const struct aco_option *opt, struct ast_variable *var, void *obj) |
A custom bitfield handler. More... | |
static char * | handle_skel_show_config (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | handle_skel_show_games (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static char * | handle_skel_show_levels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static int | load_module (void) |
Load the module. More... | |
static void | play_files_helper (struct ast_channel *chan, const char *prompts) |
static int | reload_module (void) |
static void * | skel_config_alloc (void) |
Allocate a skel_config to hold a snapshot of the complete results of parsing a config. More... | |
static void | skel_config_destructor (void *obj) |
static void * | skel_find_or_create_state (const char *category) |
Look up an existing state object, or create a new one. More... | |
static struct skel_current_game * | skel_game_alloc (struct skel_level *level) |
static void | skel_game_destructor (void *obj) |
static void | skel_global_config_destructor (void *obj) |
static void * | skel_level_alloc (const char *cat) |
Allocate a skel_level based on a category in a configuration file. More... | |
static int | skel_level_cmp (void *obj, void *arg, int flags) |
static void | skel_level_destructor (void *obj) |
static void * | skel_level_find (struct ao2_container *tmp_container, const char *category) |
Find a skel level in the specified container. More... | |
static int | skel_level_hash (const void *obj, const int flags) |
static struct skel_level * | skel_state_alloc (const char *name) |
static void | skel_state_destructor (void *obj) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Skeleton (sample) Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, } |
static char * | app = "SkelGuessNumber" |
static const struct ast_app_option | app_opts [128] = { [ 'c' ] = { .flag = OPTION_CHEAT }, [ 'n' ] = { .flag = OPTION_NUMGAMES , .arg_index = OPTION_ARG_NUMGAMES + 1 }, } |
struct aco_file | app_skel_conf |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static struct ao2_container * | games |
The container of active games. More... | |
static struct aco_type | global_option |
An aco_type structure to link the "general" category to the skel_global_config type. More... | |
struct aco_type * | global_options [] = ACO_TYPES(&global_option) |
static const char * | level_categories [] |
static struct aco_type | level_option |
An aco_type structure to link the everything but the "general" and "sounds" categories to the skel_level type. More... | |
struct aco_type * | level_options [] = ACO_TYPES(&level_option) |
static struct ast_cli_entry | skel_cli [] |
static struct aco_type | sound_option |
An aco_type structure to link the "sounds" category to the skel_global_config type. More... | |
struct aco_type * | sound_options [] = ACO_TYPES(&sound_option) |
Skeleton application.
This is a skeleton for development of an Asterisk application
Definition in file app_skel.c.
#define LEVEL_BUCKETS 1 |
Definition at line 201 of file app_skel.c.
Referenced by skel_config_alloc().
#define SKEL_FORMAT "%-15.15s %-15.15s %-15.15s\n" |
Referenced by handle_skel_show_games(), and handle_skel_show_levels().
#define SKEL_FORMAT "%-15.15s %-11.11s %-12.12s %-8.8s %-8.8s %-12.12s\n" |
#define SKEL_FORMAT1 "%-15.15s %-15u %-15u\n" |
Referenced by handle_skel_show_games(), and handle_skel_show_levels().
#define SKEL_FORMAT1 "%-15.15s %-11u %-12u %-8u %-8u %-8f\n" |
enum option_args |
Enumerator | |
---|---|
OPTION_ARG_NUMGAMES | |
OPTION_ARG_ARRAY_SIZE |
Definition at line 141 of file app_skel.c.
enum option_flags |
Enumerator | |
---|---|
OPTION_CHEAT | |
OPTION_NUMGAMES | |
OPTION_WAIT | |
OPTION_PATTERNS_DISABLED |
Definition at line 136 of file app_skel.c.
|
static |
Definition at line 773 of file app_skel.c.
|
static |
Definition at line 773 of file app_skel.c.
|
static |
A global object container that will contain the skel_config that gets swapped out on reloads.
|
static |
Definition at line 379 of file app_skel.c.
References ao2_cleanup, ao2_find, ao2_global_obj_ref, ao2_link, ao2_lock, ao2_unlink, ao2_unlock, app, app_opts, args, AST_APP_ARG, ast_app_parse_options(), ast_channel_language(), ast_debug, AST_DECLARE_APP_ARGS, ast_log, ast_parse_arg(), ast_random(), ast_readstring(), ast_say_number(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, ast_test_flag, buf, globals, LOG_ERROR, LOG_WARNING, NULL, OBJ_KEY, OPTION_ARG_ARRAY_SIZE, OPTION_ARG_NUMGAMES, OPTION_CHEAT, OPTION_NUMGAMES, options, parse(), PARSE_IN_RANGE, PARSE_INT32, PARSE_UINT32, play_files_helper(), RAII_VAR, and skel_game_alloc().
Referenced by load_module().
struct ast_module* AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 773 of file app_skel.c.
CONFIG_INFO_STANDARD | ( | cfg_info | , |
globals | , | ||
skel_config_alloc | , | ||
. | files = ACO_FILES(&app_skel_conf) |
||
) |
Register information about the configs being processed by this module.
|
static |
A custom bitfield handler.
Definition at line 356 of file app_skel.c.
References ast_true(), skel_global_config::cheat, global, ast_variable::name, and ast_variable::value.
Referenced by load_module().
|
static |
Definition at line 595 of file app_skel.c.
References ao2_cleanup, ao2_global_obj_ref, ast_cli(), AST_CLI_YESNO, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, globals, NULL, RAII_VAR, and ast_cli_entry::usage.
|
static |
Definition at line 625 of file app_skel.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, skel_current_game::games_left, skel_current_game::level_info, skel_level::name, NULL, SKEL_FORMAT, SKEL_FORMAT1, skel_current_game::total_games, and ast_cli_entry::usage.
|
static |
Definition at line 655 of file app_skel.c.
References ao2_cleanup, ao2_global_obj_ref, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli(), skel_level_state::avg_guesses, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, globals, skel_level_state::losses, skel_level::max_guesses, skel_level::max_num, skel_level::name, NULL, RAII_VAR, SKEL_FORMAT, SKEL_FORMAT1, skel_level::state, ast_cli_entry::usage, and skel_level_state::wins.
|
static |
Load the module.
Module loading including tests for configuration or dependencies. This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails tests return AST_MODULE_LOAD_FAILURE. If the module can not load the configuration file or other non-critical problem return AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
Definition at line 725 of file app_skel.c.
References ACO_EXACT, aco_info_destroy(), aco_info_init(), aco_option_register, aco_option_register_custom, aco_process_config(), ACO_PROCESS_ERROR, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_cleanup, ao2_container_alloc_list, app, app_exec(), ARRAY_LEN, ast_cli_register_multiple, AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ast_register_application_xml, ASTERISK_GPL_KEY, custom_bitfield_handler(), error(), FLDSET, skel_global_config::high, skel_global_config::lose, skel_global_config::low, NULL, skel_global_config::num_games, OPT_STRINGFIELD_T, OPT_UINT_T, skel_global_config::prompt, reload(), reload_module(), skel_global_config::right, STRFLDSET, unload_module(), and skel_global_config::wrong.
|
static |
Definition at line 369 of file app_skel.c.
References ast_stopstream(), ast_strdupa, ast_stream_and_wait(), skel_global_config::prompt, and strsep().
Referenced by app_exec().
|
static |
Definition at line 697 of file app_skel.c.
References aco_process_config(), ACO_PROCESS_ERROR, and AST_MODULE_LOAD_DECLINE.
Referenced by load_module().
|
static |
Allocate a skel_config to hold a snapshot of the complete results of parsing a config.
Definition at line 566 of file app_skel.c.
References ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, ast_string_field_init, error(), skel_config::global, LEVEL_BUCKETS, skel_config::levels, NULL, skel_config_destructor(), skel_global_config_destructor(), skel_level_cmp(), and skel_level_hash().
|
static |
Definition at line 559 of file app_skel.c.
References ao2_cleanup, skel_config::global, and skel_config::levels.
Referenced by skel_config_alloc().
|
static |
Look up an existing state object, or create a new one.
Definition at line 521 of file app_skel.c.
References ao2_cleanup, ao2_find, ao2_global_obj_ref, ao2_ref, globals, NULL, OBJ_KEY, RAII_VAR, and skel_state_alloc().
Referenced by skel_level_alloc().
|
static |
Definition at line 314 of file app_skel.c.
References ao2_alloc, ao2_ref, skel_current_game::level_info, NULL, and skel_game_destructor().
Referenced by app_exec().
|
static |
Definition at line 303 of file app_skel.c.
References ao2_cleanup, and skel_current_game::level_info.
Referenced by skel_game_alloc().
|
static |
Definition at line 297 of file app_skel.c.
References ast_string_field_free_memory, and global.
Referenced by skel_config_alloc().
|
static |
Allocate a skel_level based on a category in a configuration file.
cat | The category to base the level on |
Definition at line 532 of file app_skel.c.
References ao2_alloc, ao2_ref, ast_string_field_init, ast_string_field_set, name, NULL, skel_find_or_create_state(), skel_level_destructor(), and skel_level::state.
|
static |
Definition at line 339 of file app_skel.c.
References CMP_MATCH, CMP_STOP, match(), skel_level::name, and OBJ_KEY.
Referenced by skel_config_alloc().
|
static |
Definition at line 325 of file app_skel.c.
References ao2_cleanup, ast_string_field_free_memory, and skel_level::state.
Referenced by skel_level_alloc().
|
static |
Find a skel level in the specified container.
tmp_container | A non-active container to search for a level |
category | The category associated with the level to check for |
non-NULL | The level from the container |
NULL | The level does not exist in the container |
Definition at line 508 of file app_skel.c.
References ao2_find, and OBJ_KEY.
|
static |
Definition at line 332 of file app_skel.c.
References ast_str_case_hash(), name, skel_level::name, and OBJ_KEY.
Referenced by skel_config_alloc().
|
static |
Definition at line 497 of file app_skel.c.
References ao2_alloc, NULL, and skel_state_destructor().
Referenced by skel_find_or_create_state().
|
static |
Definition at line 309 of file app_skel.c.
Referenced by skel_state_alloc().
|
static |
Definition at line 706 of file app_skel.c.
References aco_info_destroy(), ao2_cleanup, ao2_global_obj_release, app, ARRAY_LEN, ast_cli_unregister_multiple(), ast_unregister_application(), and globals.
Referenced by load_module().
|
static |
Definition at line 773 of file app_skel.c.
|
static |
Definition at line 134 of file app_skel.c.
Referenced by app_exec(), load_module(), and unload_module().
|
static |
Definition at line 150 of file app_skel.c.
Referenced by app_exec().
struct aco_file app_skel_conf |
Definition at line 281 of file app_skel.c.
|
static |
Definition at line 773 of file app_skel.c.
|
static |
The container of active games.
Definition at line 290 of file app_skel.c.
|
static |
An aco_type structure to link the "general" category to the skel_global_config type.
Definition at line 241 of file app_skel.c.
struct aco_type* global_options[] = ACO_TYPES(&global_option) |
Definition at line 249 of file app_skel.c.
|
static |
Definition at line 262 of file app_skel.c.
|
static |
An aco_type structure to link the everything but the "general" and "sounds" categories to the skel_level type.
Definition at line 269 of file app_skel.c.
struct aco_type* level_options[] = ACO_TYPES(&level_option) |
Definition at line 279 of file app_skel.c.
|
static |
Definition at line 691 of file app_skel.c.
|
static |
An aco_type structure to link the "sounds" category to the skel_global_config type.
Definition at line 252 of file app_skel.c.
struct aco_type* sound_options[] = ACO_TYPES(&sound_option) |
Definition at line 260 of file app_skel.c.