Mon Oct 8 12:39:11 2012

Asterisk developer's documentation


asterisk.h File Reference

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

#include "asterisk/autoconfig.h"
#include "asterisk/compat.h"

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.


Detailed Description

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

Definition in file asterisk.h.


Define Documentation

#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(), action_createconfig(), ast_lock_path_lockfile(), ast_monitor_start(), chanspy_exec(), copy(), dbinit(), dictate_exec(), extenspy_exec(), festival_exec(), handle_cli_file_convert(), handle_pri_set_debug_file(), handle_recordfile(), load_module(), recordthread(), sms_log(), and try_firmware().

#define ASTERISK_FILE_VERSION ( file,
version   ) 

Register/unregister a source code file with the core.

Parameters:
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\$")

Note:
The dollar signs above have been protected with backslashes to keep SVN from modifying them in this file; under normal circumstances they would not be present and SVN would expand the Revision keyword into the file's revision number.

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 check_header(), ogg_vorbis_open(), ogg_vorbis_rewrite(), setformat(), and write_header().

#define DEFAULT_SAMPLES_PER_MS   ((DEFAULT_SAMPLE_RATE)/1000)

Definition at line 42 of file asterisk.h.

Referenced by ast_stream_fastforward(), ast_stream_rewind(), and isAnsweringMachine().

#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().


Function Documentation

int ast_add_profile ( const char *  name,
uint64_t  scale 
)

support for event profiling

Returns:
Returns the identifier of the counter.

Definition at line 704 of file asterisk.c.

References ast_calloc, ast_realloc, ast_strdup, profile_data::e, profile_data::entries, profile_entry::events, profile_entry::mark, profile_data::max_size, profile_entry::name, prof_data, profile_entry::scale, and profile_entry::value.

Referenced by extension_match_core().

00705 {
00706    int l = sizeof(struct profile_data);
00707    int n = 10; /* default entries */
00708 
00709    if (prof_data == NULL) {
00710       prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry));
00711       if (prof_data == NULL)
00712          return -1;
00713       prof_data->entries = 0;
00714       prof_data->max_size = n;
00715    }
00716    if (prof_data->entries >= prof_data->max_size) {
00717       void *p;
00718       n = prof_data->max_size + 20;
00719       p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry));
00720       if (p == NULL)
00721          return -1;
00722       prof_data = p;
00723       prof_data->max_size = n;
00724    }
00725    n = prof_data->entries++;
00726    prof_data->e[n].name = ast_strdup(name);
00727    prof_data->e[n].value = 0;
00728    prof_data->e[n].events = 0;
00729    prof_data->e[n].mark = 0;
00730    prof_data->e[n].scale = scale;
00731    return n;
00732 }

char* ast_complete_source_filename ( const char *  partial,
int  n 
)

Definition at line 355 of file asterisk.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, file_version::file, len(), and ast_atexit::list.

Referenced by handle_verbose().

00356 {
00357    struct file_version *find;
00358    size_t len = strlen(partial);
00359    int count = 0;
00360    char *res = NULL;
00361 
00362    AST_RWLIST_RDLOCK(&file_versions);
00363    AST_RWLIST_TRAVERSE(&file_versions, find, list) {
00364       if (!strncasecmp(find->file, partial, len) && ++count > n) {
00365          res = ast_strdup(find->file);
00366          break;
00367       }
00368    }
00369    AST_RWLIST_UNLOCK(&file_versions);
00370    return res;
00371 }

int ast_fd_init ( void   ) 

Provided by astfd.c

Definition at line 283 of file astfd.c.

Referenced by main().

00284 {
00285    return 0;
00286 }

const char* ast_file_version_find ( const char *  file  ) 

Find version for given module name.

Parameters:
file Module name (i.e. chan_sip.so)
Returns:
version string or NULL if the module is not found

Definition at line 374 of file asterisk.c.

References AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, file_version::file, ast_atexit::list, and file_version::version.

Referenced by manager_modulecheck().

00375 {
00376    struct file_version *iterator;
00377 
00378    AST_RWLIST_WRLOCK(&file_versions);
00379    AST_RWLIST_TRAVERSE(&file_versions, iterator, list) {
00380       if (!strcasecmp(iterator->file, file))
00381          break;
00382    }
00383    AST_RWLIST_UNLOCK(&file_versions);
00384    if (iterator)
00385       return iterator->version;
00386    return NULL;
00387 }      

int64_t ast_mark ( int  ,
int  start1_stop0 
)

Definition at line 769 of file asterisk.c.

References profile_data::e, profile_data::entries, profile_entry::events, profile_entry::mark, prof_data, rdtsc(), profile_entry::scale, and profile_entry::value.

Referenced by __ast_pthread_mutex_lock(), and extension_match_core().

00770 {
00771    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00772       return 0;
00773    if (startstop == 1)
00774       prof_data->e[i].mark = rdtsc();
00775    else {
00776       prof_data->e[i].mark = (rdtsc() - prof_data->e[i].mark);
00777       if (prof_data->e[i].scale > 1)
00778          prof_data->e[i].mark /= prof_data->e[i].scale;
00779       prof_data->e[i].value += prof_data->e[i].mark;
00780       prof_data->e[i].events++;
00781    }
00782    return prof_data->e[i].mark;
00783 }

int ast_pbx_init ( void   ) 

Provided by pbx.c

Definition at line 10700 of file pbx.c.

References ao2_container_alloc, HASH_EXTENHINT_SIZE, hint_cmp(), hint_hash(), hints, statecbs, and statecbs_cmp().

Referenced by main().

