Thu Jul 9 13:40:52 2009

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
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 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 CVS 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 CVS from modifying them in this file; under normal circumstances they would not be present and CVS would expand the Revision keyword into the file's revision number.

Definition at line 157 of file asterisk.h.

#define bcopy   0x__dont_use_bcopy__use_memmove_instead()

Definition at line 217 of file asterisk.h.

#define bzero   0x__dont_use_bzero__use_memset_instead""

Definition at line 216 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_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 529 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().

00530 {
00531    int l = sizeof(struct profile_data);
00532    int n = 10; /* default entries */
00533 
00534    if (prof_data == NULL) {
00535       prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry));
00536       if (prof_data == NULL)
00537          return -1;
00538       prof_data->entries = 0;
00539       prof_data->max_size = n;
00540    }
00541    if (prof_data->entries >= prof_data->max_size) {
00542       void *p;
00543       n = prof_data->max_size + 20;
00544       p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry));
00545       if (p == NULL)
00546          return -1;
00547       prof_data = p;
00548       prof_data->max_size = n;
00549    }
00550    n = prof_data->entries++;
00551    prof_data->e[n].name = ast_strdup(name);
00552    prof_data->e[n].value = 0;
00553    prof_data->e[n].events = 0;
00554    prof_data->e[n].mark = 0;
00555    prof_data->e[n].scale = scale;
00556    return n;
00557 }

int ast_fd_init ( void   ) 

Provided by astfd.c

Definition at line 270 of file astfd.c.

Referenced by main().

00271 {
00272    return 0;
00273 }

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

00324 {
00325    struct file_version *iterator;
00326 
00327    AST_RWLIST_WRLOCK(&file_versions);
00328    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, iterator, list) {
00329       if (!strcasecmp(iterator->file, file))
00330          break;
00331    }
00332    AST_RWLIST_TRAVERSE_SAFE_END;
00333    AST_RWLIST_UNLOCK(&file_versions);
00334    if (iterator)
00335       return iterator->version;
00336    return NULL;
00337 }      

int64_t ast_mark ( int  ,
int  start1_stop0 
)

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

00595 {
00596    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00597       return 0;
00598    if (startstop == 1)
00599       prof_data->e[i].mark = rdtsc();
00600    else {
00601       prof_data->e[i].mark = (rdtsc() - prof_data->e[i].mark);
00602       if (prof_data->e[i].scale > 1)
00603          prof_data->e[i].mark /= prof_data->e[i].scale;
00604       prof_data->e[i].value += prof_data->e[i].mark;
00605       prof_data->e[i].events++;
00606    }
00607    return prof_data->e[i].mark;
00608 }

int64_t ast_profile ( int  ,
int64_t   
)

Definition at line 559 of file asterisk.c.

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

00560 {
00561    if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
00562       return 0;
00563    if (prof_data->e[i].scale > 1)
00564       delta /= prof_data->e[i].scale;
00565    prof_data->e[i].value += delta;
00566    prof_data->e[i].events++;
00567    return prof_data->e[i].value;
00568 }

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 770 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 do_reload(), and load_module().

00771 {
00772    struct ast_atexit *ae;
00773 
00774    if (!(ae = ast_calloc(1, sizeof(*ae))))
00775       return -1;
00776 
00777    ae->func = func;
00778 
00779    ast_unregister_atexit(func);  
00780 
00781    AST_RWLIST_WRLOCK(&atexits);
00782    AST_RWLIST_INSERT_HEAD(&atexits, ae, list);
00783    AST_RWLIST_UNLOCK(&atexits);
00784 
00785    return 0;
00786 }

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 CVS 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 283 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.

00284 {
00285    struct file_version *new;
00286    char *work;
00287    size_t version_length;
00288 
00289    work = ast_strdupa(version);
00290    work = ast_strip(ast_strip_quoted(work, "$", "$"));
00291    version_length = strlen(work) + 1;
00292    
00293    if (!(new = ast_calloc(1, sizeof(*new) + version_length)))
00294       return;
00295 
00296    new->file = file;
00297    new->version = (char *) new + sizeof(*new);
00298    memcpy(new->version, work, version_length);
00299    AST_RWLIST_WRLOCK(&file_versions);
00300    AST_RWLIST_INSERT_HEAD(&file_versions, new, list);
00301    AST_RWLIST_UNLOCK(&file_versions);
00302 }

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

01279 {
01280    struct sched_param sched;
01281    memset(&sched, 0, sizeof(sched));
01282 #ifdef __linux__
01283    if (pri) {  
01284       sched.sched_priority = 10;
01285       if (sched_setscheduler(0, SCHED_RR, &sched)) {
01286          ast_log(LOG_WARNING, "Unable to set high priority\n");
01287          return -1;
01288       } else
01289          if (option_verbose)
01290             ast_verbose("Set to realtime thread\n");
01291    } else {
01292       sched.sched_priority = 0;
01293       /* According to the manpage, these parameters can never fail. */
01294       sched_setscheduler(0, SCHED_OTHER, &sched);
01295    }
01296 #else
01297    if (pri) {
01298       if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
01299          ast_log(LOG_WARNING, "Unable to set high priority\n");
01300          return -1;
01301       } else
01302          if (option_verbose)
01303             ast_verbose("Set to high priority\n");
01304    } else {
01305       /* According to the manpage, these parameters can never fail. */
01306       setpriority(PRIO_PROCESS, 0, 0);
01307    }
01308 #endif
01309    return 0;
01310 }

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 788 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(), and do_reload().

00789 {
00790    struct ast_atexit *ae = NULL;
00791 
00792    AST_RWLIST_WRLOCK(&atexits);
00793    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
00794       if (ae->func == func) {
00795          AST_RWLIST_REMOVE_CURRENT(list);
00796          break;
00797       }
00798    }
00799    AST_RWLIST_TRAVERSE_SAFE_END;
00800    AST_RWLIST_UNLOCK(&atexits);
00801 
00802    free(ae);
00803 }

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

00305 {
00306    struct file_version *find;
00307 
00308    AST_RWLIST_WRLOCK(&file_versions);
00309    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
00310       if (!strcasecmp(find->file, file)) {
00311          AST_RWLIST_REMOVE_CURRENT(list);
00312          break;
00313       }
00314    }
00315    AST_RWLIST_TRAVERSE_SAFE_END;
00316    AST_RWLIST_UNLOCK(&file_versions);
00317 
00318    if (find)
00319       ast_free(find);
00320 }


Generated on Thu Jul 9 13:40:52 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7