libamxd  6.4.1
Data Model Manager
Collaboration diagram for RPC Methods:

Functions

amxd_status_t amxd_object_add_function (amxd_object_t *const object, amxd_function_t *const func)
 Adds an RPC method definition to the object definition. More...
 
amxd_status_t amxd_object_change_function (amxd_object_t *const object, const char *name, amxd_object_fn_t impl)
 Changes the implementation of an object's RPC method. More...
 
amxd_function_tamxd_object_get_function (const amxd_object_t *const object, const char *name)
 Get the definition of a RPC method from an object. More...
 
amxd_status_t amxd_object_list_functions (amxd_object_t *const object, amxc_var_t *const list, amxd_dm_access_t access)
 Builds a linked list variant containing all function names available in the object. More...
 
amxd_status_t amxd_object_describe_functions (amxd_object_t *const object, amxc_var_t *const value, amxd_dm_access_t access)
 Fetches the full object RPC method definitions in a variant. More...
 
amxd_status_t amxd_object_invoke_function (amxd_object_t *const object, const char *func_name, amxc_var_t *const args, amxc_var_t *const ret)
 Calls an object RPC method. More...
 
uint32_t amxd_object_get_function_count (amxd_object_t *const object, amxd_dm_access_t access)
 Retruns the number of RPC methods available in an object. More...
 

Detailed Description

Function Documentation

◆ amxd_object_add_function()

amxd_status_t amxd_object_add_function ( amxd_object_t *const  object,
amxd_function_t *const  func 
)

Adds an RPC method definition to the object definition.

After defining a RPC method using amxd_function_new, the function can be added to an object.

All derived objects will inherit the method. It is possible to change the implementation on derived objects using amxd_object_change_function.

RPC methods added to template objects (multi-instance) objects will be available on all instances, if the attribute amxd_fattr_instance (default) is set in the RPC method definition. If the attribute amxd_fattr_template is set the RPC method can be called on the template object.

Parameters
objectthe object where the function must be added.
functhe name of the RPC method
Returns
amxd_status_ok when the function is added to the object definition, or another status when an error has occurred.

Definition at line 140 of file amxd_object_function.c.

141  {
143  amxd_function_t* object_func = NULL;
144  when_null(object, exit);
145  when_null(func, exit);
146  when_not_null(func->it.llist, exit);
147  when_true(amxd_object_is_attr_set(object, amxd_oattr_locked), exit);
148 
149  amxc_llist_for_each(it, (&object->functions)) {
150  const char* object_func_name = NULL;
151  const char* func_name = NULL;
152  object_func = amxc_llist_it_get_data(it, amxd_function_t, it);
153  object_func_name = amxd_function_get_name(object_func);
154  func_name = amxd_function_get_name(func);
155  if(strcmp(func_name, object_func_name) == 0) {
156  break;
157  }
158  object_func = NULL;
159  }
160 
161  if(object_func == NULL) {
162  // functions added to template object by default only work on
163  // instances. This is a design descision.
164  // For other behavior set the attributes before adding the function
165  // to the object
167  if((func->attr.instance == 0) &&
168  ( func->attr.templ == 0)) {
169  func->attr.instance = 1;
170  }
171  }
172  amxc_llist_append(&object->functions, &func->it);
173  retval = amxd_status_ok;
174  } else {
175  retval = amxd_status_duplicate;
176  }
177 
178 exit:
179  return retval;
180 }
enum _amxd_status amxd_status_t
@ amxd_status_ok
Definition: amxd_types.h:78
@ amxd_status_unknown_error
Definition: amxd_types.h:79
@ amxd_status_duplicate
Definition: amxd_types.h:91
@ amxd_oattr_locked
Definition: amxd_types.h:206
@ amxd_object_template
Definition: amxd_types.h:183
static amxd_object_type_t amxd_object_get_type(const amxd_object_t *const object)
Returns the object type.
Definition: amxd_object.h:586
bool amxd_object_is_attr_set(const amxd_object_t *const object, const amxd_oattr_id_t attr)
Checks if an attribute is set.
Definition: amxd_object.c:348
const char * amxd_function_get_name(const amxd_function_t *const func)
Get the name of a method.
uint32_t templ
Definition: amxd_types.h:326
uint32_t instance
Definition: amxd_types.h:327
RPC method structure.
Definition: amxd_types.h:341
amxc_llist_it_t it
Definition: amxd_types.h:342
amxd_func_attr_t attr
Definition: amxd_types.h:343
amxc_llist_t functions
Definition: amxd_types.h:245

◆ amxd_object_change_function()

amxd_status_t amxd_object_change_function ( amxd_object_t *const  object,
const char *  name,
amxd_object_fn_t  impl 
)

