libamxd  6.4.1
Data Model Manager
amxd_object.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 
55 #if !defined(__AMXD_OBJECT_H__)
56 #define __AMXD_OBJECT_H__
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #include <stdint.h>
64 #include <amxd/amxd_types.h>
65 #include <amxd/amxd_common.h>
70 
113 #define amxd_object_for_each(type, it, object) \
114  for(amxc_llist_it_t* it = amxd_object_first_ ## type(object), \
115  * _next = amxc_llist_it_get_next(it); \
116  it; \
117  it = _next, \
118  _next = amxc_llist_it_get_next(it))
119 
120 
149 #define amxd_object_iterate(type, it, object) \
150  for(amxc_llist_it_t* it = amxd_object_first_ ## type(object); \
151  it; \
152  it = amxc_llist_it_get_next(it))
153 
164 #define AMXD_OBJECT_NAMED 0x00
165 
176 #define AMXD_OBJECT_INDEXED 0x01
177 
188 #define AMXD_OBJECT_EXTENDED 0x02
189 
202 #define AMXD_OBJECT_REGEXP 0x04
203 
214 #define AMXD_OBJECT_TERMINATE 0x08
215 
226 #define AMXD_OBJECT_SUPPORTED 0x10
227 
228 #define AMXD_OBJECT_AUTO_PATH 0x20
229 
244 #define AMXD_OBJECT_PARAM 0x01
245 
260 #define AMXD_OBJECT_FUNC 0x02
261 
273 #define AMXD_OBJECT_CHILD 0x04
274 
287 #define AMXD_OBJECT_INSTANCE 0x08
288 
301 #define AMXD_OBJECT_NO_BASE 0x10
302 
314 #define AMXD_TEMPLATE_INFO 0x20
315 
316 #define AMXD_OBJECT_KEY_PARAM 0x40
317 
318 #define AMXD_OBJECT_EVENT 0x80
319 
328 #define AMXD_OBJECT_ALL \
329  AMXD_OBJECT_PARAM | \
330  AMXD_OBJECT_FUNC | \
331  AMXD_OBJECT_CHILD | \
332  AMXD_OBJECT_INSTANCE
333 
380  const amxd_object_type_t type,
381  const char* name);
382 
397 void amxd_object_free(amxd_object_t** object);
398 
449  amxd_object_t* templ,
450  const char* name,
451  uint32_t index,
452  amxc_var_t* values);
453 
509  amxd_object_t* templ,
510  const char* name,
511  uint32_t index,
512  amxc_var_t* values);
513 
532 void amxd_object_delete(amxd_object_t** object);
533 
548 const char* amxd_object_get_name(const amxd_object_t* const object,
549  const uint32_t flags);
550 
564 uint32_t amxd_object_get_index(const amxd_object_t* const object);
565 
585 static inline
587  return object == NULL ? amxd_object_invalid : object->type;
588 }
589 
614  const amxd_oattr_id_t attr,
615  const bool enable);
616 
617 
655  const uint32_t bitmask,
656  bool enable);
657 
682 uint32_t amxd_object_get_attrs(const amxd_object_t* const object);
683 
702 bool amxd_object_is_attr_set(const amxd_object_t* const object,
703  const amxd_oattr_id_t attr);
704 
725 char* amxd_object_get_mibs(amxd_object_t* object);
726 
748  const char* mib_name);
749 
784  const char* mib_name);
785 
811  const char* mib_name);
812 
814  int32_t depth);
815 
817  const char* name);
818 
820  uint32_t max);
821 
823  amxc_var_t* const list,
824  uint32_t flags,
825  amxd_dm_access_t access);
826 
828  amxc_var_t* const value,
829  uint32_t flags,
830  amxd_dm_access_t access);
831 
832 amxd_object_t* amxd_object_get_base(const amxd_object_t* const object);
833 
834 static inline
835 amxc_llist_it_t* amxd_object_first_function(const amxd_object_t* const object) {
836  return object == NULL ? NULL : amxc_llist_get_first(&object->functions);
837 }
838 
839 static inline
840 amxc_llist_it_t* amxd_object_first_parameter(const amxd_object_t* const object) {
841  return object == NULL ? NULL : amxc_llist_get_first(&object->parameters);
842 }
843 
844 #ifdef __cplusplus
845 }
846 #endif
847 
848 #endif // __AMXD_OBJECT_H__
849 
amxd_status_t amxd_object_list(amxd_object_t *const object, amxc_var_t *const list, uint32_t flags, amxd_dm_access_t access)
amxd_object_t * amxd_object_get_base(const amxd_object_t *const object)
Definition: amxd_object.c:389
amxd_status_t amxd_object_describe(amxd_object_t *const object, amxc_var_t *const value, uint32_t flags, amxd_dm_access_t access)
amxd_status_t amxd_object_set_counter(amxd_object_t *const object, const char *name)
Definition: amxd_object.c:362
amxd_status_t amxd_object_set_max_instances(amxd_object_t *object, uint32_t max)
static amxc_llist_it_t * amxd_object_first_function(const amxd_object_t *const object)
Definition: amxd_object.h:835
static amxc_llist_it_t * amxd_object_first_parameter(const amxd_object_t *const object)
Definition: amxd_object.h:840
amxd_status_t amxd_object_validate(amxd_object_t *const object, int32_t depth)
Ambiorix Data Model API header file.
enum _amxd_status amxd_status_t
enum _amxd_object_type amxd_object_type_t
The different object types.
enum _amxd_dm_access amxd_dm_access_t
Access level.
enum _amxd_oattr_id amxd_oattr_id_t
The object attributes.
@ amxd_object_invalid
Definition: amxd_types.h:190
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.
char * amxd_object_get_mibs(amxd_object_t *object)
Get the names of all mibs attached to this object.
amxd_status_t amxd_object_add_mib(amxd_object_t *const object, const char *mib_name)
Adds a mib to an object.
amxd_status_t amxd_object_remove_mib(amxd_object_t *const object, const char *mib_name)
Removes a mib from an object.
uint32_t amxd_object_get_index(const amxd_object_t *const object)
Get the index of an instance object.
Definition: amxd_object.c:265
amxd_status_t amxd_object_set_attr(amxd_object_t *const object, const amxd_oattr_id_t attr, const bool enable)
Sets or unsets an object attribute.
Definition: amxd_object.c:269
amxd_status_t amxd_object_new_instance(amxd_object_t **object, amxd_object_t *templ, const char *name, uint32_t index, amxc_var_t *values)
Data model object constructor function.
amxd_status_t amxd_object_new(amxd_object_t **object, const amxd_object_type_t type, const char *name)
Data model object constructor function.
Definition: amxd_object.c:185
amxd_status_t amxd_object_add_instance(amxd_object_t **object, amxd_object_t *templ, const char *name, uint32_t index, amxc_var_t *values)
Data model object constructor function.
void amxd_object_delete(amxd_object_t **object)
Invokes the destroy handler(s) of the object.
static amxd_object_type_t amxd_object_get_type(const amxd_object_t *const object)
Returns the object type.
Definition: amxd_object.h:586
void amxd_object_free(amxd_object_t **object)
Data model object destructor function.
Definition: amxd_object.c:153
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_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
amxd_status_t amxd_object_set_attrs(amxd_object_t *const object, const uint32_t bitmask, bool enable)
Sets or unsets object attributes using a bitmap.
Definition: amxd_object.c:301
uint32_t amxd_object_get_attrs(const amxd_object_t *const object)
Gets the set attributes of an object.
Definition: amxd_object.c:334
amxc_llist_t functions
Definition: amxd_types.h:245
amxc_llist_t parameters
Definition: amxd_types.h:246