コード例 #1
0
class TestWorldMapStreamWriter(object):

    SAMPLE_IMAGE = object()
    SAMPLE_WORLD_IMAGE = object()
    
    @mock.patch('services.virtual_mapping.WorldMapService.WorldMapService', autospec = False)
    @mock.patch('services.pathfinding.PathfindingService.PathfindingService', autospec = False)
    @mock.patch('services.video_streaming.stream_writers.InMemoryBufferedStreamWriter.InMemoryBufferedStreamWriter', autospec = False)
    def setup(self, world_map_service_mock, pathfinding_service_mock, stream_writer_mock):
        self._stream_writer_mock = stream_writer_mock
        world_map_service_mock.draw_world_map.return_value = self.SAMPLE_WORLD_IMAGE
        pathfinding_service_mock.draw.return_value = self.SAMPLE_WORLD_IMAGE
        self._map_drawing_stream_writer = WorldMapStreamWriter(world_map_service_mock, pathfinding_service_mock)
        self._map_drawing_stream_writer.add_output_stream_writer(stream_writer_mock)

    def test_when_writing_images_then_image_is_written_to_output_stream_writer(self):
        self._map_drawing_stream_writer.write(self.SAMPLE_IMAGE)
        self._stream_writer_mock.write.assert_called_with(self.SAMPLE_WORLD_IMAGE)
コード例 #2
0
ファイル: BaseStationMain.py プロジェクト: orobert91/Design3
 def _init_video_streaming_service(self):
     self._original_stream_buffer = InMemoryBufferedStreamWriter(self.VIDEO_STREAM_BUFFER_SIZE)
     self._processed_stream_buffer = InMemoryBufferedStreamWriter(self.VIDEO_STREAM_BUFFER_SIZE)
     self._world_map_stream_writer = WorldMapStreamWriter(self._world_map_service, self._pathfinding_service)
     self._world_map_stream_writer.add_output_stream_writer(self._processed_stream_buffer)
     self._video_stream_dispatcher = VideoStreamDispatcher(Image.from_file(self.DEFAULT_STREAM_IMAGE_FILE_NAME))
     self._video_stream_dispatcher.add_stream_writer(self._original_stream_buffer)
     self._video_stream_dispatcher.add_stream_writer(self._world_map_stream_writer)
     self._tcp_stream_reader = TcpStreamReader(self.STREAMING_SERVER_IP_ADDRESS, self.STREAMING_SERVER_PORT, self.VIDEO_STREAM_BUFFER_SIZE, False)
     self._video_streaming_service = VideoStreamingService(self._video_stream_dispatcher, self._original_stream_buffer, self._processed_stream_buffer, self._tcp_stream_reader)
