Exemple #1
0
    def CreateReadOperation(self, session, clientID, path):
        CheckNone(session, "Session is NULL")

        readOperation = self._xmlrpcSession.AwaServerReadOperation_New(session)
        CheckNone(readOperation, "Read Operation is NULL")
        CheckSuccess(
            self._xmlrpcSession.AwaServerReadOperation_AddPath(
                readOperation, clientID, path),
            "Failed to add path to Read Operation: %s (clientID = %s)" %
            (path, clientID))

        result = self._xmlrpcSession.AwaServerReadOperation_Perform(
            readOperation, test_defaults.TIMEOUT)
        response = self._xmlrpcSession.AwaServerReadOperation_GetResponse(
            readOperation, clientID)
        pathResult = None
        pathResultError = AwaError.Unspecified
        pathResultLWM2MError = AwaLWM2MError.Unspecified

        if response != None:
            pathResult = self.GetPathResultFromReadOperation(
                readOperation, clientID, path)
            pathResultError = self.GetPathResultError(pathResult)
            pathResultLWM2MError = self.GetPathResultLWM2MError(pathResult)

        CheckSuccess(result, "Failed to perform Read Operation",
                     pathResultError, pathResultLWM2MError)

        return readOperation
Exemple #2
0
    def CreateGetOperation(self, session, path):
        CheckNone(session, "Session is NULL")

        getOperation = self._xmlrpcSession.AwaClientGetOperation_New(session)
        CheckNone(getOperation, "Get Operation is NULL")
        CheckSuccess(
            self._xmlrpcSession.AwaClientGetOperation_AddPath(
                getOperation, path),
            "Failed to add path to Get Operation: %s" % (path, ))

        result = self._xmlrpcSession.AwaClientGetOperation_Perform(
            getOperation, test_defaults.TIMEOUT)
        response = self._xmlrpcSession.AwaClientGetOperation_GetResponse(
            getOperation)
        pathResult = None
        pathResultError = AwaError.Unspecified

        if response != None:
            pathResult = self._xmlrpcSession.AwaClientGetResponse_GetPathResult(
                response, path)
            pathResultError = self.GetPathResultError(pathResult)

        CheckSuccess(result, "Failed to perform Get Operation",
                     pathResultError)

        return getOperation
Exemple #3
0
    def DeleteEntity(self, session, clientID, path):
        CheckNone(session, "Session is NULL")

        deleteOperation = self._xmlrpcSession.AwaServerDeleteOperation_New(
            session)
        CheckNone(deleteOperation, "Delete Operation is NULL")

        result = self._xmlrpcSession.AwaServerDeleteOperation_AddPath(
            deleteOperation, clientID, path)
        CheckSuccess(result,
                     "Failed to add path to Delete operation: %s" % (path, ))

        result = self._xmlrpcSession.AwaServerDeleteOperation_Perform(
            deleteOperation, test_defaults.TIMEOUT)
        response = self._xmlrpcSession.AwaServerDeleteOperation_GetResponse(
            deleteOperation, clientID)
        pathResult = None
        pathResultError = AwaError.Unspecified
        pathResultLWM2MError = AwaLWM2MError.Unspecified

        if response != None:
            pathResult = self._xmlrpcSession.AwaServerDeleteResponse_GetPathResult(
                response, path)
            pathResultError = self.GetPathResultError(pathResult)
            pathResultLWM2MError = self.GetPathResultLWM2MError(pathResult)

        CheckSuccess(result, "Failed to perform Delete Operation",
                     pathResultError, pathResultLWM2MError)
        CheckSuccess(
            self._xmlrpcSession.AwaServerDeleteOperation_Free(deleteOperation),
            "Failed to free Delete Operation")
Exemple #4
0
    def DeleteEntity(self, session, path):
        CheckNone(session, "Session is NULL")

        deleteOperation = self._xmlrpcSession.AwaClientDeleteOperation_New(
            session)
        CheckNone(deleteOperation, "Delete Operation is NULL")

        result = self._xmlrpcSession.AwaClientDeleteOperation_AddPath(
            deleteOperation, path)
        CheckSuccess(result,
                     "Failed to add path to Delete operation: %s" % (path, ))

        self._PerformDeleteOperation(deleteOperation, path)
