Esempio n. 1
0
File: registry.py Progetto: nesl/esp
    def register(self, espmlString):
        """ Registers the ESPML described system/client/mediator and stores the information in
		the database. Additionally it creates unique espids. The return value of this function
		is the same document as sent by the registerer, but includes the new ids in the right
		place.

		@return An espml document which includes all the registered systems/clients/mediators
		with their new espids.
		
		"""

        espmlDocObject = espml.parseString(espmlString)

        registerElements = espmlDocObject.getRegister()

        if not registerElements:
            return "ERROR_No register tag found"

        for relement in registerElements:
            securityElement = relement.getSecurity()

            systemResponses = []
            clientResponses = []
            mediatorResponses = []

            systemElements = relement.getSystem()

            if systemElements:
                for system in systemElements:
                    systemResponses.append(self._db.addSystem(system))

            clientElements = relement.getClient()

            if clientElements:
                for client in clientElements:
                    clientResponses.append(self._db.addClient(client))

            mediatorElements = relement.getMediator()

            if mediatorElements:
                for mediator in mediatorElements:
                    mediatorResponses.append(self._db.addMediator(mediator))

        responseElement = espml.response(ttype='register',
                                         mediator=mediatorResponses,
                                         system=systemResponses,
                                         client=clientResponses)
        result = espml.esp(response=[responseElement])

        ssock = StringIO.StringIO()
        result.export(ssock, 0)

        return ssock.getvalue()
Esempio n. 2
0
File: registry.py Progetto: nesl/esp
	def unRegister(self, espmlString):
		""" Unregisters the system described in the ESPML document from the
		database.
		"""
		
		espmlDocObject = espml.parseString(espmlString)
		result = self._db.deleteSystem(espmlDocObject)

		if result[0] < 0:
			return "ERROR_%s"%(result[1],)
		else:
			logging.info("Successfully removed system: " + espmlDocObject.getId())
 			return "OK"
Esempio n. 3
0
File: registry.py Progetto: nesl/esp
	def register(self, espmlString):
		""" Registers the ESPML described system/client/mediator and stores the information in
		the database. Additionally it creates unique espids. The return value of this function
		is the same document as sent by the registerer, but includes the new ids in the right
		place.

		@return An espml document which includes all the registered systems/clients/mediators
		with their new espids.
		
		"""
		
		espmlDocObject = espml.parseString(espmlString)

		registerElements = espmlDocObject.getRegister()

		if not registerElements:
			return "ERROR_No register tag found"

		for relement in registerElements:
			securityElement = relement.getSecurity()

			systemResponses = []
			clientResponses = []
			mediatorResponses = []

			systemElements = relement.getSystem()

			if systemElements:
				for system in systemElements:
					systemResponses.append(self._db.addSystem(system))

			clientElements = relement.getClient()

			if clientElements:
				for client in clientElements:
					clientResponses.append(self._db.addClient(client))

			mediatorElements = relement.getMediator()

			if mediatorElements:
				for mediator in mediatorElements:
					mediatorResponses.append(self._db.addMediator(mediator))

		responseElement = espml.response(ttype='register', mediator=mediatorResponses, system=systemResponses,
					   client=clientResponses)
		result = espml.esp(response=[responseElement])

		ssock = StringIO.StringIO()
		result.export(ssock, 0)

		return ssock.getvalue()
Esempio n. 4
0
File: registry.py Progetto: nesl/esp
    def unRegister(self, espmlString):
        """ Unregisters the system described in the ESPML document from the
		database.
		"""

        espmlDocObject = espml.parseString(espmlString)
        result = self._db.deleteSystem(espmlDocObject)

        if result[0] < 0:
            return "ERROR_%s" % (result[1], )
        else:
            logging.info("Successfully removed system: " +
                         espmlDocObject.getId())
            return "OK"
