Asterisk main include file. File version handling, generic pbx functions. More...

Go to the source code of this file.
Defines | |
| #define | AST_DIR_MODE 0777 |
| #define | AST_FILE_MODE 0666 |
| #define | ASTERISK_FILE_VERSION(file, version) |
| Register/unregister a source code file with the core. | |
| #define | bcopy 0x__dont_use_bcopy__use_memmove_instead() |
| #define | bzero 0x__dont_use_bzero__use_memset_instead"" |
| #define | DEFAULT_LANGUAGE "en" |
| #define | DEFAULT_SAMPLE_RATE 8000 |
| #define | DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000) |
| #define | sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__ |
| #define | setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__ |
Functions | |
| int | ast_add_profile (const char *, uint64_t scale) |
| support for event profiling | |
| char * | ast_complete_source_filename (const char *partial, int n) |
| int | ast_fd_init (void) |
| const char * | ast_file_version_find (const char *file) |
| Find version for given module name. | |
| int64_t | ast_mark (int, int start1_stop0) |
| int | ast_pbx_init (void) |
| int64_t | ast_profile (int, int64_t) |
| int | ast_register_atexit (void(*func)(void)) |
| Register a function to be executed before Asterisk exits. | |
| void | ast_register_file_version (const char *file, const char *version) |
| Register the version of a source code file with the core. | |
| int | ast_set_priority (int) |
| We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy activity on it, this is a good thing. | |
| void | ast_unregister_atexit (void(*func)(void)) |
| Unregister a function registered with ast_register_atexit(). | |
| void | ast_unregister_file_version (const char *file) |
| Unregister a source code file from the core. | |
Asterisk main include file. File version handling, generic pbx functions.
Definition in file asterisk.h.
| #define AST_DIR_MODE 0777 |
Definition at line 33 of file asterisk.h.
| #define AST_FILE_MODE 0666 |
Definition at line 36 of file asterisk.h.
Referenced by __ast_play_and_record(), ast_lock_path_lockfile(), chanspy_exec(), extenspy_exec(), dictate_exec(), festival_exec(), recordthread(), record_exec(), sms_log(), load_module(), handle_pri_set_debug_file(), try_firmware(), dbinit(), copy(), action_createconfig(), handle_recordfile(), handle_cli_file_convert(), and ast_monitor_start().
| #define ASTERISK_FILE_VERSION | ( | file, | |
| version | |||
| ) |
Register/unregister a source code file with the core.
| file | the source file name |
| version | the version string (typically a SVN revision keyword string) |
This macro will place a file-scope constructor and destructor into the source of the module using it; this will cause the version of this file to registered with the Asterisk core (and unregistered) at the appropriate times.
Example:
ASTERISK_FILE_VERSION(__FILE__, "\$Revision\$")
Definition at line 164 of file asterisk.h.
| #define bcopy 0x__dont_use_bcopy__use_memmove_instead() |
Definition at line 224 of file asterisk.h.
| #define bzero 0x__dont_use_bzero__use_memset_instead"" |
Definition at line 223 of file asterisk.h.
| #define DEFAULT_LANGUAGE "en" |
Definition at line 39 of file asterisk.h.
Referenced by fileexists_core().
| #define DEFAULT_SAMPLE_RATE 8000 |
Definition at line 41 of file asterisk.h.
Referenced by setformat(), ogg_vorbis_open(), ogg_vorbis_rewrite(), check_header(), and write_header().
| #define DEFAULT_SAMPLES_PER_MS ((DEFAULT_SAMPLE_RATE)/1000) |
Definition at line 42 of file asterisk.h.
Referenced by isAnsweringMachine(), ast_stream_fastforward(), and ast_stream_rewind().
| #define sched_setscheduler __PLEASE_USE_ast_set_priority_INSTEAD_OF_sched_setscheduler__ |
Definition at line 44 of file asterisk.h.
Referenced by ast_set_priority().
| #define setpriority __PLEASE_USE_ast_set_priority_INSTEAD_OF_setpriority__ |
Definition at line 43 of file asterisk.h.
Referenced by ast_set_priority().
| int ast_add_profile | ( | const char * | name, |
| uint64_t | scale | ||
| ) |
support for event profiling
(note, this must be documented a lot more) ast_add_profile allocates a generic 'counter' with a given name, which can be shown with the command 'core show profile <name>'
The counter accumulates positive or negative values supplied by
support for event profiling
Definition at line 691 of file asterisk.c.
References prof_data, ast_calloc, profile_data::entries, profile_data::max_size, ast_realloc, profile_data::e, profile_entry::name, ast_strdup, profile_entry::value, profile_entry::events, profile_entry::mark, and profile_entry::scale.
Referenced by extension_match_core().
{
int l = sizeof(struct profile_data);
int n = 10; /* default entries */
if (prof_data == NULL) {
prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry));
if (prof_data == NULL)
return -1;
prof_data->entries = 0;
prof_data->max_size = n;
}
if (prof_data->entries >= prof_data->max_size) {
void *p;
n = prof_data->max_size + 20;
p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry));
if (p == NULL)
return -1;
prof_data = p;
prof_data->max_size = n;
}
n = prof_data->entries++;
prof_data->e[n].name = ast_strdup(name);
prof_data->e[n].value = 0;
prof_data->e[n].events = 0;
prof_data->e[n].mark = 0;
prof_data->e[n].scale = scale;
return n;
}
| char* ast_complete_source_filename | ( | const char * | partial, |
| int | n | ||
| ) |
Definition at line 342 of file asterisk.c.
References len(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, ast_strdup, and AST_RWLIST_UNLOCK.
Referenced by handle_verbose().
{
struct file_version *find;
size_t len = strlen(partial);
int count = 0;
char *res = NULL;
AST_RWLIST_RDLOCK(&file_versions);
AST_RWLIST_TRAVERSE(&file_versions, find, list) {
if (!strncasecmp(find->file, partial, len) && ++count > n) {
res = ast_strdup(find->file);
break;
}
}
AST_RWLIST_UNLOCK(&file_versions);
return res;
}
| int ast_fd_init | ( | void | ) |
| const char* ast_file_version_find | ( | const char * | file | ) |
Find version for given module name.
| file | Module name (i.e. chan_sip.so) |
Definition at line 361 of file asterisk.c.
References AST_RWLIST_WRLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.
Referenced by manager_modulecheck().
{
struct file_version *iterator;
AST_RWLIST_WRLOCK(&file_versions);
AST_RWLIST_TRAVERSE(&file_versions, iterator, list) {
if (!strcasecmp(iterator->file, file))
break;
}
AST_RWLIST_UNLOCK(&file_versions);
if (iterator)
return iterator->version;
return NULL;
}
| int64_t ast_mark | ( | int | , |
| int | start1_stop0 | ||
| ) |
Definition at line 756 of file asterisk.c.
References prof_data, profile_data::entries, profile_data::e, profile_entry::mark, rdtsc(), profile_entry::scale, profile_entry::value, and profile_entry::events.
Referenced by __ast_pthread_mutex_lock(), and extension_match_core().
{
if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
return 0;
if (startstop == 1)
prof_data->e[i].mark = rdtsc();
else {
prof_data->e[i].mark = (rdtsc() - prof_data->e[i].mark);
if (prof_data->e[i].scale > 1)
prof_data->e[i].mark /= prof_data->e[i].scale;
prof_data->e[i].value += prof_data->e[i].mark;
prof_data->e[i].events++;
}
return prof_data->e[i].mark;
}
| int ast_pbx_init | ( | void | ) |
Provided by pbx.c
Definition at line 10470 of file pbx.c.
References ao2_container_alloc, hint_hash(), hint_cmp(), and statecbs_cmp().
Referenced by main().
{
hints = ao2_container_alloc(HASH_EXTENHINT_SIZE, hint_hash, hint_cmp);
statecbs = ao2_container_alloc(HASH_EXTENHINT_SIZE, NULL, statecbs_cmp);
return (hints && statecbs) ? 0 : -1;
}
| int64_t ast_profile | ( | int | , |
| int64_t | |||
| ) |
Definition at line 721 of file asterisk.c.
References prof_data, profile_data::entries, profile_data::e, profile_entry::scale, profile_entry::value, and profile_entry::events.
| int ast_register_atexit | ( | void(*)(void) | func | ) |
Register a function to be executed before Asterisk exits.
| func | The callback function to use. |
| 0 | on success. |
| -1 | on error. |
Definition at line 932 of file asterisk.c.
References ast_calloc, ast_atexit::func, ast_unregister_atexit(), AST_RWLIST_WRLOCK, AST_RWLIST_INSERT_HEAD, and AST_RWLIST_UNLOCK.
Referenced by main(), do_reload(), ast_cel_engine_init(), load_module(), and ast_xmldoc_load_documentation().
{
struct ast_atexit *ae;
if (!(ae = ast_calloc(1, sizeof(*ae))))
return -1;
ae->func = func;
ast_unregister_atexit(func);
AST_RWLIST_WRLOCK(&atexits);
AST_RWLIST_INSERT_HEAD(&atexits, ae, list);
AST_RWLIST_UNLOCK(&atexits);
return 0;
}
| void ast_register_file_version | ( | const char * | file, |
| const char * | version | ||
| ) |
Register the version of a source code file with the core.
| file | the source file name |
| version | the version string (typically a SVN revision keyword string) |
This function should not be called directly, but instead the ASTERISK_FILE_VERSION macro should be used to register a file with the core.
Definition at line 303 of file asterisk.c.
References ast_strdupa, ast_strip(), ast_strip_quoted(), ast_calloc, AST_RWLIST_WRLOCK, AST_RWLIST_INSERT_HEAD, and AST_RWLIST_UNLOCK.
{
struct file_version *new;
char *work;
size_t version_length;
work = ast_strdupa(version);
work = ast_strip(ast_strip_quoted(work, "$", "$"));
version_length = strlen(work) + 1;
if (!(new = ast_calloc(1, sizeof(*new) + version_length)))
return;
new->file = file;
new->version = (char *) new + sizeof(*new);
memcpy(new->version, work, version_length);
AST_RWLIST_WRLOCK(&file_versions);
AST_RWLIST_INSERT_HEAD(&file_versions, new, list);
AST_RWLIST_UNLOCK(&file_versions);
}
| int ast_set_priority | ( | int | ) |
We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy activity on it, this is a good thing.
Provided by asterisk.c
Definition at line 1560 of file asterisk.c.
References sched_setscheduler, ast_log(), LOG_WARNING, ast_verbose(), and setpriority.
Referenced by spawn_ras(), app_exec(), send_waveform_to_fd(), icesencode(), mp3play(), NBScatplay(), ast_safe_system(), canary_thread(), main(), launch_script(), and spawn_mp3().
{
struct sched_param sched;
memset(&sched, 0, sizeof(sched));
#ifdef __linux__
if (pri) {
sched.sched_priority = 10;
if (sched_setscheduler(0, SCHED_RR, &sched)) {
ast_log(LOG_WARNING, "Unable to set high priority\n");
return -1;
} else
if (option_verbose)
ast_verbose("Set to realtime thread\n");
} else {
sched.sched_priority = 0;
/* According to the manpage, these parameters can never fail. */
sched_setscheduler(0, SCHED_OTHER, &sched);
}
#else
if (pri) {
if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
ast_log(LOG_WARNING, "Unable to set high priority\n");
return -1;
} else
if (option_verbose)
ast_verbose("Set to high priority\n");
} else {
/* According to the manpage, these parameters can never fail. */
setpriority(PRIO_PROCESS, 0, 0);
}
#endif
return 0;
}
| void ast_unregister_atexit | ( | void(*)(void) | func | ) |
Unregister a function registered with ast_register_atexit().
| func | The callback function to unregister. |
Definition at line 950 of file asterisk.c.
References AST_RWLIST_WRLOCK, AST_RWLIST_TRAVERSE_SAFE_BEGIN, ast_atexit::func, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, and free.
Referenced by ast_register_atexit(), do_reload(), and unload_module().
{
struct ast_atexit *ae = NULL;
AST_RWLIST_WRLOCK(&atexits);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
if (ae->func == func) {
AST_RWLIST_REMOVE_CURRENT(list);
break;
}
}
AST_RWLIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&atexits);
free(ae);
}
| void ast_unregister_file_version | ( | const char * | file | ) |
Unregister a source code file from the core.
| file | the source file name |
This function should not be called directly, but instead the ASTERISK_FILE_VERSION macro should be used to automatically unregister the file when the module is unloaded.
Definition at line 324 of file asterisk.c.
References AST_RWLIST_WRLOCK, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, and ast_free.
{
struct file_version *find;
AST_RWLIST_WRLOCK(&file_versions);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
if (!strcasecmp(find->file, file)) {
AST_RWLIST_REMOVE_CURRENT(list);
break;
}
}
AST_RWLIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&file_versions);
if (find)
ast_free(find);
}