Exemple #5
0
    def DefineWithSession(self, session, objectDefinitionSettings,
                          resourceDefinitionSettingsCollection):
        defineOperation = self._xmlrpcSession.AwaServerDefineOperation_New(
            session)
        CheckNone(defineOperation, "Define Operation is NULL")

        objectDefinition = self._xmlrpcSession.AwaObjectDefinition_New(
            objectDefinitionSettings.objectID,
            objectDefinitionSettings.objectName,
            objectDefinitionSettings.minimumInstances,
            objectDefinitionSettings.maximumInstances)
        CheckNone(
            objectDefinition,
            "Could not create object definition for objectID %d" %
            (objectDefinitionSettings.objectID, ))

        for resourceDefinitionSettings in resourceDefinitionSettingsCollection:
            if awa_enums.isArrayResourceType(
                    resourceDefinitionSettings.resourceType):
                self.DefineMultipleInstanceResource(
                    objectDefinition, resourceDefinitionSettings.resourceID,
                    resourceDefinitionSettings.resourceName,
                    resourceDefinitionSettings.resourceType,
                    resourceDefinitionSettings.minimumInstances,
                    resourceDefinitionSettings.maximumInstances,
                    int(resourceDefinitionSettings.supportedOperations),
                    resourceDefinitionSettings.defaultValue)
            else:
                self.DefineSingleInstanceResource(
                    objectDefinition, resourceDefinitionSettings.resourceID,
                    resourceDefinitionSettings.resourceName,
                    resourceDefinitionSettings.resourceType,
                    resourceDefinitionSettings.minimumInstances > 0,
                    int(resourceDefinitionSettings.supportedOperations),
                    resourceDefinitionSettings.defaultValue)

        result = self._xmlrpcSession.AwaServerDefineOperation_Add(
            defineOperation, objectDefinition)
        CheckSuccess(result,
                     "Could not add object definition to Define Operation")

        result = self._xmlrpcSession.AwaServerDefineOperation_Perform(
            defineOperation, test_defaults.TIMEOUT)
        CheckSuccess(result, "Failed to perform Define Operation")

        result = self._xmlrpcSession.AwaServerDefineOperation_Free(
            defineOperation)
        CheckSuccess(result, "Failed to free Define Operation")
Exemple #6
0
    def CancelObservation(self, session, observation, clientID):
        observeOperation = self._xmlrpcSession.AwaServerObserveOperation_New(
            session)
        CheckNone(observeOperation, "Observe Operation is NULL")

        path = self._xmlrpcSession.AwaServerObservation_GetPath(observation)
        CheckNone(path, "Failed to retrieve path from Observation")

        result = self._xmlrpcSession.AwaServerObserveOperation_AddCancelObservation(
            observeOperation, observation)
        CheckSuccess(
            result,
            "Failed to add Cancel  Observation to Observe Operation for path %s"
            % (path, ))

        self._PerformObserveOperation(observeOperation, clientID, path)
Exemple #7
0
 def CreateExecuteSubscription(self, path):
     executeSubscription = self._xmlrpcSession.AwaClientExecuteSubscription_New(
         path, None, None)
     CheckNone(
         executeSubscription,
         "Could not create Execute Subscription on path %s" % (path, ))
     return executeSubscription
Exemple #8
0
 def CreateChangeSubscription(self, path):
     self._xmlrpcSession.AwaLog_SetLevel(3)
     changeSubscription = self._xmlrpcSession.AwaClientChangeSubscription_New(
         path, None, None)
     CheckNone(changeSubscription,
               "Could not create Change Subscription on path %s" % (path, ))
     return changeSubscription
Exemple #9
0
    def CancelSubscribeToExecute(self, session, executeSubscription):
        subscribeOperation = self._xmlrpcSession.AwaClientSubscribeOperation_New(
            session)
        CheckNone(subscribeOperation, "Subscribe Operation is NULL")

        path = self._xmlrpcSession.AwaClientExecuteSubscription_GetPath(
            executeSubscription)
        CheckNone(path, "Failed to retrieve path from Execute Subscription")

        result = self._xmlrpcSession.AwaClientSubscribeOperation_AddCancelExecuteSubscription(
            subscribeOperation, executeSubscription)
        CheckSuccess(
            result,
            "Failed to add Cancel Execute Subscription to Subscribe Operation for path %s"
            % (path, ))

        self._PerformSubscribeOperation(subscribeOperation, path)
