libamxb  4.8.2
Bus Agnostic C API
Data Model Operators

Functions

int amxb_call (amxb_bus_ctx_t *const bus_ctx, const char *object, const char *method, amxc_var_t *args, amxc_var_t *ret, int timeout)
 Invokes a data model function. More...
 
amxb_request_tamxb_async_call (amxb_bus_ctx_t *const bus_ctx, const char *object, const char *method, amxc_var_t *args, amxb_be_done_cb_fn_t done_fn, void *priv)
 Invokes a data model function. More...
 
int amxb_get (amxb_bus_ctx_t *const bus_ctx, const char *object, int32_t depth, amxc_var_t *ret, int timeout)
 Fetches one or more objects or a single parameter. More...
 
int amxb_get_filtered (amxb_bus_ctx_t *const bus_ctx, const char *object, const char *filter, int32_t depth, amxc_var_t *ret, int timeout)
 Fetches one or more objects and their parameters that are matching a filter. More...
 
int amxb_get_multiple (amxb_bus_ctx_t *const bus_ctx, amxc_var_t *req_paths, int32_t depth, amxc_var_t *ret, int timeout)
 Fetches one or more (root) objects or multiple parameters. More...
 
int amxb_set (amxb_bus_ctx_t *const bus_ctx, const char *object, amxc_var_t *values, amxc_var_t *ret, int timeout)
 Sets parameter values of one single object or of multiple instance objects. More...
 
int amxb_set_multiple (amxb_bus_ctx_t *const bus_ctx, uint32_t flags, amxc_var_t *req_paths, amxc_var_t *ret, int timeout)
 Sets parameter values for multiple objects (request paths) More...
 
int amxb_add (amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t index, const char *name, amxc_var_t *values, amxc_var_t *ret, int timeout)
 Adds an instance to a multi-instance object. More...
 
int amxb_del (amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t index, const char *name, amxc_var_t *ret, int timeout)
 Deletes one or more instances of a multi-instance object. More...
 
int amxb_get_supported (amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxc_var_t *ret, int timeout)
 Gets the supported data model. More...
 
int amxb_describe (amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxc_var_t *ret, int timeout)
 Describes an object. More...
 
int amxb_list (amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxb_be_cb_fn_t fn, void *priv)
 List the service elements/nodes of an object. More...
 
int amxb_get_instances (amxb_bus_ctx_t *const bus_ctx, const char *search_path, int32_t depth, amxc_var_t *ret, int timeout)
 Fetches the instances and the unique keys of a multi-instance object. More...
 

Detailed Description

Function Documentation

◆ amxb_add()

int amxb_add ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
uint32_t  index,
const char *  name,
amxc_var_t *  values,
amxc_var_t *  ret,
int  timeout 
)

Adds an instance to a multi-instance object.

Using this method, an instance can be created and the parameters values of that instance can be set.

It is not possible to create an instance for a read-only multi instance object.

It is not possible to set the value of read-only parameters using this function.

This function supports following paths:

  • object path - must end with a "."

The parameter values must be passed as a variant containing a hash-table where each key is a parameter name and the value is the value for that parameter.

It is possible to choose the index (instance identifier) of the new instance using the index argument. The index provided must not be in use, otherwise the creation of the instance fails. When specifying 0 as the index, the next available index will be chosen. The automatic instance numbering never re-uses an already used index, even if the instance that was using the index has been deleted.

Optionally a name can be specified for the instance. When the multi-instance object has an "Alias" parameter that is defined as a "unique key", the name is used as the value for the "Alias" parameter. When no name needs to be set a NULL pointer can be passed.

When the multi-instance object has "key" parameters the values of these parameters must be given using the "values" argument, except for the "Alias" parameter if a name is provided. The values of "key" parameters can only be set when the instance is created, and are immutable.

Values of non key parameters are optional and can be set later with amxb_set function.

The return value of an add is always an Ambiorix variant and will contain the newly created instance and all its key parameters.

Example of a return variant:

[
{
index = 5,
name = "5",
object = "Phonebook.Contact.5.",
parameters = {
},
path = "Phonebook.Contact.5."
}
]
Parameters
bus_ctxThe bus context (or connection)
objectFull multi-instance object path
indexthe index of the instance set to 0 to assign an index automatically
namethe name of the instance, or when an Alias parameter exists, the value for the Alias. The name can be NULL.
valuesvariant hash-table containing the parameter values, can be NULL when key parameters are defined, at least the key parameters must be set and present in the hash-table.
retwill contain the created object, its key parameters and exta information
timeoutin seconds
Returns
amxd_status_ok_OK when successful, any other value indicates an error.

Definition at line 115 of file amxb_ba_op_add.c.

121  {
122  int retval = amxd_status_unknown_error;
123  const amxb_be_funcs_t* fns = NULL;
124  bool lobject = false;
125  amxd_path_t path;
126  char* fixed = NULL;
127  const char* rel_path = NULL;
128 
129  amxd_path_init(&path, NULL);
130  when_null(bus_ctx, exit);
131  when_null(bus_ctx->bus_ctx, exit);
132 
133  amxd_path_setf(&path, true, "%s", object);
134 
135  while(amxd_path_get_type(&path) == amxd_path_reference) {
136  retval = amxb_follow_reference(bus_ctx, &path, timeout);
137  when_failed(retval, exit);
138  }
139 
140  fixed = amxd_path_get_fixed_part(&path, true);
141  rel_path = amxd_path_get(&path, AMXD_OBJECT_TERMINATE);
142 
143  lobject = amxb_is_local_object(bus_ctx, fixed);
144  fns = bus_ctx->bus_fn;
145 
146  if(amxc_var_is_null(values)) {
147  amxc_var_set_type(values, AMXC_VAR_ID_HTABLE);
148  }
149 
150  if(lobject || !amxb_is_valid_be_func(fns, add, fns->add)) {
151  retval = amxb_invoke_add(bus_ctx, fixed, rel_path, index,
152  name, values, ret, timeout);
153  } else {
154  retval = fns->add(bus_ctx->bus_ctx, fixed, rel_path, index,
155  name, values, bus_ctx->access, ret, timeout);
156  }
157 
158 exit:
159  free(fixed);
160  amxd_path_clean(&path);
161  return retval;
162 }
static int amxb_invoke_add(amxb_bus_ctx_t *const bus_ctx, const char *object, const char *rel_path, uint32_t index, const char *name, amxc_var_t *values, amxc_var_t *ret, int timeout)
#define amxb_is_valid_be_func(ft, member, ptr)
Definition: amxb_priv.h:78
int PRIVATE amxb_follow_reference(amxb_bus_ctx_t *const bus_ctx, amxd_path_t *reference, int timeout)
Definition: amxb_ba_priv.c:116
bool PRIVATE amxb_is_local_object(amxb_bus_ctx_t *ctx, const char *obj_path)
Definition: amxb_ba_priv.c:94
The back-end interface structure.
amxb_be_add_t add
const amxb_be_funcs_t * bus_fn
Definition: amxb_types.h:121
uint32_t access
Definition: amxb_types.h:125
void * bus_ctx
Definition: amxb_types.h:122
static amxb_bus_ctx_t * bus_ctx
Definition: test_amxb_e2e.c:84

