Exemplo n.º 1
0
    def deleteSituations(self, sitInCtxt, context):
        logger.debug("Got <deleteSituations> from %s" %
                     sitInCtxt.context.client)
        self._update_current_links(sitInCtxt.context.client,
                                   sitInCtxt.context.world, PROVIDER)

        client_id, world = sitInCtxt.context.client, sitInCtxt.context.world
        _, timeline = self._get_scene_timeline(sitInCtxt.context)

        situations_to_invalidate_delete = []
        for gRPCSit in sitInCtxt.situations:

            situation = Situation.deserialize(gRPCSit)

            timeline.remove(situation)

            logger.info("<%s> deleted situation <%s> in world <%s>" % \
                                (self._clientname(client_id),
                                repr(situation),
                                world))

            # tells everyone about the change
            logger.debug("Sent invalidation action [delete]")
            situations_to_invalidate_delete.append(situation.id)

        if situations_to_invalidate_delete:
            self._emit_invalidation(gRPC.Invalidation.TIMELINE, world,
                                    situations_to_invalidate_delete, DELETE)

        logger.debug("<deleteSituations> completed")
        return gRPC.Empty()
Exemplo n.º 2
0
    def byebye(self, client, context):
        logger.debug("Got <byebye> from %s" % (self._clientname(client.id)))

        with self._client_lock:
            self._clients[client.id].close()
            del self._clients[client.id]

        logger.debug("<byebye> completed")
        return gRPC.Empty()
Exemplo n.º 3
0
    def pushMesh(self, meshInCtxt, context):
        logger.debug("Got <pushMesh> from %s" % meshInCtxt.client.id)

        mesh_id = meshInCtxt.mesh.id
        self.meshes[mesh_id] = meshInCtxt.mesh

        logger.info("<%s> added a new mesh ID %s (%d faces)" % \
                                (self._clientname(meshInCtxt.client.id),
                                mesh_id,
                                len(self.meshes[mesh_id].faces)))

        logger.debug("<pushMesh> completed")
        return gRPC.Empty()
Exemplo n.º 4
0
    def deleteNodes(self, nodesInCtxt, context):
        logger.debug("Got <deleteNodes> from %s" % nodesInCtxt.context.client)
        self._update_current_links(nodesInCtxt.context.client,
                                   nodesInCtxt.context.world, PROVIDER)

        client_id, world = nodesInCtxt.context.client, nodesInCtxt.context.world
        scene, _ = self._get_scene_timeline(nodesInCtxt.context)

        nodes_to_invalidate_delete = []
        nodes_to_invalidate_update = []
        for gRPCNode in nodesInCtxt.nodes:
            node = scene.node(gRPCNode.id)
            logger.info("<%s> deleted node <%s> in world <%s>" % \
                                (self._clientname(client_id),
                                repr(node),
                                world))

            action = self._delete_node(scene, gRPCNode.id)

            # tells everyone about the change
            logger.debug("Sent invalidation action [delete]")
            nodes_to_invalidate_delete.append(gRPCNode.id)

            # reparent children to the scene's root node
            children_to_update = []
            for child_id in node.children:
                child = scene.node(child_id)
                child.parent = scene.rootnode.id
                logger.debug("Reparenting child " + child_id + " to root node")
                nodes_to_invalidate_update.append(child_id)

            # Also remove the node from its parent's children
            parent = scene.node(node.parent)
            if parent:
                parent._children.remove(node.id)
                # tells everyone about the change to the parent
                logger.debug("Sent invalidation action [update " + parent.id +
                             "] due to hierarchy update")
                nodes_to_invalidate_update.append(parent.id)

        if nodes_to_invalidate_update:
            self._emit_invalidation(gRPC.Invalidation.SCENE, world,
                                    nodes_to_invalidate_update, UPDATE)
        if nodes_to_invalidate_delete:
            self._emit_invalidation(gRPC.Invalidation.SCENE, world,
                                    nodes_to_invalidate_delete, DELETE)

        logger.debug("<deleteNodes> completed")
        return gRPC.Empty()
Exemplo n.º 5
0
    def reset(self, client, context):
        logger.debug("Got <reset> from %s" % client.id)
        logger.warning("Resetting Underworlds upon client <%s> request" %
                       client.id)
        logger.warning("This might break other clients!")

        self._worlds = {}

        with self._client_lock:
            for cid, c in self._clients.items():
                c.reset_links()

        logger.debug("<reset> completed")

        return gRPC.Empty()