10701 {
10702    hints = ao2_container_alloc(HASH_EXTENHINT_SIZE, hint_hash, hint_cmp);
10703    statecbs = ao2_container_alloc(1, NULL, statecbs_cmp);
10704 
10705    return (hints && statecbs) ? 0 : -1;
10706 }

int64_t ast_profile ( int  ,
int64_t   
)

Definition at line 734 of file asterisk.c.

References profile_data::e, profile_data::entries, profile_entry::events, prof_data, profile_entry::scale, and profile_entry::value.

00735 {
00736    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00737       return 0;
00738    if (prof_data->e[i].scale > 1)
00739       delta /= prof_data->e[i].scale;
00740    prof_data->e[i].value += delta;
00741    prof_data->e[i].events++;
00742    return prof_data->e[i].value;
00743 }

int ast_register_atexit ( void(*)(void)  func  ) 

Register a function to be executed before Asterisk exits.

Parameters:
func The callback function to use.
Return values:
0 on success.
-1 on error.

Definition at line 945 of file asterisk.c.

References ast_calloc, AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_unregister_atexit(), and ast_atexit::list.

Referenced by ast_cel_engine_init(), do_reload(), load_module(), and main().

00946 {
00947    struct ast_atexit *ae;
00948 
00949    if (!(ae = ast_calloc(1, sizeof(*ae))))
00950       return -1;
00951 
00952    ae->func = func;
00953 
00954    ast_unregister_atexit(func);  
00955 
00956    AST_RWLIST_WRLOCK(&atexits);
00957    AST_RWLIST_INSERT_HEAD(&atexits, ae, list);
00958    AST_RWLIST_UNLOCK(&atexits);
00959 
00960    return 0;
00961 }

void ast_register_file_version ( const char *  file,
const char *  version 
)

Register the version of a source code file with the core.

Parameters:
file the source file name
version the version string (typically a SVN revision keyword string)
Returns:
nothing
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 316 of file asterisk.c.

References ast_calloc, AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strdupa, ast_strip(), ast_strip_quoted(), and ast_atexit::list.

00317 {
00318    struct file_version *new;
00319    char *work;
00320    size_t version_length;
00321 
00322    work = ast_strdupa(version);
00323    work = ast_strip(ast_strip_quoted(work, "$", "$"));
00324    version_length = strlen(work) + 1;
00325    
00326    if (!(new = ast_calloc(1, sizeof(*new) + version_length)))
00327       return;
00328 
00329    new->file = file;
00330    new->version = (char *) new + sizeof(*new);
00331    memcpy(new->version, work, version_length);
00332    AST_RWLIST_WRLOCK(&file_versions);
00333    AST_RWLIST_INSERT_HEAD(&file_versions, new, list);
00334    AST_RWLIST_UNLOCK(&file_versions);
00335 }

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 1615 of file asterisk.c.

References ast_log(), ast_verbose, LOG_WARNING, sched_setscheduler, and setpriority.

Referenced by ast_safe_system(), canary_thread(), icesencode(), launch_script(), main(), mp3play(), NBScatplay(), send_waveform_to_fd(), spawn_mp3(), and spawn_ras().

01616 {
01617    struct sched_param sched;
01618    memset(&sched, 0, sizeof(sched));
01619 #ifdef __linux__
01620    if (pri) {  
01621       sched.sched_priority = 10;
01622       if (sched_setscheduler(0, SCHED_RR, &sched)) {
01623          ast_log(LOG_WARNING, "Unable to set high priority\n");
01624          return -1;
01625       } else
01626          if (option_verbose)
01627             ast_verbose("Set to realtime thread\n");
01628    } else {
01629       sched.sched_priority = 0;
01630       /* According to the manpage, these parameters can never fail. */
01631       sched_setscheduler(0, SCHED_OTHER, &sched);
01632    }
01633 #else
01634    if (pri) {
01635       if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
01636          ast_log(LOG_WARNING, "Unable to set high priority\n");
01637          return -1;
01638       } else
01639          if (option_verbose)
01640             ast_verbose("Set to high priority\n");
01641    } else {
01642       /* According to the manpage, these parameters can never fail. */
01643       setpriority(PRIO_PROCESS, 0, 0);
01644    }
01645 #endif
01646    return 0;
01647 }

void ast_unregister_atexit ( void(*)(void)  func  ) 

Unregister a function registered with ast_register_atexit().

Parameters:
func The callback function to unregister.

Definition at line 963 of file asterisk.c.

References AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, free, ast_atexit::func, and ast_atexit::list.

Referenced by ast_register_atexit(), do_reload(), and unload_module().

00964 {
00965    struct ast_atexit *ae = NULL;
00966 
00967    AST_RWLIST_WRLOCK(&atexits);
00968    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
00969       if (ae->func == func) {
00970          AST_RWLIST_REMOVE_CURRENT(list);
00971          break;
00972       }
00973    }
00974    AST_RWLIST_TRAVERSE_SAFE_END;
00975    AST_RWLIST_UNLOCK(&atexits);
00976 
00977    free(ae);
00978 }

void ast_unregister_file_version ( const char *  file  ) 

Unregister a source code file from the core.

Parameters:
file the source file name
Returns:
nothing
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 337 of file asterisk.c.

References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, file_version::file, and ast_atexit::list.

00338 {
00339    struct file_version *find;
00340 
00341    AST_RWLIST_WRLOCK(&file_versions);
00342    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
00343       if (!strcasecmp(find->file, file)) {
00344          AST_RWLIST_REMOVE_CURRENT(list);
00345          break;
00346       }
00347    }
00348    AST_RWLIST_TRAVERSE_SAFE_END;
00349    AST_RWLIST_UNLOCK(&file_versions);
00350 
00351    if (find)
00352       ast_free(find);
00353 }


Generated on Mon Oct 8 12:39:11 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7