コード例 #1
0
ファイル: bcp.py プロジェクト: Clohman11/mpf
    def _setup_bcp_connections(self, queue: QueuedEvent, **kwargs):
        """Connect to BCP servers from MPF config."""
        del kwargs
        if ('connections' not in self.machine.config['bcp'] or not
                self.machine.config['bcp']['connections']):
            return

        client_connect_futures = []
        for name, settings in self.machine.config['bcp']['connections'].items():
            self.machine.events.post('bcp_connection_attempt',
                                     name=name,
                                     host=settings['host'],
                                     port=settings['port'])
            '''event: bcp_connection_attempt
            desc: MPF is attempting to make a BCP connection.
            args:
            name: The name of the connection.
            host: The host name MPF is attempting to connect to.
            port: The TCP port MPF is attempting to connect to'''

            client = Util.string_to_class(settings['type'])(self.machine, name, self.machine.bcp)
            client.exit_on_close = settings['exit_on_close']
            connect_future = asyncio.ensure_future(client.connect(settings))
            connect_future.add_done_callback(partial(self.transport.register_transport, client))
            client_connect_futures.append(connect_future)

        # block init until all clients are connected
        if client_connect_futures:
            queue.wait()
            future = asyncio.ensure_future(asyncio.wait(iter(client_connect_futures)))
            future.add_done_callback(lambda x: queue.clear())
            future.add_done_callback(self._bcp_clients_connected)
コード例 #2
0
 def _initialize_late(self, queue: QueuedEvent, **kwargs):
     """Create ball counters."""
     del kwargs
     queue.wait()
     complete_future = asyncio.ensure_future(self._initialize_async(),
                                             loop=self.machine.clock.loop)
     complete_future.add_done_callback(lambda x: queue.clear())
コード例 #3
0
ファイル: bcp.py プロジェクト: unRARed/mpf
    def _setup_bcp_servers(self, queue: QueuedEvent, **kwargs):
        """Start BCP servers to allow other clients to connect."""
        del kwargs
        if 'servers' not in self.machine.config[
                'bcp'] or not self.machine.config['bcp']['servers']:
            return

        servers_start_futures = []
        for settings in self.machine.config['bcp']['servers'].values():
            settings = self.machine.config_validator.validate_config(
                "bcp:servers", settings)
            server = BcpServer(self.machine, settings['ip'], settings['port'],
                               settings['type'])
            server_future = Util.ensure_future(server.start(),
                                               loop=self.machine.clock.loop)
            server_future.add_done_callback(
                lambda x, s=server: self.servers.append(s))
            servers_start_futures.append(server_future)

        # block init until all servers were started
        if servers_start_futures:
            queue.wait()
            future = Util.ensure_future(asyncio.wait(
                iter(servers_start_futures), loop=self.machine.clock.loop),
                                        loop=self.machine.clock.loop)
            future.add_done_callback(lambda x: queue.clear())
コード例 #4
0
ファイル: bcp.py プロジェクト: vgrillot/mpf
    def _setup_bcp_connections(self, queue: QueuedEvent, **kwargs):
        """Connect to BCP servers from MPF config."""
        del kwargs
        if ('connections' not in self.machine.config['bcp']
                or not self.machine.config['bcp']['connections']):
            return

        client_connect_futures = []
        for name, settings in self.machine.config['bcp']['connections'].items(
        ):
            settings = self.machine.config_validator.validate_config(
                "bcp:connections", settings)
            client = Util.string_to_class(settings['type'])(self.machine, name,
                                                            self.machine.bcp)
            client.exit_on_close = settings['exit_on_close']
            connect_future = Util.ensure_future(client.connect(settings),
                                                loop=self.machine.clock.loop)
            connect_future.add_done_callback(
                lambda x: self.transport.register_transport(client))
            client_connect_futures.append(connect_future)

        # block init until all clients are connected
        if client_connect_futures:
            queue.wait()
            future = Util.ensure_future(asyncio.wait(
                iter(client_connect_futures), loop=self.machine.clock.loop),
                                        loop=self.machine.clock.loop)
            future.add_done_callback(lambda x: queue.clear())
コード例 #5
0
ファイル: ball_device.py プロジェクト: vgrillot/mpf
    def _create_ball_counters(self, queue: QueuedEvent, **kwargs):
        """Create ball counters."""
        del kwargs
        if self.config['ball_switches']:
            self.counter = SwitchCounter(self, self.config)
        else:
            self.counter = EntranceSwitchCounter(self, self.config)

        queue.wait()
        complete_future = Util.ensure_future(self._initialize_async(), loop=self.machine.clock.loop)
        complete_future.add_done_callback(lambda x: queue.clear())
コード例 #6
0
    def _stop_game_modes(self, queue: QueuedEvent, **kwargs):
        """Stop all game modes and wait until they stopped."""
        del kwargs
        self._stopping_modes = []
        for mode in self.machine.modes.values():
            if mode.is_game_mode and mode.active:
                self._stopping_modes.append(mode)
                mode.stop(callback=partial(self._game_mode_stopped, mode=mode))

        if self._stopping_modes:
            queue.wait()
            self._stopping_queue = queue