◆ amxb_async_call()

amxb_request_t* amxb_async_call ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
const char *  method,
amxc_var_t *  args,
amxb_be_done_cb_fn_t  done_fn,
void *  priv 
)

Invokes a data model function.

Calls a data model method. A data model method is a function that is exposed in the data model in a specific object.

The arguments passed must be in a amxc variant of type AMXC_VAR_ID_HTABLE. The order of the arguments is not important.

This function makes uses of amxb_new_invoke and amxb_async_invoke.

When the method call fails, the done function is called with NULL as amxb_request_t and the status will be the failure status.

The returned amxb_request_t pointer can be used with amxb_wait_for_request to wait until the method call is finished.

The returned pointer must be freed with amxb_close_request. After calling amxb_close_request, the callback function will not be called anymore.

Parameters
bus_ctxThe bus context (or connection)
objectobject path to the object that contains the function, object paths must end with a "."
methodname of the function being called
argsthe function arguments in a amxc variant htable type
done_fna done callback function
privprivate data that will be passed to the callback function (optional, can be NULL)
Returns
returns an amxb_request_t pointer or NULL when failed to call the method.

Definition at line 98 of file amxb_ba_op_call.c.

103  {
104  amxb_invoke_t* invoke_ctx = NULL;
105  int retval = amxd_status_unknown_error;
106  amxb_request_t* req = NULL;
107 
108  retval = amxb_new_invoke(&invoke_ctx, bus_ctx, object, NULL, method);
109  when_failed(retval, exit);
110  amxb_async_invoke(invoke_ctx, args, NULL, done_fn, priv, &req);
111 
112 exit:
113  amxb_free_invoke(&invoke_ctx);
114  return req;
115 }
int amxb_new_invoke(amxb_invoke_t **invoke_ctx, amxb_bus_ctx_t *const ctx, const char *object, const char *interface, const char *method)
Prepares a remote function invocation.
void amxb_free_invoke(amxb_invoke_t **invoke_ctx)
Deletes a function invoke context, and frees allocated memory.
int amxb_async_invoke(amxb_invoke_t *invoke_ctx, amxc_var_t *args, amxb_be_cb_fn_t fn, amxb_be_done_cb_fn_t done_fn, void *priv, amxb_request_t **req)
Invokes a remote function, as defined by the function invoke context.
A request structure.
Definition: amxb_types.h:138

◆ amxb_call()

int amxb_call ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
const char *  method,
amxc_var_t *  args,
amxc_var_t *  ret,
int  timeout 
)

Invokes a data model function.

Calls a data model method. A data model method is a function that is exposed in the data model in a specific object.

The arguments passed must be in a amxc variant of type AMXC_VAR_ID_HTABLE. The order of the arguments is not important.

This function makes uses of amxb_new_invoke and Remote Function Invoke.

If no response is received before the timeout expires, this function will return an error, but it is possible that the RPC method is still busy.

Parameters
bus_ctxThe bus context (or connection)
objectobject path to the object that contains the function, object paths must end with a "."
methodname of the function being called
argsthe function arguments in a amxc variant htable type
retwill contain the return value(s) and/or the out arguments
timeoutin seconds
Returns
amxd_status_ok remote function has completed successful

Definition at line 78 of file amxb_ba_op_call.c.

83  {
84 
85  amxb_invoke_t* invoke_ctx = NULL;
86  int retval = amxd_status_unknown_error;
87 
88  retval = amxb_new_invoke(&invoke_ctx, bus_ctx, object, NULL, method);
89  when_failed(retval, exit);
90  retval = amxb_invoke(invoke_ctx, args, ret, NULL, NULL, timeout);
91  when_failed(retval, exit);
92 
93 exit:
94  amxb_free_invoke(&invoke_ctx);
95  return retval;
96 }
int amxb_invoke(amxb_invoke_t *invoke_ctx, amxc_var_t *args, amxc_var_t *ret, amxb_be_cb_fn_t fn, void *priv, int timeout)
Invokes a remote function, as defined by the function invoke context.

◆ amxb_del()

int amxb_del ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
uint32_t  index,
const char *  name,
amxc_var_t *  ret,
int  timeout 
)

Deletes one or more instances of a multi-instance object.

Using this method, one or more instances can be deleted from a multi-instance object.

It is not possible to delete instances from a read-only multi instance object.

This function supports following paths:

  • object path - must end with a "."
  • search path - must end with a "." or "*"

The provided paths must either result or point to:

  • a multi-instance object (should be exactly one)
  • an instance (can be more then one)

When the given path is a multi-instance object, an index or name of the instance that will be deleted must be given. If both an index (instance identifier) and a name are given, the index takes precedence.

When the given path is an instance path, index and name arguments are ignored.

When the given path is a search path where multiple-instances match, all of the matching instances will be deleted and the index and name arguments are ignored.

