]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/qobj.h
tests: Add test consecutive frrscript_call
[mirror_frr.git] / lib / qobj.h
index d63988cbab0b5f4b46170e8baa4128b97abafc52..5012c98d7482eb04826138678caf4db42f6d360a 100644 (file)
@@ -21,6 +21,8 @@
 #include <stdlib.h>
 #include <stddef.h>
 
+#include "typesafe.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -69,6 +71,8 @@ struct qobj_nodetype_capnp {
 };
 #endif
 
+#include "typesafe.h"
+
 /* each different kind of object will have a global variable of this type,
  * which can be used by various other pieces to store type-related bits.
  * type equality can be tested as pointer equality. (cf. QOBJ_GET_TYPESAFE)
@@ -79,13 +83,16 @@ struct qobj_nodetype {
        RESERVED_SPACE_STRUCT(qobj_nodetype_capnp, capnp, 256)
 };
 
+PREDECL_HASH(qobj_nodes);
+
 /* anchor to be embedded somewhere in the object's struct */
 struct qobj_node {
        uint64_t nid;
-       struct qobj_nodetype *type;
+       struct qobj_nodes_item nodehash;
+       const struct qobj_nodetype *type;
 };
 
-#define QOBJ_FIELDS struct qobj_node qobj_node;
+#define QOBJ_FIELDS struct qobj_node qobj_node
 
 /* call these at the end of any _create function (QOBJ_REG)
  * and beginning of any _destroy function (QOBJ_UNREG) */
@@ -104,23 +111,26 @@ struct qobj_node {
  *
  * in the long this may need another touch, e.g. built-in per-object locking.
  */
-void qobj_reg(struct qobj_node *node, struct qobj_nodetype *type);
+void qobj_reg(struct qobj_node *node, const struct qobj_nodetype *type);
 void qobj_unreg(struct qobj_node *node);
 struct qobj_node *qobj_get(uint64_t id);
-void *qobj_get_typed(uint64_t id, struct qobj_nodetype *type);
+void *qobj_get_typed(uint64_t id, const struct qobj_nodetype *type);
 
 /* type declarations */
 #define DECLARE_QOBJ_TYPE(structname)                                          \
-       extern struct qobj_nodetype qobj_t_##structname;
+       extern const struct qobj_nodetype qobj_t_##structname                  \
+       /* end */
 #define DEFINE_QOBJ_TYPE(structname)                                           \
-       struct qobj_nodetype qobj_t_##structname = {                           \
+       const struct qobj_nodetype qobj_t_##structname = {                     \
                .node_member_offset =                                          \
-                       (ptrdiff_t)offsetof(struct structname, qobj_node)};
+                       (ptrdiff_t)offsetof(struct structname, qobj_node)}     \
+       /* end */
 #define DEFINE_QOBJ_TYPE_INIT(structname, ...)                                 \
-       struct qobj_nodetype qobj_t_##structname = {                           \
+       const struct qobj_nodetype qobj_t_##structname = {                     \
                .node_member_offset =                                          \
                        (ptrdiff_t)offsetof(struct structname, qobj_node),     \
-               __VA_ARGS__};
+               __VA_ARGS__}                                                   \
+       /* end */
 
 /* ID dereference with typecheck.
  * will return NULL if id not found or wrong type. */