12ebe82f5Skasunath #include "bej_tree.h"
22ebe82f5Skasunath
bejTreeInitParent(struct RedfishPropertyParent * node,const char * name,enum BejPrincipalDataType type)32ebe82f5Skasunath static void bejTreeInitParent(struct RedfishPropertyParent* node,
42ebe82f5Skasunath const char* name, enum BejPrincipalDataType type)
52ebe82f5Skasunath {
62ebe82f5Skasunath node->nodeAttr.name = name;
72ebe82f5Skasunath node->nodeAttr.format.principalDataType = type;
82ebe82f5Skasunath node->nodeAttr.format.deferredBinding = 0;
92ebe82f5Skasunath node->nodeAttr.format.readOnlyProperty = 0;
102ebe82f5Skasunath node->nodeAttr.format.nullableProperty = 0;
11*a46f9850SBrian Ma node->nodeAttr.format.reserved = 0;
122ebe82f5Skasunath node->nodeAttr.sibling = NULL;
132ebe82f5Skasunath node->nChildren = 0;
142ebe82f5Skasunath node->firstChild = NULL;
152ebe82f5Skasunath node->lastChild = NULL;
162ebe82f5Skasunath }
172ebe82f5Skasunath
bejTreeInitSet(struct RedfishPropertyParent * node,const char * name)182ebe82f5Skasunath void bejTreeInitSet(struct RedfishPropertyParent* node, const char* name)
192ebe82f5Skasunath {
202ebe82f5Skasunath bejTreeInitParent(node, name, bejSet);
212ebe82f5Skasunath }
222ebe82f5Skasunath
bejTreeInitArray(struct RedfishPropertyParent * node,const char * name)232ebe82f5Skasunath void bejTreeInitArray(struct RedfishPropertyParent* node, const char* name)
242ebe82f5Skasunath {
252ebe82f5Skasunath bejTreeInitParent(node, name, bejArray);
262ebe82f5Skasunath }
272ebe82f5Skasunath
bejTreeInitPropertyAnnotated(struct RedfishPropertyParent * node,const char * name)282ebe82f5Skasunath void bejTreeInitPropertyAnnotated(struct RedfishPropertyParent* node,
292ebe82f5Skasunath const char* name)
302ebe82f5Skasunath {
312ebe82f5Skasunath bejTreeInitParent(node, name, bejPropertyAnnotation);
322ebe82f5Skasunath }
332ebe82f5Skasunath
bejTreeIsParentType(struct RedfishPropertyNode * node)34dc3f214bSkasunath bool bejTreeIsParentType(struct RedfishPropertyNode* node)
35dc3f214bSkasunath {
36dc3f214bSkasunath return node->format.principalDataType == bejSet ||
37dc3f214bSkasunath node->format.principalDataType == bejArray ||
38dc3f214bSkasunath node->format.principalDataType == bejPropertyAnnotation;
39dc3f214bSkasunath }
40dc3f214bSkasunath
bejTreeInitChildNode(struct RedfishPropertyLeaf * node,const char * name,enum BejPrincipalDataType type)412ebe82f5Skasunath static void bejTreeInitChildNode(struct RedfishPropertyLeaf* node,
422ebe82f5Skasunath const char* name,
432ebe82f5Skasunath enum BejPrincipalDataType type)
442ebe82f5Skasunath {
452ebe82f5Skasunath node->nodeAttr.name = name;
462ebe82f5Skasunath node->nodeAttr.format.principalDataType = type;
472ebe82f5Skasunath node->nodeAttr.format.deferredBinding = 0;
482ebe82f5Skasunath node->nodeAttr.format.readOnlyProperty = 0;
492ebe82f5Skasunath node->nodeAttr.format.nullableProperty = 0;
50*a46f9850SBrian Ma node->nodeAttr.format.reserved = 0;
512ebe82f5Skasunath node->nodeAttr.sibling = NULL;
522ebe82f5Skasunath }
532ebe82f5Skasunath
bejTreeAddNull(struct RedfishPropertyParent * parent,struct RedfishPropertyLeafNull * child,const char * name)54bde1bfa1Skasunath void bejTreeAddNull(struct RedfishPropertyParent* parent,
55bde1bfa1Skasunath struct RedfishPropertyLeafNull* child, const char* name)
56bde1bfa1Skasunath {
57bde1bfa1Skasunath bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejNull);
58bde1bfa1Skasunath bejTreeLinkChildToParent(parent, child);
59bde1bfa1Skasunath }
60bde1bfa1Skasunath
bejTreeAddInteger(struct RedfishPropertyParent * parent,struct RedfishPropertyLeafInt * child,const char * name,int64_t value)612ebe82f5Skasunath void bejTreeAddInteger(struct RedfishPropertyParent* parent,
622ebe82f5Skasunath struct RedfishPropertyLeafInt* child, const char* name,
632ebe82f5Skasunath int64_t value)
642ebe82f5Skasunath {
652ebe82f5Skasunath bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejInteger);
662ebe82f5Skasunath child->value = value;
672ebe82f5Skasunath bejTreeLinkChildToParent(parent, child);
682ebe82f5Skasunath }
692ebe82f5Skasunath
bejTreeSetInteger(struct RedfishPropertyLeafInt * node,int64_t newValue)702ebe82f5Skasunath void bejTreeSetInteger(struct RedfishPropertyLeafInt* node, int64_t newValue)
712ebe82f5Skasunath {
722ebe82f5Skasunath node->value = newValue;
732ebe82f5Skasunath }
742ebe82f5Skasunath
bejTreeAddEnum(struct RedfishPropertyParent * parent,struct RedfishPropertyLeafEnum * child,const char * name,const char * value)752ebe82f5Skasunath void bejTreeAddEnum(struct RedfishPropertyParent* parent,
762ebe82f5Skasunath struct RedfishPropertyLeafEnum* child, const char* name,
772ebe82f5Skasunath const char* value)
782ebe82f5Skasunath {
792ebe82f5Skasunath bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejEnum);
802ebe82f5Skasunath child->value = value;
812ebe82f5Skasunath bejTreeLinkChildToParent(parent, child);
822ebe82f5Skasunath }
832ebe82f5Skasunath
bejTreeAddString(struct RedfishPropertyParent * parent,struct RedfishPropertyLeafString * child,const char * name,const char * value)84dc3f214bSkasunath void bejTreeAddString(struct RedfishPropertyParent* parent,
85dc3f214bSkasunath struct RedfishPropertyLeafString* child, const char* name,
86dc3f214bSkasunath const char* value)
87dc3f214bSkasunath {
88dc3f214bSkasunath bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejString);
89dc3f214bSkasunath child->value = value;
90dc3f214bSkasunath bejTreeLinkChildToParent(parent, child);
91dc3f214bSkasunath }
92dc3f214bSkasunath
bejTreeAddReal(struct RedfishPropertyParent * parent,struct RedfishPropertyLeafReal * child,const char * name,double value)93dc3f214bSkasunath void bejTreeAddReal(struct RedfishPropertyParent* parent,
94dc3f214bSkasunath struct RedfishPropertyLeafReal* child, const char* name,
95dc3f214bSkasunath double value)
96dc3f214bSkasunath {
97dc3f214bSkasunath bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejReal);
98dc3f214bSkasunath child->value = value;
99dc3f214bSkasunath bejTreeLinkChildToParent(parent, child);
100dc3f214bSkasunath }
101dc3f214bSkasunath
bejTreeSetReal(struct RedfishPropertyLeafReal * node,double newValue)102dc3f214bSkasunath void bejTreeSetReal(struct RedfishPropertyLeafReal* node, double newValue)
103dc3f214bSkasunath {
104dc3f214bSkasunath node->value = newValue;
105dc3f214bSkasunath }
106dc3f214bSkasunath
bejTreeAddBool(struct RedfishPropertyParent * parent,struct RedfishPropertyLeafBool * child,const char * name,bool value)107dc3f214bSkasunath void bejTreeAddBool(struct RedfishPropertyParent* parent,
108dc3f214bSkasunath struct RedfishPropertyLeafBool* child, const char* name,
109dc3f214bSkasunath bool value)
110dc3f214bSkasunath {
111dc3f214bSkasunath bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejBoolean);
112dc3f214bSkasunath child->value = value;
113dc3f214bSkasunath bejTreeLinkChildToParent(parent, child);
114dc3f214bSkasunath }
115dc3f214bSkasunath
bejTreeLinkChildToParent(struct RedfishPropertyParent * parent,void * child)1162ebe82f5Skasunath void bejTreeLinkChildToParent(struct RedfishPropertyParent* parent, void* child)
1172ebe82f5Skasunath {
1182ebe82f5Skasunath // A new node is added at the end of the list.
1192ebe82f5Skasunath if (parent->firstChild == NULL)
1202ebe82f5Skasunath {
1212ebe82f5Skasunath parent->firstChild = child;
1222ebe82f5Skasunath }
1232ebe82f5Skasunath else
1242ebe82f5Skasunath {
1252ebe82f5Skasunath struct RedfishPropertyNode* lastChild = parent->lastChild;
1262ebe82f5Skasunath lastChild->sibling = child;
1272ebe82f5Skasunath }
1282ebe82f5Skasunath parent->lastChild = child;
1292ebe82f5Skasunath parent->nChildren += 1;
1302ebe82f5Skasunath }
131dc3f214bSkasunath
bejTreeUpdateNodeFlags(struct RedfishPropertyNode * node,bool deferredBinding,bool readOnlyProperty,bool nullableProperty)132dc3f214bSkasunath void bejTreeUpdateNodeFlags(struct RedfishPropertyNode* node,
133dc3f214bSkasunath bool deferredBinding, bool readOnlyProperty,
134dc3f214bSkasunath bool nullableProperty)
135dc3f214bSkasunath {
136dc3f214bSkasunath node->format.deferredBinding = deferredBinding;
137dc3f214bSkasunath node->format.readOnlyProperty = readOnlyProperty;
138dc3f214bSkasunath node->format.nullableProperty = nullableProperty;
139dc3f214bSkasunath }
14099bd6c90Skasunath
bejParentGoToNextChild(struct RedfishPropertyParent * parent,struct RedfishPropertyNode * currentChild)14199bd6c90Skasunath void* bejParentGoToNextChild(struct RedfishPropertyParent* parent,
14299bd6c90Skasunath struct RedfishPropertyNode* currentChild)
14399bd6c90Skasunath {
14499bd6c90Skasunath if (parent == NULL || currentChild == NULL)
14599bd6c90Skasunath {
14699bd6c90Skasunath return NULL;
14799bd6c90Skasunath }
14899bd6c90Skasunath
14999bd6c90Skasunath parent->metaData.nextChildIndex += 1;
15099bd6c90Skasunath parent->metaData.nextChild = currentChild->sibling;
15199bd6c90Skasunath return currentChild->sibling;
15299bd6c90Skasunath }
153