Esempio n. 5
0
    def __init__(self):
        
        self.system = SOAPpy.SOAPProxy("http://localhost:7081")
        espmlFile = "soundscape_function.xml"
		
        espmlDocObject = espml.parse(espmlFile)
        espmlDocXml = StringIO.StringIO()
        espmlDocObject.export(espmlDocXml, 0)
        r = self.system.execute(espmlDocXml.getvalue())

        espmlResponse = espml.parseString(r)
        field = espmlResponse.getField()[0]
        functions = field.getFunction()
        sessionId = None
        for f in functions:
            if f.getName() == "getSessionId":
                sessionId = f.getOutput()[0].getUri()

        if sessionId == None:
            print "No session ID received."
            sys.exit(1)
        

        #now, submit a timestamp and audio file at the same time
        espmlDocObject = espml.parse("soundscape_function2.xml")
        field = espmlDocObject.getField()[0]
        functions = field.getFunction()
        for f in functions:
            if f.getName() == "uploadLocation":
                f.addParameter(espml.parameter(name="sessionId", value=sessionId))
                f.addParameter(espml.parameter(name="timestamp", value=timestamp))
                f.addParameter(espml.parameter(name="location", value=location))
            if f.getName() == "uploadMedia":
                f.addParameter(espml.parameter(name="sessionId", value=sessionId))
                f.addParameter(espml.parameter(name="timestamp", value=timestamp))
                f.addParameter(espml.parameter(name="mediaFile", value=base64.b64encode(mediaFileString)))

        espmlDocXml = StringIO.StringIO()
        espmlDocObject.export(espmlDocXml, 0)
        #print espmlDocXml.getvalue()

        r = self.system.execute(espmlDocXml.getvalue())
Esempio n. 6
0
        def processRequest(self, dict, baseFunctionCallFile):
                print "Content-Type: text/html\n"
                print "<html><head><title>functionCall</title></head>"
                print "<body>"
                print "<pre>"

		#print self.dict

		tempKey = 0
		espmlDocObject = espml.parse(baseFunctionCallFile)

		if(dict.has_key('system')):
			if(dict.has_key('system')):
				espmlDocObject.setId(str(dict['system']))

		for field in espmlDocObject.getField():
			if(dict.has_key('field')):
				field.setId(int(dict['field']))
				if(dict.has_key('platform')):
					pass
				else:
					field.addFunction(espml.function(dict['name'], 'General Function Description'))				
					for key in dict.keys():
						if((key != 'system') and (key != 'name') and (key != 'platform') and (key != 'sensor') and (key != 'field')):
							for function in field.getFunction():
								param = espml.parameter(str(key))
								param.setValue(str(dict[key]))
                               	                                function.addParameter(param)
			for platform in field.getPlatform():
				if(dict.has_key('platform')):
					platform.setId(int(dict['platform']))
                                	if(dict.has_key('sensor')):     
                                        	pass
                                	else:
        		                        platform.addFunction(espml.function(dict['name'], 'General Function Description'))
                		                for key in dict.keys():
                        		                if((key != 'system') and (key != 'name') and (key != 'platform') and (key != 'sensor') and (key != 'field')):
                                		                for function in platform.getFunction():
									param = espml.parameter(str(key))
									param.setValue(str(dict[key]))
                                	                                function.addParameter(param)
				for sensor in platform.getSensor():
					if(dict.has_key('sensor')):
						sensor.setId(int(dict['sensor']))
	        	                        sensor.addFunction(espml.function(dict['name'], 'General Function Description'))
        	                                for key in dict.keys():
                	                                if((key != 'system') and (key != 'name') and (key != 'platform') and (key != 'sensor') and (key != 'field')):
                        	                                for function in sensor.getFunction():
									param = espml.parameter(str(key))
									param.setValue(str(dict[key]))
                                	                                function.addParameter(param)


                espmlDocXml = StringIO.StringIO()
                espmlDocObject.export(espmlDocXml, 0)
                                
                #print espmlDocXml.getvalue()
		#print espmlDocObject.getId()

		system = SOAPpy.SOAPProxy(espmlDocObject.getId())
		functionOutputXML = system.execute(espmlDocXml.getvalue())

		espmlDocObject = espml.parseString(functionOutputXML)

		for field in espmlDocObject.getField():
			for function in field.getFunction():
				print 'Function:', function.getName()
				for output in function.getOutput():
					print 'Type:', output.getType()
					if((str(output.getType()) == "OK") or (str(output.getType()) == "ERROR")):
						print 'Response: ' + str(output.getUri())				
					else:
						print 'URI:' + '<a href="' + str(output.getUri()) + '">' + str(output.getUri()) + '</a>'
			for platform in field.getPlatform():
	                        for function in platform.getFunction():
					print 'Function:', function.getName()
                	                for output in function.getOutput():
						print 'Type:', output.getType()
	                                        if((str(output.getType()) == "OK") or (str(output.getType()) == "ERROR")):
        	                                        print 'Response: ' + str(output.getUri())
                	                        else:
                        	                        print 'URI:' + '<a href="' + str(output.getUri()) + '">' + str(output.getUri()) + '</a>'
				for sensor in platform.getSensor():
		                        for function in sensor.getFunction():
						print 'Function:', function.getName()
        	                	        for output in function.getOutput():
							print 'Type:', output.getType()
		                                        if((str(output.getType()) == "OK") or (str(output.getType()) == "ERROR")):
                		                                print 'Response: ' + str(output.getUri())
                                		        else:
                                                		print 'URI:' + '<a href="' + str(output.getUri()) + '">' + str(output.getUri()) + '</a>'

                print "</pre>"
                print "</body>"
                print "</html>"
