Beispiel #1
0
    def run(self):
        name = self.getName()

        logger.info('%s started!'%name)
        while True:
            try:
                operation = self.queue.get()

                if operation == FINISH_FLAG:
                    logger.info('%s stoped!'%name)
                    break

                try:
                    PluginManager.process(operation)
                except Exception, err:
                    logger.error('Processing operation %s failed! Details: %s.\
                                  \nInput parameters: session_id=%s, node=%s, parameters=%s'%
                                    (operation.operation_name, err, operation.session_id,
                                    operation.node, operation.parameters))

                op_args = Dictionary(signature='ss')
                op_args.update(operation.parameters)
                self.dbus_client.operationProcessedEvent(str(operation.session_id), str(operation.node), 
                                    str(operation.operation_name), op_args)
            except Exception, err:
                logger.error('%s failed: %s'%(name, err))
    def _contacts_changed(self):
        changes = Dictionary(signature='u(uus)')
        identifiers = Dictionary(signature='us')
        removals = Dictionary(signature='us')

        for contact in CONTACTS:
            handle = self.ensure_handle(HANDLE_TYPE_CONTACT, contact)
            changes[handle] = Struct((True, True, ''), signature='uus')
            identifiers[handle] = contact

        self.ContactsChangedWithID(changes, identifiers, removals)
        self.ContactsChanged(changes, Array([], signature='u'))
Beispiel #3
0
    def _send_message(self, message, flags, token):
        headers = Dictionary({
            String('message-sent'): UInt64(time()),
            String('message-type'): UInt32(CHANNEL_TEXT_MESSAGE_TYPE_NORMAL),
        }, signature='sv')
        body = Dictionary({
            String('content-type'): String('text/plain'),
            String('content'): message[1]['content'],
        }, signature='sv')
        message = Array([headers, body], signature='a{sv}')
        self.MessageSent(message, flags, String(token))

        gobject.timeout_add(50, self._message_received, str(message[1]['content']))
Beispiel #4
0
 def _message_received(self, msg):
     self.__message_received_id += 1
     header = Dictionary({
         'pending-message-id': UInt32(self.__message_received_id),
         'message-received': UInt64(time()),
         'message-sender': UInt32(self.handle),
         'message-type': UInt32(CHANNEL_TEXT_MESSAGE_TYPE_NORMAL),
         'sender-nickname': String(self.handle.get_name()),
         }, signature='sv')
     body = Dictionary({
         String('content-type'): String('text/plain'),
         String('content'): String(msg),
     }, signature='sv')
     message = Array([header, body], signature='a{sv}')
     self.MessageReceived(message)
 def GetPresences(self, contacts):
     presences = Dictionary(signature='u(uss)')
     for handle_id in contacts:
         handle = self.handle(HANDLE_TYPE_CONTACT, handle_id)
         presences[handle] = Struct(
             (CONNECTION_PRESENCE_TYPE_AVAILABLE, CONNECTION_PRESENCE_STATUS_AVAILABLE, "avail"),
             signature='uss',
         )
     return presences
Beispiel #6
0
    def onDataReceive( self, json_object ):
        #get session_id
        session_id = json_object.get('id', None)
        if session_id is None:
            raise Exception('Element <id> is not found in FRI packet!')

        try:
            session_id = int(session_id)
        except:
            raise Exception('Session is should be integer! But: %s'%session_id)

        if session_id == 0: #LIVE packet
            return


        #get node
        node = json_object.get('node', None)
        if not node:
            raise Exception('Element <node> is not found in FRI packet!')
        node = node.strip()

        #get operation
        operation = json_object.get('operation', None)
        if not operation:
            raise Exception('Element <operation> is not found in FRI packet')
        operation = operation.strip()

        #get parameters
        parameters = json_object.get('parameters', None)

        #send message to D-BUS
        op_args = Dictionary(signature='ss')
        op_args.update(parameters)
        self.dbus_client.operationReceivedEvent(str(session_id), str(node), str(operation), op_args)

        #check appropriate plugin
        can_process = PluginManager.can_process_operation( operation )
        if not can_process:
            raise Exception('NodeAgent can not process operation %s. No appropriate plugin found!'%operation)

        op = Operation(session_id, node, operation, parameters)

        self.__operations_queue.put(op)
    def GetContactListAttributes(self, interfaces, hold):
        ret = Dictionary(signature='ua{sv}')
        for contact in CONTACTS:
            handle = self.ensure_handle(HANDLE_TYPE_CONTACT, contact)
            ret[int(handle)] = Dictionary(signature='sv')
            ret[int(handle)][CONNECTION + '/contact-id'] = contact
            ret[int(handle)][CONNECTION_INTERFACE_ALIASING + '/alias'] = contact
            ret[int(handle)][CONNECTION_INTERFACE_AVATARS + '/token'] = contact
            ret[int(handle)][CONNECTION_INTERFACE_CONTACT_LIST + '/subscribe'] = SUBSCRIPTION_STATE_YES
            ret[int(handle)][CONNECTION_INTERFACE_CONTACT_LIST + '/publish'] = SUBSCRIPTION_STATE_YES
            ret[int(handle)][CONNECTION_INTERFACE_CONTACT_GROUPS + '/groups'] = Array([String(GROUP)], signature='s')
            ret[int(handle)][CONNECTION_INTERFACE_SIMPLE_PRESENCE + '/presence'] = Struct(
                (CONNECTION_PRESENCE_TYPE_AVAILABLE, CONNECTION_PRESENCE_STATUS_AVAILABLE, "avail"),
                signature='uss',
            )
            ret[int(handle)][CONNECTION_INTERFACE_CONTACT_INFO + '/info'] = Array([
                    Struct(('nickname', Array([], signature='s'), Array([contact], signature='s')), signature='sasas'),
                    Struct(('email', Array([], signature='s'), Array([contact+'@example.com'], signature='s')), signature='sasas'),
                ]
            )

        return ret
 def GetKnownAvatarTokens(self, contacts):
     tokens = Dictionary(signature='us')
     for handle_id in contacts:
         handle = self.handle(HANDLE_TYPE_CONTACT, handle_id)
         tokens[handle_id] = String(handle.name)
     return tokens
 def GetAliases(self, contacts):
     aliases = Dictionary(signature='us')
     for handle_id in contacts:
         handle = self.handle(HANDLE_TYPE_CONTACT, handle_id)
         aliases[handle_id] = String(handle.name)
     return aliases