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 __stringify(x)   __stringify_1(x)
#define __stringify_1(x)   #x
#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 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_cancel_shutdown (void)
 Cancel an existing shutdown and return to normal operation.
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.
int ast_register_cleanup (void(*func)(void))
 Register a function to be executed before Asterisk gracefully 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.
int ast_shutdown_final (void)
int ast_shutting_down (void)
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 __stringify (  )     __stringify_1(x)

#define __stringify_1 (  )     #x

Definition at line 274 of file asterisk.h.

#define AST_DIR_MODE   0777

Definition at line 33 of file asterisk.h.

#define AST_FILE_MODE   0666

#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.
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 221 of file asterisk.h.

#define DEFAULT_LANGUAGE   "en"

Definition at line 39 of file asterisk.h.

Referenced by fileexists_core(), options_incoming_request(), and send_options_response().

#define DEFAULT_SAMPLE_RATE   8000

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


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 104 of file astman.c.

Referenced by extension_match_core().

00105 {
00106    return -1;
00107 }

int ast_cancel_shutdown ( void   ) 

Cancel an existing shutdown and return to normal operation.

Note:
Shutdown can be cancelled while the server is waiting for any existing channels to be destroyed before shutdown becomes irreversible.
Returns:
non-zero if shutdown cancelled.

Definition at line 1895 of file asterisk.c.

References ast_mutex_lock, ast_mutex_unlock, NOT_SHUTTING_DOWN, safe_system_lock, SHUTDOWN_FAST, shutdown_pending, and shuttingdown.

Referenced by handle_abort_shutdown().

01896 {
01897    int shutdown_aborted = 0;
01898 
01899    ast_mutex_lock(&safe_system_lock);
01900    if (shuttingdown >= SHUTDOWN_FAST) {
01901       shuttingdown = NOT_SHUTTING_DOWN;
01902       shutdown_pending = 0;
01903       shutdown_aborted = 1;
01904    }
01905    ast_mutex_unlock(&safe_system_lock);
01906    return shutdown_aborted;
01907 }

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

Definition at line 525 of file asterisk.c.

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

Referenced by handle_debug().

00526 {
00527    struct file_version *find;
00528    size_t len = strlen(partial);
00529    int count = 0;
00530    char *res = NULL;
00531 
00532    AST_RWLIST_RDLOCK(&file_versions);
00533    AST_RWLIST_TRAVERSE(&file_versions, find, list) {
00534       if (!strncasecmp(find->file, partial, len) && ++count > n) {
00535          res = ast_strdup(find->file);
00536          break;
00537       }
00538    }
00539    AST_RWLIST_UNLOCK(&file_versions);
00540    return res;
00541 }

int ast_fd_init ( void   ) 

Provided by astfd.c

Definition at line 289 of file astfd.c.

Referenced by main().

00290 {
00291    return 0;
00292 }

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

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

Referenced by manager_modulecheck().

00545 {
00546    struct file_version *iterator;
00547 
00548    AST_RWLIST_WRLOCK(&file_versions);
00549    AST_RWLIST_TRAVERSE(&file_versions, iterator, list) {
00550       if (!strcasecmp(iterator->file, file))
00551          break;
00552    }
00553    AST_RWLIST_UNLOCK(&file_versions);
00554    if (iterator)
00555       return iterator->version;
00556    return NULL;
00557 }

int64_t ast_mark ( int  key,
int  start1_stop0 
)

Definition at line 115 of file astman.c.

Referenced by __ast_pthread_mutex_lock(), and extension_match_core().

00116 {
00117    return 0;
00118 }

int ast_pbx_init ( void   ) 

int64_t ast_profile ( int  key,
int64_t  val 
)

Definition at line 110 of file astman.c.

00111 {
00112    return 0;
00113 }

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.
Note:
This function should be rarely used in situations where something must be shutdown to avoid corruption, excessive data loss, or when external programs must be stopped. All other cleanup in the core should use ast_register_cleanup.

Definition at line 13 of file clicompat.c.

Referenced by ast_cdr_engine_init(), astdb_init(), load_module(), and main().

00014 {
00015    return 0;
00016 }

int ast_register_cleanup ( void(*)(void)  func  ) 

Register a function to be executed before Asterisk gracefully exits.

Since:
11.9 If Asterisk is immediately shutdown (core stop now, or sending the TERM signal), the callback is not run. When the callbacks are run, they are run in sequence with ast_register_atexit() callbacks, in the reverse order of registration.
Parameters:
func The callback function to use.
Return values:
0 on success.
-1 on error.
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 19 of file clicompat.c.

