1 #include "bej_tree.h" 2 3 static 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 17 void bejTreeInitSet(struct RedfishPropertyParent* node, const char* name) 18 { 19 bejTreeInitParent(node, name, bejSet); 20 } 21 22 void bejTreeInitArray(struct RedfishPropertyParent* node, const char* name) 23 { 24 bejTreeInitParent(node, name, bejArray); 25 } 26 27 void bejTreeInitPropertyAnnotated(struct RedfishPropertyParent* node, 28 const char* name) 29 { 30 bejTreeInitParent(node, name, bejPropertyAnnotation); 31 } 32 33 static void bejTreeInitChildNode(struct RedfishPropertyLeaf* node, 34 const char* name, 35 enum BejPrincipalDataType type) 36 { 37 node->nodeAttr.name = name; 38 node->nodeAttr.format.principalDataType = type; 39 node->nodeAttr.format.deferredBinding = 0; 40 node->nodeAttr.format.readOnlyProperty = 0; 41 node->nodeAttr.format.nullableProperty = 0; 42 node->nodeAttr.sibling = NULL; 43 } 44 45 void bejTreeAddInteger(struct RedfishPropertyParent* parent, 46 struct RedfishPropertyLeafInt* child, const char* name, 47 int64_t value) 48 { 49 bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejInteger); 50 child->value = value; 51 bejTreeLinkChildToParent(parent, child); 52 } 53 54 void bejTreeSetInteger(struct RedfishPropertyLeafInt* node, int64_t newValue) 55 { 56 node->value = newValue; 57 } 58 59 void bejTreeAddEnum(struct RedfishPropertyParent* parent, 60 struct RedfishPropertyLeafEnum* child, const char* name, 61 const char* value) 62 { 63 bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejEnum); 64 child->value = value; 65 bejTreeLinkChildToParent(parent, child); 66 } 67 68 void bejTreeLinkChildToParent(struct RedfishPropertyParent* parent, void* child) 69 { 70 // A new node is added at the end of the list. 71 if (parent->firstChild == NULL) 72 { 73 parent->firstChild = child; 74 } 75 else 76 { 77 struct RedfishPropertyNode* lastChild = parent->lastChild; 78 lastChild->sibling = child; 79 } 80 parent->lastChild = child; 81 parent->nChildren += 1; 82 } 83