Esempio n. 7
0
    def execute(self, espmlString):
        """ Executes actions based on a ESPML query or actuation and returns an approrpriate
		action based on the action.
		"""

        print espmlString

        class FunctionInfo:
            def __init__(self):
                self.id = 0
                self.name = ""
                self.paramList = {}

        # Really what you want to do is check the xml that comes in and compare it with
        # the xml you have and make sure that the functions that are asked for are actually
        # valid.

        espmlDocObject = espml.parseString(espmlString)
        functionList = []
        functionObject = FunctionInfo()

        # ** Convert this into a function maybe?
        for field in espmlDocObject.getField():
            for fieldFunc in field.getFunction():
                tempFunctionName = 'field_' + fieldFunc.name
                if hasattr(self, tempFunctionName):
                    functionObject.id = field.getId()
                    functionObject.name = tempFunctionName
                    for param in fieldFunc.getParameter():
                        functionObject.paramList[
                            param.getName()] = param.getValue()
                    outputList = getattr(self, functionObject.name)(
                        functionObject.id, functionObject.paramList)
                    functionOutput = output(outputList[0], outputList[1])
                    fieldFunc.addOutput(functionOutput)
                else:
                    raise FunctionError(tempFunctionName)
            for platform in field.getPlatform():
                for platformFunc in platform.getFunction():
                    tempFunctionName = 'platform_' + platformFunc.name
                    if hasattr(self, tempFunctionName):
                        functionObject.id = (field.getId(), platform.getId())
                        functionObject.name = tempFunctionName
                        for param in platformFunc.getParameter():
                            functionObject.paramList[
                                param.getName()] = param.getValue()
                        outputList = getattr(self, functionObject.name)(
                            functionObject.id, functionObject.paramList)
                        functionOutput = output(outputList[0], outputList[1])
                        platformFunc.addOutput(functionOutput)
                    else:
                        raise FunctionError(tempFunctionName)
                for sensor in platform.getSensor():
                    for sensorFunc in sensor.getFunction():
                        tempFunctionName = 'sensor_' + sensorFunc.name
                        if hasattr(self, tempFunctionName):
                            functionObject.id = (field.getId(),
                                                 platform.getId(),
                                                 sensor.getId())
                            functionObject.name = tempFunctionName
                            for param in sensorFunc.getParameter():
                                functionObject.paramList[
                                    param.getName()] = param.getValue()
                            outputList = getattr(self, functionObject.name)(
                                functionObject.id, functionObject.paramList)
                            functionOutput = output(outputList[0],
                                                    outputList[1])
                            sensorFunc.addOutput(functionOutput)
                        else:
                            raise FunctionError(tempFunctionName)

        # After validation, you want to do sometype of callback system that registers
        # for each of the different types of functions at each of the levels and then
        # delegates in someway.

        espmlDocXml = StringIO.StringIO()
        espmlDocObject.export(espmlDocXml, 0)
        #print "\nQuery XML:"
        #print espmlDocXml.getvalue()

        return espmlDocXml.getvalue()