Exemplo n.º 6
0
    def emitInvalidation(self, invalidation, context):
        logger.info("Got <emitInvalidation> for world <%s>" %
                    invalidation.world)

        target, action, world, ids = invalidation.target, invalidation.type, invalidation.world, invalidation.ids

        if target == gRPC.Invalidation.SCENE:
            if action == UPDATE:
                logger.debug("Server notification: nodes updated: " + str(ids))
                self.ctx.worlds[world].scene.nodes._on_remotely_updated_nodes(
                    ids)
            elif action == NEW:
                logger.debug("Server notification: nodes added: " + str(ids))
                self.ctx.worlds[world].scene.nodes._on_remotely_added_nodes(
                    ids)
            elif action == DELETE:
                logger.debug("Server notification: nodes deleted: " + str(ids))
                self.ctx.worlds[world].scene.nodes._on_remotely_deleted_nodes(
                    ids)
            else:
                raise RuntimeError("Unexpected invalidation action")

        elif target == gRPC.Invalidation.TIMELINE:
            if action == UPDATE:
                logger.debug("Server notification: situations updated: " +
                             str(ids))
                self.ctx.worlds[
                    world].timeline._on_remotely_updated_situations(ids)
            elif action == NEW:
                logger.debug("Server notification: situations added: " +
                             str(ids))
                self.ctx.worlds[world].timeline._on_remotely_added_situations(
                    ids)
            elif action == DELETE:
                logger.debug("Server notification: situations deleted: " +
                             str(ids))
                self.ctx.worlds[
                    world].timeline._on_remotely_deleted_situations(ids)
            else:
                raise RuntimeError("Unexpected invalidation action")
        else:
            raise RuntimeError("Unexpected invalidation target")

        return gRPC.Empty()
Exemplo n.º 7
0
    def updateSituations(self, sitInCtxt, context):
        logger.debug("Got <updateSituations> from %s" %
                     sitInCtxt.context.client)
        self._update_current_links(sitInCtxt.context.client,
                                   sitInCtxt.context.world, PROVIDER)

        client_id, world = sitInCtxt.context.client, sitInCtxt.context.world
        _, timeline = self._get_scene_timeline(sitInCtxt.context)

        situations_to_invalidate_update = []
        situations_to_invalidate_new = []
        for gRPCSit in sitInCtxt.situations:

            situation = Situation.deserialize(gRPCSit)

            invalidation_type = self._update_situation(timeline, situation)

            logger.info("<%s> updated situation <%s> in world <%s>" % \
                                (self._clientname(client_id),
                                repr(situation),
                                world))

            logger.debug("Adding invalidation action [" +
                         str(INVALIDATIONTYPE_NAMES[invalidation_type]) + " " +
                         repr(situation) + "]")

            if invalidation_type == UPDATE:
                situations_to_invalidate_update.append(situation.id)
            elif invalidation_type == NEW:
                situations_to_invalidate_new.append(situation.id)
            else:
                raise RuntimeError("Unexpected invalidation type")

        if situations_to_invalidate_update:
            self._emit_invalidation(gRPC.Invalidation.TIMELINE, world,
                                    situations_to_invalidate_update, UPDATE)
        if situations_to_invalidate_new:
            self._emit_invalidation(gRPC.Invalidation.TIMELINE, world,
                                    situations_to_invalidate_new, NEW)

        logger.debug("<updateSituations> completed")
        return gRPC.Empty()
Exemplo n.º 8
0
    def updateNodes(self, nodesInCtxt, context):
        logger.debug("Got <updateNodes> from %s" % nodesInCtxt.context.client)
        self._update_current_links(nodesInCtxt.context.client,
                                   nodesInCtxt.context.world, PROVIDER)

        client_id, world = nodesInCtxt.context.client, nodesInCtxt.context.world
        scene, _ = self._get_scene_timeline(nodesInCtxt.context)

        nodes_to_invalidate_new = []
        nodes_to_invalidate_update = []
        for gRPCNode in nodesInCtxt.nodes:
            node = Node.deserialize(gRPCNode)

            invalidation_type, parent_has_changed = self._update_node(
                scene, node)

            logger.info("<%s> %s node <%s> in world <%s>" % \
                                (self._clientname(client_id),
                                "updated" if invalidation_type==UPDATE else "created",
                                repr(node),
                                world))

            if invalidation_type == UPDATE:
                nodes_to_invalidate_update.append(gRPCNode.id)
            elif invalidation_type == NEW:
                nodes_to_invalidate_new.append(gRPCNode.id)
            else:
                raise RuntimeError("Unexpected invalidation type")

            ## If necessary, update the node hierarchy
            if parent_has_changed:
                parent = scene.node(node.parent)
                if parent is None:
                    logger.warning(
                        "Node %s references a non-exisiting parent" % node)
                elif node.id not in parent.children:
                    parent._children.append(node.id)
                    # tells everyone about the change to the parent
                    logger.debug("Adding invalidation action [update " +
                                 parent.id + "] due to hierarchy update")
                    nodes_to_invalidate_update.append(parent.id)

                    # As a node has only one parent, if the parent has changed we must
                    # remove our node from its previous parent
                    for othernode in scene.nodes:
                        if othernode.id != parent.id and node.id in othernode.children:
                            othernode._children.remove(node.id)
                            # tells everyone about the change to the former parent
                            logger.debug(
                                "Adding invalidation action [update " +
                                othernode.id + "] due to hierarchy update")
                            nodes_to_invalidate_update.append(othernode.id)
                            break

        if nodes_to_invalidate_update:
            self._emit_invalidation(gRPC.Invalidation.SCENE, world,
                                    nodes_to_invalidate_update, UPDATE)
        if nodes_to_invalidate_new:
            self._emit_invalidation(gRPC.Invalidation.SCENE, world,
                                    nodes_to_invalidate_new, NEW)

        logger.debug("<updateNodes> completed")
        return gRPC.Empty()