libamxd  6.4.1
Data Model Manager
Data Model Objects MIBs
Collaboration diagram for Data Model Objects MIBs:

Functions

char * amxd_object_get_mibs (amxd_object_t *object)
 Get the names of all mibs attached to this object. More...
 
bool amxd_object_has_mib (amxd_object_t *object, const char *mib_name)
 Checks if a mib has been added to a data model object. More...
 
amxd_status_t amxd_object_add_mib (amxd_object_t *const object, const char *mib_name)
 Adds a mib to an object. More...
 
amxd_status_t amxd_object_remove_mib (amxd_object_t *const object, const char *mib_name)
 Removes a mib from an object. More...
 

Detailed Description

Function Documentation

◆ amxd_object_add_mib()

amxd_status_t amxd_object_add_mib ( amxd_object_t *const  object,
const char *  mib_name 
)

Adds a mib to an object.

When it is possible adds a mib with the given name to an object.

When there is no mib defined with the given name this functions returns an error.

When the mib was already added to the object this function returns an error.

A mib can not be added to an object when there are name conflicts:

  • when the mib contains a parameter with the same name as a parameter in the object
  • when the mib contains a child object with the same name as a child object in the object
  • when the mib contains a method with the same name as a method in the object

When a mib is applied to an object, the object has been extended and will contain the parameters, methods and child objects as defined in the mib.

The mib can be removed from the object using amxd_object_remove_mib

Parameters
objectthe object pointer
mib_namethe mib name
Returns
Returns amxd_status_ok when the mib is applied to the object. Returns amxd_status_object_not_found when there is no mib with the given name. Returns amxd_status_duplicate when the mib can not be applied due to naming conflicts.

Definition at line 254 of file amxd_object_mib.c.

255  {
257  amxd_dm_t* dm = amxd_object_get_dm(object);
258  amxd_object_t* mib = amxd_dm_get_mib(dm, mib_name);
259  amxc_array_it_t* ait = NULL;
260 
261  when_null(dm, exit);
262  when_null_status(mib, exit, status = amxd_status_object_not_found);
263  if(amxd_object_has_mib(object, mib_name) ||
264  !amxd_object_can_add_mib(object, mib)) {
266  goto exit;
267  }
268 
269  amxd_object_copy_children(object, mib);
270  amxd_object_send_add_objects(object, mib);
271  amxd_object_copy_params(object, mib);
272  amxd_object_copy_funcs(object, mib);
273  amxd_object_copy_events(object, mib);
274 
275  mib_name = amxd_object_get_name(mib, AMXD_OBJECT_NAMED);
276  amxd_object_send_mib(object, mib_name, true);
277  ait = amxc_array_get_first_free(&object->mib_names);
278  if(ait == NULL) {
279  amxc_array_append_data(&object->mib_names, (void*) mib_name);
280  } else {
281  amxc_array_it_set_data(ait, (void*) mib_name);
282  }
283 
285 
286 exit:
287  return status;
288 }
amxd_object_t * amxd_dm_get_mib(amxd_dm_t *const dm, const char *name)
Definition: amxd_dm.c:397
static bool amxd_object_can_add_mib(amxd_object_t *const object, amxd_object_t *const mib)
static void amxd_object_send_mib(amxd_object_t *object, const char *mib_name, bool added)
static void amxd_object_send_add_objects(amxd_object_t *object, amxd_object_t *mib)
PRIVATE amxd_status_t amxd_object_copy_funcs(amxd_object_t *const dst, const amxd_object_t *const src)
PRIVATE amxd_status_t amxd_object_copy_events(amxd_object_t *const dst, const amxd_object_t *const src)
PRIVATE amxd_status_t amxd_object_copy_params(amxd_object_t *const dst, const amxd_object_t *const src)
PRIVATE amxd_status_t amxd_object_copy_children(amxd_object_t *const dst, const amxd_object_t *const src)
enum _amxd_status amxd_status_t
@ amxd_status_object_not_found
Definition: amxd_types.h:80
@ 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
#define AMXD_OBJECT_NAMED
Name and path format flag - default behavior, use name for instance objects.
Definition: amxd_object.h:164
amxd_dm_t * amxd_object_get_dm(const amxd_object_t *const object)
Get the data model.
bool amxd_object_has_mib(amxd_object_t *object, const char *mib_name)
Checks if a mib has been added to a data model object.
const char * amxd_object_get_name(const amxd_object_t *const object, const uint32_t flags)
Get the name of the object (or index as a string for instance objects)
Definition: amxd_object.c:239
amxc_array_t mib_names
Definition: amxd_types.h:254
static amxd_dm_t dm
static amxd_status_t status