Changes the implementation of an object's RPC method.

Using this function it is possible to change the implementation of a RPC method in an object.

If the implementation is changed for a certain object which has derived objects, the implementation is changed for all these derived objects as well. When changing the implementation of a derived object (like an instance object), the implementation is only changed for this object (or any object derived from that object).

Parameters
objectthe object pointer
namethe name of the RPC method
implfunction pointer to the new implementation
Returns
amxd_status_ok when the function implementation is set, or another status when an error has occurred.

Definition at line 182 of file amxd_object_function.c.

184  {
186  amxd_function_t* func = NULL;
187  amxd_object_t* owner = NULL;
188 
189  when_null(object, exit);
190  when_str_empty(name, exit);
191 
192  func = amxd_object_get_function(object, name);
193  when_null(func, exit);
194  owner = amxd_function_get_owner(func);
195  if(owner == object) {
196  func->impl = impl;
197  retval = amxd_status_ok;
198  } else {
199  amxd_function_t* new_func = NULL;
200  retval = amxd_function_copy(&new_func, func);
201  when_true(retval != amxd_status_ok, exit);
202  new_func->impl = impl;
203  when_failed(amxc_llist_append(&object->functions, &new_func->it), exit);
204  }
205 
206 exit:
207  return retval;
208 }
amxd_function_t * amxd_object_get_function(const amxd_object_t *const object, const char *name)
Get the definition of a RPC method from an object.
amxd_object_t * amxd_function_get_owner(const amxd_function_t *const func)
Get the object pointer of the object containing the function definition.
amxd_status_t amxd_function_copy(amxd_function_t **dest, const amxd_function_t *const source)
Data model RPC method copy constructor function.
amxd_object_fn_t impl
Definition: amxd_types.h:347

◆ amxd_object_describe_functions()

amxd_status_t amxd_object_describe_functions ( amxd_object_t *const  object,
amxc_var_t *const  value,
amxd_dm_access_t  access 
)

Fetches the full object RPC method definitions in a variant.

It can be very handy to get the full definitions of the object RPC methods.

This function is mainly intended for introspection.

Parameters
objectthe object pointer
valuevariant where the RPC method defintions can be stored
accessmust be one of amxd_dm_access_t
Returns
amxd_status_ok when the function implementation is set, or another status when an error has occurred.

Definition at line 420 of file amxd_action_object_describe.c.

422  {
423  return amxd_object_describe_item(object,
424  value,
426  access,
427  "functions");
428 }
static amxd_status_t amxd_object_describe_item(amxd_object_t *const object, amxc_var_t *const value, uint32_t flags, amxd_dm_access_t access, const char *item)
#define AMXD_OBJECT_FUNC
List and describe flag.
Definition: amxd_object.h:260

◆ amxd_object_get_function()

amxd_function_t* amxd_object_get_function ( const amxd_object_t *const  object,
const char *  name 
)

Get the definition of a RPC method from an object.

Returns the RPC method definition, if found, with the given name.

When using a derived object, it is possible that the RPC method definition is not owned by the object, use amxd_function_get_owner to get a pointer to the data model object that owns the RPC method definition.

The returned RPC method can be removed from the object using amxd_function_delete. If the object has derived objects, the method is also removed from the derrived objects, unless it was overriden in the derived object using amxd_object_change_function

Parameters
objectthe object pointer
namethe name of the RPC method
Returns
returns the function definition if found, NULL otherwise

Definition at line 210 of file amxd_object_function.c.

211  {
212  amxd_function_t* func = NULL;
213  amxc_string_t normalized;
214 
215  amxc_string_init(&normalized, 0);
216 
217  when_null(object, exit);
218  when_str_empty(name, exit);
219 
220  amxc_string_setf(&normalized, "%s", name);
221  amxc_string_trimr(&normalized, is_brace);
222 
223  func = amxd_object_get_self_func(object, amxc_string_get(&normalized, 0));
224 
225  when_not_null(func, exit);
226 
228  func = amxd_object_get_function(amxd_object_get_parent(object), amxc_string_get(&normalized, 0));
229  } else {
230  if(amxc_llist_it_is_in_list(&object->derived_from)) {
231  amxd_object_t* super = NULL;
232  super = amxc_container_of(object->derived_from.llist,
234  derived_objects);
235  func = amxd_object_get_function(super, amxc_string_get(&normalized, 0));
236  }
237  }
238 
239 exit:
240  amxc_string_clean(&normalized);
241 
242  return func;
243 }
static int is_brace(int c)
PRIVATE amxd_function_t * amxd_object_get_self_func(const amxd_object_t *const object, const char *name)
@ amxd_object_instance
Definition: amxd_types.h:186
amxd_object_t * amxd_object_get_parent(const amxd_object_t *const object)
Get the parent object.
amxc_llist_it_t derived_from
Definition: amxd_types.h:249