The full list of deleted objects is returned in a variant containing an array of all deleted object paths, this includes the full tree underneath the delete instance(s).

Parameters
bus_ctxThe bus context (or connection)
objectFull object path or search path
indexthe index of the instance that will be deleted
namethe name of the instance that will be deleted
retwill contain a list of all deleted objects
timeoutin seconds
Returns
amxd_status_ok when successful, any other value indicates an error.

Definition at line 117 of file amxb_ba_op_del.c.

122  {
123  int retval = amxd_status_unknown_error;
124  const amxb_be_funcs_t* fns = NULL;
125  bool lobject = false;
126  amxd_path_t path;
127  char* fixed = NULL;
128  const char* rel_path = NULL;
129 
130  amxd_path_init(&path, NULL);
131  when_null(bus_ctx, exit);
132  when_null(bus_ctx->bus_ctx, exit);
133 
134  amxd_path_setf(&path, true, "%s", object);
135 
136  while(amxd_path_get_type(&path) == amxd_path_reference) {
137  retval = amxb_follow_reference(bus_ctx, &path, timeout);
138  when_failed(retval, exit);
139  }
140 
141  fixed = amxd_path_get_fixed_part(&path, true);
142  rel_path = amxd_path_get(&path, AMXD_OBJECT_TERMINATE);
143 
144  lobject = amxb_is_local_object(bus_ctx, fixed);
145  fns = bus_ctx->bus_fn;
146 
147  if(lobject || !amxb_is_valid_be_func(fns, del, fns->del)) {
148  retval = amxb_invoke_del(bus_ctx, fixed, rel_path, index,
149  name, ret, timeout);
150  } else {
151  retval = fns->del(bus_ctx->bus_ctx, fixed, rel_path, index,
152  name, bus_ctx->access, ret, timeout);
153  }
154 
155 exit:
156  free(fixed);
157  amxd_path_clean(&path);
158  return retval;
159 }
static int amxb_invoke_del(amxb_bus_ctx_t *const bus_ctx, const char *object, const char *rel_path, uint32_t index, const char *name, amxc_var_t *ret, int timeout)
amxb_be_del_t del

◆ amxb_describe()

int amxb_describe ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
uint32_t  flags,
amxc_var_t *  ret,
int  timeout 
)

Describes an object.

This function is mainly used for data model introspection. Besides the values of the parameters, more information can be obtained.

Information included in the returned data structure is:

  • parameter, object, function attributes
  • index and name - for instance objects
  • indexed and named object path (path and object fields)
  • type information for parameters, objects and functions
  • function names, and all function arguments

Use this function for introspection purposes.

Using the flags argument, the requested information can be manipulated:

  • AMXB_FLAG_FUNCTIONS - include all RPC methods of the object
  • AMXB_FLAG_PARAMETERS - include all parameters of the object
  • AMXB_FLAG_EVENTS - include all events of the object
  • AMXB_FLAG_OBJECTS - include the names of child objects
  • AMXB_FLAG_INSTANCES - include index and name of instance objects
  • AMXB_FLAG_EXISTS - return true if the object exists, when this flag is set all others are ignored.

All other flags will be ignored.

The return value of this function is always an Ambiorix variant and will contain the requested information. The return data is stored in the ret argument.

Example of a return variant:

[
{
attributes = {
locked = false,
persistent = false
private = false,
protected = false,
read-only = false,
},
index = 1,
name = "1",
object = "Phonebook.Contact.1.E-Mail.",
objects = [
],
parameters = {
E-Mail = {
attributes = {
counter = false,
instance = true,
key = false
persistent = false,
private = false,
protected = false,
read-only = false,
template = false,
unique = false,
volatile = false,
},
name = "E-Mail",
type_id = 1,
type_name = "cstring_t"
value = "john.d@ambiorix.com",
}
}
path = "Phonebook.Contact.1.E-Mail.",
type_id = 3,
type_name = "instance",
}
]
Parameters
bus_ctxThe bus context (or connection)
objectThe object path
flagsbitmap field of or'ed flags
retwill contain the requested information
timeoutin seconds
Returns
amxd_status_ok when successful, any other value indicates an error.

Definition at line 114 of file amxb_ba_op_describe.c.

118  {
119  int retval = amxd_status_unknown_error;
120  const amxb_be_funcs_t* fns = NULL;
121  bool lobject = false;
122  amxd_path_t path;
123  char* fixed = NULL;
124  const char* rel_path = NULL;
125 
126  amxd_path_init(&path, NULL);
127  when_null(bus_ctx, exit);
128  when_null(bus_ctx->bus_ctx, exit);
129 
130  amxd_path_setf(&path, true, "%s", object);
131  fixed = amxd_path_get_fixed_part(&path, true);
132  rel_path = amxd_path_get(&path, AMXD_OBJECT_TERMINATE);
133 
134  lobject = amxb_is_local_object(bus_ctx, fixed);
135  fns = bus_ctx->bus_fn;
136 
137  if(lobject || !amxb_is_valid_be_func(fns, describe, fns->describe)) {
138  retval = amxb_invoke_describe(bus_ctx, fixed, rel_path,
139  flags, ret, timeout);
140  } else {
141  retval = fns->describe(bus_ctx->bus_ctx, fixed, rel_path,
142  flags, bus_ctx->access, ret, timeout);
143  }
144 
145 exit:
146  free(fixed);
147  amxd_path_clean(&path);
148  return retval;
149 }
static int amxb_invoke_describe(amxb_bus_ctx_t *const bus_ctx, const char *object, const char *rel_path, uint32_t flags, amxc_var_t *values, int timeout)
amxb_be_describe_t describe

◆ amxb_get()

int amxb_get ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
int32_t  depth,
amxc_var_t *  ret,
int  timeout 
)

Fetches one or more objects or a single parameter.

Using this method, the parameter values of an object can be retrieved.

It is possible to get the parameters from multiple objects at once or to get one single parameter of one or more objects.

This function supports following paths:

  • object path - must end with a "."
  • search path - can contain expressions or wildcard to filter out instances. they can end with a parameter name, a "." or a "*"
  • parameter path - must end with a parameter name (no "." at the end)