Esempio n. 8
0
File: system.py Progetto: nesl/esp
	def execute(self, espmlString):
		""" Executes actions based on a ESPML query or actuation and returns an approrpriate
		action based on the action.
		"""

		print espmlString
		class FunctionInfo:
			def __init__(self):
				self.id = 0
				self.name = ""
				self.paramList = {}
			

		# Really what you want to do is check the xml that comes in and compare it with
		# the xml you have and make sure that the functions that are asked for are actually
		# valid.

                espmlDocObject = espml.parseString(espmlString)
        	functionList = []
		functionObject = FunctionInfo()

		# ** Convert this into a function maybe?
                for field in espmlDocObject.getField():
                        for fieldFunc in field.getFunction():
                                tempFunctionName = 'field_' + fieldFunc.name
                                if hasattr(self, tempFunctionName):
					functionObject.id = field.getId()
					functionObject.name = tempFunctionName
					for param in fieldFunc.getParameter():
						functionObject.paramList[param.getName()]=param.getValue()
					outputList = getattr(self, functionObject.name)(functionObject.id, functionObject.paramList)
					functionOutput = output(outputList[0], outputList[1])
					fieldFunc.addOutput(functionOutput)
                                else:
                                        raise FunctionError(tempFunctionName)
                        for platform in field.getPlatform():
                                for platformFunc in platform.getFunction():
                                        tempFunctionName = 'platform_' + platformFunc.name
                                        if hasattr(self, tempFunctionName):
	                                        functionObject.id = (field.getId(), platform.getId())
        	                                functionObject.name = tempFunctionName
                	                        for param in platformFunc.getParameter():
                        	                        functionObject.paramList[param.getName()]=param.getValue()
                                        	outputList = getattr(self, functionObject.name)(functionObject.id, functionObject.paramList)
                                        	functionOutput = output(outputList[0], outputList[1])
                                        	platformFunc.addOutput(functionOutput)
                                        else:
                                                raise FunctionError(tempFunctionName)
                                for sensor in platform.getSensor():
                                        for sensorFunc in sensor.getFunction():
                                                tempFunctionName = 'sensor_' + sensorFunc.name
                                                if hasattr(self, tempFunctionName):
		                                        functionObject.id = (field.getId(), platform.getId(), sensor.getId())
                		                        functionObject.name = tempFunctionName
                                		        for param in sensorFunc.getParameter():
                                                		functionObject.paramList[param.getName()]=param.getValue()
                                        		outputList = getattr(self, functionObject.name)(functionObject.id, functionObject.paramList)
                                        		functionOutput = output(outputList[0], outputList[1])
                                        		sensorFunc.addOutput(functionOutput)
                                                else:
                                                        raise FunctionError(tempFunctionName)

		# After validation, you want to do sometype of callback system that registers
		# for each of the different types of functions at each of the levels and then
		# delegates in someway.		

                espmlDocXml = StringIO.StringIO()
                espmlDocObject.export(espmlDocXml, 0)                                             
		#print "\nQuery XML:"   
                #print espmlDocXml.getvalue()

		return espmlDocXml.getvalue()
