Пример #1
0
    def WriteSingleInstanceResourceValue(self, writeOperation, path,
                                         resourceType, value):
        result = AwaError.Unspecified

        if resourceType == AwaResourceType.Integer:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsInteger(
                writeOperation, path, int(value))
        elif resourceType == AwaResourceType.String:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsCString(
                writeOperation, path, str(value))
        elif resourceType == AwaResourceType.Float:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsFloat(
                writeOperation, path, float(value))
        elif resourceType == AwaResourceType.Boolean:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsBoolean(
                writeOperation, path, bool(value))
        elif resourceType == AwaResourceType.Opaque:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsOpaque(
                writeOperation, path, value)
        elif resourceType == AwaResourceType.ObjectLink:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsObjectLink(
                writeOperation, path, value)
        elif resourceType == AwaResourceType.Time:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsTime(
                writeOperation, path, int(value))
        else:
            raise AwaInvalidArgumentException("Invalid resource type",
                                              resourceType)

        CheckSuccess(
            result,
            "Failed to add value to Write Operation: %s" % (str(value), ))
Пример #2
0
    def WriteMultipleInstanceResourceValues(self, writeOperation, path,
                                            resourceType, values):
        result = AwaError.Unspecified
        array = self.CreateArray(resourceType, values)

        if resourceType == AwaResourceType.IntegerArray:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsIntegerArray(
                writeOperation, path, array)
        elif resourceType == AwaResourceType.StringArray:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsStringArray(
                writeOperation, path, array)
        elif resourceType == AwaResourceType.FloatArray:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsFloatArray(
                writeOperation, path, array)
        elif resourceType == AwaResourceType.BooleanArray:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsBooleanArray(
                writeOperation, path, array)
        elif resourceType == AwaResourceType.OpaqueArray:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsOpaqueArray(
                writeOperation, path, array)
        elif resourceType == AwaResourceType.ObjectLinkArray:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsObjectLinkArray(
                writeOperation, path, array)
        elif resourceType == AwaResourceType.TimeArray:
            result = self._xmlrpcSession.AwaServerWriteOperation_AddValueAsTimeArray(
                writeOperation, path, array)
        else:
            raise AwaInvalidArgumentException(
                "%s is not a valid multiple instance resource type" %
                (resourceType, ))

        CheckSuccess(
            result, "Failed to add values as array to Write Operation: %s" %
            (str(values), ))
Пример #3
0
    def SetMultipleInstanceResourceValues(self, setOperation, path,
                                          resourceType, values):
        result = AwaError.Unspecified

        for resInstanceID, value in values.iteritems():
            if resourceType == AwaResourceType.IntegerArray:
                result = self._xmlrpcSession.AwaClientSetOperation_AddArrayValueAsInteger(
                    setOperation, path, resInstanceID, int(value))
            elif resourceType == AwaResourceType.StringArray:
                result = self._xmlrpcSession.AwaClientSetOperation_AddArrayValueAsCString(
                    setOperation, path, resInstanceID, str(value))
            elif resourceType == AwaResourceType.FloatArray:
                result = self._xmlrpcSession.AwaClientSetOperation_AddArrayValueAsFloat(
                    setOperation, path, resInstanceID, float(value))
            elif resourceType == AwaResourceType.BooleanArray:
                result = self._xmlrpcSession.AwaClientSetOperation_AddArrayValueAsBoolean(
                    setOperation, path, resInstanceID, bool(value))
            elif resourceType == AwaResourceType.OpaqueArray:
                result = self._xmlrpcSession.AwaClientSetOperation_AddArrayValueAsOpaque(
                    setOperation, path, resInstanceID, value)
            elif resourceType == AwaResourceType.ObjectLinkArray:
                result = self._xmlrpcSession.AwaClientSetOperation_AddArrayValueAsObjectLink(
                    setOperation, path, resInstanceID, value)
            elif resourceType == AwaResourceType.TimeArray:
                result = self._xmlrpcSession.AwaClientSetOperation_AddArrayValueAsTime(
                    setOperation, path, resInstanceID, int(value))
            else:
                raise AwaInvalidArgumentException(
                    "Invalid resource type for key %s:" %
                    (str(resInstanceID), ), resourceType)

        CheckSuccess(
            result, "Failed to add value to Set Operation: %s:%s" %
            (str(resInstanceID), str(value)))
Пример #4
0
    def GetResourceValuesFromGetOperation(self, operation, path, resourceType):
        if not awa_enums.isArrayResourceType(resourceType):
            raise AwaInvalidArgumentException("resourceType is not an array",
                                              resourceType)

        response = self._xmlrpcSession.AwaClientGetOperation_GetResponse(
            operation)
        CheckNone(response, "Response is NULL")
        values = self.__GetResourceValuesFromGetResponse(
            response, path, resourceType)
        return values