In a search path a wildcard "*" or an expression can be put where an instance identifier (instance index) is in an object path.

Examples of valid search paths:

"Phonebook.Contact.*."
"Phonebook.Contact.*"
"Phonebook.Contact.[FirstName == 'Jane']."
"Phonebook.Contact.*.FirstName"
"Device.IP.Interface.[Type=='Normal'].IPv4Address.[AddressingType=='Static'].IPAddress"
"Device.IP.Interface.[Type=='Normal' && Stats.ErrorsSent>0].IPv4Address.[AddressingType=='Static'].IPAddress"

The return value of a get is always an Ambiorix variant:

[
{
Phonebook.Contact.1. = {
FirstName = "John"
LastName = "Doe",
},
Phonebook.Contact.2. = {
FirstName = "Jane"
LastName = "Doe",
},
Phonebook.Contact.3. = {
FirstName = "Eva"
LastName = "Elliott",
}
}
]
Parameters
bus_ctxThe bus context (or connection)
objectFull object path, search path or parameter path
depthrelative depth, if not zero it indicates how many levels of child objects are returned
retwill contain the objects and their parameters
timeoutin seconds
Returns
amxd_status_ok when successful, any other value indicates an error.

Definition at line 114 of file amxb_ba_op_get.c.

118  {
119  return amxb_get_filtered(bus_ctx, search_path, NULL, depth, ret, timeout);
120 }
int amxb_get_filtered(amxb_bus_ctx_t *const bus_ctx, const char *search_path, const char *filter, int32_t depth, amxc_var_t *ret, int timeout)
Fetches one or more objects and their parameters that are matching a filter.

◆ amxb_get_filtered()

int amxb_get_filtered ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
const char *  filter,
int32_t  depth,
amxc_var_t *  ret,
int  timeout 
)

Fetches one or more objects and their parameters that are matching a filter.

Using this method, the parameter values of an object can be retrieved. This function works exactly the same as amxb_get, but can filter the parameters of an object on the meta-data.

For more details see amxb_get.

The meta-data of the parameters can be retrieved using amxb_describe. If a filter is provided, the filter will be evaluated on the meta-data of the parameters, only matching parameters will be available in the result data.

Example of parameter meta-data:

attributes = {
counter = 1,
instance = 0,
key = 0,
mutable = 0,
persistent = 0,
private = 0,
protected = 0,
read-only = 1,
template = 0,
unique = 0,
volatile = 0
},
flags = [
],
name = "NumberOfHistoryEntries",
type_id = 8,
type_name = "uint32_t",
value = 1

Example of a filter:

"attributes.persistent==true || 'usersetting' in flags"

The above filter example will only return parameters that have the persistent attribute set or have the flag "usersetting", all other parameters will be filtered out.

If no filter (NULL or empty string) is provided, this function will return exactly the same as amxb_get.

Warning
It is possible that a bus/protocol backend doesn't have support for filtering parameters. When this functionality is not available by the used backend, the filter is ignored and this function will return exactly the same as amxb_get.
Parameters
bus_ctxThe bus context (or connection)
objectFull object path, search path or parameter path
filterLogical filter expression, only matching parameters are returned.
depthrelative depth, if not zero it indicates how many levels of child objects are returned
retwill contain the objects and their parameters
timeoutin seconds
Returns
amxd_status_ok when successful, any other value indicates an error.

Definition at line 122 of file amxb_ba_op_get.c.

127  {
128  int retval = amxd_status_unknown_error;
129  const amxb_be_funcs_t* fns = NULL;
130  amxd_path_t path;
131  bool islocal = false;
132  char* object = NULL;
133  const char* param = NULL;
134  amxc_string_t temp;
135 
136  amxc_string_init(&temp, 0);
137  amxd_path_init(&path, search_path);
138  when_null(bus_ctx, exit);
139  when_null(bus_ctx->bus_ctx, exit);
140 
141  while(amxd_path_get_type(&path) == amxd_path_reference) {
142  retval = amxb_follow_reference(bus_ctx, &path, timeout);
143  when_failed(retval, exit);
144  }
145 
146  object = amxd_path_get_fixed_part(&path, true);
147  if((object == NULL) || (strcmp(object, ".") == 0)) {
148  retval = amxd_status_object_not_found;
149  goto exit;
150  }
151  search_path = amxd_path_get(&path, AMXD_OBJECT_TERMINATE);
152  search_path = search_path == NULL ? "" : search_path;
153  param = amxd_path_get_param(&path);
154  islocal = amxb_is_local_object(bus_ctx, object);
155  fns = bus_ctx->bus_fn;
156 
157  if(param != NULL) {
158  amxc_string_setf(&temp, "%s%s", search_path, param);
159  search_path = amxc_string_get(&temp, 0);
160  }
161 
162  if(islocal ||
163  (!amxb_is_valid_be_func(fns, get, fns->get) &&
164  !amxb_is_valid_be_func(fns, get, fns->get_filtered))) {
165  retval = amxb_invoke_get(bus_ctx, object, search_path, filter,
166  depth, ret, timeout);
167  } else {
168  if(amxb_is_valid_be_func(fns, get, fns->get_filtered)) {
169  retval = fns->get_filtered(bus_ctx->bus_ctx, object, search_path, filter,
170  depth, bus_ctx->access, ret, timeout);
171 
172  } else if(amxb_is_valid_be_func(fns, get, fns->get)) {
173  retval = fns->get(bus_ctx->bus_ctx, object, search_path,
174  depth, bus_ctx->access, ret, timeout);
175  }
176  }
177 
178  if(retval == amxd_status_invalid_path) {
179  retval = amxd_status_object_not_found;
180  }
181 
182 exit:
183  amxc_string_clean(&temp);
184  free(object);
185  amxd_path_clean(&path);
186  return retval;
187 }
static int amxb_invoke_get(amxb_bus_ctx_t *const bus_ctx, const char *object, const char *search_path, const char *filter, int32_t depth, amxc_var_t *ret, int timeout)
amxb_be_get_t get
amxb_be_get_filtered_t get_filtered

