示例#1
0
class AdapterSOAPServer():
    def __init__(self):
        #self.address = "http://localhost:8008/"
        self.address = "http://%s:%s/" % (HOST_NAME, PORT_NUMBER)
        self.adapter_utility = AdapterUtility()
        self.resource_alloc_flag = False

    def adapt(self, nodeID, resourceName, duration, options={}):
        print resourceName
        resource = {'nodeID': nodeID, 'resourceName': resourceName, 'duration': duration, 'options': options}
        self.adapter_utility.allocate(resource)

        return "Result"

    def run(self):
        dispatcher = SoapDispatcher('op_adapter_soap_disp', location = self.address, action = self.address,
                namespace = "http://smartylab.co.kr/products/op/adapter", prefix="tns", trace = True, ns = True)
        dispatcher.register_function('adapt', self.adapt, returns={'out': str},
                args={'nodeID': str, 'resourceName': str, 'duration': str, 'options': str})
        print("Starting a SOAP server for adapter layer of OP...")
        httpd = HTTPServer(("", int(PORT_NUMBER)), SOAPHandler)
        httpd.dispatcher = dispatcher

        print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
        httpd.serve_forever()
示例#2
0
class AdapterSOAPServer:
    def __init__(self):
        self.address = "http://localhost:8008/"
        self.adapter_utility = AdapterUtility()
        self.resource_alloc_flag = False

    def adapt(self, nodeID, resourceName, duration, options={}):
        '''
        Adapt a service request to a ROCON request.
        @ param nodeID: Not used
        @ param resourceName: URI
        @ param duration: Invoke an activity for the duration
        @ param options: Command from BP (i.e. forward or cycle_left)
        '''
        print("Adapt...")
        print("Node ID: %s, Resource Name: %s, Duration: %s, Options: %s" % (nodeID, resourceName, duration, options))

        command_flag = False

        print "ready to request resources"
        print "resource_alloc_flag: ", self.resource_alloc_flag

        # To publish request to allocate resource
        if resourceName != None and self.resource_alloc_flag != True:
            print "===================server - Resource Allocating ==================="
            time.sleep(1)
            self.adapter_utility.pub_resource_alloc(resourceName, options)

            while self.resource_alloc_flag !=True:
                time.sleep(0.5)
                self.resource_alloc_flag = self.adapter_utility.resource_alloc_flag
            print "Receive reply of the allocation request"

        # To publish command to resource
        elif duration != None :
            print "===================server - Commanding ==================="
            time.sleep(1)
            self.adapter_utility.pub_command(duration, options)

            while command_flag !=True:
                time.sleep(0.5)
                command_flag = self.adapter_utility.command_flag
            print "Receive reply of the command"

        return "Result"

    def run(self):
        dispatcher = SoapDispatcher('op_adapter_soap_disp', location = self.address, action = self.address,
                namespace = "http://smartylab.co.kr/products/op/adapter", prefix="tns", trace = True, ns = True)
        dispatcher.register_function('adapt', self.adapt, returns={'out': str},
                args={'nodeID': str, 'resourceName': str, 'duration': str, 'options': str})
        print("Starting a SOAP server for adapter layer of OP...")
        httpd = HTTPServer(("", 8008), SOAPHandler)
        httpd.dispatcher = dispatcher
        httpd.serve_forever()
示例#3
0
class AdapterSOAPServer():
    def __init__(self):
        #self.address = "http://localhost:8008/"
        self.address = "http://%s:%s/" % (HOST_NAME, PORT_NUMBER)
        self.adapter_utility = AdapterUtility()
        self.resource_alloc_flag = False

    def adapt(self, nodeID, resourceName, duration, options={}):
        print resourceName
        resource = {
            'nodeID': nodeID,
            'resourceName': resourceName,
            'duration': duration,
            'options': options
        }
        self.adapter_utility.allocate(resource)

        return "Result"

    def run(self):
        dispatcher = SoapDispatcher(
            'op_adapter_soap_disp',
            location=self.address,
            action=self.address,
            namespace="http://smartylab.co.kr/products/op/adapter",
            prefix="tns",
            trace=True,
            ns=True)
        dispatcher.register_function('adapt',
                                     self.adapt,
                                     returns={'out': str},
                                     args={
                                         'nodeID': str,
                                         'resourceName': str,
                                         'duration': str,
                                         'options': str
                                     })
        print("Starting a SOAP server for adapter layer of OP...")
        httpd = HTTPServer(("", int(PORT_NUMBER)), SOAPHandler)
        httpd.dispatcher = dispatcher

        print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME,
                                                         PORT_NUMBER)
        httpd.serve_forever()
示例#4
0
 def __init__(self):
     #self.address = "http://localhost:8008/"
     self.address = "http://%s:%s/" % (HOST_NAME, PORT_NUMBER)
     self.adapter_utility = AdapterUtility()
     self.resource_alloc_flag = False
示例#5
0
 def __init__(self):
     self.address = "http://localhost:8008/"
     self.adapter_utility = AdapterUtility()
     self.resource_alloc_flag = False
示例#6
0
class AdapterSOAPServer:
    def __init__(self):
        self.address = "http://localhost:8008/"
        self.adapter_utility = AdapterUtility()
        self.resource_alloc_flag = False

    def adapt(self, nodeID, resourceName, duration, options={}):
        '''
        Adapt a service request to a ROCON request.
        @ param nodeID: Not used
        @ param resourceName: URI
        @ param duration: Invoke an activity for the duration
        @ param options: Command from BP (i.e. forward or cycle_left)
        '''
        print("Adapt...")
        print("Node ID: %s, Resource Name: %s, Duration: %s, Options: %s" %
              (nodeID, resourceName, duration, options))

        command_flag = False

        print "ready to request resources"
        print "resource_alloc_flag: ", self.resource_alloc_flag

        # To publish request to allocate resource
        if resourceName != None and self.resource_alloc_flag != True:
            print "===================server - Resource Allocating ==================="
            time.sleep(1)
            self.adapter_utility.pub_resource_alloc(resourceName, options)

            while self.resource_alloc_flag != True:
                time.sleep(0.5)
                self.resource_alloc_flag = self.adapter_utility.resource_alloc_flag
            print "Receive reply of the allocation request"

        # To publish command to resource
        elif duration != None:
            print "===================server - Commanding ==================="
            time.sleep(1)
            self.adapter_utility.pub_command(duration, options)

            while command_flag != True:
                time.sleep(0.5)
                command_flag = self.adapter_utility.command_flag
            print "Receive reply of the command"

        return "Result"

    def run(self):
        dispatcher = SoapDispatcher(
            'op_adapter_soap_disp',
            location=self.address,
            action=self.address,
            namespace="http://smartylab.co.kr/products/op/adapter",
            prefix="tns",
            trace=True,
            ns=True)
        dispatcher.register_function('adapt',
                                     self.adapt,
                                     returns={'out': str},
                                     args={
                                         'nodeID': str,
                                         'resourceName': str,
                                         'duration': str,
                                         'options': str
                                     })
        print("Starting a SOAP server for adapter layer of OP...")
        httpd = HTTPServer(("", 8008), SOAPHandler)
        httpd.dispatcher = dispatcher
        httpd.serve_forever()
示例#7
0
 def __init__(self):
     self.address = "http://localhost:8008/"
     self.adapter_utility = AdapterUtility()
     self.resource_alloc_flag = False
示例#8
0
 def __init__(self):
     #self.address = "http://localhost:8008/"
     self.address = "http://%s:%s/" % (HOST_NAME, PORT_NUMBER)
     self.adapter_utility = AdapterUtility()
     self.resource_alloc_flag = False