◆ amxd_object_get_mibs()

char* amxd_object_get_mibs ( amxd_object_t object)

Get the names of all mibs attached to this object.

Note
Memory is allocated to store the mib names, the returned pointer must be freed. Failing to do so will result in a memory leak.
Parameters
objectthe object pointer
Returns
Returns a space separated string containing the names of the mibs that are applied to this object. If no mibs are applied, returns NULL.

Definition at line 205 of file amxd_object_mib.c.

205  {
206  char* mibs = NULL;
207  amxc_array_it_t* ait = NULL;
208  amxc_string_t str;
209 
210  amxc_string_init(&str, 0);
211  when_null(object, exit);
212 
213  ait = amxc_array_get_first(&object->mib_names);
214  while(ait != NULL) {
215  const char* name = (const char*) amxc_array_it_get_data(ait);
216  if(name != NULL) {
217  amxc_string_appendf(&str, "%s ", name);
218  }
219  ait = amxc_array_it_get_next(ait);
220  }
221 
222  amxc_string_trim(&str, NULL);
223  mibs = amxc_string_take_buffer(&str);
224 
225 exit:
226  amxc_string_clean(&str);
227  return mibs;
228 }

◆ amxd_object_has_mib()

bool amxd_object_has_mib ( amxd_object_t object,
const char *  mib_name 
)

Checks if a mib has been added to a data model object.

Verifies if the mib with the given name is applied on the object

if a mib with the given name does not exists, this function returns false.

Parameters
objectthe object pointer
mib_namethe mib name
Returns
Returns true if mib was set on the object, false otherwise

Definition at line 230 of file amxd_object_mib.c.

231  {
232  bool retval = false;
233  amxc_array_it_t* ait = NULL;
234 
235  when_null(object, exit);
236  when_str_empty(mib_name, exit);
237 
238  ait = amxc_array_get_first(&object->mib_names);
239  while(ait != NULL) {
240  const char* name = (const char*) amxc_array_it_get_data(ait);
241  if(name != NULL) {
242  if(strcmp(name, mib_name) == 0) {
243  retval = true;
244  break;
245  }
246  }
247  ait = amxc_array_it_get_next(ait);
248  }
249 
250 exit:
251  return retval;
252 }

◆ amxd_object_remove_mib()

amxd_status_t amxd_object_remove_mib ( amxd_object_t *const  object,
const char *  mib_name 
)

Removes a mib from an object.

Removes a mib with the given name from the object.

Removing a mib will remove all parameters, methods and child objects from the object as defined in the mib.

All data stored in the parameters will be lost.

If there is no mib found with the given name this function returns an error.

If the mib with the given name was not set on the object, this function returns amxd_status_ok.

Parameters
objectthe object pointer
mib_namethe mib name
Returns
Returns amxd_status_ok when the mib is removed from the object. Returns amxd_status_object_not_found when there is no mib with the given name.

Definition at line 290 of file amxd_object_mib.c.

291  {
293  amxd_dm_t* dm = amxd_object_get_dm(object);
294  amxd_object_t* mib = amxd_dm_get_mib(dm, mib_name);
295 
296  when_null(dm, exit);
297  when_null_status(mib, exit, status = amxd_status_object_not_found);
298  when_false_status(amxd_object_has_mib(object, mib_name), exit, status = amxd_status_ok);
299 
300  mib_name = amxd_object_get_name(mib, AMXD_OBJECT_NAMED);
301  amxd_object_send_mib(object, mib_name, false);
302  amxd_object_remove_mib_params(object, mib);
304  amxd_object_send_del_objects(object, mib);
305  amxd_object_remove_mib_objects(object, mib);
306  amxd_object_remove_mib_events(object, mib);
307  amxd_object_clear_mib(object, mib_name);
308 
310 exit:
311  return status;
312 }
static void amxd_object_remove_mib_functions(amxd_object_t *const object, amxd_object_t *const mib)
static void amxd_object_send_del_objects(amxd_object_t *object, amxd_object_t *mib)
static void amxd_object_remove_mib_params(amxd_object_t *const object, amxd_object_t *const mib)
static void amxd_object_clear_mib(amxd_object_t *const object, const char *mib_name)
static void amxd_object_remove_mib_objects(amxd_object_t *const object, amxd_object_t *const mib)
static void amxd_object_remove_mib_events(amxd_object_t *const object, amxd_object_t *const mib)