◆ amxb_get_instances()

int amxb_get_instances ( amxb_bus_ctx_t *const  bus_ctx,
const char *  search_path,
int32_t  depth,
amxc_var_t *  ret,
int  timeout 
)

Fetches the instances and the unique keys of a multi-instance object.

Using this method, the instances of a multi-instance object and their unique keys can be retrieved.

It is possible to get the instances and keys from child objects of the provided multi-instance object as well by specifying a depth larger than 0.

This function supports following paths:

  • object path - must end with a "." and must point to a multi-instance object
  • search path - can contain expressions or wildcard to filter out instances, but the expression must resolve to one or several multi-instance objects to get a non-empty result

In a search path a wildcard "*" or an expression can be put where an instance identifier (instance index) is in an object path.

Examples of valid search paths:

"Phonebook.Contact.*.PhoneNumber."
"Phonebook.Contact.[FirstName == 'Jane'].PhoneNumber."

The return value of a get instances is always an Ambiorix variant:

[
{
"Phonebook.Contact.1.E-Mail.1.": {
},
"Phonebook.Contact.1.": {
"FirstName": "Jane"
},
"Phonebook.Contact.1.PhoneNumber.1.": {
}
}
]

In the above example, the FirstName parameter was a unique key parameter

Parameters
bus_ctxThe bus context (or connection)
objectMulti-instance object path or search path
depthrelative depth, if not zero it indicates for how many levels the child instances are returned
retwill contain the objects and their keys
timeoutin seconds
Returns
amxd_status_ok when successful, any other value indicates an error.

Definition at line 121 of file amxb_ba_op_get_instances.c.

125  {
126  int retval = amxd_status_unknown_error;
127  const amxb_be_funcs_t* fns = NULL;
128  amxd_path_t path;
129  bool islocal = false;
130  char* object = NULL;
131  const char* param = NULL;
132  amxc_string_t temp;
133 
134  amxc_string_init(&temp, 0);
135  amxd_path_init(&path, search_path);
136  when_null(bus_ctx, exit);
137  when_null(bus_ctx->bus_ctx, exit);
138 
139  object = amxd_path_get_fixed_part(&path, true);
140  if((object == NULL) || (strcmp(object, ".") == 0)) {
141  retval = amxd_status_object_not_found;
142  goto exit;
143  }
144  search_path = amxd_path_get(&path, AMXD_OBJECT_TERMINATE);
145  search_path = search_path == NULL ? "" : search_path;
146  param = amxd_path_get_param(&path);
147  islocal = amxb_is_local_object(bus_ctx, object);
148  fns = bus_ctx->bus_fn;
149 
150  if(param != NULL) {
151  amxc_string_setf(&temp, "%s%s", search_path, param);
152  search_path = amxc_string_get(&temp, 0);
153  }
154 
155  if(islocal || !amxb_is_valid_be_func(fns, get, fns->get_instances)) {
156  retval = amxb_invoke_get_instances(bus_ctx, islocal, object, search_path,
157  depth, ret, timeout);
158  } else {
159  retval = fns->get_instances(bus_ctx->bus_ctx, object, search_path,
160  depth, bus_ctx->access, ret, timeout);
161  }
162 
163 exit:
164  amxc_string_clean(&temp);
165  free(object);
166  amxd_path_clean(&path);
167  return retval;
168 }
static int amxb_invoke_get_instances(amxb_bus_ctx_t *const bus_ctx, bool islocal, const char *object, const char *search_path, int32_t depth, amxc_var_t *ret, int timeout)
amxb_be_get_instances_t get_instances

◆ amxb_get_multiple()

int amxb_get_multiple ( amxb_bus_ctx_t *const  bus_ctx,
amxc_var_t *  req_paths,
int32_t  depth,
amxc_var_t *  ret,
int  timeout 
)

Fetches one or more (root) objects or multiple parameters.

It is possible to get the parameters from multiple objects at once or to get one single parameter of one or more objects.

This function supports an amxc linked list with paths, each path must follow these rules:

  • object path - must end with a "."
  • search path - can contain expressions or wildcard to filter out instances. they can end with a parameter name, a "." or a "*"
  • parameter path - must end with a parameter name (no "." at the end)

In a search path a wildcard "*" or an expression can be put where an instance identifier (instance index) is in an object path.

Examples of valid use case:

amxc_var_t paths;
amxc_var_init(&paths);
amxc_var_set_type(&paths, AMXC_VAR_ID_LIST);
amxc_var_add(cstring_t, &paths, "Phonebook.Contact.1.FirstName");
amxc_var_add(cstring_t, &paths, "Phonebook.Contact.2.");
amxc_var_add(cstring_t, &paths, "Phonebook.Contact.*");
amxc_var_add(cstring_t, &paths, "Phonebook.Contact.[FirstName == 'Jane'].");
amxc_var_add(cstring_t, &paths, "Device.IP.Interface.[Type=='Normal'].IPv4Address.[AddressingType=='Static'].IPAddress");
amxb_get_multiple(bus_ctx, &paths, 0, &ret, 5);
int amxb_get_multiple(amxb_bus_ctx_t *const bus_ctx, amxc_var_t *req_paths, int32_t depth, amxc_var_t *ret, int timeout)
Fetches one or more (root) objects or multiple parameters.

The return value of a get_multiple is always an Ambiorix htable variant containing the individual responses from amxb_get for each path:

{
Device.IP.Interface.[Type=='Normal'].IPv4Address.[AddressingType=='Static'].IPAddress = {
result = [
{
}
],
status = 2
},
Phonebook.Contact.* = {
result = [
{
Phonebook.Contact.1. = {
FirstName = "John"
LastName = "Doe",
},
Phonebook.Contact.2. = {
FirstName = "Pony"
LastName = "Goffin",
}
}
],
status = 0
}
Phonebook.Contact.1.FirstName = {
result = [
{
Phonebook.Contact.1. = {
FirstName = "John"
}
}
],
status = 0
},
Phonebook.Contact.2. = {
result = [
{
Phonebook.Contact.2. = {
FirstName = "Pony"
LastName = "Goffin",
}
}
],
status = 0
},
Phonebook.Contact.[FirstName == 'Jane']. = {
result = [
{
}
],
status = 0
},
}
Parameters
bus_ctxThe bus context (or connection)
req_pathsAmxc variant containing a list of all paths to search for.
depthrelative depth, if not zero it indicates how many levels of child objects are returned. This depth is the same for all paths.
retwill contain an amxc variant containing a htable with the objects and their parameters
timeoutin seconds (for every individual amxb_get lookup)
Returns
amxd_status_ok when successful, any other value indicates an error.

Definition at line 78 of file amxb_ba_op_get_multiple.c.

82  {
83  int retval = amxd_status_ok;
84  amxc_var_set_type(ret, AMXC_VAR_ID_HTABLE);
85 
86  when_false(amxc_var_type_of(req_paths) == AMXC_VAR_ID_LIST, exit);
87 
88  amxc_var_for_each(path, req_paths) {
89  int rv = 0;
90  amxc_var_t* sub_ret = NULL;
91  amxc_var_t* sub_ret_result = NULL;
92  const char* path_string = NULL;
93 
94  path_string = amxc_var_constcast(cstring_t, path);
95  sub_ret = amxc_var_add_key(amxc_htable_t, ret, path_string, NULL);
96  sub_ret_result = amxc_var_add_new_key(sub_ret, "result");
97  rv = amxb_get(bus_ctx, path_string, depth, sub_ret_result, timeout);
98  if(amxc_var_type_of(sub_ret_result) == AMXC_VAR_ID_NULL) {
99  amxc_var_set_type(sub_ret_result, AMXC_VAR_ID_LIST);
100  amxc_var_add(amxc_htable_t, sub_ret_result, NULL);
101  rv = amxd_status_object_not_found;
102  }
103  amxc_var_add_key(uint32_t, sub_ret, "status", rv);
104  }
105 
106  retval = amxd_status_ok;
107 
108 exit:
109  return retval;
110 
111 }
int amxb_get(amxb_bus_ctx_t *const bus_ctx, const char *object, int32_t depth, amxc_var_t *ret, int timeout)
Fetches one or more objects or a single parameter.

◆ amxb_get_supported()

int amxb_get_supported ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
uint32_t  flags,
amxc_var_t *  ret,
int  timeout 
)

Gets the supported data model.

This function is mainly used to have support for the USP "get supported dm" message.

Use this function for introspection purposes.

This function does not return any instance, it only indicates which objects are multi-instance objects. The place in the object path where normally an instance identifier (index) is set, the place holder "{i}" is used.

The object argument must be in this supported data model notation.

Example:

"Phonebook.Contact.{i}.PhoneNumber.{i}."

Using the flags argument, the requested information can be manipulated:

  • AMXB_FLAG_FIRST_LVL - do not return child objects
  • AMXB_FLAG_FUNCTIONS - include all RPC methods of the object
  • AMXB_FLAG_PARAMETERS - include all parameters of the object
  • AMXB_FLAG_EVENTS - include all events of the object

All other flags will be ignored.

The return value of this function is always an Ambiorix variant and will contain the requested information. The return data is stored in the ret argument.

Example of a return variant:

[
{
Phonebook.Contact.{i}.PhoneNumber.{i}. = {
access = 1
is_multi_instance = true,
supported_commands = [
],
supported_params = [
{
access = 1
param_name = "Phone",
}
],
}
}
]
Parameters
bus_ctxThe bus context (or connection)
objectThe object path (in supported path notation)
flagsbitmap field of or'ed flags
retwill contain the requested information
timeoutin seconds
Returns
amxd_status_ok when successful, any other value indicates an error.

Definition at line 113 of file amxb_ba_op_get_sup.c.

117  {
118  int retval = amxd_status_unknown_error;
119  const amxb_be_funcs_t* fns = NULL;
120  bool lobject = false;
121  amxd_path_t path;
122  char* fixed = NULL;
123  const char* rel_path = NULL;
124 
125  amxd_path_init(&path, NULL);
126  when_null(bus_ctx, exit);
127  when_null(bus_ctx->bus_ctx, exit);
128 
129  amxd_path_setf(&path, true, "%s", object);
130  fixed = amxd_path_get_fixed_part(&path, true);
131  rel_path = amxd_path_get(&path, AMXD_OBJECT_TERMINATE);
132 
133  lobject = amxb_is_local_object(bus_ctx, fixed);
134  fns = bus_ctx->bus_fn;
135 
136  if(lobject || !amxb_is_valid_be_func(fns, get_supported, fns->get_supported)) {
137  retval = amxb_invoke_get_supported(bus_ctx, fixed, rel_path, flags,
138  values, timeout);
139  } else {
140  if(bus_ctx->access == amxd_dm_access_protected) {
141  flags |= AMXB_FLAG_PROTECTED;
142  }
143  retval = fns->get_supported(bus_ctx->bus_ctx, fixed, rel_path, flags,
144  values, timeout);
145  }
146 
147 exit:
148  free(fixed);
149  amxd_path_clean(&path);
150  return retval;
151 }
static int amxb_invoke_get_supported(amxb_bus_ctx_t *const bus_ctx, const char *object, const char *rel_path, uint32_t flags, amxc_var_t *values, int timeout)
#define AMXB_FLAG_PROTECTED
amxb_be_get_supported_t get_supported

◆ amxb_list()

int amxb_list ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
uint32_t  flags,
amxb_be_cb_fn_t  fn,
void *  priv 
)

List the service elements/nodes of an object.

This function is mainly used for data model introspection and provides list of the service elements/nodes that are part of the object

Use this function for introspection purposes.

Using the flags argument, the requested information can be manipulated:

  • AMXB_FLAG_FUNCTIONS - include all RPC methods of the object
  • AMXB_FLAG_PARAMETERS - include all parameters of the object
  • AMXB_FLAG_OBJECTS - include the names of child objects
  • AMXB_FLAG_INSTANCES - include index and name of instance objects