Esempio n. 9
0
    def processRequest(self, dict, baseFunctionCallFile):
        print "Content-Type: text/html\n"
        print "<html><head><title>functionCall</title></head>"
        print "<body>"
        print "<pre>"

        #print self.dict

        tempKey = 0
        espmlDocObject = espml.parse(baseFunctionCallFile)

        if (dict.has_key('system')):
            if (dict.has_key('system')):
                espmlDocObject.setId(str(dict['system']))

        for field in espmlDocObject.getField():
            if (dict.has_key('field')):
                field.setId(int(dict['field']))
                if (dict.has_key('platform')):
                    pass
                else:
                    field.addFunction(
                        espml.function(dict['name'],
                                       'General Function Description'))
                    for key in dict.keys():
                        if ((key != 'system') and (key != 'name')
                                and (key != 'platform') and (key != 'sensor')
                                and (key != 'field')):
                            for function in field.getFunction():
                                param = espml.parameter(str(key))
                                param.setValue(str(dict[key]))
                                function.addParameter(param)
            for platform in field.getPlatform():
                if (dict.has_key('platform')):
                    platform.setId(int(dict['platform']))
                    if (dict.has_key('sensor')):
                        pass
                    else:
                        platform.addFunction(
                            espml.function(dict['name'],
                                           'General Function Description'))
                        for key in dict.keys():
                            if ((key != 'system') and (key != 'name')
                                    and (key != 'platform')
                                    and (key != 'sensor')
                                    and (key != 'field')):
                                for function in platform.getFunction():
                                    param = espml.parameter(str(key))
                                    param.setValue(str(dict[key]))
                                    function.addParameter(param)
                for sensor in platform.getSensor():
                    if (dict.has_key('sensor')):
                        sensor.setId(int(dict['sensor']))
                        sensor.addFunction(
                            espml.function(dict['name'],
                                           'General Function Description'))
                        for key in dict.keys():
                            if ((key != 'system') and (key != 'name')
                                    and (key != 'platform')
                                    and (key != 'sensor')
                                    and (key != 'field')):
                                for function in sensor.getFunction():
                                    param = espml.parameter(str(key))
                                    param.setValue(str(dict[key]))
                                    function.addParameter(param)

        espmlDocXml = StringIO.StringIO()
        espmlDocObject.export(espmlDocXml, 0)

        #print espmlDocXml.getvalue()
        #print espmlDocObject.getId()

        system = SOAPpy.SOAPProxy(espmlDocObject.getId())
        functionOutputXML = system.execute(espmlDocXml.getvalue())

        espmlDocObject = espml.parseString(functionOutputXML)

        for field in espmlDocObject.getField():
            for function in field.getFunction():
                print 'Function:', function.getName()
                for output in function.getOutput():
                    print 'Type:', output.getType()
                    if ((str(output.getType()) == "OK")
                            or (str(output.getType()) == "ERROR")):
                        print 'Response: ' + str(output.getUri())
                    else:
                        print 'URI:' + '<a href="' + str(
                            output.getUri()) + '">' + str(
                                output.getUri()) + '</a>'
            for platform in field.getPlatform():
                for function in platform.getFunction():
                    print 'Function:', function.getName()
                    for output in function.getOutput():
                        print 'Type:', output.getType()
                        if ((str(output.getType()) == "OK")
                                or (str(output.getType()) == "ERROR")):
                            print 'Response: ' + str(output.getUri())
                        else:
                            print 'URI:' + '<a href="' + str(
                                output.getUri()) + '">' + str(
                                    output.getUri()) + '</a>'
                for sensor in platform.getSensor():
                    for function in sensor.getFunction():
                        print 'Function:', function.getName()
                        for output in function.getOutput():
                            print 'Type:', output.getType()
                            if ((str(output.getType()) == "OK")
                                    or (str(output.getType()) == "ERROR")):
                                print 'Response: ' + str(output.getUri())
                            else:
                                print 'URI:' + '<a href="' + str(
                                    output.getUri()) + '">' + str(
                                        output.getUri()) + '</a>'

        print "</pre>"
        print "</body>"
        print "</html>"