Example #1
0
  def __init__ (self, connection, params):
    self.connection = connection
    connection._newlines = params.get("newlines", True) == True #HACK

    # Make LogMessenger always send back "source":"logger"
    params['opaque'] = {'type':'log'}
    self._logService = LogMessenger(connection, params) # Aggregate
    # Unhook its message received listener (we will pass it those events
    # manually ourselves...)
    connection.removeListener(dict(self._logService._listeners)[MessageReceived])

    self.listenTo(connection)
Example #2
0
class GuiMessengerService (EventMixin):
  def __init__ (self, connection, params):
    self.connection = connection
    connection._newlines = params.get("newlines", True) == True #HACK

    # Make LogMessenger always send back "source":"logger"
    params['opaque'] = {'type':'log'}
    self._logService = LogMessenger(connection, params) # Aggregate
    # Unhook its message received listener (we will pass it those events
    # manually ourselves...)
    connection.removeListener(dict(self._logService._listeners)[MessageReceived])

    self.listenTo(connection)

  def _handle_MessageReceived (self, event, msg):
    if event.con.isReadable():
      r = event.con.read()
      if type(r) is dict:
        if "bye" in r:
          event.con.close()
        else:
          if "type" in r:
            # Dispatch message
            if r["type"] == "topology":
              pass
            elif r["type"] == "monitoring":
              pass
            elif r["type"] == "spanning_tree":
              pass
            elif r["type"] == "sample_routing":
              pass
            elif r["type"] == "flowtracer":
              pass
            elif r["type"] == "log":
              self._logService._processParameters(r)
            else:
              log.warn("Unknown type for message: %s", r)
          else:
            log.warn("Missing type for message: %s", r)