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; }
AwaError AwaClientSetOperation_CreateObjectInstance(AwaClientSetOperation * operation, const char * path) { AwaError result = AwaError_Unspecified; if (path != NULL) { AwaObjectID objectID; AwaResourceID resourceID; if (Path_IsValid(path)) { objectID = Path_GetObjectID(path); resourceID = Path_GetResourceID(path); if ((objectID != AWA_INVALID_ID) && (resourceID == AWA_INVALID_ID)) { if (operation != NULL) { TreeNode resultNode; if ((result = OperationCommon_AddPathV2(operation->Common, path, &resultNode)) == AwaError_Success && resultNode != NULL) { //NB: if object instance ID isn't specified in the path we have to check the response for the generated ID if (ClientSetOperation_AddCreate(resultNode) == InternalError_Success) { result = AwaError_Success; } else { result = LogErrorWithEnum(AwaError_Internal, "Failed to add value to path"); } } } else { result = LogErrorWithEnum(AwaError_OperationInvalid, "Operation is NULL"); } } else { result = LogErrorWithEnum(AwaError_PathInvalid, "%s is not a valid object or object instance path", path); } } else { result = LogErrorWithEnum(AwaError_PathInvalid, "%s is not a valid path", path); } } else { result = LogErrorWithEnum(AwaError_PathInvalid, "Path 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; }