libamxd
6.4.1
Data Model Manager
|
A transaction is a sequence of actions that needs to be performed on one or more objects. More...
Macros | |
#define | amxd_trans_set_value(type, trans, name, value) amxd_trans_set_ ## type(trans, name, value) |
Helper macro for setting a value. More... | |
Typedefs | |
typedef enum _amxd_tattr_id | amxd_tattr_id_t |
Transaction attributes. More... | |
Enumerations | |
enum | _amxd_tattr_id { amxd_tattr_change_ro , amxd_tattr_change_pub , amxd_tattr_change_prot , amxd_tattr_change_priv } |
Transaction attributes. More... | |
Functions | |
amxd_status_t | amxd_trans_init (amxd_trans_t *const trans) |
Initializes a transaction object. More... | |
void | amxd_trans_clean (amxd_trans_t *const trans) |
Cleans the transaction object. More... | |
amxd_status_t | amxd_trans_new (amxd_trans_t **trans) |
Allocates a transaction object on the heap and initializes it. More... | |
void | amxd_trans_delete (amxd_trans_t **trans) |
Frees the memory previously allocated for a transaction object. More... | |
amxd_status_t | amxd_trans_set_attr (amxd_trans_t *trans, amxd_tattr_id_t attr, bool enable) |
Set the transaction attributes. More... | |
amxd_status_t | amxd_trans_add_action (amxd_trans_t *const trans, const amxd_action_t reason, const amxc_var_t *data) |
Adds an action to a transaction. More... | |
amxd_status_t | amxd_trans_select_pathf (amxd_trans_t *const trans, const char *path,...) __attribute__((format(printf |
Selects an object using a absolute or relative path. More... | |
amxd_status_t amxd_status_t | amxd_trans_select_object (amxd_trans_t *trans, const amxd_object_t *const object) |
Selects an object using an object pointer. More... | |
amxd_status_t | amxd_trans_set_param (amxd_trans_t *const trans, const char *param_name, amxc_var_t *const value) |
Adds a set value action to a transaction. More... | |
amxd_status_t | amxd_trans_add_inst (amxd_trans_t *const trans, const uint32_t index, const char *name) |
Adds an instance add action to a transaction. More... | |
amxd_status_t | amxd_trans_del_inst (amxd_trans_t *const trans, const uint32_t index, const char *name) |
Adds an instance delete action to a transaction. More... | |
amxd_status_t | amxd_trans_apply (amxd_trans_t *const trans, amxd_dm_t *const dm) |
Applies all previously added actions. More... | |
void | amxd_trans_dump (const amxd_trans_t *const trans, const int fd, const bool reverse) |
Dumps the transaction to a file descriptor. More... | |
A transaction is a sequence of actions that needs to be performed on one or more objects.
The squence of actions (transaction) can be considered as an atomic operation. Either all actions succeed or none is applied.
Typically an object is selected to work on with amxd_trans_select_pathf or amxd_trans_select_object, and the a set of actions is added.
Adding action to a transaction have no effect immediatly. The actions are executed as soon as amxd_trans_apply is called.
When amxd_trans_apply fails no changes are done. When amxd_trans_apply succeeds all changes are applied and events are send.
In one transaction it is possible to change many objects.
#define amxd_trans_set_value | ( | type, | |
trans, | |||
name, | |||
value | |||
) | amxd_trans_set_ ## type(trans, name, value) |
Helper macro for setting a value.
This helper macro sets a value, using a type indicator
type | the data type, must be a valid parameter type, or must be convertable to a valid parameter type |
trans | pointer to a transaction object |
name | parameter name of the current selected object |
value | the new value, must match the type |
Definition at line 144 of file amxd_transaction.h.
typedef enum _amxd_tattr_id amxd_tattr_id_t |
Transaction attributes.
Transaction attributes can be set using amxd_trans_set_attr
enum _amxd_tattr_id |
Transaction attributes.
Transaction attributes can be set using amxd_trans_set_attr
Definition at line 102 of file amxd_transaction.h.
amxd_status_t amxd_trans_add_action | ( | amxd_trans_t *const | trans, |
const amxd_action_t | reason, | ||
const amxc_var_t * | data | ||
) |
Adds an action to a transaction.
Adds an action to a transaction, providing the action data.
This function is mostly no called directly, some convience wrapper functions are provide to make it easier to add an action to a transaction.
Use one of these methods instead
trans | pointer to a transaction object |
reason | the action identifier |
data | the action data |
Definition at line 597 of file amxd_transaction.c.
amxd_status_t amxd_trans_add_inst | ( | amxd_trans_t *const | trans, |
const uint32_t | index, | ||
const char * | name | ||
) |
Adds an instance add action to a transaction.
The instance add action works on the currently selected object. The currently selected object must be a multi-instance object.
The newly added instance will become the currently selected object.
trans | pointer to a transaction object |
index | the index for the instance, no other instance should exist with this index, or 0 to automatically assing an index |
name | name of the instance or NULL. If the multi-instance object contains a "Alias" parameter the name is stored in that parameter. No other instance of the selected multi-instance object should have the same name. When no names need to be set, use a NULL pointer for this argument |
Definition at line 738 of file amxd_transaction.c.
amxd_status_t amxd_trans_apply | ( | amxd_trans_t *const | trans, |
amxd_dm_t *const | dm | ||
) |
Applies all previously added actions.
Executes all actions of the transaction in the order the actions were added. During execution, a reverse transaction is created. Whenever the execution of one of the actions fail, the reverse transaction is executed to restore the original state.
Either all actions of a transaction are applied, or none.
When the transaction succeeds (all actions executed) the transaction will send events for all changed/adds/deletes done.
trans | pointer to a transaction object |
dm | the data model the transaction needs to be applied on |
Definition at line 841 of file amxd_transaction.c.
void amxd_trans_clean | ( | amxd_trans_t *const | trans | ) |
Cleans the transaction object.
After cleaning the transaction obnject, it is ready to be re-used.
This function will reset all internal bookkeeping objects, but keeps the current selected object and the transaction attributes
trans | pointer to a transaction object |
Definition at line 529 of file amxd_transaction.c.
amxd_status_t amxd_trans_del_inst | ( | amxd_trans_t *const | trans, |
const uint32_t | index, | ||
const char * | name | ||
) |
Adds an instance delete action to a transaction.
The instance delete action works on the currently selected object. The currently selected object must be a multi-instance object.
The deleted instance is selected by index or by name. When both are specified, the index takes precedence over the name. At least one of them should be specified.
The transaction will fail if no instance is found with the index or name specified.
trans | pointer to a transaction object |
index | the index for the instance that will be deleted or 0 |
name | name of the instance that will be deleted or NULL. |
Definition at line 776 of file amxd_transaction.c.
void amxd_trans_delete | ( | amxd_trans_t ** | trans | ) |
Frees the memory previously allocated for a transaction object.
First calls amxd_trans_clean and then frees the memory allocated for the transaction object.
trans | pointer to pointer to a transaction object |
Definition at line 557 of file amxd_transaction.c.
void amxd_trans_dump | ( | const amxd_trans_t *const | trans, |
const int | fd, | ||
const bool | reverse | ||
) |
Dumps the transaction to a file descriptor.
Dumps in human readable text format all actions of a transaction in the order the actions were added.
This function can be used for debugging purposes.
trans | pointer to a transaction object |
fd | a valid file descriptor |
reverse | when set to true, dumps the action in reverse order |
Definition at line 882 of file amxd_transaction.c.
amxd_status_t amxd_trans_init | ( | amxd_trans_t *const | trans | ) |
Initializes a transaction object.
Sets the internal transaction fields to a default value:
trans | pointer to a transaction object |
Definition at line 507 of file amxd_transaction.c.
amxd_status_t amxd_trans_new | ( | amxd_trans_t ** | trans | ) |
Allocates a transaction object on the heap and initializes it.
Allocates memory for a transaction object and then calls amxd_trans_init
trans | pointer to pointer to a transaction object |
Definition at line 544 of file amxd_transaction.c.
amxd_status_t amxd_status_t amxd_trans_select_object | ( | amxd_trans_t * | trans, |
const amxd_object_t *const | object | ||
) |
Selects an object using an object pointer.
Selects an object on which the next actions must be applied.
The path of the object is stored in the select action, not the object itself.
trans | pointer to a transaction object |
object | pointer to an object in the data model |
Definition at line 666 of file amxd_transaction.c.
amxd_status_t amxd_trans_select_pathf | ( | amxd_trans_t *const | trans, |
const char * | path, | ||
... | |||
) |
Selects an object using a absolute or relative path.
Selects an object on which the next actions must be applied. The object is selected using a path. This path can be absolute or relative.
A relative path must start with a '.' and is relative to the currently selected object in the transaction.
The path may be a search path. The search path must only return one object.
This function supports printf formatting.
To go up in the hierarchy of objects, relative from the current object the symbol '^' can be used.
trans | pointer to a transaction object |
path | relative or abosule path, can be a search path |
amxd_status_t amxd_trans_set_attr | ( | amxd_trans_t * | trans, |
amxd_tattr_id_t | attr, | ||
bool | enable | ||
) |
Set the transaction attributes.
Using the transaction attributes it is possible to change the behavior of a transaction.
By default a transaction can not change or update read-only parameters or objects and only works on public or protected parameters and objects.
The following attributes can be set:
trans | pointer to a transaction object |
attr | one of amxd_tattr_id_t |
enable | enable or disables the attrivbute |
Definition at line 570 of file amxd_transaction.c.
amxd_status_t amxd_trans_set_param | ( | amxd_trans_t *const | trans, |
const char * | param_name, | ||
amxc_var_t *const | value | ||
) |
Adds a set value action to a transaction.
The set action works on the currently selected object.
When mutiple set actions are added to the transaction in sequence, the transaction will combine these as one write action on the selected object.
trans | pointer to a transaction object |
param_name | name of the parameter |
value | the new value |
Definition at line 695 of file amxd_transaction.c.