134 static char *
app =
"SkelGuessNumber";
201 #define LEVEL_BUCKETS 1 246 .category =
"general",
257 .category =
"sounds",
273 .category = (
const char *)level_categories,
283 .types =
ACO_TYPES(&global_option, &sound_option, &level_option),
342 const char *
match = (flags &
OBJ_KEY) ? arg : two->name;
360 if (!strcasecmp(var->
name,
"cheat")) {
408 if (
args.argc == 2) {
432 game->total_games = cfg->global->num_games;
434 game->games_left = game->total_games;
437 for (game->games_left = game->total_games; game->games_left; game->games_left--) {
440 ast_debug(1,
"They should totally should guess %u\n", num);
446 for (guesses = 0; guesses < level->max_guesses; guesses++) {
447 size_t buflen = log10(level->max_num) + 1;
455 if (guesses < level->max_guesses - 1) {
462 if (guess == num && !game->cheat) {
468 }
else if (guess < num) {
474 if (guesses < level->max_guesses - 1) {
482 ++level->state->wins;
483 level->state->avg_guesses = ((level->state->wins - 1) * level->state->avg_guesses + guesses) / level->state->wins;
486 level->state->losses++;
525 if (!cfg || !cfg->levels || !(level =
ao2_find(cfg->levels, category,
OBJ_KEY))) {
601 e->
command =
"skel show config";
603 "Usage: skel show config\n" 604 " List app_skel global config\n";
614 ast_cli(a->
fd,
"games per call: %u\n", cfg->global->num_games);
618 ast_cli(a->
fd,
" prompt: %s\n", cfg->global->prompt);
619 ast_cli(a->
fd,
" wrong guess: %s\n", cfg->global->wrong);
620 ast_cli(a->
fd,
" right guess: %s\n", cfg->global->right);
632 e->
command =
"skel show games";
634 "Usage: skel show games\n" 635 " List app_skel active games\n";
641 #define SKEL_FORMAT "%-15.15s %-15.15s %-15.15s\n" 642 #define SKEL_FORMAT1 "%-15.15s %-15u %-15u\n" 663 e->
command =
"skel show levels";
665 "Usage: skel show levels\n" 666 " List the app_skel levels\n";
676 #define SKEL_FORMAT "%-15.15s %-11.11s %-12.12s %-8.8s %-8.8s %-12.12s\n" 677 #define SKEL_FORMAT1 "%-15.15s %-11u %-12u %-8u %-8u %-8f\n" 678 ast_cli(a->
fd,
SKEL_FORMAT,
"Name",
"Max number",
"Max Guesses",
"Wins",
"Losses",
"Avg Guesses");
aco_type_item_find item_find
Main Channel structure associated with a channel.
#define AST_CLI_DEFINE(fn, txt,...)
Asterisk locking-related definitions:
const ast_string_field lose
Asterisk main include file. File version handling, generic pbx functions.
static void skel_level_destructor(void *obj)
static void skel_config_destructor(void *obj)
const ast_string_field wrong
static struct aco_type global
String manipulation functions.
static struct aco_type sound_option
An aco_type structure to link the "sounds" category to the skel_global_config type.
#define aco_option_register_custom(info, name, matchtype, types, default_val, handler, flags)
Register a config option.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
static struct skel_current_game * skel_game_alloc(struct skel_level *level)
#define ast_test_flag(p, flag)
const ast_string_field right
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
descriptor for a cli entry.
static struct ast_cli_entry skel_cli[]
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Structure for variables, used for configurations and for channel variables.
static int skel_level_hash(const void *obj, const int flags)
struct ao2_container * levels
static char * levels[NUMLOGLEVELS]
Logging channels used in the Asterisk logging system.
static void * skel_level_alloc(const char *cat)
Allocate a skel_level based on a category in a configuration file.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
enum aco_process_status aco_process_config(struct aco_info *info, int reload)
Process a config info via the options registered with an aco_info.
#define ao2_global_obj_ref(holder)
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
const ast_string_field high
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
static char * handle_skel_show_games(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static AO2_GLOBAL_OBJ_STATIC(globals)
A global object container that will contain the skel_config that gets swapped out on reloads...
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
const ast_string_field prompt
The representation of a single configuration file to be processed.
void ast_cli(int fd, const char *fmt,...)
int ast_unregister_application(const char *app)
Unregister an application.
struct skel_level * level_info
#define ACO_TYPES(...)
A helper macro to ensure that aco_info types always have a sentinel.
static struct ao2_container * games
The container of active games.
#define ast_strlen_zero(foo)
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
struct aco_file app_skel_conf
Configuration File Parser.
#define ast_debug(level,...)
Log a DEBUG message.
static int custom_bitfield_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
A custom bitfield handler.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
General Asterisk PBX channel definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Type for default option handler for unsigned integers.
static void play_files_helper(struct ast_channel *chan, const char *prompts)
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Access Control of various sorts.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
static struct skel_level * skel_state_alloc(const char *name)
long int ast_random(void)
const ast_string_field low
#define ast_strdupa(s)
duplicate a string in memory from the stack
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_le...
aco_type_item_alloc item_alloc
static struct console_pvt globals
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Core PBX routines and definitions.
struct skel_level_state * state
struct aco_type * global_options[]
Their was an error and no changes were applied.
static int app_exec(struct ast_channel *chan, const char *data)
Configuration option-handling.
static const struct ast_app_option app_opts[128]
static char * handle_skel_show_levels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Object to hold level config information.
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
#define ao2_unlink(container, obj)
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
#define ao2_global_obj_release(holder)
static char * handle_skel_show_config(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static void skel_state_destructor(void *obj)
#define ao2_iterator_next(iter)
#define ao2_alloc(data_size, destructor_fn)
static void parse(struct mgcp_request *req)
struct aco_type * sound_options[]
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits)
stream file until digit If the file name is non-empty, try to play it.
struct skel_global_config * global
A container that holds all config-related information.
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *result,...)
The argument parsing routine.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
Module has failed to load, may be in an inconsistent state.
#define ao2_find(container, arg, flags)
static struct aco_type global_option
An aco_type structure to link the "general" category to the skel_global_config type.
Structure used to handle boolean flags.
static int unload_module(void)
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
char * strsep(char **str, const char *delims)
static void * skel_find_or_create_state(const char *category)
Look up an existing state object, or create a new one.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options)
says a number
Standard Command Line Interface.
static int skel_level_cmp(void *obj, void *arg, int flags)
Type information about a category-level configurable object.
A structure to hold global configuration-related options.
const ast_string_field name
static void * skel_level_find(struct ao2_container *tmp_container, const char *category)
Find a skel level in the specified container.
const char * ast_channel_language(const struct ast_channel *chan)
A structure to maintain level state across reloads.
Type for default option handler for stringfields.
static int load_module(void)
Load the module.
static void skel_game_destructor(void *obj)
int error(const char *format,...)
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.
#define AST_CLI_YESNO(x)
Return Yes or No depending on the argument.
int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders)
Reads multiple digits.
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
struct aco_type * level_options[]
Say numbers and dates (maybe words one day too)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static int reload_module(void)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
int ast_stopstream(struct ast_channel *c)
Stops a stream.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
#define AST_APP_ARG(name)
Define an application argument.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
static void * skel_config_alloc(void)
Allocate a skel_config to hold a snapshot of the complete results of parsing a config.
static void skel_global_config_destructor(void *obj)
Information about a currently running set of games.
#define ao2_link(container, obj)