Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Functions
transaction.h File Reference
#include "asterisk/res_aeap.h"
Include dependency graph for transaction.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int aeap_transaction_cancel_timer (struct aeap_transaction *tsx)
 Cancel the transaction timer. More...
 
struct aeap_transactionaeap_transaction_create_and_add (struct ao2_container *transactions, const char *id, struct ast_aeap_tsx_params *params, struct ast_aeap *aeap)
 Create a transaction object, and add it to the given container. More...
 
void aeap_transaction_end (struct aeap_transaction *tsx, int result)
 End a transaction, and remove it from the given container. More...
 
struct aeap_transactionaeap_transaction_get (struct ao2_container *transactions, const char *id)
 Retrieve a transaction for the id from the container. More...
 
void aeap_transaction_params_cleanup (struct ast_aeap_tsx_params *params)
 Clean up parameter references, and possibly call optional user object cleanup. More...
 
int aeap_transaction_result (struct aeap_transaction *tsx)
 Get a transaction's result. More...
 
int aeap_transaction_start (struct aeap_transaction *tsx)
 Start the transaction. More...
 
void * aeap_transaction_user_obj (struct aeap_transaction *tsx)
 Retrieve the user object associated with the transaction. More...
 
struct ao2_containeraeap_transactions_create (void)
 Create an Asterisk external application transactions container. More...
 

Function Documentation

◆ aeap_transaction_cancel_timer()

int aeap_transaction_cancel_timer ( struct aeap_transaction tsx)

Cancel the transaction timer.

Stops the transaction timer, but does not end/stop the transaction itself

Parameters
tsxA transaction to cancel the timer on
Returns
0 if canceled, non zero otherwise

Definition at line 57 of file transaction.c.

58{
59 if (tsx && tsx->sched_id != -1) {
61 return tsx->sched_id != -1;
62 }
63
64 return 0;
65}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct ast_sched_context * aeap_sched_context(void)
Retrieve the scheduling context.
Definition: general.c:29
#define AST_SCHED_DEL_UNREF(sched, id, refcall)
schedule task to get deleted and call unref function
Definition: sched.h:82

References aeap_sched_context(), ao2_ref, AST_SCHED_DEL_UNREF, and aeap_transaction::sched_id.

Referenced by raise_msg(), transaction_destructor(), and transaction_end().

◆ aeap_transaction_create_and_add()

struct aeap_transaction * aeap_transaction_create_and_add ( struct ao2_container transactions,
const char *  id,
struct ast_aeap_tsx_params params,
struct ast_aeap aeap 
)

Create a transaction object, and add it to the given container.

Parameters
transactionsA transactions container
idAn id to use for the transaction
paramsTransaction parameters
aeapThe aeap object that "owns" this transaction
Returns
0 if successfully create and added, -1 on error

Definition at line 232 of file transaction.c.

234{
235 struct aeap_transaction *tsx;
236
237 tsx = transaction_create(id, params, aeap);
238 if (!tsx) {
239 return NULL;
240 }
241
242 if (!ao2_link(transactions, tsx)) {
243 aeap_error(tsx->aeap, "transaction", "unable to add '%s' to container", id);
244 ao2_ref(tsx, -1);
245 return NULL;
246 }
247
248 /*
249 * Yes, this creates a circular reference. This reference is removed though
250 * upon transaction end. It's assumed here that the given transactions container
251 * takes "ownership", and ultimate responsibility of its contained transactions.
252 * Thus when the given container needs to be unref'ed/freed it must call
253 * aeap_transaction_end for each transaction prior to doing so.
254 */
255 /* tsx->container = ao2_bump(transactions); */
256
257 /*
258 * The transaction needs to know what container manages it, so it can remove
259 * itself from the given container under certain conditions (e.g. transaction
260 * timeout).
261 *
262 * It's expected that the given container will out live any contained transaction
263 * (i.e. the container will not itself be destroyed before ensuring all contained
264 * transactions are ended, and removed). Thus there is no reason to bump the given
265 * container's reference here.
266 */
267 tsx->container = transactions;
268
269 return tsx;
270}
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
#define aeap_error(obj, name, fmt,...)
Log an Asterisk external application error.
#define NULL
Definition: resample.c:96
struct ao2_container * container
Definition: transaction.c:36
struct ast_aeap * aeap
Definition: transaction.c:34
struct ast_aeap_tsx_params params
Definition: transaction.c:46
static struct aeap_transaction * transaction_create(const char *id, struct ast_aeap_tsx_params *params, struct ast_aeap *aeap)
Definition: transaction.c:88

References aeap_transaction::aeap, aeap_error, ao2_link, ao2_ref, aeap_transaction::container, NULL, aeap_transaction::params, and transaction_create().

Referenced by ast_aeap_send_msg_tsx(), and exec().

◆ aeap_transaction_end()

void aeap_transaction_end ( struct aeap_transaction tsx,
int  result 
)

