blob: ff4a9a400c1c118622dafeabada623131010d701 [file] [log] [blame]
kasunath2ebe82f2023-01-31 13:59:22 -08001#include "bej_tree.h"
2
3static void bejTreeInitParent(struct RedfishPropertyParent* node,
4 const char* name, enum BejPrincipalDataType type)
5{
6 node->nodeAttr.name = name;
7 node->nodeAttr.format.principalDataType = type;
8 node->nodeAttr.format.deferredBinding = 0;
9 node->nodeAttr.format.readOnlyProperty = 0;
10 node->nodeAttr.format.nullableProperty = 0;
11 node->nodeAttr.sibling = NULL;
12 node->nChildren = 0;
13 node->firstChild = NULL;
14 node->lastChild = NULL;
15}
16
17void bejTreeInitSet(struct RedfishPropertyParent* node, const char* name)
18{
19 bejTreeInitParent(node, name, bejSet);
20}
21
22void bejTreeInitArray(struct RedfishPropertyParent* node, const char* name)
23{
24 bejTreeInitParent(node, name, bejArray);
25}
26
27void bejTreeInitPropertyAnnotated(struct RedfishPropertyParent* node,
28 const char* name)
29{
30 bejTreeInitParent(node, name, bejPropertyAnnotation);
31}
32
kasunathdc3f2142023-01-31 15:09:10 -080033bool bejTreeIsParentType(struct RedfishPropertyNode* node)
34{
35 return node->format.principalDataType == bejSet ||
36 node->format.principalDataType == bejArray ||
37 node->format.principalDataType == bejPropertyAnnotation;
38}
39
kasunath2ebe82f2023-01-31 13:59:22 -080040static void bejTreeInitChildNode(struct RedfishPropertyLeaf* node,
41 const char* name,
42 enum BejPrincipalDataType type)
43{
44 node->nodeAttr.name = name;
45 node->nodeAttr.format.principalDataType = type;
46 node->nodeAttr.format.deferredBinding = 0;
47 node->nodeAttr.format.readOnlyProperty = 0;
48 node->nodeAttr.format.nullableProperty = 0;
49 node->nodeAttr.sibling = NULL;
50}
51
kasunathbde1bfa2023-08-18 00:38:36 -070052void bejTreeAddNull(struct RedfishPropertyParent* parent,
53 struct RedfishPropertyLeafNull* child, const char* name)
54{
55 bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejNull);
56 bejTreeLinkChildToParent(parent, child);
57}
58
kasunath2ebe82f2023-01-31 13:59:22 -080059void bejTreeAddInteger(struct RedfishPropertyParent* parent,
60 struct RedfishPropertyLeafInt* child, const char* name,
61 int64_t value)
62{
63 bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejInteger);
64 child->value = value;
65 bejTreeLinkChildToParent(parent, child);
66}
67
68void bejTreeSetInteger(struct RedfishPropertyLeafInt* node, int64_t newValue)
69{
70 node->value = newValue;
71}
72
73void bejTreeAddEnum(struct RedfishPropertyParent* parent,
74 struct RedfishPropertyLeafEnum* child, const char* name,
75 const char* value)
76{
77 bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejEnum);
78 child->value = value;
79 bejTreeLinkChildToParent(parent, child);
80}
81
kasunathdc3f2142023-01-31 15:09:10 -080082void bejTreeAddString(struct RedfishPropertyParent* parent,
83 struct RedfishPropertyLeafString* child, const char* name,
84 const char* value)
85{
86 bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejString);
87 child->value = value;
88 bejTreeLinkChildToParent(parent, child);
89}
90
91void bejTreeAddReal(struct RedfishPropertyParent* parent,
92 struct RedfishPropertyLeafReal* child, const char* name,
93 double value)
94{
95 bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejReal);
96 child->value = value;
97 bejTreeLinkChildToParent(parent, child);
98}
99
100void bejTreeSetReal(struct RedfishPropertyLeafReal* node, double newValue)
101{
102 node->value = newValue;
103}
104
105void bejTreeAddBool(struct RedfishPropertyParent* parent,
106 struct RedfishPropertyLeafBool* child, const char* name,
107 bool value)
108{
109 bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejBoolean);
110 child->value = value;
111 bejTreeLinkChildToParent(parent, child);
112}
113
kasunath2ebe82f2023-01-31 13:59:22 -0800114void bejTreeLinkChildToParent(struct RedfishPropertyParent* parent, void* child)
115{
116 // A new node is added at the end of the list.
117 if (parent->firstChild == NULL)
118 {
119 parent->firstChild = child;
120 }
121 else
122 {
123 struct RedfishPropertyNode* lastChild = parent->lastChild;
124 lastChild->sibling = child;
125 }
126 parent->lastChild = child;
127 parent->nChildren += 1;
128}
kasunathdc3f2142023-01-31 15:09:10 -0800129
130void bejTreeUpdateNodeFlags(struct RedfishPropertyNode* node,
131 bool deferredBinding, bool readOnlyProperty,
132 bool nullableProperty)
133{
134 node->format.deferredBinding = deferredBinding;
135 node->format.readOnlyProperty = readOnlyProperty;
136 node->format.nullableProperty = nullableProperty;
137}
kasunath99bd6c92023-07-30 18:19:00 -0700138
139void* bejParentGoToNextChild(struct RedfishPropertyParent* parent,
140 struct RedfishPropertyNode* currentChild)
141{
142 if (parent == NULL || currentChild == NULL)
143 {
144 return NULL;
145 }
146
147 parent->metaData.nextChildIndex += 1;
148 parent->metaData.nextChild = currentChild->sibling;
149 return currentChild->sibling;
150}