Fri Nov 12 11:53:19 2010

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"
Include dependency graph for asterisk.h:

Go to the source code of this file.

Defines

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

(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

See also:
ast_add_profile(), dividing them by the 'scale' value passed in the create call, and also counts the number of 'events'. Values can also be taked by the TSC counter on ia32 architectures, in which case you can mark the start of an event calling ast_mark(id, 1) and then the end of the event with ast_mark(id, 0). For non-i386 architectures, these two calls return 0.

support for event profiling

Returns:
Returns the identifier of the counter.

Definition at line 673 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().

00674 {
00675    int l = sizeof(struct profile_data);
00676    int n = 10; /* default entries */
00677 
00678    if (prof_data == NULL) {
00679       prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry));
00680       if (prof_data == NULL)
00681          return -1;
00682       prof_data->entries = 0;
00683       prof_data->max_size = n;
00684    }
00685    if (prof_data->entries >= prof_data->max_size) {
00686       void *p;
00687       n = prof_data->max_size + 20;
00688       p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry));
00689       if (p == NULL)
00690          return -1;
00691       prof_data = p;
00692       prof_data->max_size = n;
00693    }
00694    n = prof_data->entries++;
00695    prof_data->e[n].name = ast_strdup(name);
00696    prof_data->e[n].value = 0;
00697    prof_data->e[n].events = 0;
00698    prof_data->e[n].mark = 0;
00699    prof_data->e[n].scale = scale;
00700    return n;
00701 }

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

Definition at line 335 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().

00336 {
00337    struct file_version *find;
00338    size_t len = strlen(partial);
00339    int count = 0;
00340    char *res = NULL;
00341 
00342    AST_RWLIST_RDLOCK(&file_versions);
00343    AST_RWLIST_TRAVERSE(&file_versions, find, list) {
00344       if (!strncasecmp(find->file, partial, len) && ++count > n) {
00345          res = ast_strdup(find->file);
00346          break;
00347       }
00348    }
00349    AST_RWLIST_UNLOCK(&file_versions);
00350    return res;
00351 }

int ast_fd_init ( void   ) 

Provided by astfd.c

Definition at line 275 of file astfd.c.

Referenced by main().

00276 {
00277    return 0;
00278 }

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

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

Referenced by manager_modulecheck().

00355 {
00356    struct file_version *iterator;
00357 
00358    AST_RWLIST_WRLOCK(&file_versions);
00359    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, iterator, list) {
00360       if (!strcasecmp(iterator->file, file))
00361          break;
00362    }
00363    AST_RWLIST_TRAVERSE_SAFE_END;
00364    AST_RWLIST_UNLOCK(&file_versions);
00365    if (iterator)
00366       return iterator->version;
00367    return NULL;
00368 }      

int64_t ast_mark ( int  ,
int  start1_stop0 
)

Definition at line 738 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 extension_match_core().

00739 {
00740    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00741       return 0;
00742    if (startstop == 1)
00743       prof_data->e[i].mark = rdtsc();
00744    else {
00745       prof_data->e[i].mark = (rdtsc() - prof_data->e[i].mark);
00746       if (prof_data->e[i].scale > 1)
00747          prof_data->e[i].mark /= prof_data->e[i].scale;
00748       prof_data->e[i].value += prof_data->e[i].mark;
00749       prof_data->e[i].events++;
00750    }
00751    return prof_data->e[i].mark;
00752 }

int64_t ast_profile ( int  ,
int64_t   
)

Definition at line 703 of file asterisk.c.

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

00704 {
00705    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00706       return 0;
00707    if (prof_data->e[i].scale > 1)
00708       delta /= prof_data->e[i].scale;
00709    prof_data->e[i].value += delta;
00710    prof_data->e[i].events++;
00711    return prof_data->e[i].value;
00712 }

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

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

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

00915 {
00916    struct ast_atexit *ae;
00917 
00918    if (!(ae = ast_calloc(1, sizeof(*ae))))
00919       return -1;
00920 
00921    ae->func = func;
00922 
00923    ast_unregister_atexit(func);  
00924 
00925    AST_RWLIST_WRLOCK(&atexits);
00926    AST_RWLIST_INSERT_HEAD(&atexits, ae, list);
00927    AST_RWLIST_UNLOCK(&atexits);
00928 
00929    return 0;
00930 }

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

References ast_calloc, AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strip(), and ast_strip_quoted().

00297 {
00298    struct file_version *new;
00299    char *work;
00300    size_t version_length;
00301 
00302    work = ast_strdupa(version);
00303    work = ast_strip(ast_strip_quoted(work, "$", "$"));
00304    version_length = strlen(work) + 1;
00305    
00306    if (!(new = ast_calloc(1, sizeof(*new) + version_length)))
00307       return;
00308 
00309    new->file = file;
00310    new->version = (char *) new + sizeof(*new);
00311    memcpy(new->version, work, version_length);
00312    AST_RWLIST_WRLOCK(&file_versions);
00313    AST_RWLIST_INSERT_HEAD(&file_versions, new, list);
00314    AST_RWLIST_UNLOCK(&file_versions);
00315 }

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

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

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

01505 {
01506    struct sched_param sched;
01507    memset(&sched, 0, sizeof(sched));
01508 #ifdef __linux__
01509    if (pri) {  
01510       sched.sched_priority = 10;
01511       if (sched_setscheduler(0, SCHED_RR, &sched)) {
01512          ast_log(LOG_WARNING, "Unable to set high priority\n");
01513          return -1;
01514       } else
01515          if (option_verbose)
01516             ast_verbose("Set to realtime thread\n");
01517    } else {
01518       sched.sched_priority = 0;
01519       /* According to the manpage, these parameters can never fail. */
01520       sched_setscheduler(0, SCHED_OTHER, &sched);
01521    }
01522 #else
01523    if (pri) {
01524       if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
01525          ast_log(LOG_WARNING, "Unable to set high priority\n");
01526          return -1;
01527       } else
01528          if (option_verbose)
01529             ast_verbose("Set to high priority\n");
01530    } else {
01531       /* According to the manpage, these parameters can never fail. */
01532       setpriority(PRIO_PROCESS, 0, 0);
01533    }
01534 #endif
01535    return 0;
01536 }

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

00933 {
00934    struct ast_atexit *ae = NULL;
00935 
00936    AST_RWLIST_WRLOCK(&atexits);
00937    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
00938       if (ae->func == func) {
00939          AST_RWLIST_REMOVE_CURRENT(list);
00940          break;
00941       }
00942    }
00943    AST_RWLIST_TRAVERSE_SAFE_END;
00944    AST_RWLIST_UNLOCK(&atexits);
00945 
00946    free(ae);
00947 }

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 317 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.

00318 {
00319    struct file_version *find;
00320 
00321    AST_RWLIST_WRLOCK(&file_versions);
00322    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
00323       if (!strcasecmp(find->file, file)) {
00324          AST_RWLIST_REMOVE_CURRENT(list);
00325          break;
00326       }
00327    }
00328    AST_RWLIST_TRAVERSE_SAFE_END;
00329    AST_RWLIST_UNLOCK(&file_versions);
00330 
00331    if (find)
00332       ast_free(find);
00333 }


Generated by  doxygen 1.6.2