Generic Plug-in. More...

#include <gplugin.h>

Inheritance diagram for GPlugIn:
[legend]

Public Member Functions

 GPlugIn (GSession *session, GPlugInFactory *fac)
 
virtual void ApplyConfig (void)
 
void InsertParam (R::RParam *param)
 
template<class T >
T * FindParam (const R::RString &name)
 
R::RCursor< R::RParamGetParams (const R::RString &cat=R::RString::Null)
 
void GetCategories (R::RContainer< R::RString, true, false > &cats)
 
virtual void Init (void)
 
virtual void CreateConfig (void)
 
virtual void Reset (void)
 
GPlugInFactoryGetFactory (void) const
 
int Compare (const GPlugIn &plugin) const
 
int Compare (const R::RString &plugin) const
 
R::RString GetName (void) const
 
R::RString GetDesc (void) const
 
GSessionGetSession (void) const
 
virtual void Done (void)
 
virtual ~GPlugIn (void)
 

Protected Attributes

GPlugInFactoryFactory
 
GSessionSession
 
size_t Id
 

Private Member Functions

R::RParamGetParam (const R::RString &name)
 

Detailed Description

Generic Plug-in.

The GPlugIn class provides a template for a generic plug-in. Plug-ins are managed by GGALILEIApp, but they are used in relation to a particular session.

Each plug-in goes through an identical process when a session is created :

  • The session variable is set.
  • The method GPlugIn::CreateConfig is called. The plug-in creates its parameters. This parameters are then automatically read from a configuration file of the particular session.
  • The method GPlugIn::ApplyConfig is called. The plug-in can use the configuration read.
  • The method GPlugIn::Init is called. The plug-in makes some initialization of its internal structures. Since all plug-ins are allocated, it is the right place to make a plug-in an observer of another's plug-in notifications.

When a session is closed, the method GPlugIn::Done is called for each plug-in.

The method GPlugin::Reset can be used to force a plug-in to reset itself. In particular, if plug-ins managed important permanent information, it can be in an unknown state (for example after a crash or when a plug-in becomes enabled with an existing session). A user can call this method to force the plug-in to do the necessary work to be again in a coherent state.

It should be understand that a plug-in is create once by GGALILEIApp, but that the methods GPlugIn::Init and GPlugIn::Done are called each time a session is created or deleted. Therefore, if a plug-in manages some internal structures, the developer has two choices :

  1. The structures are created and deleted each time (by GPlugIn::Init and GPlugIn::Done).
  2. The structures are created and deleted once (by the constructor and the destructor). The methods GPlugIn::Init and GPlugIn::Done are then just responsible to put the structures updated with the current session.

Generally, the best approach is to create internal structures as late as possible.

Constructor & Destructor Documentation

GPlugIn ( GSession session,
GPlugInFactory fac 
)

Constructor of the plug-in.

Parameters
sessionSession.
facFactory.
virtual ~GPlugIn ( void  )
virtual

Destruct of the plug-in.

Member Function Documentation

virtual void ApplyConfig ( void  )
virtual

Configuration parameters were changed (or loaded).

It is the good place to get the parameters and store them in variables (it is faster than to use the FindParam method each time). Here is an example of an implementation.

void MyPlugIn::ApplyConfig(void)
{
bool a(FindParam<RParamValue>("EnableOption")->GetBool());
int b(FindParam<RParamValue>("IntNumber")->GetInt());
}

Reimplemented in GMatrixMeasure, and GEngine.

void InsertParam ( R::RParam param)

Declare a new parameter. If it exist, the parameter passed as argument is deleted.

Parameters
paramParameter.
R::RParam* GetParam ( const R::RString name)
private

Find a given parameter.

Parameters
nameName of the parameter.
Returns
Pointer or null if not found.
T* FindParam ( const R::RString name)

Find a given parameter (template version).

Template Parameters
TType of the parameter.
Parameters
nameName of the parameter.
Returns
Pointer or null if not found.
R::RCursor<R::RParam> GetParams ( const R::RString cat = R::RString::Null)
Returns
a cursor over the parameters of the plug-in.
Parameters
catCategory of the parameter.
void GetCategories ( R::RContainer< R::RString, true, false > &  cats)

Fill a container with the categories.

Parameters
catsContainer that will be filled (it is emptied by the method).
virtual void Init ( void  )
virtual

Initialize the plug-in. This method is called each time a session is opened. A first call to ApplyConfig was already done and the session dictionaries were loaded.

Reimplemented in GMatrixMeasure, and GMetaEngine.

virtual void CreateConfig ( void  )
virtual

Create the configuration (attached to the session).

Reimplemented in GMatrixMeasure, and GEngine.

virtual void Reset ( void  )
virtual

The plug-in should be reseted. This method is "manually" called (typically by an user through an application) to ensure that the plug-in state is coherent with a session. This can be useful if after a crash during some tasks done by the plug-in.

For example, if the plug-in holds the results of some computations, they should be redone.

Reimplemented in GMatrixMeasure.

GPlugInFactory* GetFactory ( void  ) const

Get the factory of the plug-in.

int Compare ( const GPlugIn plugin) const

Comparison method needed by R::RContainer.

Parameters
pluginPlug-in to compare.
int Compare ( const R::RString plugin) const

Comparison method needed by R::RContainer.

Parameters
pluginPlug-in to compare.
R::RString GetName ( void  ) const

Get the name of the Plug-in

R::RString GetDesc ( void  ) const

Get the description of the Plug-in

GSession* GetSession ( void  ) const

Get the session associated with the plug-in.

virtual void Done ( void  )
virtual

The method is called each time a session is closed.

Reimplemented in GMetaEngine.

Member Data Documentation

GPlugInFactory* Factory
protected

Pointer to the factory.

GSession* Session
protected

Session.

size_t Id
protected

Identifier of the plug-in.