Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Functions | Variables
command.c File Reference

Stasis application command support. More...

#include "asterisk.h"
#include "command.h"
#include "asterisk/lock.h"
#include "asterisk/stasis_app_impl.h"

Go to the source code of this file.

Data Structures

struct  stasis_app_command
 

Functions

void command_complete (struct stasis_app_command *command, int retval)
 
struct stasis_app_commandcommand_create (stasis_app_command_cb callback, void *data, command_data_destructor_fn data_destructor)
 
static void command_dtor (void *obj)
 
void command_invoke (struct stasis_app_command *command, struct stasis_app_control *control, struct ast_channel *chan)
 
int command_join (struct stasis_app_command *command)
 
struct ao2_containercommand_prestart_get_container (struct ast_channel *chan)
 Get the Stasis() prestart commands for a channel. More...
 
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. More...
 
static void command_queue_prestart_destroy (void *obj)
 

Variables

static const struct ast_datastore_info command_queue_prestart
 

Detailed Description

Stasis application command support.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file command.c.

Function Documentation

struct ao2_container* command_prestart_get_container ( struct ast_channel chan)

Get the Stasis() prestart commands for a channel.

Precondition
chan must be locked
Parameters
chanThe channel from which to get prestart commands
Returns
The command prestart container for chan (must be ao2_cleanup()'d)

Definition at line 160 of file command.c.

References ao2_bump, ast_channel_datastore_find(), and ast_datastore::data.

Referenced by control_prestart_dispatch_all().

161 {
162  struct ast_datastore *datastore = ast_channel_datastore_find(chan, &command_queue_prestart, NULL);
163 
164  if (!datastore) {
165  return NULL;
166  }
167 
168  return ao2_bump(datastore->data);
169 }
Structure for a data store object.
Definition: datastore.h:64
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.
Definition: channel.c:2399
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
void * data
Definition: datastore.h:66
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.

Precondition
chan must be locked
Parameters
chanThe channel on which to queue the prestart command
command_fnThe callback to call for the command
dataThe data to pass to the command callback
data_destructorOptional function which will be called on the data in either the event of command completion or failure to schedule or complete the command
Return values
zeroon success
non-zeroon failure

Definition at line 123 of file command.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_list, ao2_link, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_datastore::data, and RAII_VAR.

125 {
126  struct ast_datastore *datastore;
127  struct ao2_container *command_queue;
128  RAII_VAR(struct stasis_app_command *, command,
129  command_create(command_fn, data, data_destructor), ao2_cleanup);
130 
131  if (!command) {
132  return -1;
133  }
134 
135  datastore = ast_channel_datastore_find(chan, &command_queue_prestart, NULL);
136  if (datastore) {
137  command_queue = datastore->data;
138  ao2_link(command_queue, command);
139  return 0;
140  }
141 
142  command_queue = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
143  if (!command_queue) {
144  return -1;
145  }
146 
147  datastore = ast_datastore_alloc(&command_queue_prestart, NULL);
148  if (!datastore) {
149  ao2_cleanup(command_queue);
150  return -1;
151  }
152  ast_channel_datastore_add(chan, datastore);
153 
154  datastore->data = command_queue;
155  ao2_link(command_queue, command);
156 
157  return 0;
158 }
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition: astobj2.h:1327
Structure for a data store object.
Definition: datastore.h:64
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.
Definition: channel.c:2399
void * data
Definition: datastore.h:66
Generic container type.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2385
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532

Variable Documentation

const struct ast_datastore_info command_queue_prestart
static
Initial value:
= {
.type = "stasis-command-prestart-queue",
.destroy = command_queue_prestart_destroy,
}

Definition at line 118 of file command.c.