All other flags will be ignored.

Parameters
bus_ctxThe bus context (or connection)
objectThe object path (in supported path notation)
flagsbitmap field of ored flags
fncallback function
privprivate data that will be passed as is to the callback function
Returns
amxd_status_ok when successful, any other value indicates an error.

Definition at line 177 of file amxb_ba_op_list.c.

181  {
182  int retval = amxd_status_unknown_error;
183  const amxb_be_funcs_t* fns = NULL;
184  amxd_path_t path;
185  bool lobject = false;
186 
187  amxd_path_init(&path, NULL);
188  when_null(bus_ctx, exit);
189  when_null(bus_ctx->bus_ctx, exit);
190  if((object != NULL) && ((*object) != 0)) {
191  lobject = amxb_is_local_object(bus_ctx, object);
192  }
193  fns = bus_ctx->bus_fn;
194 
195  if((object != NULL) && (*object != 0)) {
196  amxd_path_setf(&path, true, "%s", object);
197  if(lobject || !amxb_is_valid_be_func(fns, list, fns->list)) {
198  retval = amxb_invoke_list(bus_ctx, object, flags, fn, priv);
199  } else {
200  amxb_req_t* req = (amxb_req_t*) calloc(1, sizeof(amxb_req_t));
201  when_null(req, exit);
202  req->data.cb_fn = fn;
203  req->data.priv = priv;
204  amxc_llist_append(&bus_ctx->requests, &req->it);
205  retval = fns->list(bus_ctx->bus_ctx, object, flags,
206  bus_ctx->access, &req->data);
207  }
208  } else {
209  if(amxb_is_valid_be_func(fns, list, fns->list)) {
210  amxb_req_t* req = (amxb_req_t*) calloc(1, sizeof(amxb_req_t));
211  when_null(req, exit);
212  req->data.cb_fn = fn;
213  req->data.priv = priv;
214  amxc_llist_append(&bus_ctx->requests, &req->it);
215  retval = fns->list(bus_ctx->bus_ctx, object, flags,
216  bus_ctx->access, &req->data);
217  } else {
218  if(fn != NULL) {
219  fn(bus_ctx, NULL, priv);
220  }
222  }
223  }
224 
225 exit:
226  amxd_path_clean(&path);
227  return retval;
228 }
static int amxb_invoke_list(amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxb_be_cb_fn_t fn, void *priv)
#define AMXB_ERROR_NOT_SUPPORTED_OP
Function/operation not supported.
Definition: amxb_error.h:110
amxb_be_list_t list
amxc_llist_t requests
Definition: amxb_types.h:118
amxb_be_cb_fn_t cb_fn
Definition: amxb_types.h:141
Definition: amxb_priv.h:69
amxc_llist_it_t it
Definition: amxb_priv.h:70
amxb_request_t data
Definition: amxb_priv.h:71

◆ amxb_set()

int amxb_set ( amxb_bus_ctx_t *const  bus_ctx,
const char *  object,
amxc_var_t *  values,
amxc_var_t *  ret,
int  timeout 
)

Sets parameter values of one single object or of multiple instance objects.

Using this method, the parameter values of an object can be changed.

It is not possible to change read-only parameter values using this function.

This function supports following paths:

  • object path - must end with a "."
  • search path - can contain expressions or wildcard to filter out instances. and must end with a "." or "*"

In a search path a wildcard "*" or an expression can be put where an instance identifier (instance index) is in an object path.

Examples of valid search paths:

"Phonebook.Contact.*."
"Phonebook.Contact.*"
"Phonebook.Contact.[FirstName == 'Jane']."
"Device.IP.Interface.[Type=='Normal'].IPv4Address.[AddressingType=='Static']."
"Device.IP.Interface.[Type=='Normal' && Stats.ErrorsSent>0].IPv4Address.[AddressingType=='Static']."

The parameter values must be passed as a variant containing a hash-table where each key is a parameter name and the value is the new value for that parameter.

When using a search path and multiple instances match the search path, all the mentioned parameters are modified for all matching instances.

The return value of a set is always an Ambiorix variant and will contain all changed objects, and the changed parameters. Unchanged parameters are not provided in the return value.

Example: When changing all "LastNames" to "Ambiorix" of all contacts using search path "Phonebook.Contact.*" the return value could be

[
Phonebook.Contact.1. = {
LastName = "Ambiorix"
},
Phonebook.Contact.2. = {
LastName = "Ambiorix"
},
Phonebook.Contact.3. = {
LastName = "Ambiorix"
}
]
Parameters
bus_ctxThe bus context (or connection)
objectFull object path, search path or parameter path
valuesvariant hash-table containing the new values
retwill contain the objects and their changed parameters
timeoutin seconds
Returns
amxd_status_ok when successful, any other value indicates an error.

Definition at line 172 of file amxb_ba_op_set.c.

176  {
177  return amxb_set_impl(bus_ctx, object, 0, values, NULL, ret, timeout);
178 }
int amxb_set_impl(amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxc_var_t *values, amxc_var_t *ovalues, amxc_var_t *ret, int timeout)

◆ amxb_set_multiple()

int amxb_set_multiple ( amxb_bus_ctx_t *const  bus_ctx,
uint32_t  flags,
amxc_var_t *  req_paths,
amxc_var_t *  ret,
int  timeout 
)

Sets parameter values for multiple objects (request paths)

Using this method, the parameter values of an object can be changed.

It is not possible to change read-only parameter values using this function.

This function supports following paths:

  • object path - must end with a "."
  • search path - can contain expressions or wildcard to filter out instances. and must end with a "." or "*"

In a search path a wildcard "*" or an expression can be put where an instance identifier (instance index) is in an object path.

Examples of valid search paths:

"Phonebook.Contact.*."
"Phonebook.Contact.*"
"Phonebook.Contact.[FirstName == 'Jane']."
"Device.IP.Interface.[Type=='Normal'].IPv4Address.[AddressingType=='Static']."
"Device.IP.Interface.[Type=='Normal' && Stats.ErrorsSent>0].IPv4Address.[AddressingType=='Static']."

