42#define TEST_CATEGORY "/main/extension_state/"
43#define TEST_CONTEXT "test_extension_state"
44#define TEST_REGISTRAR "test_extension_state"
52#define TEST_DEVICE_PREFIX "Custom:test_extension_state_"
139 if (watcher->
id >= 0) {
174 struct timespec deadline = {
176 .tv_nsec = now.tv_usec * 1000,
191 if (destroyed != 1) {
193 watcher->
exten, destroyed);
204 struct timespec deadline = {
206 .tv_nsec = now.tv_usec * 1000,
262 const char *base,
const char *suffix,
int dashed_first)
270 int added[2] = { 0, 0 };
277 snprintf(
first,
sizeof(
first),
"%s%u%s%s", base, run, dashed_first ?
"-" :
"", suffix);
278 snprintf(second,
sizeof(second),
"%s%u%s%s", base, run, dashed_first ?
"" :
"-", suffix);
284 if (!watchers[0] || !watchers[1]) {
297 for (i = 0; i <
ARRAY_LEN(watchers); i++) {
308 for (i = 0; i <
ARRAY_LEN(watchers); i++) {
317 for (i = 0; i <
ARRAY_LEN(watchers); i++) {
326 for (i = 0; i <
ARRAY_LEN(watchers); i++) {
345 info->name = __func__;
347 info->summary =
"Watch a dashed extension after the dashless spelling created the hint";
349 "Dashes are ignored in extension matching, so '1000x' and '1000-x' are the\n"
350 "same extension. Watching the dashless spelling first creates the hint from a\n"
351 "pattern. Watching the dashed spelling must then also succeed, both watchers\n"
352 "must be notified of state changes of the hint's device, and both must be\n"
353 "destroyed exactly once.";
366 info->name = __func__;
368 info->summary =
"Watch a dashless extension after the dashed spelling created the hint";
370 "Watching the dashed spelling first creates the hint from a pattern. Watching\n"
371 "the dashless spelling must then also succeed, both watchers must be notified\n"
372 "of state changes of the hint's device, and both must be destroyed exactly once.";
388 info->name = __func__;
390 info->summary =
"Failed callback registration leaves data owned by the caller";
392 "Adding a callback for an extension that does not exist must fail without\n"
393 "invoking the destroy callback, so the caller can release its own data.";
struct sla_ringing_trunk * first
Asterisk main include file. File version handling, generic pbx functions.
@ AO2_ALLOC_OPT_LOCK_NOLOCK
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc_options(data_size, destructor_fn, options)
#define AST_MAX_EXTENSION
int ast_device_state_clear_cache(const char *device)
Clear the device from the stasis cache.
int ast_devstate_changed_literal(enum ast_device_state state, enum ast_devstate_cache cachable, const char *device)
Tells Asterisk the State for Device is changed.
Asterisk locking-related definitions:
#define ast_cond_destroy(cond)
#define ast_cond_init(cond, attr)
#define ast_cond_timedwait(cond, mutex, time)
#define ast_mutex_unlock(a)
#define ast_cond_broadcast(cond)
pthread_cond_t ast_cond_t
#define ast_mutex_lock(a)
#define AST_MUTEX_DEFINE_STATIC(mutex)
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
Core PBX routines and definitions.
int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Add and extension to an extension context.
int ast_context_destroy_by_name(const char *context, const char *registrar)
Destroy a context by name.
int ast_extension_state_add_destroy_extended(const char *context, const char *exten, ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data)
Add watcher for extended extension states with destructor.
struct ast_context * ast_context_find_or_create(struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *name, const char *registrar)
Register a new context or find an existing one.
ast_extension_states
Extension states.
@ AST_EXTENSION_NOT_INUSE
int ast_extension_state_del(int id, ast_state_cb_type change_cb)
Deletes a state change watcher by ID.
static void cleanup(void)
Clean up any old apps that we don't need any more.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Tracking for a single extension state callback.
enum ast_extension_states last_state
char exten[AST_MAX_EXTENSION]
#define AST_TEST_REGISTER(cb)
#define ast_test_status_update(a, b, c...)
#define AST_TEST_UNREGISTER(cb)
#define AST_TEST_DEFINE(hdr)
static int dialplan_setup(void)
#define TEST_DEVICE_PREFIX
Prefix for the devices used by the test hints.
static int test_watcher_remove(struct ast_test *test, struct test_watcher *watcher)
Remove an extension state callback and wait for it to be destroyed.
static unsigned int test_run
Used to make the extensions, and so the devices, differ between test runs.
static int state_changed(const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
static int test_watcher_wait_for_state(struct test_watcher *watcher, enum ast_extension_states state)
Wait until a watcher has received the given extension state.
static void state_destroyed(int id, void *data)
#define TEST_TIMEOUT
How long to wait for asynchronous events, in seconds.
static int load_module(void)
static void dialplan_cleanup(void)
static ast_mutex_t test_lock
Protects watcher state and test_run.
static int unload_module(void)
static int test_watcher_add(struct ast_test *test, const char *context, struct test_watcher *watcher)
Add an extension state callback for a watcher.
static struct test_watcher * test_watcher_alloc(const char *exten)
static enum ast_test_result_state dash_spelling_check(struct ast_test *test, const char *base, const char *suffix, int dashed_first)
Watch two spellings of an extension that differ only by dashes.
static ast_cond_t test_cond
Time-related functions and macros.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
long int ast_random(void)