static void AddTarget(AwaClientGetOperation * operation, const Target * target) { if (operation != NULL) { if (target != NULL) { if (IsIDValid(target->ResourceInstanceID)) { Verbose("Get %s/%d\n", target->Path, target->ResourceInstanceID); // Use a combination of single-item ranges - may not be the most efficient way in some cases if (AwaClientGetOperation_AddPathWithArrayRange(operation, target->Path, target->ResourceInstanceID, 1) != AwaError_Success) { Error("AwaClientGetOperation_AddPath failed\n"); } } else { Verbose("Get %s\n", target->Path); if (AwaClientGetOperation_AddPath(operation, target->Path) != AwaError_Success) { Error("AwaClientGetOperation_AddPath failed\n"); } } } else { Error("target is NULL\n"); } } else { Error("operation is NULL\n"); } }
static AwaOpaque MakeOpaqueValue(const char * value, int length) { return (AwaOpaque) { .Data = (void *)value, length }; } static int AddTargetWithValue(const AwaServerSession * session, AwaServerWriteOperation * operation, const Target * target, const char * value) { int result = 0; if (operation != NULL) { if (target != NULL) { if (value != NULL) { if (Server_IsResourceDefined(session, target->Path)) { AwaResourceType resourceType = Server_GetResourceType(session, target->Path); if (resourceType != AwaResourceType_Invalid ) { if (IsIDValid(target->ResourceInstanceID)) { Verbose("Set %s %s/%d <- %s\n", ResourceTypeToString(resourceType), target->Path, target->ResourceInstanceID, value); if (!IsArrayType(resourceType)) { Error("Error: resource %s is not an array; do not specify a resource instance ID\n", target->Path); result = -1; } } else { Verbose("Set %s %s <- %s\n", ResourceTypeToString(resourceType), target->Path, value); if (IsArrayType(resourceType)) { Error("Error: resource is an array; specify a resource instance ID: %s/x\n", target->Path); result = -1; } } if (result == 0) { switch (resourceType) { case AwaResourceType_None: { Error("Resource %s is of type None and cannot be set\n", target->Path); result = -1; break; } case AwaResourceType_String: { if (AwaServerWriteOperation_AddValueAsCString(operation, target->Path, value) != AwaError_Success) { Error("AwaServerWriteOperation_AddValueAsCString failed\n"); result = -1; } break; } case AwaResourceType_Integer: { AwaInteger tmp = strtoimax(value, NULL, 10); if (AwaServerWriteOperation_AddValueAsInteger(operation, target->Path, tmp) != AwaError_Success) { Error("AwaServerWriteOperation_AddValueAsInteger failed\n"); result = -1; } break; } case AwaResourceType_Float: { AwaFloat tmp = 0.0; sscanf(value, "%20lf", &tmp); if (AwaServerWriteOperation_AddValueAsFloat(operation, target->Path, tmp) != AwaError_Success) { Error("AwaServerWriteOperation_AddValueAsFloat failed\n"); result = -1; } break; } case AwaResourceType_Boolean: { AwaBoolean boolValue = GetBooleanValue(value); if (AwaServerWriteOperation_AddValueAsBoolean(operation, target->Path, boolValue) != AwaError_Success) { Error("AwaServerWriteOperation_AddValueAsBoolean failed\n"); result = -1; } break; } case AwaResourceType_Opaque: { AwaOpaque opaqueValue = MakeOpaqueValue(value, strlen(value)); if (AwaServerWriteOperation_AddValueAsOpaque(operation, target->Path, opaqueValue) != AwaError_Success) { Error("AwaServerWriteOperation_AddValueAsOpaque failed\n"); result = -1; } break; } case AwaResourceType_Time: { AwaTime tmp = strtoimax(value, NULL, 10); if (AwaServerWriteOperation_AddValueAsTime(operation, target->Path, tmp) != AwaError_Success) { Error("AwaServerWriteOperation_AddValueAsTime failed\n"); result = -1; } break; } case AwaResourceType_ObjectLink: { AwaObjectLink objectLink; if (!SetObjectLinkFromInput(&objectLink, value)) { Error("AwaServerWriteOperation_AddValueAsObjectLink failed\n"); result = -1; break; } if (AwaServerWriteOperation_AddValueAsObjectLink(operation, target->Path, objectLink) != AwaError_Success) { Error("AwaServerWriteOperation_AddValueAsObjectLink failed\n"); result = -1; } break; } case AwaResourceType_IntegerArray: { AwaInteger tmp = strtoimax(value, NULL, 10); if (AwaServerWriteOperation_AddArrayValueAsInteger(operation, target->Path, target->ResourceInstanceID, tmp) != AwaError_Success) { Error("AwaServerWriteOperation_AddArrayValueAsInteger failed\n"); result = -1; } break; } case AwaResourceType_StringArray: { if (AwaServerWriteOperation_AddArrayValueAsCString(operation, target->Path, target->ResourceInstanceID, value) != AwaError_Success) { Error("AwaServerWriteOperation_AddArrayValueAsCString failed\n"); result = -1; } break; } case AwaResourceType_FloatArray: { AwaFloat tmp = 0.0; sscanf(value, "%20lf", &tmp); if (AwaServerWriteOperation_AddArrayValueAsFloat(operation, target->Path, target->ResourceInstanceID, tmp) != AwaError_Success) { Error("AwaServerWriteOperation_AddArrayValueAsFloat failed\n"); result = -1; } break; } case AwaResourceType_BooleanArray: { AwaBoolean boolValue = GetBooleanValue(value); if (AwaServerWriteOperation_AddArrayValueAsBoolean(operation, target->Path, target->ResourceInstanceID, boolValue) != AwaError_Success) { Error("AwaServerWriteOperation_AddArrayValueAsBoolean failed\n"); result = -1; } break; } case AwaResourceType_OpaqueArray: { AwaOpaque opaqueValue = MakeOpaqueValue(value, strlen(value)); if (AwaServerWriteOperation_AddArrayValueAsOpaque(operation, target->Path, target->ResourceInstanceID, opaqueValue) != AwaError_Success) { Error("AwaServerWriteOperation_AddArrayValueAsOpaque failed\n"); result = -1; } break; } case AwaResourceType_TimeArray: { AwaTime tmp = strtoimax(value, NULL, 10); if (AwaServerWriteOperation_AddArrayValueAsTime(operation, target->Path, target->ResourceInstanceID, tmp) != AwaError_Success) { Error("AwaServerWriteOperation_AddArrayValueAsTime failed\n"); result = -1; } break; } case AwaResourceType_ObjectLinkArray: { AwaObjectLink objectLink; if (!SetObjectLinkFromInput(&objectLink, value)) { Error("AwaServerWriteOperation_AddArrayValueAsObjectLink failed\n"); result = -1; break; } if (AwaServerWriteOperation_AddArrayValueAsObjectLink(operation, target->Path, target->ResourceInstanceID, objectLink) != AwaError_Success) { Error("AwaServerWriteOperation_AddArrayValueAsObjectLink failed\n"); result = -1; } break; } default: Error("Unhandled type\n"); result = -1; } } } } else { Error("%s is not defined\n", target->Path); result = -1; } } else { Error("value is NULL\n"); result = -1; } } else { Error("target is NULL\n"); result = -1; } } else { Error("operation is NULL\n"); result = -1; } return result; }