◆ amxd_object_get_function_count()

uint32_t amxd_object_get_function_count ( amxd_object_t *const  object,
amxd_dm_access_t  access 
)

Retruns the number of RPC methods available in an object.

Parameters
objectthe object pointer
accessmust be one of amxd_dm_access_t
Returns
amxd_status_ok when the function implementation is set, or another status when an error has occurred.

Definition at line 276 of file amxd_object_function.c.

277  {
278  uint32_t count = 0;
279  amxc_var_t funcs;
280  const amxc_llist_t* funcs_list = NULL;
281 
282  when_null(object, exit);
283 
284  amxc_var_init(&funcs);
285  amxd_object_list_functions(object, &funcs, access);
286  funcs_list = amxc_var_constcast(amxc_llist_t, &funcs);
287  count = amxc_llist_size(funcs_list);
288  amxc_var_clean(&funcs);
289 
290 exit:
291  return count;
292 }
amxd_status_t amxd_object_list_functions(amxd_object_t *const object, amxc_var_t *const list, amxd_dm_access_t access)
Builds a linked list variant containing all function names available in the object.

◆ amxd_object_invoke_function()

amxd_status_t amxd_object_invoke_function ( amxd_object_t *const  object,
const char *  func_name,
amxc_var_t *const  args,
amxc_var_t *const  ret 
)

Calls an object RPC method.

Using this function a RPC method of an object in the local data model can be called (that is an object in the data model of the process you are running in).

To call a function of a remote data model (data model in another process), use the amxb (BAAPI) function amxb_invoke.

When status amxd_status_deferred is returned, the ret will contain the call id and the real return value and status will be returned later. Use amxd_function_set_deferred_cb to register a callback function.

Parameters
objectthe object pointer
func_namename of the function
argsa hash table variant containing the function arguments
reta variant pointer where the return value can be stored
Returns
amxd_status_ok when the function implementation is set, or another status when an error has occurred.

Definition at line 245 of file amxd_object_function.c.

248  {
250  amxd_function_t* func = NULL;
251 
252  when_null(ret, exit);
253  retval = amxd_object_invoke_check(object, &func, func_name, args);
254  when_failed(retval, exit);
255 
256  retval = func->impl(object, func, args, ret);
257  amxd_function_remove_in_args(func, args);
258 
259  if(retval == amxd_status_deferred) {
260  amxd_dm_t* dm = amxd_object_get_dm(object);
261  uint64_t call_id = amxc_var_constcast(uint64_t, ret);
263  if(call_ctx == NULL) {
264  retval = amxd_status_unknown_error;
265  amxc_var_clean(ret);
266  goto exit;
267  }
268 
269  amxc_llist_append(&dm->deferred, &call_ctx->dm_it);
270  }
271 
272 exit:
273  return retval;
274 }
amxd_deferred_ctx_t *PRIVATE amxd_find_deferred(uint64_t call_id)
static amxd_status_t amxd_object_invoke_check(amxd_object_t *const object, amxd_function_t **func, const char *func_name, amxc_var_t *const args)
static void amxd_function_remove_in_args(amxd_function_t *func, amxc_var_t *args)
@ amxd_status_deferred
Definition: amxd_types.h:92
amxd_dm_t * amxd_object_get_dm(const amxd_object_t *const object)
Get the data model.
amxc_llist_it_t dm_it
Definition: amxd_dm_priv.h:64
amxc_llist_t deferred
Definition: amxd_types.h:264
static amxd_dm_t dm
static uint64_t call_id

◆ amxd_object_list_functions()

amxd_status_t amxd_object_list_functions ( amxd_object_t *const  object,
amxc_var_t *const  list,
amxd_dm_access_t  access 
)

Builds a linked list variant containing all function names available in the object.

Initializes the variant to amxc_llist_t type and adds all function names available in the object.

The list also includes the functions of the objects from which this object is derived.

It is possible to filter the functions on access. Access token can be one of

Parameters
objectthe object pointer
listan initialized variant, will be filled with the RPC method names
accessfilter functions at a certain access level
Returns
amxd_status_ok when the function implementation is set, or another status when an error has occurred.

Definition at line 363 of file amxd_action_object_list.c.

365  {
366  return amxd_object_list_item(object,
367  list,
369  access,
370  "functions");
371 }
static amxd_status_t amxd_object_list_item(amxd_object_t *const object, amxc_var_t *const value, uint32_t flags, amxd_dm_access_t access, const char *item)
#define AMXD_TEMPLATE_INFO
List and describe flag.
Definition: amxd_object.h:314