Exemple #10
0
    def SubscribeToChange(self, session, changeSubscription):
        subscribeOperation = self._xmlrpcSession.AwaClientSubscribeOperation_New(
            session)
        CheckNone(subscribeOperation, "Subscribe Operation is NULL")

        path = self._xmlrpcSession.AwaClientChangeSubscription_GetPath(
            changeSubscription)
        CheckNone(path, "Failed to retrieve path from Change Subscription")

        result = self._xmlrpcSession.AwaClientSubscribeOperation_AddChangeSubscription(
            subscribeOperation, changeSubscription)
        CheckSuccess(
            result,
            "Failed to add change subscription to Subscribe Operation for path %s"
            % (path, ))

        self._PerformSubscribeOperation(subscribeOperation, path)
Exemple #11
0
    def ListClients(self, session):
        CheckNone(session, "Session is NULL")
        clients = {}
        listClientsOperation = self._xmlrpcSession.AwaServerListClientsOperation_New(
            session)
        CheckNone(listClientsOperation, "List Clients Operation is NULL")
        result = self._xmlrpcSession.AwaServerListClientsOperation_Perform(
            listClientsOperation, test_defaults.TIMEOUT)
        CheckSuccess(result, "Failed to perform List clients operation")

        clientIterator = self._xmlrpcSession.AwaServerListClientsOperation_NewClientIterator(
            listClientsOperation)
        while self._xmlrpcSession.AwaClientIterator_Next(clientIterator):
            clientID = self._xmlrpcSession.AwaClientIterator_GetClientID(
                clientIterator)
            registeredEntities = []
            response = self._xmlrpcSession.AwaServerListClientsOperation_GetResponse(
                listClientsOperation, clientID)
            CheckNone(
                response,
                "No List Clients response for ClientID %s" % (clientID, ))

            entityIterator = self._xmlrpcSession.AwaServerListClientsResponse_NewRegisteredEntityIterator(
                response)
            CheckNone(
                entityIterator,
                "Failed to create Entity Iterator for List Clients response for ClientID %s"
                % (clientID, ))

            while self._xmlrpcSession.AwaRegisteredEntityIterator_Next(
                    entityIterator):
                registeredEntities.append(
                    self._xmlrpcSession.AwaRegisteredEntityIterator_GetPath(
                        entityIterator))
            self._xmlrpcSession.AwaRegisteredEntityIterator_Free(
                entityIterator)

            #print "Client: %s: %s" % (clientID, str(registeredEntities))
            clients[clientID] = registeredEntities
        self._xmlrpcSession.AwaClientIterator_Free(clientIterator)
        CheckSuccess(
            self._xmlrpcSession.AwaServerListClientsOperation_Free(
                listClientsOperation), "Failed to free List Clients Operation")
        return clients
Exemple #12
0
 def CreateObservation(self, clientID, path):
     observation = self._xmlrpcSession.AwaServerObservation_New(
         clientID, path, None, None)
     CheckNone(
         observation,
         "Could not create Observation for clientID %s on path %s" % (
             clientID,
             path,
         ))
     return observation
Exemple #13
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
Exemple #14
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
Exemple #15
0
    def DeleteResourceInstancesWithArrayRange(self, session, path, startIndex,
                                              count):
        deleteOperation = self._xmlrpcSession.AwaClientDeleteOperation_New(
            session)
        CheckNone(deleteOperation, "Delete Operation is NULL")

        result = self._xmlrpcSession.AwaClientDeleteOperation_AddPathWithArrayRange(
            deleteOperation, path, startIndex, count)
        CheckSuccess(
            result,
            "Failed to add array range to Delete operation on path %s: %d, %d"
            % (path, startIndex, count))

        self._PerformDeleteOperation(deleteOperation, path)
Exemple #16
0
 def CreateSession(self, address, port):
     session = self._xmlrpcSession.AwaServerSession_New()
     CheckNone(session, "Session is NULL")
     try:
         CheckSuccess(
             self._xmlrpcSession.AwaServerSession_SetIPCAsUDP(
                 session, address, int(port)),
             "Failed to set _session IPC connection as UDP")
         CheckSuccess(self._xmlrpcSession.AwaServerSession_Connect(session),
                      "Failed to connect _session")
     except AwaUnexpectedErrorException as exception:
         self._xmlrpcSession.AwaServerSession_Free(session)
         raise exception
     return session
