Example #1
0
    def __handle_message(self, client, id, bindata):

        if message.is_control(id):

            log.debug("control from client %s" % client)

            self.__handle_message_control(id, bindata)

        elif message.is_action(id):

            log.debug("action from client %s" % client)

            self.__handle_message_action(id, bindata)

        elif message.is_request(id):

            log.debug("request from client %s" % client)

            self.__handle_message_request(client, id, bindata)

        elif id == message.PRIV_INITIAL_SYNC:

            msg = net.build_message(message.SYNC_STATE, self.__state)
            client.send(msg)

            msg = net.build_message(message.SYNC_PROGRESS, self.__progress)
            client.send(msg)

            msg = net.build_message(message.SYNC_ITEM, self.__item(client))
            client.send(msg)

        else:
            log.error("** BUG ** unexpected message: %d" % id)
Example #2
0
    def send(self):
        """Send the requested item list to the requesting client."""

        ### paging ###

        page_size = self.__client.info.page_size
        len_all = len(self.__ids or []) + len(self.__nested or [])
        # P3K: remove float() and int()
        page_max = int(max(math.ceil(float(len_all) / page_size) - 1, 0))

        # number of pages may have changed since client sent the request
        self.__page = min(self.__page, page_max)

        index_start = self.__page * page_size
        index_end = index_start + page_size

        nested, ids, names = [], [], []
        item_offset = 0

        if self.__nested and index_start < len(self.__nested):
            # page contains nested lists and maybe items
            nested = self.__nested[index_start:index_end]
            if len(nested) < page_size:
                # page contains nested lists and items
                num_items = page_size - len(nested)
                ids = self.__ids[0:num_items]
                names = self.__names[0:num_items]
        else:
            # page contains only items
            index_start -= len(self.__nested)
            index_end -= len(self.__nested)
            ids = self.__ids[index_start:index_end]
            names = self.__names[index_start:index_end]
            item_offset = index_start

        ### sending ###

        ilist = ItemList(
            self.__request_id,
            self.__path,
            nested,
            ids,
            names,
            item_offset,
            self.__page,
            page_max,
            self.__item_actions,
            self.__list_actions,
        )

        msg = net.build_message(self.__reply_msg_id, ilist)

        gobject.idle_add(self.__client.send, msg)
Example #3
0
    def __sync_item(self):

        del self.__sync_triggers[self.__sync_item]

        log.debug("broadcast new item to clients: %s" % self.__item_id)

        for c in self.__clients:

            msg = net.build_message(message.SYNC_ITEM, self.__item(c))

            if msg is not None:
                c.send(msg)

        return False
Example #4
0
    def __sync_progress(self):

        del self.__sync_triggers[self.__sync_progress]

        log.debug("broadcast new progress to clients: %s" % self.__progress)

        msg = net.build_message(message.SYNC_PROGRESS, self.__progress)

        if msg is None:
            return

        for c in self.__clients:
            c.send(msg)

        return False
Example #5
0
    def __sync_state(self):

        del self.__sync_triggers[self.__sync_state]

        log.debug("broadcast new state to clients: %s" % self.__state)

        msg = net.build_message(message.SYNC_STATE, self.__state)

        if msg is None:
            return

        for c in self.__clients:
            c.send(msg)

        return False