ERC CISST - cisst software

ireFramework Class Reference
[Interactive Research Environment]

#include <ireFramework.h>

Collaboration diagram for ireFramework:

Collaboration graph
[legend]
List of all members.

Detailed Description

Class to manage the preparation of Python for the Interactive Robot Environment, and for launching the IRE IDE and shell.

The goal of the IRE is to be mindlessly simple to incorporate in already complicated applications.

The purpose of this class is to abstract the mechanics of preparing and launching Python in general and the IRE in particular from the end user. It is also used to ensure creation of a single extended Python shell with global scope.

This class is instantiated, and runs as a singleton object. The method is borrowed from Design Principles and the CISST Logger.

Note:
The IRE is *not* thread-safe; all threads will run the IRE in the Python shell created by this singleton class. This behavior is DESIRED; we are attempting to prevent multiple copies of the Object Register from being created from within the same application. Note that it is theoretically possible for the user to nevertheless create a new copy of the Object Register referenced by this application from within a separate Python shell (the IRE IDE permits spawning new shells).

Definition at line 69 of file ireFramework.h.

Static Public Member Functions

Protected Member Functions


Constructor & Destructor Documentation

ireFramework::ireFramework (  )  [inline, protected]

Constructor for this singleton object. Initialize the Python subsystem upon creation. InitShellInstance changes the IRE state from IRE_NOT_CONSTRUCTED to IRE_INITIALIZED.

Definition at line 106 of file ireFramework.h.

ireFramework::~ireFramework (  )  [inline, protected]

Dereferences everything and cleans Python shell. Changes the IRE state to IRE_FINISHED.

Definition at line 112 of file ireFramework.h.


Member Function Documentation

static ireFramework* ireFramework::Instance ( void   )  [static]

Return a pointer to the instantiated instance of this object. Note that the IRE state will change from IRE_NOT_CONSTRUCTED to IRE_INITIALIZED on the first call to this function.

static void ireFramework::InitShell ( void   )  throw (std::runtime_error) [inline, static]

Initializes the Python environment. Called from the constructor, the user needs never call this function explicitly. As ireFramework is a singleton object, the underlying Python shell will have application scope ONLY. The "irepy" package will remain instantiated for the duration of the application. All modules loaded and variables created from this class will remain in scope; note that this does NOT include objects created from within the IRE IDE shell. Changes IRE state to IRE_INITIALIZED.

Definition at line 131 of file ireFramework.h.

static void ireFramework::FinalizeShell ( void   )  throw (std::runtime_error) [inline, static]

Called explicitly from the class destructor, it removes all references to the Python shell. Python is then free to clean itself up. If the application wishes to restart the IRE, it will be necessary to explicitly call InitShell(). Changes IRE state to IRE_FINISHED.

Definition at line 141 of file ireFramework.h.

static void ireFramework::LaunchIREShell ( char *  startup = "",
bool  newPythonThread = false,
bool  useIPython = false 
) throw (std::runtime_error) [inline, static]

Loads the "irepy" Python IRE package and calls the "launch()" method to launch the GUI.

Note:
Although the "irepy" package itself remains loaded for the duration of the application, any variables/objects instantiated within the IRE interpreter are contained in a separate, session-scope interpreter; they will not be available from the C++ environment after the IRE GUI is shut down.
The Python shell will first run the "startup" string. This can be used, for example, to import application-specific Python scripts. The "startup" string is not declared const because that would not be compatible with PySys_SetArgv().

If the newPythonThread parameter is true, the IRE will be started in a separate thread. Note, however, that the C++ code will have to periodically call JoinIREShell(); otherwise, the C++ program will not relinquish any execution time to the IRE thread. An alternate implementation would be to create the IRE thread in the C++ code before launching the IRE. This, however, is less portable and would best be implemented using cisstOSAbstraction.

If the useIPython parameter is true, then IPython shell will be started instead of the IRE (GUI). IPython is an enhanced interactive Python shell, allowing autocompletion, etc. For more information, see http://ipython.scipy.org/moin/

If the IRE state on entry is IRE_INITIALIZED, this method changes it to IRE_LAUNCHED; otherwise, it throws an exception. When the Python code finishes its initialization, it will call a callback function to change the state to IRE_ACTIVE prior to entering the wxPython main event loop. On exit from the event loop, it will call the callback function to change the state to IRE_FINISHED.

Definition at line 178 of file ireFramework.h.

static void* ireFramework::RunIRE_wxPython ( char *  startup  )  [inline, static]

Single argument function that can be passed directly to osaThread::Create, e.g.,:

        osaThread IreThread;
        IreThread.Create<char *> (&ireFramework::RunIRE_wxPython, "print 'using wxPython'");

Definition at line 188 of file ireFramework.h.

References CMN_LOG_INIT_ERROR.

static void* ireFramework::RunIRE_IPython ( char *  startup  )  [inline, static]

Single argument function that can be passed directly to osaThread::Create, e.g.,:

        osaThread IreThread;
        IreThread.Create<char *> (&ireFramework::RunIRE_IPython, "print 'using IPython'");

Definition at line 205 of file ireFramework.h.

References CMN_LOG_INIT_ERROR.

static void ireFramework::JoinIREShell ( double  timeout  )  [inline, static]

Wait for IRE shell to finish (if started in a new Python thread). Specify a negative timeout to wait forever.

Definition at line 218 of file ireFramework.h.

static bool ireFramework::IsStarting (  )  [static]

Check whether the IRE shell is (or could be) starting (i.e., not active and not finished). We do not check the "obvious" case of the IRE state being IRE_LAUNCHED because if the IRE is being launched from a new C++ thread, the thread may not yet have been created.

static bool ireFramework::IsActive (  )  [static]

Check whether IRE shell is active (i.e., all initialization complete and wxPython app loop entered). Note that there will be some time delay between when LaunchIREShell() is invoked and when IsActive() becomes true.

static bool ireFramework::IsFinished (  )  [static]

Check whether the IRE has been exited.

static void ireFramework::SetActiveFlag ( bool  flag  )  [static]

This is provided as a callback to the Python code that launches the IRE, so that it can change the state to IRE_ACTIVE or IRE_FINISHED.

static bool ireFramework::IsInitialized (  )  [static]

Check whether the Python interpreter has been initialized (i.e., the ireFramework instance has been created and FinalizeIREShell() has not been called).

static void ireFramework::Reset (  )  [static]

If the current IRE state is IRE_FINISHED, change it to IRE_INITIALIZED (calling InitShell if necessary). This is provided to facililate relaunching of the IRE.


The documentation for this class was generated from the following file:
erc-cisst-devel<at>lists.johnshopkins.edu