libamxd
6.4.1
Data Model Manager
|
Functions | |
amxd_status_t | amxd_function_new (amxd_function_t **func, const char *name, const uint32_t ret_type, amxd_object_fn_t impl) |
Data model RPC method constructor function. More... | |
void | amxd_function_delete (amxd_function_t **func) |
Data model RPC method destructor function. More... | |
amxd_status_t | amxd_function_copy (amxd_function_t **dest, const amxd_function_t *const source) |
Data model RPC method copy constructor function. More... | |
amxd_object_t * | amxd_function_get_owner (const amxd_function_t *const func) |
Get the object pointer of the object containing the function definition. More... | |
amxd_function_t * | amxd_function_get_base (const amxd_function_t *const func) |
Get the base function definition of an overridden function. More... | |
amxd_status_t | amxd_function_call_base (const amxd_function_t *const func, amxd_object_t *const object, amxc_var_t *const args, amxc_var_t *const ret) |
Call the base function of an overridden function. More... | |
const char * | amxd_function_get_name (const amxd_function_t *const func) |
Get the name of a method. More... | |
static uint32_t | amxd_function_get_type (const amxd_function_t *const func) |
Gets the return type of a method. More... | |
amxd_status_t | amxd_function_set_attr (amxd_function_t *func, const amxd_fattr_id_t attr, const bool enable) |
Sets or unsets a method attribute. More... | |
amxd_status_t | amxd_function_set_attrs (amxd_function_t *func, const uint32_t bitmask, bool enable) |
Sets or unsets method attributes using a bitmap. More... | |
uint32_t | amxd_function_get_attrs (const amxd_function_t *const func) |
Gets the set attributes of a RPC method. More... | |
bool | amxd_function_is_attr_set (const amxd_function_t *const func, const amxd_fattr_id_t attr) |
Checks if a method attribute is set. More... | |
void | amxd_function_set_flag (amxd_function_t *func, const char *flag) |
Sets a flag on a function. More... | |
void | amxd_function_unset_flag (amxd_function_t *func, const char *flag) |
Removes a flag from a function. More... | |
bool | amxd_function_has_flag (const amxd_function_t *const func, const char *flag) |
Checks if a flag is set. More... | |
amxd_status_t | amxd_function_set_impl (amxd_function_t *const func, amxd_object_fn_t impl) |
Set an implementation for a RPC method. More... | |
amxd_status_t | amxd_function_describe (amxd_function_t *const func, amxc_var_t *const value) |
Fetches the full RPC method definition in a variant. More... | |
amxd_status_t | amxd_function_defer (const amxd_function_t *const func, uint64_t *call_id, amxc_var_t *const ret, amxd_deferred_cancel_t cancel_fn, void *priv) |
Creates a deferred RPC context. More... | |
void | amxd_function_deferred_remove (uint64_t call_id) |
Removes a deferred RPC context. More... | |
void * | amxd_function_deferred_get_priv (uint64_t call_id) |
Gets the callee private data of an deferred function. More... | |
amxd_status_t | amxd_function_set_deferred_cb (uint64_t call_id, amxp_deferred_fn_t cb, void *priv) |
Sets a callback function to get the result of the deferred call. More... | |
amxd_status_t | amxd_function_deferred_done (uint64_t call_id, amxd_status_t status, amxc_var_t *out_args, amxc_var_t *ret) |
Finishes a deferred method and removes the deferred function context. More... | |
amxd_status_t | amxd_function_deferred_call_done (uint64_t call_id, amxd_status_t status, amxc_var_t *out_args, amxc_var_t *ret) |
Finishes a deferred method and removes the deferred function context. More... | |
amxd_status_t | amxd_function_new_arg (amxd_function_t *func, const char *name, const uint32_t type, amxc_var_t *default_value) |
Adds an argument definition to a RPC method definition. More... | |
void | amxd_function_del_arg (amxd_function_t *func, const char *name) |
Removes an argument definition from a RPC method definition. More... | |
amxd_func_arg_t * | amxd_function_get_arg (const amxd_function_t *const func, const char *name) |
Gets the argument definition of a RPC method. More... | |
amxd_status_t | amxd_function_arg_set_attr (amxd_function_t *const func, const char *name, const amxd_aattr_id_t attr, const bool enable) |
Sets or unsets a method argument attribute. More... | |
amxd_status_t | amxd_function_arg_set_attrs (amxd_function_t *func, const char *name, const uint32_t bitmask, bool enable) |
Sets or unsets method argument attributes using a bitmap. More... | |
bool | amxd_function_arg_is_attr_set (const amxd_function_t *const func, const char *name, const amxd_aattr_id_t attr) |
Checks if a method argument attribute is set. More... | |
amxd_status_t | amxd_function_arg_describe (amxd_func_arg_t *const arg, amxc_var_t *const value) |
Fetches the argument definition in a variant. More... | |
bool | amxd_function_are_args_valid (amxd_function_t *func, amxc_var_t *args) |
Validates that the input arguments are valid. More... | |
bool amxd_function_are_args_valid | ( | amxd_function_t * | func, |
amxc_var_t * | args | ||
) |
Validates that the input arguments are valid.
The arguments must be provided as a htable variant, where each argument is an entry in the hash table.
This function will check that:
Missing optional arguments with a default value defined will be added to the htable variant.
func | pointer to a function definition |
args | variant containing a htable with function arguments |
Definition at line 486 of file amxd_function.c.
amxd_status_t amxd_function_arg_describe | ( | amxd_func_arg_t *const | arg, |
amxc_var_t *const | value | ||
) |
Fetches the argument definition in a variant.
It can be very handy to get the full definition of the argument.
This function is mainly intended for introspection.
arg | pointer to a argument definition |
value | variant where the argument defintion can be stored |
Definition at line 278 of file amxd_function_args.c.
bool amxd_function_arg_is_attr_set | ( | const amxd_function_t *const | func, |
const char * | name, | ||
const amxd_aattr_id_t | attr | ||
) |
Checks if a method argument attribute is set.
The following attribute identifiers can be checked
func | pointer to a function definition |
name | the argument name |
attr | the method attribute id |
Definition at line 260 of file amxd_function_args.c.
amxd_status_t amxd_function_arg_set_attr | ( | amxd_function_t *const | func, |
const char * | name, | ||
const amxd_aattr_id_t | attr, | ||
const bool | enable | ||
) |
Sets or unsets a method argument attribute.
The following attributes can be set - unset:
func | pointer to a function definition |
name | the argument name |
attr | the attribute id |
enable | when true, sets the attribute, when false unsets the attribute |
Definition at line 183 of file amxd_function_args.c.
amxd_status_t amxd_function_arg_set_attrs | ( | amxd_function_t * | func, |
const char * | name, | ||
const uint32_t | bitmask, | ||
bool | enable | ||
) |
Sets or unsets method argument attributes using a bitmap.
The following attributes can be set - unset:
Use the macro SET_BIT to transform the attribute id to a bit. The bits can be joined together using the bitwise or operator '|'
When setting or unsetting one single attribute the function amxd_function_arg_set_attr can be used.
func | pointer to a function definition |
name | the argument name |
bitmask | the function attribute bitmask |
enable | when true, sets the attributes, when false unsets the attributes |
Definition at line 220 of file amxd_function_args.c.
amxd_status_t amxd_function_call_base | ( | const amxd_function_t *const | func, |
amxd_object_t *const | object, | ||
amxc_var_t *const | args, | ||
amxc_var_t *const | ret | ||
) |
Call the base function of an overridden function.
In derived objects it is possible to override methods and set a different implementation. Using this function the base implementation from which the method is derived is called.
func | pointer to a function definition |
object | the object on which the function must be called |
args | htable variant containing the function arguments |
ret | variant that can be filled with the function return data |
Definition at line 260 of file amxd_function.c.
amxd_status_t amxd_function_copy | ( | amxd_function_t ** | dest, |
const amxd_function_t *const | source | ||
) |
Data model RPC method copy constructor function.
Makes an exact deep copy a RPC method definition.
The newly created RPC method definition will not be added to any data model object, that can be done using amxd_object_add_function
dest | pointer to a pointer to the new RPC method definition (the copy) |
source | pointer to a RPC method definition |
Definition at line 181 of file amxd_function.c.
amxd_status_t amxd_function_defer | ( | const amxd_function_t *const | func, |
uint64_t * | call_id, | ||
amxc_var_t *const | ret, | ||
amxd_deferred_cancel_t | cancel_fn, | ||
void * | priv | ||
) |
Creates a deferred RPC context.
If an RPC method can take a while before it can return the result, it can reply the result later (ie asynchronous I/O). To indicate the result will be available later, the RPC method must return status amxd_status_deferred and must call this function before returning.
When the result is available (ie asynchronous I/O is done), the method amxd_function_deferred_done must be called.
It is also possible to remove the deferred call by calling amxd_function_deferred_remove. This will send an error back to the caller.
func | pointer to a function definition |
call_id | each deferred method gets a call_id, it will be filled in this integer. The call_id is needed in all other calls related to deferred RPC methods |
ret | The call id will also be filled in the return value of the RPC method. This will enable the caller to add a callback function to get informed when the result is available. |
cancel_fn | Optionally a cancel callback function can be given. This will be called when the deferred function is removed. |
priv | Some private data for the callee, will be provided to the cancel callback function. Typically used to be able to free allocated memory when the deferred function is canceled. |
Definition at line 126 of file amxd_function_deferred.c.
amxd_status_t amxd_function_deferred_call_done | ( | uint64_t | call_id, |
amxd_status_t | status, | ||
amxc_var_t * | out_args, | ||
amxc_var_t * | ret | ||
) |
Finishes a deferred method and removes the deferred function context.
When the result is available, a callee can finish the deferred method by calling this function. It must provide the final status and the return value.
This will trigger the callback function registered by the caller. The callback function will be called immediately.
call_id | The id of the deferred function. |
status | The final status of the RPC method |
out_args | Out arguments if any (can be NULL) |
ret | The return value of the RPC method |
Definition at line 249 of file amxd_function_deferred.c.
amxd_status_t amxd_function_deferred_done | ( | uint64_t | call_id, |
amxd_status_t | status, | ||
amxc_var_t * | out_args, | ||
amxc_var_t * | ret | ||
) |
Finishes a deferred method and removes the deferred function context.
When the result is available, a callee can finish the deferred method by calling this function. It must provide the final status and the return value.
This will trigger the callback function registered by the caller. The callback function will be called from the eventloop, in other words the callback function is scheduled to be called and is not called immediately.
call_id | The id of the deferred function. |
status | The final status of the RPC method |
out_args | Out arguments if any (can be NULL) |
ret | The return value of the RPC method |
Definition at line 242 of file amxd_function_deferred.c.
void* amxd_function_deferred_get_priv | ( | uint64_t | call_id | ) |
Gets the callee private data of an deferred function.
When a callee creates a deferred function contexts it can provide private data. Using this method it can retrieve the private data using the deferred call id.
call_id | The id of the deferred function. |
Definition at line 173 of file amxd_function_deferred.c.
void amxd_function_deferred_remove | ( | uint64_t | call_id | ) |
Removes a deferred RPC context.
A deferred function context can be removed by the caller or the callee.
When the caller wants to remove a deferred function its deferred callback must be removed first.
If the callee wants to remove a deferred function its cancel callback must be removed first.
call_id | The id of the deferred function. |
Definition at line 154 of file amxd_function_deferred.c.
void amxd_function_del_arg | ( | amxd_function_t * | func, |
const char * | name | ||
) |
Removes an argument definition from a RPC method definition.
func | pointer to a function definition |
name | the argument name |
Definition at line 168 of file amxd_function_args.c.
void amxd_function_delete | ( | amxd_function_t ** | func | ) |
Data model RPC method destructor function.
Frees all memory allocated to store the RPC method definition.
If the RPC method was added to a data model object using amxd_object_add_function, the RPC method is removed from that object.
func | pointer to a pointer to the RPC method definition |
Definition at line 169 of file amxd_function.c.
amxd_status_t amxd_function_describe | ( | amxd_function_t *const | func, |
amxc_var_t *const | value | ||
) |
Fetches the full RPC method definition in a variant.
It can be very handy to get the full definition of the RPC method.
This function is mainly intended for introspection.
func | pointer to a function definition |
value | variant where the RPC method defintion can be stored |
Definition at line 413 of file amxd_function.c.
amxd_func_arg_t* amxd_function_get_arg | ( | const amxd_function_t *const | func, |
const char * | name | ||
) |
Gets the argument definition of a RPC method.
func | pointer to a function definition |
name | the argument name |
Definition at line 468 of file amxd_function.c.
uint32_t amxd_function_get_attrs | ( | const amxd_function_t *const | func | ) |
Gets the set attributes of a RPC method.
This function returns the set attributes of a method as a bitmask. To verify if a certain attribute is set, use the macro IS_BIT_SET.
To verify that one single attribute is set the function amxd_function_is_attr_set can be used.
func | pointer to a function definition |
Definition at line 339 of file amxd_function.c.
amxd_function_t* amxd_function_get_base | ( | const amxd_function_t *const | func | ) |
Get the base function definition of an overridden function.
In derived objects it is possible to override methods and set a different implementation. Using this function the base definition from which the method is derived is returned.
func | pointer to a function definition |
Definition at line 237 of file amxd_function.c.
const char* amxd_function_get_name | ( | const amxd_function_t *const | func | ) |
Get the name of a method.
Returns the name of the method. There is no need to free the returned pointer.
func | pointer to a function definition |
Definition at line 279 of file amxd_function.c.
amxd_object_t* amxd_function_get_owner | ( | const amxd_function_t *const | func | ) |
Get the object pointer of the object containing the function definition.
When using a derived object, the object containing the function defintion can be different than the object where the function definition pointer was retrieved from.
It is possible to change the implementation of the method in a derived object. This can be done using amxd_object_change_function. When changing the implementation in a derived object, a copy of the function definition is created and stored in the derived object. To retrieve the base implementation use amxd_function_get_base.
func | pointer to a function definition |
Definition at line 226 of file amxd_function.c.
|
inlinestatic |
Gets the return type of a method.
Returns the return type of a method. The return type matches with a amxc variant type.
func | pointer to a function definition |
Definition at line 260 of file amxd_function.h.
bool amxd_function_has_flag | ( | const amxd_function_t *const | func, |
const char * | flag | ||
) |
Checks if a flag is set.
A flag is any arbitrary string and can be set or unset.
The flags set on a function can be seen in the description data of the function.
When a derived object overrides a function, the flags are reset for that derived object.
func | pointer to a function definition |
flag | the flag name |
Definition at line 389 of file amxd_function.c.
bool amxd_function_is_attr_set | ( | const amxd_function_t *const | func, |
const amxd_fattr_id_t | attr | ||
) |
Checks if a method attribute is set.
The following attribute identifiers can be checked
func | pointer to a function definition |
attr | the method attribute id |
Definition at line 353 of file amxd_function.c.
amxd_status_t amxd_function_new | ( | amxd_function_t ** | func, |
const char * | name, | ||
const uint32_t | ret_type, | ||
amxd_object_fn_t | impl | ||
) |
Data model RPC method constructor function.
Allocates memory for a new data model rpc method and initializes the struct _amxd_function.
Creates a RPC method definition. Each RPC method has a return type and must be one of the available amxc variant types. A name must be provided as well.
When adding the rpc method to an object using amxd_object_add_function the name of the RPC method should not exist in that object as a RPC method.
Optionally a function pointer can be provided. If no function implementation is set, the function definition exists, but calling the function will fail.
Function implementation must match with this prototype definition:
To be able to call the function it must be added to an object.
When the RPC method definition is not added to any data model object, the pointer must be freed using amxd_function_delete.
When the RPC method definition is added to a data model object, it will be automatically freed when the object that contains the method is deleted.
func | pointer to a pointer to the new RPC method definition |
name | the name of the RPC method |
ret_type | the return type of the RPC method, must be a valid amxc variant type |
impl | pointer to the implementation function |
Definition at line 146 of file amxd_function.c.
amxd_status_t amxd_function_new_arg | ( | amxd_function_t * | func, |
const char * | name, | ||
const uint32_t | type, | ||
amxc_var_t * | default_value | ||
) |
Adds an argument definition to a RPC method definition.
func | pointer to a function definition |
name | the argument name |
type | the argument type, must be one of the amxc variant types |
default_value | a default value for the argument |
Definition at line 140 of file amxd_function_args.c.
amxd_status_t amxd_function_set_attr | ( | amxd_function_t * | func, |
const amxd_fattr_id_t | attr, | ||
const bool | enable | ||
) |
Sets or unsets a method attribute.
The following attributes can be set - unset:
func | pointer to a function definition |
attr | the attribute id |
enable | when true, sets the attribute, when false unsets the attribute |
Definition at line 283 of file amxd_function.c.
amxd_status_t amxd_function_set_attrs | ( | amxd_function_t * | func, |
const uint32_t | bitmask, | ||
bool | enable | ||
) |
Sets or unsets method attributes using a bitmap.
The following attributes can be set - unset:
Use the macro SET_BIT to transform the attribute id to a bit. The bits can be joined together using the bitwise or operator '|'
When setting or unsetting one single attribute the function amxd_function_set_attr can be used.
func | pointer to a function definition |
bitmask | the function attribute bitmask |
enable | when true, sets the attributes, when false unsets the attributes |
Definition at line 310 of file amxd_function.c.
amxd_status_t amxd_function_set_deferred_cb | ( | uint64_t | call_id, |
amxp_deferred_fn_t | cb, | ||
void * | priv | ||
) |
Sets a callback function to get the result of the deferred call.
When a caller invokes an object method with amxd_object_invoke_function and gets amxd_status_defer
as status code, the caller can set a callback function that will be called when the deferred methods finishes.
The call identifier will be provided in the return value.
call_id | The id of the deferred function. |
cb | The callback function |
priv | Some private data, will be passed to the callback function |
Definition at line 184 of file amxd_function_deferred.c.
void amxd_function_set_flag | ( | amxd_function_t * | func, |
const char * | flag | ||
) |
Sets a flag on a function.
A flag is any arbitrary string and can be set or unset.
The flags set on a function can be seen in the description data of the function.
When a derived object overrides a function, the flags are reset for that derived object.
func | pointer to a function definition |
flag | the flag name |
Definition at line 367 of file amxd_function.c.
amxd_status_t amxd_function_set_impl | ( | amxd_function_t *const | func, |
amxd_object_fn_t | impl | ||
) |
Set an implementation for a RPC method.
Data model object can contain methods. Remote clients can invoke these methods. An implementation must be set, the implementation must match with this prototype:
func | pointer to a function definition |
impl | function pointer to the implementation |
Definition at line 401 of file amxd_function.c.
void amxd_function_unset_flag | ( | amxd_function_t * | func, |
const char * | flag | ||
) |
Removes a flag from a function.
A flag is any arbitrary string and can be set or unset.
The flags set on a function can be seen in the description data of the function.
When a derived object overrides a function, the flags are reset for that derived object.
func | pointer to a function definition |
flag | the flag name |
Definition at line 378 of file amxd_function.c.