End a transaction, and remove it from the given container.

The "result" parameter is a value representing the state (success/failure, perhaps even something else) of transactional processing upon ending.

Parameters
tsxA transaction to end
resultA result to give to the transaction

Definition at line 217 of file transaction.c.

218{
219 transaction_end(tsx, 0, result);
220}
static PGresult * result
Definition: cel_pgsql.c:84
static void transaction_end(struct aeap_transaction *tsx, int timed_out, int result)
Definition: transaction.c:122

References result, and transaction_end().

Referenced by ast_aeap_send_msg_tsx(), end_transaction(), exec(), raise_msg(), and tsx_end().

◆ aeap_transaction_get()

struct aeap_transaction * aeap_transaction_get ( struct ao2_container transactions,
const char *  id 
)

Retrieve a transaction for the id from the container.

Parameters
transactionsA transactions container
idA transaction id
Returns
an AEAP transaction object, NULL if no transaction is found

Definition at line 212 of file transaction.c.

213{
214 return ao2_find(transactions, id, OBJ_SEARCH_KEY);
215}
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101

References ao2_find, and OBJ_SEARCH_KEY.

Referenced by raise_msg().

◆ aeap_transaction_params_cleanup()

void aeap_transaction_params_cleanup ( struct ast_aeap_tsx_params params)

Clean up parameter references, and possibly call optional user object cleanup.

Parameters
paramsTransaction parameters

Definition at line 67 of file transaction.c.

68{
69 ao2_cleanup(params->msg);
70
71 if (params->obj_cleanup) {
72 params->obj_cleanup(params->obj);
73 }
74}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
struct ast_aeap_message * msg
Definition: res_aeap.h:333
ast_aeap_user_obj_cleanup obj_cleanup
Definition: res_aeap.h:350

References ao2_cleanup, ast_aeap_tsx_params::msg, ast_aeap_tsx_params::obj, and ast_aeap_tsx_params::obj_cleanup.

Referenced by ast_aeap_send_msg_tsx(), transaction_create(), and transaction_destructor().

◆ aeap_transaction_result()

int aeap_transaction_result ( struct aeap_transaction tsx)

Get a transaction's result.

A transaction's result is a value that represents the relative success (0), or failure (-1) of a transaction. For example, a timeout is considered a failure and will elicit a -1.

This value though is also dependent upon the result of the message handler associated with the transaction. Meaning if an associated message is handled, then its result is stored as the transaction result and returned here.

Parameters
tsxA transaction object
Returns
The transaction result

Definition at line 222 of file transaction.c.

223{
224 return tsx->result;
225}

References aeap_transaction::result.

Referenced by ast_aeap_send_msg_tsx().

◆ aeap_transaction_start()

int aeap_transaction_start ( struct aeap_transaction tsx)

Start the transaction.

Parameters
tsxThe transaction to initiate
Returns
0 if successfully raised, and handled. Otherwise non zero.

Definition at line 198 of file transaction.c.

199{
200 if (transaction_sched_timer(tsx)) {
201 return -1;
202 }
203
204 if (tsx->params.wait) {
205 /* Wait until transaction completes, or times out */
206 transaction_wait(tsx);
207 }
208
209 return 0;
210}
static int transaction_sched_timer(struct aeap_transaction *tsx)
Definition: transaction.c:170
static void transaction_wait(struct aeap_transaction *tsx)
Definition: transaction.c:187

References aeap_transaction::params, transaction_sched_timer(), transaction_wait(), and ast_aeap_tsx_params::wait.

Referenced by ast_aeap_send_msg_tsx(), and exec().

◆ aeap_transaction_user_obj()

void * aeap_transaction_user_obj ( struct aeap_transaction tsx)

Retrieve the user object associated with the transaction.

Parameters
tsxA transaction object
Returns
A user object, or NULL if non associated

Definition at line 227 of file transaction.c.

228{
229 return tsx->params.obj;
230}

References ast_aeap_tsx_params::obj, and aeap_transaction::params.

Referenced by end_transaction(), and raise_msg().

◆ aeap_transactions_create()

struct ao2_container * aeap_transactions_create ( void  )

Create an Asterisk external application transactions container.

Returns
A transaction object, or NULL on error

Definition at line 272 of file transaction.c.

273{
274 struct ao2_container *transactions;
275
277 aeap_transaction_hash_fn, NULL, aeap_transaction_cmp_fn);
278 if (!transactions) {
279 ast_log(LOG_ERROR, "AEAP transaction: unable to create container\n");
280 return NULL;
281 }
282
283 return transactions;
284}
#define ast_log
Definition: astobj2.c:42
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
#define LOG_ERROR
Generic container type.
#define AEAP_TRANSACTION_BUCKETS
Number of transaction buckets.
Definition: transaction.c:52

References AEAP_TRANSACTION_BUCKETS, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_log, LOG_ERROR, and NULL.

Referenced by ast_aeap_create(), and exec().