예제 #1
0
    def createSession(self, name):
        """
    Creates a new session by copying the common session
    and registers the new session with the engine.

    @param name: the name of the session
    @type  name: string

    @return: the new session
    @rtype: session.Session instance
    """
        ses = session.Session(self)
        ses.setName(name)
        self.registerSession(ses, name)
        return ses
예제 #2
0
    def __init__(self):
        """ Initializes the engine."""

        # this is the event queue that holds all the events in
        # the system.
        self._event_queue = Queue.Queue()

        # this is a lock for writing stuff to the ui--makes sure
        # we're not hosing things by having multiple things write
        # to the ui simultaneously....  ick.
        self._ui_lock = thread.allocate_lock()

        # this is the master shutdown flag for the event queue
        # handling.
        self._shutdownflag = 0

        # Lyntin counts the total number of errors it's encountered.
        # This enables us to shut ourselves down if we encounter too
        # many which indicates a "bigger problem".
        self._errorcount = 0

        # listeners exist at an engine level.  if you sign up for
        # an input hook, you get the input hook for ALL sessions.
        # this might change at some point....  we'll see.
        self._listeners = {}

        self._managers = {}

        # the help manager manages all the help content in a hierarchical
        # structure.
        self._managers["help"] = helpmanager.HelpManager(self)

        # our config manager
        self._managers["config"] = config.ConfigManager(self)

        # our history manager
        self._managers["history"] = history.HistoryManager(self)

        # our command manager
        self._managers["command"] = commandmanager.CommandManager(self)

        # there is only one ui in the system.
        self._ui = None

        # current tick count
        self._current_tick = 0

        # list of registered threads
        self._threads = []

        # counts the total number of events processed--for diagnostics
        self._num_events_processed = 0

        # holds all the sessions
        self._sessions = {}

        # the current session.  points to a Session object.
        self._current_session = None

        # map of hook name -> utils.PriorityQueue objects
        self._hooks = {}

        # we register ourselves with the shutdown hook
        self.hookRegister("shutdown_hook", self.shutdown)

        commonsession = session.Session(self)
        commonsession.setName("common")

        # this creates a "common" entry in all the managers that manage
        # session scoped data--the session base is None
        # for mem in self._managers.values():
        #   mem.addSession(commonsession, None)

        self._sessions["common"] = commonsession
        self._current_session = commonsession

        self.hookRegister("user_filter_hook", self._managers["command"].filter,
                          100)