コード例 #1
0
class CameraService(BackgroundProcessServiceStart, BaseService):
    def __init__(self, config):
        self.server = VideoStreamManager(self, config)
        self.rpc = RPCServer("Camera", "Manage Cameras/CCTV", [
            ServerAPI("start_stream", "Starts the stream of given camera",
                      [ArgParameter("camera_id", "ID of the camera", str)],
                      self.server.start_stream),
            ServerAPI("stop_stream", "Stops the stream of given camera",
                      [ArgParameter("camera_id", "ID of the camera", str)],
                      self.server.stop_stream),
            ServerAPI("list_streams", "Lists all available streams.", [],
                      self.server.list_streams)
        ], self)
        self.http = AppHTTPServer(self, fa_favicon="video-camera")
        super().__init__()

    def handle_cameras_request(self):
        return json.dumps(self.server.info_message)

    def get_component_name(self):
        return "camera"

    def on_service_start(self, *args, **kwargs):
        self.http.start()
        self.rpc.start()
        self.server.run(self.notify_start)

    def on_service_stop(self):
        self.server.stop()
コード例 #2
0
ファイル: webos.py プロジェクト: supersaiyanmode/WeaveServer
    def __init__(self, service, mac, client):
        store = {'client_key': 'c2a6e6a1a8ebf46ccddaabaf7c15bad6'}
        client.connect()
        list(client.register(store))

        self.mac = mac
        apis = get_apis(client)
        self.rpc = RPCServer("LG TV Commands", "Remote control for LG TVs.",
                             apis, service)
コード例 #3
0
 def __init__(self):
     apis = [
         ServerAPI("api1", "desc1", [
             ArgParameter("p1", "d1", str),
             ArgParameter("p2", "d2", int),
             KeywordParameter("k3", "d3", bool)
         ], self.api1),
         ServerAPI("api2", "desc2", [], self.api2),
         ServerAPI("exception", "desc2", [], self.exception)
     ]
     self.rpc_server = RPCServer("name", "desc", apis, self)
     self.paused = False
     super(DummyService, self).__init__()
コード例 #4
0
 def __init__(self, config):
     self.server = VideoStreamManager(self, config)
     self.rpc = RPCServer("Camera", "Manage Cameras/CCTV", [
         ServerAPI("start_stream", "Starts the stream of given camera",
                   [ArgParameter("camera_id", "ID of the camera", str)],
                   self.server.start_stream),
         ServerAPI("stop_stream", "Stops the stream of given camera",
                   [ArgParameter("camera_id", "ID of the camera", str)],
                   self.server.stop_stream),
         ServerAPI("list_streams", "Lists all available streams.", [],
                   self.server.list_streams)
     ], self)
     self.http = AppHTTPServer(self, fa_favicon="video-camera")
     super().__init__()
コード例 #5
0
    def __init__(self, config):
        self.update_scanner = UpdateScanner(self)
        self.updater = Updater(self, self.update_scanner)
        self.shutdown = Event()
        self.rpc = RPCServer("System Update", "Update the System", [
            ServerAPI("check_updates", "Check for updates", [],
                      self.update_scanner.check_updates),
            ServerAPI("perform_upgrade", "Perform update", [],
                      self.updater.perform_upgrade),
        ], self)

        self.http = AppHTTPServer(self)
        self.http.flask.add_url_rule("/status", self.get_status)
        self.status_lock = RLock()
        self.status = "No updates available."
        super().__init__()
コード例 #6
0
class UpdaterService(BackgroundProcessServiceStart, BaseService):
    def __init__(self, config):
        self.update_scanner = UpdateScanner(self)
        self.updater = Updater(self, self.update_scanner)
        self.shutdown = Event()
        self.rpc = RPCServer("System Update", "Update the System", [
            ServerAPI("check_updates", "Check for updates", [],
                      self.update_scanner.check_updates),
            ServerAPI("perform_upgrade", "Perform update", [],
                      self.updater.perform_upgrade),
        ], self)

        self.http = AppHTTPServer(self)
        self.http.flask.add_url_rule("/status", self.get_status)
        self.status_lock = RLock()
        self.status = "No updates available."
        super().__init__()

    def get_component_name(self):
        return "updater"

    def on_service_start(self, *args, **kwargs):
        super().on_service_start(*args, **kwargs)
        self.rpc.start()
        self.update_scanner.start()
        self.updater.start()
        self.http.start()
        self.notify_start()
        self.shutdown.wait()

    def on_service_stop(self):
        logger.info("Stopping update scanner..")
        self.update_scanner.stop()
        self.shutdown.set()
        self.rpc.stop()
        super().on_service_stop()

    def update_status(self, msg):
        logger.info("Updater status: %s", msg)
        with self.status_lock:
            self.status = msg

    def get_status(self):
        with self.status_lock:
            return self.status
コード例 #7
0
class DummyService(BaseService):
    def __init__(self):
        apis = [
            ServerAPI("api1", "desc1", [
                ArgParameter("p1", "d1", str),
                ArgParameter("p2", "d2", int),
                KeywordParameter("k3", "d3", bool)
            ], self.api1),
            ServerAPI("api2", "desc2", [], self.api2),
            ServerAPI("exception", "desc2", [], self.exception)
        ]
        self.rpc_server = RPCServer("name", "desc", apis, self)
        self.paused = False
        super(DummyService, self).__init__()

    def api1(self, p1, p2, k3):
        if type(p1) != str or type(p2) != int or type(k3) != bool:
            return "BAD"

        if self.paused:
            while self.paused:
                sleep_time = random.randrange(500, 1500) / 1000.0
                time.sleep(sleep_time)

        return "{}{}{}".format(p1, p2, k3)

    def api2(self):
        return "API2"

    def exception(self):
        raise RuntimeError("dummy")

    def get_service_queue_name(self, path):
        return "/" + path

    def start(self):
        self.rpc_server.start()

    def stop(self):
        self.rpc_server.stop()