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