Esempio n. 1
0
async def register(websocket: WsClient) -> None:

    glob.logger.info("Registering new ui")
    glob.USERS.add_interface(websocket)

    if glob.LOCK.project:
        assert glob.LOCK.scene
        await notif.event(
            websocket,
            evts.p.OpenProject(
                evts.p.OpenProject.Data(glob.LOCK.scene.scene,
                                        glob.LOCK.project.project)))
    elif glob.LOCK.scene:
        await notif.event(
            websocket,
            evts.s.OpenScene(evts.s.OpenScene.Data(glob.LOCK.scene.scene)))
    elif glob.PACKAGE_INFO:

        # this can't be done in parallel - ui expects this order of events
        await websocket.send(events.PackageState(glob.PACKAGE_STATE).to_json())
        await websocket.send(events.PackageInfo(glob.PACKAGE_INFO).to_json())

        if glob.ACTION_STATE_BEFORE:
            await websocket.send(
                events.ActionStateBefore(glob.ACTION_STATE_BEFORE).to_json())
    else:
        assert glob.MAIN_SCREEN
        await notif.event(websocket, evts.c.ShowMainScreen(glob.MAIN_SCREEN))

    if glob.LOCK.project or glob.LOCK.scene:
        await notif.event(websocket, scene.get_scene_state())
Esempio n. 2
0
async def start_scene_cb(req: srpc.s.StartScene.Request, ui: WsClient) -> None:

    scene = glob.LOCK.scene_or_exception()

    if get_scene_state(
    ).data.state != sevts.s.SceneState.Data.StateEnum.Stopped:
        raise Arcor2Exception("Scene not stopped.")

    # online scene can't be modified so we demand that UIs free all their locks first
    # when editing project, changes can be done both online and offline
    if not glob.LOCK.project and await glob.LOCK.get_write_locks_count():
        raise LockingException(glob.LOCK.ErrMessages.SOMETHING_LOCKED.value)

    if await glob.LOCK.is_write_locked(glob.LOCK.SpecialValues.SCENE_NAME,
                                       glob.LOCK.SpecialValues.SERVER_NAME):
        raise Arcor2Exception("Scene locked.")

    if await glob.LOCK.is_write_locked(glob.LOCK.SpecialValues.PROJECT_NAME,
                                       glob.LOCK.SpecialValues.SERVER_NAME):
        raise Arcor2Exception("Project locked.")

    if req.dry_run:
        return

    asyncio.ensure_future(start_scene(scene))
Esempio n. 3
0
async def start_scene_cb(req: srpc.s.StartScene.Request, ui: WsClient) -> None:

    if get_scene_state() != sevts.s.SceneState.Data.StateEnum.Stopped:
        raise Arcor2Exception("Scene not stopped.")

    if req.dry_run:
        return

    asyncio.ensure_future(start_scene())
Esempio n. 4
0
async def stop_scene_cb(req: srpc.s.StopScene.Request, ui: WsClient) -> None:

    # TODO it should not be possible to stop scene while some action runs

    if get_scene_state() != sevts.s.SceneState.Data.StateEnum.Started:
        raise Arcor2Exception("Scene not started.")

    if req.dry_run:
        return

    asyncio.ensure_future(stop_scene())
Esempio n. 5
0
async def stop_scene_cb(req: srpc.s.StopScene.Request, ui: WsClient) -> None:

    scene = glob.LOCK.scene_or_exception()

    if get_scene_state(
    ).data.state != sevts.s.SceneState.Data.StateEnum.Started:
        raise Arcor2Exception("Scene not started.")

    if await glob.LOCK.is_write_locked(glob.LOCK.SpecialValues.SCENE_NAME,
                                       glob.LOCK.SpecialValues.SERVER_NAME):
        raise Arcor2Exception("Scene locked.")

    if await glob.LOCK.is_write_locked(glob.LOCK.SpecialValues.PROJECT_NAME,
                                       glob.LOCK.SpecialValues.SERVER_NAME):
        raise Arcor2Exception("Project locked.")

    if glob.RUNNING_ACTION:  # TODO acquire lock?
        raise Arcor2Exception("There is a running action.")

    if req.dry_run:
        return

    asyncio.ensure_future(stop_scene(scene))
Esempio n. 6
0
async def notify_project_opened(evt: OpenProject) -> None:

    await notif.broadcast_event(evt)
    await notif.broadcast_event(get_scene_state())