40 unsigned int is_done:1;
43 static void command_dtor(
void *obj)
47 if (command->data_destructor) {
48 command->data_destructor(command->data);
51 ast_mutex_destroy(&command->lock);
52 ast_cond_destroy(&command->condition);
60 command = ao2_alloc(
sizeof(*command), command_dtor);
62 if (data_destructor) {
63 data_destructor(data);
68 ast_mutex_init(&command->lock);
69 ast_cond_init(&command->condition, 0);
70 command->callback = callback;
72 command->data_destructor = data_destructor;
79 ast_mutex_lock(&command->lock);
81 command->retval = retval;
82 ast_cond_signal(&command->condition);
83 ast_mutex_unlock(&command->lock);
90 ast_mutex_lock(&command->lock);
91 while (!command->is_done) {
92 ast_cond_wait(&command->condition, &command->lock);
95 ret = command->retval;
96 ast_mutex_unlock(&command->lock);
104 int retval = command->callback(control, chan, command->data);
105 if (command->data_destructor) {
106 command->data_destructor(command->data);
107 command->data_destructor = NULL;
109 command_complete(command, retval);
112 static void command_queue_prestart_destroy(
void *obj)
119 .
type =
"stasis-command-prestart-queue",
120 .destroy = command_queue_prestart_destroy,
129 command_create(command_fn, data, data_destructor), ao2_cleanup);
137 command_queue = datastore->
data;
143 if (!command_queue) {
147 datastore = ast_datastore_alloc(&command_queue_prestart, NULL);
149 ao2_cleanup(command_queue);
154 datastore->
data = command_queue;
Main Channel structure associated with a channel.
Asterisk locking-related definitions:
int command_prestart_queue_command(struct ast_channel *chan, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor)
Queue a Stasis() prestart command for a channel.
Asterisk main include file. File version handling, generic pbx functions.
Internal API for the Stasis application commands.
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Structure for a data store type.
struct ao2_container * command_prestart_get_container(struct ast_channel *chan)
Get the Stasis() prestart commands for a channel.
Structure for a data store object.
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
int(* stasis_app_command_cb)(struct stasis_app_control *control, struct ast_channel *chan, void *data)
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
void(* command_data_destructor_fn)(void *data)
Typedef for data destructor for stasis app commands.
Backend API for implementing components of res_stasis.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Structure for mutex and tracking information.
#define ao2_link(container, obj)
Add an object to a container.