Пример #5
0
    def GetResourceValueFromReadOperation(self, operation, clientID, path,
                                          resourceType):
        if awa_enums.isArrayResourceType(resourceType):
            raise AwaInvalidArgumentException(
                "resourceType is not single instance", resourceType)

        response = self._xmlrpcSession.AwaServerReadOperation_GetResponse(
            operation, clientID)
        CheckNone(response, "Response is NULL")
        value = self.__GetResourceValueFromReadResponse(
            response, path, resourceType)
        return value
Пример #6
0
 def CreateArray(self, resType, values):
     array = None
     if values != None:
         if resType == AwaResourceType.StringArray:
             array = self._xmlrpcSession.AwaStringArray_New()
             for index, value in values.iteritems():
                 self._xmlrpcSession.AwaStringArray_SetValueAsCString(array, index, value)
         elif resType == AwaResourceType.IntegerArray:
             array = self._xmlrpcSession.AwaStringArray_New()
             for index, value in values.iteritems():
                 self._xmlrpcSession.AwaIntegerArray_SetValue(array, index, value)
         #elif TODO rest of array types
         else:
             raise AwaInvalidArgumentException("Unsupported resource type: " + str(resType))
     return array
Пример #7
0
    def __GetResourceValuesFromReadResponse(self, response, path,
                                            resourceType):
        values = None
        if resourceType == AwaResourceType.StringArray:
            values = pickle.loads(
                self._xmlrpcSession.
                AwaServerReadResponse_GetValuesAsStringArrayPointer(
                    response, path, None))
        elif resourceType == AwaResourceType.IntegerArray:
            values = pickle.loads(
                self._xmlrpcSession.
                AwaServerReadResponse_GetValuesAsIntegerArrayPointer(
                    response, path, None))
        elif resourceType == AwaResourceType.FloatArray:
            values = pickle.loads(
                self._xmlrpcSession.
                AwaServerReadResponse_GetValuesAsFloatArrayPointer(
                    response, path, None))
        elif resourceType == AwaResourceType.BooleanArray:
            values = pickle.loads(
                self._xmlrpcSession.
                AwaServerReadResponse_GetValuesAsBooleanArrayPointer(
                    response, path, None))
        elif resourceType == AwaResourceType.OpaqueArray:
            values = pickle.loads(
                self._xmlrpcSession.
                AwaServerReadResponse_GetValuesAsOpaqueArrayPointer(
                    response, path, None))
        elif resourceType == AwaResourceType.TimeArray:
            values = pickle.loads(
                self._xmlrpcSession.
                AwaServerReadResponse_GetValuesAsTimeArrayPointer(
                    response, path, None))
        elif resourceType == AwaResourceType.ObjectLinkArray:
            values = pickle.loads(
                self._xmlrpcSession.
                AwaServerReadResponse_GetValuesAsObjectLinkArrayPointer(
                    response, path, None))
        else:
            raise AwaInvalidArgumentException("Invalid resource type",
                                              resourceType)

        #CheckSuccess(error, "Failed to retrieve values on path %s" % (path, ))

        return values
Пример #8
0
 def FreeArray(self, resType, array):
     result = None
     if resType == AwaResourceType.StringArray:
         result = self._xmlrpcSession.AwaStringArray_Free(array)
     if resType == AwaResourceType.IntegerArray:
         result = self._xmlrpcSession.AwaIntegerArray_Free(array)
     if resType == AwaResourceType.FloatArray:
         result = self._xmlrpcSession.AwaFloatArray_Free(array)
     if resType == AwaResourceType.TimeArray:
         result = self._xmlrpcSession.AwaTimeArray_Free(array)
     if resType == AwaResourceType.OpaqueArray:
         result = self._xmlrpcSession.AwaOpaqueArray_Free(array)
     if resType == AwaResourceType.ObjectLinkArray:
         result = self._xmlrpcSession.AwaObjectLinkArray_Free(array)
     #elif TODO rest of array types
     else:
         raise AwaInvalidArgumentException("Unsupported resource type: " + str(resType))
     return result