The parameter values must be passed as a variant containing a hash-table where each key is a parameter name and the value is the new value for that parameter.

When using a search path and multiple instances match the search path, all the mentioned parameters are modified for all matching instances.

The return value of a set is always an Ambiorix variant and will contain all changed objects, and the changed parameters. Unchanged parameters are not provided in the return value. For each request path a status is added as well.

When the status code is 0, the set for that request path was successful. All other status codes indicate an error and is always referring to one of the amxd_status_t enum.

When the flag AMXB_FLAG_PARTIAL is set, an error code is returned for each parameter that could not be set. The error code is one of the amxd_status_t codes.

When failed to set an optional parameter, an error code is returned for that parameter.

Example of a valid req_paths variant:

[
{
path = "Device.Ethernet.Interface.2.",
parameters = {
Status = "dummy-invalid"
}
},
{
path = "Device.Ethernet.Interface.[Status == 'Dormant'].",
parameters = {
Enable = false
}
},
{
path = "MQTT.Client.*.",
parameters = {
Enable = true
},
oparameters = {
TransportProtocol = "TLS"
}
},
{
path = "MQTT.Client.1.",
parameters = {
Enable = true,
TransportProtocol = "TLS"
}
}
]

The above req_paths variant will return in case AMXB_FLAG_PARTIAL is provided:

[
{
path = "Device.Ethernet.Interface.2.",
result = {
Device.Ethernet.Interface.2. = {
Status = {
error_code = 10,
required = true
}
}
},
status = 10
},
{
path = "Device.Ethernet.Interface.[Status == 'Dormant'].",
result = {
Device.Ethernet.Interface.1. = {
Enable = false
}
Device.Ethernet.Interface.5. = {
Enable = false
},
},
status = 0
},
{
path = "MQTT.Client.*.",
result = {
MQTT.Client.1. = {
Enable = true,
TransportProtocol = "TLS"
},
MQTT.Client.2. = {
Enable = true,
TransportProtocol = "TLS"
}
},
status = 0
},
{
path = "MQTT.Client.[Alias == 'cpe-mybroker'].",
result = {
MQTT.Client.1. = {
Enable = true,
TransportProtocol = "TLS"
}
},
status = 0
}
]

In case the AMXB_FLAG_PARTIAL is not provided only the first failing request path is returned and all others are not applied.

[
{
path = "Device.Ethernet.Interface.2.",
result = {
Device.Ethernet.Interface.2. = {
Status = {
error_code = 10,
required = true
}
}
},
status = 10
}
}
Parameters
bus_ctxThe bus context (or connection)
flagsSupported flags are AMXB_FLAG_PARTIAL.
req_pathshash-table variant containing the request paths and parameters to be set
retwill contain for each request path the result and status
timeoutin seconds
Returns
amxd_status_ok when successful, any other value indicates an error.

Definition at line 141 of file amxb_ba_op_set_multiple.c.

145  {
146  int retval = amxd_status_unknown_error;
147  amxc_var_t sub_ret;
148  amxc_var_t rollback;
149  amxc_var_t current;
150  int count = 0;
151  bool allow_partial = ((flags & AMXB_FLAG_PARTIAL) != 0);
152  amxc_var_init(&sub_ret);
153  amxc_var_init(&rollback);
154  amxc_var_init(&current);
155  amxc_var_set_type(ret, AMXC_VAR_ID_LIST);
156  amxc_var_set_type(&rollback, AMXC_VAR_ID_HTABLE);
157 
158  when_false(amxc_var_type_of(req_paths) == AMXC_VAR_ID_LIST, exit);
159 
160  count = amxc_llist_size(amxc_var_constcast(amxc_llist_t, req_paths));
161 
162  retval = amxd_status_ok;
163 
164  amxc_var_for_each(req_path, req_paths) {
165  int rv = 0;
166  const char* object = GET_CHAR(req_path, "path");
167  amxc_var_t* params = GET_ARG(req_path, "parameters");
168  amxc_var_t* oparams = GET_ARG(req_path, "oparameters");
169  if(!allow_partial && (count > 1)) {
170  amxc_var_clean(&current);
171  amxb_get(bus_ctx, object, 0, &current, 5);
172  amxb_filter_params(GETI_ARG(&current, 0), params, oparams);
173  }
174  rv = amxb_set_impl(bus_ctx, object, flags, params, oparams, &sub_ret, timeout);
175 
176  if((rv != 0) && !allow_partial) {
177  // reset return variant, only keep failed set
178  amxc_var_set_type(ret, AMXC_VAR_ID_LIST);
179  }
180 
181  // add results
182  amxb_set_result(object, ret, &sub_ret, rv);
183 
184  // what is next? continue or fail.
185  if(rv != 0) {
186  if(!allow_partial) {
187  if(count > 1) {
188  amxb_set_rollback(bus_ctx, &rollback);
189  }
190  retval = rv;
191  break;
192  }
193  } else {
194  if(!allow_partial && (count > 1)) {
195  amxb_add_rollback(GETI_ARG(&current, 0), &rollback);
196  }
197  }
198 
199  amxc_var_clean(&sub_ret);
200  }
201 
202 exit:
203  amxc_var_clean(&current);
204  amxc_var_clean(&rollback);
205  amxc_var_clean(&sub_ret);
206  return retval;
207 }
static void amxb_filter_params(amxc_var_t *current, amxc_var_t *parameters, amxc_var_t *oparameters)
static void amxb_set_rollback(amxb_bus_ctx_t *const bus_ctx, amxc_var_t *rollback)
static void amxb_add_rollback(amxc_var_t *current, amxc_var_t *rollback)
static void amxb_set_result(const char *req_path, amxc_var_t *ret, amxc_var_t *sub_ret, int rv)
#define AMXB_FLAG_PARTIAL
int PRIVATE amxb_set_impl(amxb_bus_ctx_t *const bus_ctx, const char *object, uint32_t flags, amxc_var_t *values, amxc_var_t *ovalues, amxc_var_t *ret, int timeout)