Referenced by __init_manager(), aco_init(), app_init(), ast_aoc_cli_init(), ast_autoservice_init(), ast_bridging_init(), ast_bucket_init(), ast_builtins_init(), ast_cc_init(), ast_cdr_engine_init(), ast_cel_engine_init(), ast_channels_init(), ast_codec_init(), ast_data_init(), ast_dns_resolver_register(), ast_endpoint_init(), ast_endpoint_stasis_init(), ast_features_init(), ast_file_init(), ast_format_cache_init(), ast_format_init(), ast_http_init(), ast_image_init(), ast_indications_init(), ast_local_init(), ast_msg_init(), ast_named_acl_init(), ast_parking_stasis_init(), ast_pbx_init(), ast_pickup_init(), ast_presence_state_engine_init(), ast_rtp_engine_init(), ast_security_stasis_init(), ast_sorcery_init(), ast_sounds_index_init(), ast_stasis_bridging_init(), ast_stasis_channels_init(), ast_stasis_system_init(), ast_stun_init(), ast_test_init(), ast_timing_init(), ast_tps_init(), ast_translate_init(), ast_udptl_init(), ast_utils_init(), astobj2_init(), container_init(), devstate_init(), dnsmgr_init(), load_pbx(), main(), manager_bridging_init(), manager_channels_init(), manager_endpoints_init(), manager_mwi_init(), manager_system_init(), register_config_cli(), stasis_cache_init(), and stasis_init().

00020 {
00021    return 0;
00022 }

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 93 of file astman.c.

00094 {
00095 }

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

References ast_log, ast_verb, 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().

01854 {
01855    struct sched_param sched;
01856    memset(&sched, 0, sizeof(sched));
01857 #ifdef __linux__
01858    if (pri) {
01859       sched.sched_priority = 10;
01860       if (sched_setscheduler(0, SCHED_RR, &sched)) {
01861          ast_log(LOG_WARNING, "Unable to set high priority\n");
01862          return -1;
01863       } else
01864          ast_verb(1, "Set to realtime thread\n");
01865    } else {
01866       sched.sched_priority = 0;
01867       /* According to the manpage, these parameters can never fail. */
01868       sched_setscheduler(0, SCHED_OTHER, &sched);
01869    }
01870 #else
01871    if (pri) {
01872       if (setpriority(PRIO_PROCESS, 0, -10) == -1) {
01873          ast_log(LOG_WARNING, "Unable to set high priority\n");
01874          return -1;
01875       } else
01876          ast_verb(1, "Set to high priority\n");
01877    } else {
01878       /* According to the manpage, these parameters can never fail. */
01879       setpriority(PRIO_PROCESS, 0, 0);
01880    }
01881 #endif
01882    return 0;
01883 }

int ast_shutdown_final ( void   ) 

Returns:
non-zero if the server is actively shutting down.
Since:
13.3.0
The server is releasing resources and unloading modules. It won't be long now.

Definition at line 1885 of file asterisk.c.

References SHUTTING_DOWN_FINAL, and shuttingdown.

Referenced by httpd_process_request(), and send_notify().

01886 {
01887    return shuttingdown == SHUTTING_DOWN_FINAL;
01888 }

int ast_shutting_down ( void   ) 

The server is preventing new channel creation in preparation for shutdown and may actively be releasing resources. The shutdown process may be canceled by ast_cancel_shutdown() if it is not too late.

Note:
The preparation to shutdown phase can be quite lengthy if we are gracefully shutting down. How long existing calls will last is not up to us.
Returns:
non-zero if the server is preparing to or actively shutting down.

Definition at line 1890 of file asterisk.c.

References shutdown_pending.

Referenced by __ast_channel_alloc_ap(), confbridge_exec(), handle_request_options(), and options_on_rx_request().

01891 {
01892    return shutdown_pending;
01893 }

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

References __ast_unregister_atexit(), AST_LIST_LOCK, AST_LIST_UNLOCK, and ast_atexit::func.

Referenced by unload_module().

01185 {
01186    AST_LIST_LOCK(&atexits);
01187    __ast_unregister_atexit(func);
01188    AST_LIST_UNLOCK(&atexits);
01189 }

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 98 of file astman.c.

00099 {
00100 }


Generated on Thu Apr 16 06:28:58 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6