Exemple #17
0
    def GetObjectDefinition(self, session, objectID):
        """Return the definition of an object defined on the device server with the specified objectID"""
        result = None
        try:
            entrypoint = session.get_entry_point()
            objdeflink = session.find_link(entrypoint, 'objectdefinitions')
            objdefs = session.get_all(objdeflink['href'])
            for index in range(0, objdefs['PageInfo']['ItemsCount']):
                if objdefs['Items'][index]['ObjectID'] == str(objectID):
                    result = self._GetObjectDefinition(objdefs['Items'][index])
                    break

        except Exception as exception:
            print "Error encountered when retrieving object definitions to retrieve an object definition."
            print exception
        CheckNone(result, "No Object definition exists for ID %d" % (objectID, ))
        return result
Exemple #18
0
    def GetResourceDefinition(self, objectdefinition, resourceID):
        """Return the definition of a object resource defined on the device server with the specified objectID and resourceID"""
        result = None
        try:
            entrypoint = self._session.get_entry_point()
            objdeflink = self._session.find_link(entrypoint, 'objectdefinitions')
            objdefs = self._session.get_all(objdeflink['href'])

            for index in range(0, int(objdefs['PageInfo']['ItemsCount'])):
                if objdefs['Items'][index]['ObjectID'] == str(self.GetObjectID(objectdefinition)):
                    for resourceindex in range(0, len(objdefs['Items'][index]['Properties'])):
                        if objdefs['Items'][index]['Properties'][resourceindex]['PropertyID'] == str(resourceID):
                            result = self._GetResourceDefinition(objdefs['Items'][index]['Properties'][resourceindex])
                            break
                    break

        except Exception as exception:
            print "Error encountered when retrieving resource definitions."
            print exception
        CheckNone(result, "No Resource definition exists for " +  self.GetObjectName(objectdefinition) + " object, resourceID %d" % (resourceID, ))
        return result
Exemple #19
0
 def GetPathResultFromGetOperation(self, operation, path):
     response = self._xmlrpcSession.AwaClientGetOperation_GetResponse(
         operation)
     CheckNone(response, "Response is NULL")
     return self._xmlrpcSession.AwaClientGetResponse_GetPathResult(
         response, path)
Exemple #20
0
 def SetCreateOptionalResource(self, setOperation, path):
     CheckNone(setOperation, "Set Operation is NULL")
     result = self._xmlrpcSession.AwaClientSetOperation_CreateOptionalResource(
         setOperation, path)
     CheckSuccess(result,
                  "Failed to create object instance on path: %s" % (path, ))
Exemple #21
0
 def CreateSetOperation(self, session):
     setOperation = self._xmlrpcSession.AwaClientSetOperation_New(session)
     CheckNone(setOperation, "Set Operation is NULL")
     return setOperation
Exemple #22
0
 def GetPathResultFromReadOperation(self, operation, clientID, path):
     response = self._xmlrpcSession.AwaServerReadOperation_GetResponse(
         operation, clientID)
     CheckNone(response, "Response is NULL")
     return self._xmlrpcSession.AwaServerReadResponse_GetPathResult(
         response, path)
Exemple #23
0
 def GetResourceDefinition(self, objectDefinition, resourceID):
     resourceDefinition = self._xmlrpcSession.AwaObjectDefinition_GetResourceDefinition(
         objectDefinition, resourceID)
     CheckNone(resourceDefinition,
               "No Resource definition exists for ID %d" % (resourceID, ))
     return resourceDefinition
Exemple #24
0
 def GetObjectDefinition(self, session, objectID):
     objectDefinition = self._xmlrpcSession.AwaServerSession_GetObjectDefinition(
         session, objectID)
     CheckNone(objectDefinition,
               "No Object definition exists for ID %d" % (objectID, ))
     return objectDefinition
Exemple #25
0
 def WriteCreateOptionalResource(self, writeOperation, path):
     CheckNone(writeOperation, "Write Operation is NULL")
     result = self._xmlrpcSession.AwaServerWriteOperation_CreateOptionalResource(
         writeOperation, path)
     CheckSuccess(result,
                  "Failed to create object instance on path: %s" % (path, ))
Exemple #26
0
 def CreateWriteOperation(self, session, writeMode):
     writeOperation = self._xmlrpcSession.AwaServerWriteOperation_New(
         session, int(writeMode))
     CheckNone(writeOperation, "Write Operation is NULL")
     return writeOperation