Example #1
0
 def subscribe_tell(self, tell_type):
     msg = KQMLPerformative('subscribe')
     content = KQMLList('tell')
     content.append('&key')
     content.set('content', KQMLList.from_string('(%s . *)' % tell_type))
     msg.set('content', content)
     self.send(msg)
Example #2
0
 def subscribe_request(self, req_type):
     msg = KQMLPerformative('subscribe')
     content = KQMLList('request')
     content.append('&key')
     content.set('content', KQMLList.from_string('(%s . *)' % req_type))
     msg.set('content', content)
     self.send(msg)
Example #3
0
 def receive_request(self, msg, content):
     if not isinstance(content, KQMLList):
         self.error_reply(msg, "expected :content to be a list")
         return
     verb = content[0].to_string().lower()
     if verb == "hello":
         reply_msg = KQMLPerformative("tell")
         reply_content = KQMLList()
         reply_content.add("hello")
         sender = msg.get_parameter(":sender")
         if sender is not None:
             reply_content.add(sender)
         reply_msg.set_parameter(":content", reply_content)
         self.reply(msg, reply_msg)
     else:
         self.error_reply(msg, "unknown request verb " + verb)
Example #4
0
 def init(self):
     self.name = "hello"
     TripsModule.init(self)
     self.send(
         KQMLPerformative.from_string(
             "(subscribe :content (request &key :content (hello . *)))"))
     self.ready()
Example #5
0
 def register(self):
     if self.name is not None:
         perf = KQMLPerformative('register')
         perf.set('name', self.name)
         if self.group_name is not None:
             try:
                 if self.group_name.startswith('('):
                     perf.sets('group', self.group_name)
                 else:
                     perf.set('group', self.group_name)
             except IOError:
                 logger.error('bad group name: ' + self.group_name)
         self.send(perf)
Example #6
0
 def error_reply(self, msg, comment):
     reply_msg = KQMLPerformative('error')
     reply_msg.sets('comment', comment)
     self.reply(msg, reply_msg)
Example #7
0
 def ready(self):
     msg = KQMLPerformative('tell')
     content = KQMLList(['module-status', 'ready'])
     msg.set('content', content)
     self.send(msg)
Example #8
0
 def ready(self):
     perf = KQMLPerformative('tell')
     content = KQMLList(['module-status', 'ready'])
     perf.set('content', content)
     self.send(perf)