Asterisk - The Open Source Telephony Project
21.4.1
|
#include "asterisk.h"
#include "asterisk/optional_api.h"
#include "asterisk/utils.h"
#include "asterisk/vector.h"
Go to the source code of this file.
Data Structures | |
struct | optional_api |
An optional API. More... | |
struct | optional_api_user |
A user of an optional API. More... | |
Macros | |
#define | OPTIONAL_API_SYMNAME_CMP(ele, value) (!strcmp(ele->symname, value)) |
#define | USER_OPTIONAL_REF_CMP(ele, value) (ele->optional_ref == value) |
Functions | |
void | ast_optional_api_provide (const char *symname, ast_optional_fn impl) |
void | ast_optional_api_unprovide (const char *symname, ast_optional_fn impl) |
void | ast_optional_api_unuse (const char *symname, ast_optional_fn *optional_ref, const char *module) |
void | ast_optional_api_use (const char *symname, ast_optional_fn *optional_ref, ast_optional_fn stub, const char *module) |
static struct optional_api * | get_api (const char *symname) |
Gets (or creates) the optional_api for the given function. More... | |
static struct optional_api * | optional_api_create (const char *symname) |
Create and link an optional_api. More... | |
static void | optional_api_destroy (struct optional_api *api) |
Free an optional_api. More... | |
static void | optional_api_set_impl (struct optional_api *api, ast_optional_fn impl) |
Sets the implementation function pointer for an api. More... | |
static struct optional_api_user * | optional_api_user_create (ast_optional_fn *optional_ref, ast_optional_fn stub, const char *module) |
Create an optional_api_user. More... | |
static void | optional_api_user_destroy (struct optional_api_user *user) |
Free an optional_api_user. More... | |
static void | optional_api_user_relink (struct optional_api_user *user, struct optional_api *api) |
Re-links a given user against its associated api. More... | |
Variables | |
struct { | |
size_t current | |
struct optional_api ** elems | |
size_t max | |
} | apis |
The calls to ast_optional_api_*() happen implicitly from constructor
calls which are defined in header files. This means that some number of them happen before main() is called. This makes calling most Asterisk APIs dangerous, since we could be called before they are initialized. This includes things like AO2, malloc debug, and static mutexes.
Another limitation is that most functions are called from the midst of dlopen() or dlclose(), and there is no opportunity to return a failure code. The best we can do is log an error, and call ast_do_crash().
Fortunately, there are some constraints that help us out. The ast_optional_api_*
() are called during module loads, which happens either before main(), or during dlopen() calls. These are already serialized, so we don't have to lock ourselves.
Definition in file optional_api.c.
|
static |
Gets (or creates) the optional_api for the given function.
symname | Name of the function to look up. |
NULL | on error. |
Definition at line 158 of file optional_api.c.
References AST_VECTOR_GET_CMP, and optional_api_create().
|
static |
Create and link an optional_api.
symname | Name of the optional function. |
NULL | on error. |
Definition at line 134 of file optional_api.c.
References ast_calloc, ast_do_crash(), AST_VECTOR_APPEND, and optional_api::symname.
Referenced by get_api().
|
static |
Free an optional_api.
api | API struct to free. |
Definition at line 118 of file optional_api.c.
References AST_VECTOR_CALLBACK_VOID, AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_ELEM_DEFAULT_CMP, AST_VECTOR_FREE, AST_VECTOR_REMOVE_CMP_UNORDERED, optional_api_user_destroy(), and optional_api::users.
Referenced by optional_api_set_impl().
|
static |
Sets the implementation function pointer for an api.
api | API to implement/stub out. |
impl | Pointer to implementation function. Can be 0 to remove implementation. |
Definition at line 198 of file optional_api.c.
References AST_VECTOR_CALLBACK_VOID, AST_VECTOR_SIZE, optional_api::impl, optional_api_destroy(), optional_api_user_relink(), and optional_api::users.
|
static |
Create an optional_api_user.
optional_ref | Pointer-to-function-pointer to link to impl/stub. |
stub | Stub function to link to when impl is not available. |
module | Name of the module requesting the API. |
NULL | on error. |
Definition at line 93 of file optional_api.c.
References ast_calloc, ast_do_crash(), optional_api_user::module, optional_api_user::optional_ref, and optional_api_user::stub.
|
static |
Free an optional_api_user.
user | User struct to free. |
Definition at line 77 of file optional_api.c.
References optional_api_user::optional_ref, and optional_api_user::stub.
Referenced by optional_api_destroy().
|
static |
Re-links a given user against its associated api.
If the api has an implementation, the user is linked to that implementation. Otherwise, the user is linked to its stub.
user | optional_api_user to link. |
api | optional_api to link. |
Definition at line 181 of file optional_api.c.
References optional_api::impl, optional_api_user::optional_ref, and optional_api_user::stub.
Referenced by optional_api_set_impl().
struct { ... } apis |
Vector of optional_api functions