AwaError OperationCommon_AddPathToObjectsTree(TreeNode objectsTree, const char * path, TreeNode * resultNode) { AwaError result = AwaError_Unspecified; if (objectsTree != NULL) { if (path != NULL) { if (Path_IsValid(path)) { // Drop paths that are already represented // E.g. /3/0/0 should be dropped if /3/0 is already present if (ObjectsTree_IsPathCovered(objectsTree, path, resultNode) == false) { // if a new path that covers existing paths is added, remove any existing path nodes TreeNode existing = NULL; if (ObjectsTree_FindPathNode(objectsTree, path, &existing) == InternalError_Success) { if (resultNode != NULL) { *resultNode = existing; } ObjectsTree_RemovePathNodes(existing); LogDebug("Removing nodes below %s", path); result = AwaError_Success; } else { if (ObjectsTree_AddPath(objectsTree, path, resultNode) == InternalError_Success) { result = AwaError_Success; } else { result = LogErrorWithEnum(AwaError_Internal, "AddPath failed"); } } } else { LogDebug("Dropping path %s", path); result = AwaError_Success; } } else { result = LogErrorWithEnum(AwaError_PathInvalid, "Path %s is not valid", path); } } else { result = LogErrorWithEnum(AwaError_PathInvalid, "Path is NULL"); } } else { result = LogErrorWithEnum(AwaError_OperationInvalid, "Objects Tree is NULL"); } return result; }
/** * @brief Adds a path of interest to a Set operation, as a request to create an optional Resource. * If the path refers to an optional resource that does not exist, the operation will result in the creation of the resource. * The resource will have the default value assigned, if not overridden in the same operation. * @param[in] operation The current Set operation to add the create request to. * @param[in] path The path of the resource requested for creation. * @return Error_Success on success, error code on failure. */ AwaError AwaClientSetOperation_CreateOptionalResource(AwaClientSetOperation * operation, const char * path) { AwaError result = AwaError_Unspecified; if (operation != NULL) { TreeNode objectsTree = OperationCommon_GetObjectsTree(operation->Common); if (objectsTree != NULL) { if (path != NULL) { if (Path_IsValidForResource(path)) { TreeNode resultNode; if (ObjectsTree_AddPath(objectsTree, path, &resultNode) == InternalError_Success && resultNode != NULL) { if (ClientSetOperation_AddCreate(resultNode) == InternalError_Success) { result = AwaError_Success; } else { result = LogErrorWithEnum(AwaError_Internal, "Failed to add value to path"); } } else { result = LogErrorWithEnum(AwaError_Internal, "AddPath failed"); } } else { result = LogErrorWithEnum(AwaError_PathInvalid, "%s is not a resource path", path); } } else { result = LogErrorWithEnum(AwaError_PathInvalid, "Path is NULL"); } } else { result = LogErrorWithEnum(AwaError_Internal, "ObjectsTree is NULL"); } } else { result = LogErrorWithEnum(AwaError_OperationInvalid, "Operation is NULL"); } return result; }
AwaError OperationCommon_AddPathWithArrayRange(OperationCommon * operation, const char * path, AwaArrayIndex startIndex, AwaArrayLength indexCount) { AwaError result = AwaError_Unspecified; if (operation != NULL) { if (path != NULL) { if (Path_IsValid(path)) { if (Path_IsValidForResource(path)) { // catch zero count and index overflow if (startIndex + indexCount > startIndex) { // build up the required tree (may already exist) if (ObjectsTree_AddPath(operation->ObjectsTree, path, NULL) == InternalError_Success) { // find the corresponding Property/Resource node TreeNode resourceNode = NULL; if (ObjectsTree_FindPathNode(operation->ObjectsTree, path, &resourceNode) == InternalError_Success) { if (resourceNode != NULL) { if (AddIDRange(resourceNode, startIndex, startIndex + indexCount) != NULL) { result = AwaError_Success; } else { result = LogErrorWithEnum(AwaError_Internal, "failed to add IDRange"); } } else { result = LogErrorWithEnum(AwaError_Internal, "propertyNode is NULL"); } } else { result = LogErrorWithEnum(AwaError_Internal, "propertyNode not found"); } } else { result = LogErrorWithEnum(AwaError_Internal, "unable to build tree"); } } else { if (indexCount == 0) { result = LogErrorWithEnum(AwaError_AddInvalid, "Index count is not greater than zero"); } else { result = LogErrorWithEnum(AwaError_AddInvalid, "Range overflow"); } } } else { result = LogErrorWithEnum(AwaError_PathInvalid, "Path %s is not supported for this operation", path); } } else { result = LogErrorWithEnum(AwaError_PathInvalid, "Path %s is not valid", path); } } else { result = LogErrorWithEnum(AwaError_PathInvalid, "Path is NULL"); } } else { result = LogErrorWithEnum(AwaError_OperationInvalid, "Operation is NULL"); } return result; }