def _startHttpObjectService(self):
     from wsgiref.simple_server import make_server
     # HttpObjectService constructor method creates a Smart Object service and 
     # returns a constructor for a restlite router instance
     self.httpObjectService = HttpObjectService(self._baseObject)
     self.httpd = make_server('', self._port, restlite.router(self.httpObjectService.routes))
     try: self.httpd.serve_forever()
     except KeyboardInterrupt: pass
def setup_server(units):
    rest_handler = RestHandler()    
    rest_handler.configure(units)
    httpd = make_server('', 8080, restlite.router(rest_handler.routes))

    httpserver = threading.Thread(target=httpd.serve_forever)
    httpserver.setDaemon(True)
    httpserver.start()  
def setup_server(units):
    rest_handler = RestHandler()
    rest_handler.configure(units)
    httpd = make_server('', 8080, restlite.router(rest_handler.routes))

    httpserver = threading.Thread(target=httpd.serve_forever)
    httpserver.setDaemon(True)
    httpserver.start()
 def _startCoapObjectService(self):
     # Use similar pattern for CoAP service, emulate with another http server for now
     from wsgiref.simple_server import make_server
     # coapObjectServices = CoapObjectService(self.objectService)
     # self.coapd = make_server('', 61616, restlite.router(coapObjectService.routes))
     self.coapObjectService = HttpObjectService(self._baseObject)
     self.coapd = make_server('', self._port, restlite.router(self.coapObjectService.routes))
     try: self.coapd.serve_forever()
     except KeyboardInterrupt: pass
 def _startCoapObjectService(self):
     # Use similar pattern for CoAP service, emulate with another http server for now
     from wsgiref.simple_server import make_server
     # coapObjectServices = CoapObjectService(self.objectService)
     # self.coapd = make_server('', 61616, restlite.router(coapObjectService.routes))
     self.coapObjectService = HttpObjectService(self._baseObject)
     self.coapd = make_server('', self._port, restlite.router(self.coapObjectService.routes))
     try: self.coapd.serve_forever()
     except KeyboardInterrupt: pass
     
         
Example #6
0
def main():  
    

    
    unit_handler = UnitHandler()
    rest_handler = RestHandler()
    
    unit_handler.configure()
    rest_handler.configure(unit_handler.unit_set)
    
    httpd = make_server('', rest_handler.port, restlite.router(rest_handler.routes))


    print "Establishing unit thread"
    unitserver = threading.Thread(target=unit_handler.loop)
    unitserver.setDaemon(True)
    unitserver.start()
    
    print "Establishing server thread"
    httpserver = threading.Thread(target=httpd.serve_forever)
    httpserver.setDaemon(True)
    httpserver.start()
    
    
    


    # Ensure that each unit on this device is called
    # at the minimum update cycle



    while True:

  
        unit_handler.update()
Example #7
0
        #bind returns the RestObject handler which uses the Request object
        # the handler calls the overriding _handleXX methods in this module
        self.routes = [(r'GET /favicon.ico$', self.favicon_handler),
                       (r'GET,PUT,POST,DELETE ', self.objectHandler)]
        return

    def favicon_handler(self, env, start_response):
        start_response('200 OK', [('Content-Type', 'image/gif')])
        try:
            with open('favicon.ico', 'rb') as f:
                result = f.read()
        except:
            raise restlite.Status, '400 Error Reading File'
        return (result)


# Standalone service mode
if __name__ == '__main__':
    import sys
    from wsgiref.simple_server import make_server
    # Create a Smart Object service,, return a reference to the top level resources dict
    objectService = ObjectService()
    httpObjectService = HttpObjectService(objectService)
    httpd = make_server('', 8000, restlite.router(httpObjectService.routes))
    print("Heres the server\n")
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        print("stopping\n")
        pass
        self.objectService = objectService
        self.objectHandler = bind(self.objectService, users=None) 
        #bind to root resource dictionary passed to constructor  
        #bind returns the RestObject handler which uses the Request object
        # the handler calls the overriding _handleXX methods in this module
        self.routes = [(r'GET /favicon.ico$', self.favicon_handler),(r'GET,PUT,POST,DELETE ', self.objectHandler )]
        return 
    
    def favicon_handler(self, env, start_response) :
        start_response('200 OK', [('Content-Type', 'image/gif')]) 
        try:
            with open('favicon.ico', 'rb') as f: result = f.read()
        except: raise restlite.Status, '400 Error Reading File'
        return(result)

                  
# Standalone service mode
if __name__ == '__main__' :
    import sys
    from wsgiref.simple_server import make_server
    # Create a Smart Object service,, return a reference to the top level resources dict
    objectService = ObjectService()
    httpObjectService = HttpObjectService(objectService)
    httpd = make_server('', 8000, restlite.router(httpObjectService.routes))
    print("Heres the server\n")
    try: httpd.serve_forever()
    except KeyboardInterrupt: 
        print("stopping\n")
        pass