コード例 #3
0
ファイル: BaseStationMain.py プロジェクト: orobert91/Design3
class BaseStationApplication(object):

    LOGGING_DIRECTORY = "../data/logs"
    IMAGE_LOGGING_DIRECTORY = "../data/logs/images"
    SERVER_PORT = 8080
    REMOTE_SERVER_PORT = 8081
    STREAMING_SERVER_PORT = 5000
    STREAMING_SERVER_IP_ADDRESS = "192.168.0.60"
    REMOTE_SERVER_IP_ADDRESS = "192.168.0.60"
    DEFAULT_STREAM_IMAGE_FILE_NAME = "../resources/default-stream-image.png"
    VIDEO_STREAM_BUFFER_SIZE = 1

    def initialize(self):
        #ptvsd.enable_attach(secret = 'd3sign3')

        self._init_logging()
        self._init_services()
        self._embedded_application = RemotableOf(EmbeddedApplication, self._remoting_client)
        self._init_web_app()
        self._logger.close()

    def _init_logging(self):
        self._logger = Logger()
        self._logger.similar_log_entry_skip_interval = 0
        self._csv_log_subscriber = CsvLogSubscriber(self.LOGGING_DIRECTORY)
        self._image_log_subscriber = ImageLogSubscriber(self.IMAGE_LOGGING_DIRECTORY)
        self._console_log_subscriber = ConsoleLogSubscriber()
        self._logger.subscribe(self._csv_log_subscriber)
        self._logger.subscribe(self._image_log_subscriber)
        self._logger.subscribe(self._console_log_subscriber)

    def _init_services(self):
        self._init_remoting_services()
        self._coordinate_factory = CoordinateFactory()
        self._world_map_service = WorldMapService(self._coordinate_factory)
        self._local_world_map_service =  RemotableOf(LocalWorldMapService, self._remoting_client)
        self._pathfinding_service = PathfindingService(Pathfinder(PathSimplifier()), self._world_map_service, self._coordinate_factory)
        self._embedded_video_streaming_service = RemotableOf(VideoStreamingService, self._remoting_client)
        self._movement_executor = RemotableOf(MovementExecutor, self._remoting_client)
        self._path_navigator = PathNavigator(self._movement_executor, self._world_map_service, self._coordinate_factory)
        self._motion_service = MotionService(self._movement_executor, self._path_navigator)
        self._hardware_status_collector_service = RemotableOf(HardwareStatusCollectorService, self._remoting_client)
        self._secret_code_decoding_service = RemotableOf(SecretCodeDecodingService, self._remoting_client)
        self._treasure_handling_service = RemotableOf(TreasureHandlingService, self._remoting_client)
        self._camera_arm_control_service = RemotableOf(CameraArmControlService, self._remoting_client)
        self._game_cycle_control_service = GameCycleControlService(StateFactory(), self._world_map_service, self._pathfinding_service, self._motion_service, self._secret_code_decoding_service, self._treasure_handling_service, self._hardware_status_collector_service, self._local_world_map_service)
        self._init_video_streaming_service()

    def _init_video_streaming_service(self):
        self._original_stream_buffer = InMemoryBufferedStreamWriter(self.VIDEO_STREAM_BUFFER_SIZE)
        self._processed_stream_buffer = InMemoryBufferedStreamWriter(self.VIDEO_STREAM_BUFFER_SIZE)
        self._world_map_stream_writer = WorldMapStreamWriter(self._world_map_service, self._pathfinding_service)
        self._world_map_stream_writer.add_output_stream_writer(self._processed_stream_buffer)
        self._video_stream_dispatcher = VideoStreamDispatcher(Image.from_file(self.DEFAULT_STREAM_IMAGE_FILE_NAME))
        self._video_stream_dispatcher.add_stream_writer(self._original_stream_buffer)
        self._video_stream_dispatcher.add_stream_writer(self._world_map_stream_writer)
        self._tcp_stream_reader = TcpStreamReader(self.STREAMING_SERVER_IP_ADDRESS, self.STREAMING_SERVER_PORT, self.VIDEO_STREAM_BUFFER_SIZE, False)
        self._video_streaming_service = VideoStreamingService(self._video_stream_dispatcher, self._original_stream_buffer, self._processed_stream_buffer, self._tcp_stream_reader)

    def _init_remoting_services(self):
        self._remote_method_invoker = RemoteMethodInvoker(JsonSerializer())
        self._remoting_client = RemotingClient(self._remote_method_invoker, self.REMOTE_SERVER_IP_ADDRESS, self.REMOTE_SERVER_PORT)

    def _init_web_app(self):
        self._web_server = WebServer(self.SERVER_PORT, self._logger, self._embedded_application, self._remoting_client, self._world_map_service,
                                     self._local_world_map_service, self._pathfinding_service, self._video_streaming_service, self._embedded_video_streaming_service, self._game_cycle_control_service, 
                                     self._motion_service, self._hardware_status_collector_service, self._secret_code_decoding_service, self._treasure_handling_service, self._camera_arm_control_service)
        self._web_server.run()
コード例 #4
0
 def setup(self, world_map_service_mock, pathfinding_service_mock, stream_writer_mock):
     self._stream_writer_mock = stream_writer_mock
     world_map_service_mock.draw_world_map.return_value = self.SAMPLE_WORLD_IMAGE
     pathfinding_service_mock.draw.return_value = self.SAMPLE_WORLD_IMAGE
     self._map_drawing_stream_writer = WorldMapStreamWriter(world_map_service_mock, pathfinding_service_mock)
     self._map_drawing_stream_writer.add_output_stream_writer(stream_writer_mock)