Esempio n. 1
0
    def __new__(cls):
        # Singleton
        if not cls._instance:
            # first instance
            cls.config = Configuration()
            cls.dct_filter = {}
            cls.dct_media = {}

            # {"filter_name" : class_filter}
            cls.dct_filterchain = {}
            cls.dct_filter = {}

            # initialize subscriber server
            publisher = Publisher(5031)
            cls.publisher = publisher
            # self.resource.set_all_publisher(publisher)
            publisher.start()

            publisher.register(keys.get_key_execution_list())
            publisher.register(keys.get_key_filter_param())
            publisher.register(keys.get_key_media_param())
            publisher.register(keys.get_key_lst_rec_historic())
            publisher.register(keys.get_key_count())

            # instance class
            cls._instance = super(Resource, cls).__new__(cls)
        return cls._instance
Esempio n. 2
0
    def __new__(cls):
        # Singleton
        if not cls._instance:
            # first instance
            cls.config = Configuration()
            cls.dct_filter = {}
            cls.dct_media = {}

            # {"filter_name" : class_filter}
            cls.dct_filterchain = {}
            cls.dct_filter = {}

            # initialize subscriber server
            publisher = Publisher(5031)
            cls.publisher = publisher
            # self.resource.set_all_publisher(publisher)
            publisher.start()

            publisher.register(keys.get_key_execution_list())
            publisher.register(keys.get_key_filter_param())
            publisher.register(keys.get_key_media_param())
            publisher.register(keys.get_key_lst_rec_historic())
            publisher.register(keys.get_key_count())

            # instance class
            cls._instance = super(Resource, cls).__new__(cls)
        return cls._instance
Esempio n. 3
0
    def start_filterchain_execution(
            self, execution_name, media_name, filterchain_name, file_name,
            is_client_manager):
        self._post_command_(locals())
        execution = self.dct_exec.get(execution_name, None)

        if execution:
            log.print_function(
                logger.error, "The execution %s is already created." %
                execution_name)
            return False

        filterchain = self.resource.get_filterchain(
            filterchain_name,
            force_new_filterchain=True)
        if not filterchain:
            log.print_function(
                logger.error, "Filterchain %s not exist or contain error." %
                filterchain_name)
            return False

        # Exception, if not media_name, we take the default media_name from the
        # filterchain
        if not media_name:
            media_name = filterchain.get_default_media_name()
            if not media_name:
                media_name = self.config.get_default_media_name()

        media = self.resource.get_media(media_name)
        if not media:
            log.print_function(
                logger.error,
                "Media %s not exist or you didn't set the default media on "
                "filterchain." % media_name)
            return False

        if media.is_media_video() and file_name:
            media.set_file(file_name)

        media.set_is_client_manager(is_client_manager)

        filterchain.set_media_param(media.get_params())
        filterchain.set_execution_name(execution_name)

        media.add_observer(filterchain.execute)
        if self._is_keep_alive_media:
            media.add_observer(self._keep_alive_media)

        self.dct_exec[execution_name] = {
            KEY_FILTERCHAIN: filterchain, KEY_MEDIA: media}

        publisher = self.publisher
        publisher.publish(
            keys.get_key_execution_list(), "+%s" % execution_name)

        for o_filter in filterchain.get_filter():
            o_filter.set_publisher(publisher)
        return True
Esempio n. 4
0
    def close(self):
        logger.info("Close cmdHandler and close server.")
        for media_name in self.resource.get_media_name_list():
            media = self.resource.get_media(media_name)
            media.close()
            media.destroy()

        self.server_observer.stop()
        self.publisher.stop()
        self.publisher.deregister(keys.get_key_execution_list())
        self.publisher.deregister(keys.get_key_filter_param())
        self.publisher.deregister(keys.get_key_media_param())
        self.publisher.deregister(keys.get_key_lst_rec_historic())
        self.publisher.deregister(keys.get_key_count())
Esempio n. 5
0
    def __init__(self, controller, subscriber):
        super(WinExecution, self).__init__()
        self.controller = controller
        self.subscriber = subscriber
        self.shared_info = SharedInfo()

        self.mode_edit = False
        self.last_index = 0

        self.ui = None
        self.reload_ui()

        self.shared_info.connect(SharedInfo.GLOBAL_MEDIA, self._change_media)
        self.shared_info.connect(SharedInfo.GLOBAL_FILTERCHAIN,
                                 self._change_filterchain)
        self.shared_info.connect(SharedInfo.GLOBAL_HIST_REC_PATH_MEDIA,
                                 self._change_media_path)

        self.subscriber.subscribe(keys.get_key_execution_list(),
                                  self.update_execution_list)
Esempio n. 6
0
    def stop_filterchain_execution(self, execution_name):
        self._post_command_(locals())
        execution = self.dct_exec.get(execution_name, None)

        if not execution:
            log.print_function(
                logger.warning,
                "The execution %s is already stopped." % execution_name)
            return False

        # Remove execution image observer from media
        observer = execution.get(KEY_MEDIA, None)
        if observer is None:
            logger.critical(
                "Not found the observer about execution %s" % execution_name)
            return False
        filterchain = execution.get(KEY_FILTERCHAIN, None)
        if filterchain is None:
            logger.critical("Not found the filterchain about \
                execution %s" % execution_name)
            return False

        observer.remove_observer(filterchain.execute)

        # deregiste key
        # TODO move this in filter destroy
        for filter_name in filterchain.get_filter_name():
            key = keys.create_unique_exec_filter_name(execution_name,
                                                      filter_name)
            self.publisher.deregister(key)

        filterchain.destroy()
        del self.dct_exec[execution_name]
        # publish removing filterchain
        self.publisher.publish(
            keys.get_key_execution_list(), "-%s" %
            execution_name)

        return True