Пример #1
0
    def __init__(self, client, prefix, site=None):
        assert site is not None
        super().__init__()

        self.clientid = clientcommon.clientid('serialclient')

        staticfmt = {'site': site}
        _topics = mqttcommon.generate_topics_dict(
            self.SERVER.TOPICS, prefix, self.SERVER.AGENTTOPIC, staticfmt)

        _print_wrapper = self.async_print_handle_readlinebuff()
        line_cb = _print_wrapper(self.line_handler)
        error_cb = _print_wrapper(self.error_cb)

        self.topics = {
            'line': mqttcommon.ChannelClient(_topics['line'], line_cb),
            'linestart': mqttcommon.RequestClient(
                _topics['line'], 'start', clientid=self.clientid),
            'linestop': mqttcommon.RequestClient(
                _topics['line'], 'stop', clientid=self.clientid),

            'stop': mqttcommon.RequestClient(
                _topics['node'], 'stop', clientid=self.clientid),

            'stopall': mqttcommon.RequestClient(
                _topics['agenttopic'], 'stopall', clientid=self.clientid),

            'error': mqttcommon.ErrorClient(_topics['agenttopic'],
                                            callback=error_cb),
        }

        self.client = client
        self.client.topics = list(self.topics.values())
Пример #2
0
    def _topics_dict(self, prefix, site=None, agenttopic=None):
        """Return topics formated for site or agenttopic.

        Allows overwriting default prefix with agenttopic.
        """

        # Prefix topics with 'agenttopic'
        agenttopic = (agenttopic
                      if agenttopic is not None else self.SERVER.AGENTTOPIC)
        staticfmt = {'site': site} if site is not None else {}

        err = 'site required for agenttopic format'
        assert not ('site' in agenttopic and site is None), err

        return mqttcommon.generate_topics_dict(self.SERVER.TOPICS, prefix,
                                               agenttopic, staticfmt)
Пример #3
0
    def __init__(self, client, prefix='', site=None):
        assert site is not None
        super().__init__()

        clientid = clientcommon.clientid('radiosnifferclient')

        staticfmt = {'site': site}
        _topics = mqttcommon.generate_topics_dict(self.SERVER.TOPICS, prefix,
                                                  self.SERVER.AGENTTOPIC,
                                                  staticfmt)

        _print_wrapper = self.async_print_handle_readlinebuff()
        error_cb = _print_wrapper(self.error_cb)
        raw_cb = _print_wrapper(self.raw_handler)
        self.topics = {
            'raw':
            mqttcommon.ChannelClient(_topics['noderaw'], raw_cb),
            'rawheader':
            mqttcommon.RequestClient(_topics['raw'],
                                     'rawheader',
                                     clientid=clientid),
            'rawstart':
            mqttcommon.RequestClient(_topics['noderaw'],
                                     'start',
                                     clientid=clientid),
            'stop':
            mqttcommon.RequestClient(_topics['node'],
                                     'stop',
                                     clientid=clientid),
            'stopall':
            mqttcommon.RequestClient(_topics['agenttopic'],
                                     'stopall',
                                     clientid=clientid),
            'error':
            mqttcommon.ErrorClient(_topics['agenttopic'], callback=error_cb),
        }

        self.pcap_files = PcapFiles()
        self.client = client
        self.client.topics = list(self.topics.values())
Пример #4
0
    def __init__(self, client, prefix, site=None):
        assert site is not None
        super().__init__()

        clientid = clientcommon.clientid('nodeclient')

        staticfmt = {'site': site}
        _topics = mqttcommon.generate_topics_dict(self.SERVER.TOPICS, prefix,
                                                  self.SERVER.AGENTTOPIC,
                                                  staticfmt)

        _print_wrapper = self.async_print_handle_readlinebuff()
        error_cb = _print_wrapper(self.error_cb)

        self.topics = {
            'reset':
            mqttcommon.RequestClient(_topics['node'],
                                     'reset',
                                     clientid=clientid),
            'update':
            mqttcommon.RequestClient(_topics['node'],
                                     'update',
                                     clientid=clientid),
            'poweron':
            mqttcommon.RequestClient(_topics['node'],
                                     'poweron',
                                     clientid=clientid),
            'poweroff':
            mqttcommon.RequestClient(_topics['node'],
                                     'poweroff',
                                     clientid=clientid),
            'error':
            mqttcommon.ErrorClient(_topics['agenttopic'], callback=error_cb),
        }

        self.client = client
        self.client.topics = list(self.topics.values())
Пример #5
0
    def __init__(self, client, prefix, agenttopic):
        _topics = mqttcommon.generate_topics_dict(PROCESS_SERVER.TOPICS,
                                                  prefix, agenttopic)

        clientid = clientcommon.clientid('customprocessclient')
        # Copied from clients/process.py
        self.topics = {
            'new':
            mqttcommon.RequestClient(_topics['agenttopic'],
                                     'new',
                                     clientid=clientid),
            'list':
            mqttcommon.RequestClient(_topics['agenttopic'],
                                     'list',
                                     clientid=clientid),
            'free':
            mqttcommon.RequestClient(_topics['agenttopic'],
                                     'free',
                                     clientid=clientid),
            'freeall':
            mqttcommon.RequestClient(_topics['agenttopic'],
                                     'freeall',
                                     clientid=clientid),

            # I use common callback for all processes
            'procrun':
            mqttcommon.RequestClient(_topics['process'],
                                     'run',
                                     clientid=clientid),
            'procpoll':
            mqttcommon.RequestClient(_topics['process'],
                                     'poll',
                                     clientid=clientid),
            'prockill':
            mqttcommon.RequestClient(_topics['process'],
                                     'kill',
                                     clientid=clientid),
            'procrerun':
            mqttcommon.RequestClient(_topics['process'],
                                     'rerun',
                                     clientid=clientid),
            'procstdin':
            mqttcommon.InputClient(_topics['procstdin']),
            'procstdout':
            mqttcommon.OutputClient(_topics['procstdout'],
                                    callback=self._stdout_cb),
            'procstderr':
            mqttcommon.OutputClient(_topics['procstderr'],
                                    callback=self._stderr_cb),
            'procret':
            mqttcommon.OutputClient(_topics['procret'],
                                    callback=self._returncode_cb),
            'error':
            mqttcommon.ErrorClient(_topics['agenttopic'],
                                   callback=self.error_cb),
        }
        self._rlock = threading.RLock()
        self._process_queues = {}

        self.client = client
        self.client.topics = list(self.topics.values())