Пример #9
0
    def DefineMultipleInstanceResource(self, objectDefinition, resourceID, resourceName, resourceType, resMinInstance, resMaxInstance, operations, defaultValues):
        defaultArray = self.CreateArray(resourceType, defaultValues)

        if resourceType == AwaResourceType.StringArray:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsStringArray(objectDefinition, resourceID, resourceName, resMinInstance, resMaxInstance, operations, defaultArray)
        elif resourceType == AwaResourceType.IntegerArray:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsIntegerArray(objectDefinition, resourceID, resourceName, resMinInstance, resMaxInstance, operations, defaultArray)
        elif resourceType == AwaResourceType.FloatArray:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsFloatArray(objectDefinition, resourceID, resourceName, resMinInstance, resMaxInstance, operations, defaultArray)
        elif resourceType == AwaResourceType.BooleanArray:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsBooleanArray(objectDefinition, resourceID, resourceName, resMinInstance, resMaxInstance, operations, defaultArray)
        elif resourceType == AwaResourceType.TimeArray:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsTimeArray(objectDefinition, resourceID, resourceName, resMinInstance, resMaxInstance, operations, defaultArray)
        elif resourceType == AwaResourceType.OpaqueArray:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsOpaqueArray(objectDefinition, resourceID, resourceName, resMinInstance, resMaxInstance, operations, defaultArray)
        elif resourceType == AwaResourceType.ObjectLinkArray:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsObjectLinkArray(objectDefinition, resourceID, resourceName, resMinInstance, resMaxInstance, operations, defaultArray)
        else:
            raise AwaInvalidArgumentException("Invalid resource type for single instance resource %s:" % (str(AwaResourceType(resourceType), )))

        CheckSuccess(result, "Could not add resource definition to object definition")
Пример #10
0
    def DefineSingleInstanceResource(self, objectDefinition, resourceID, resourceName, resourceType, isMandatory, operations, defaultValue):

        if resourceType == AwaResourceType.String:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsString(objectDefinition, resourceID, resourceName, isMandatory, operations, defaultValue)
        elif resourceType == AwaResourceType.Integer:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsInteger(objectDefinition, resourceID, resourceName, isMandatory, operations, defaultValue)
        elif resourceType == AwaResourceType.Float:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsFloat(objectDefinition, resourceID, resourceName, isMandatory, operations, defaultValue)
        elif resourceType == AwaResourceType.Boolean:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsBoolean(objectDefinition, resourceID, resourceName, isMandatory, operations, defaultValue)
        elif resourceType == AwaResourceType.Time:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsTime(objectDefinition, resourceID, resourceName, isMandatory, operations, defaultValue)
        elif resourceType == AwaResourceType.Opaque:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsOpaque(objectDefinition, resourceID, resourceName, isMandatory, operations, defaultValue)
        elif resourceType == AwaResourceType.ObjectLink:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsObjectLink(objectDefinition, resourceID, resourceName, isMandatory, operations, defaultValue)
        elif resourceType == AwaResourceType.NoneType:
            result = self._xmlrpcSession.AwaObjectDefinition_AddResourceDefinitionAsNoType(objectDefinition, resourceID, resourceName, isMandatory, operations)
        else:
            raise AwaInvalidArgumentException("Invalid resource type for single instance resource %s:" % (str(AwaResourceType(resourceType), )))

        CheckSuccess(result, "Could not add resource definition to object definition")
Пример #11
0
    def __GetResourceValueFromReadResponse(self, response, path, resourceType):
        value = None
        if resourceType == AwaResourceType.Integer:
            value, error = self._xmlrpcSession.AwaServerReadResponse_GetValueAsIntegerPointer(
                response, path, None)
            if value != None:
                value = pickle.loads(value)  # deserialise long integer
        elif resourceType == AwaResourceType.String:
            value, error = self._xmlrpcSession.AwaServerReadResponse_GetValueAsCStringPointer(
                response, path, None)
        elif resourceType == AwaResourceType.Float:
            value, error = self._xmlrpcSession.AwaServerReadResponse_GetValueAsFloatPointer(
                response, path, None)
        elif resourceType == AwaResourceType.Boolean:
            value, error = self._xmlrpcSession.AwaServerReadResponse_GetValueAsBooleanPointer(
                response, path, None)
        elif resourceType == AwaResourceType.Opaque:
            value, error = self._xmlrpcSession.AwaServerReadResponse_GetValueAsOpaque(
                response, path, None)
            if value != None:
                value = binascii.a2b_base64(value)  # deserialise opaque base64
        elif resourceType == AwaResourceType.ObjectLink:
            value, error = self._xmlrpcSession.AwaServerReadResponse_GetValueAsObjectLink(
                response, path, None)
        elif resourceType == AwaResourceType.Time:
            value, error = self._xmlrpcSession.AwaServerReadResponse_GetValueAsTimePointer(
                response, path, None)
            if value != None:
                value = pickle.loads(value)  # deserialise long integer
        else:
            raise AwaInvalidArgumentException("Invalid resource type",
                                              resourceType)

        CheckSuccess(error, "Failed to retrieve value on path %s" % (path, ))

        return value