Aria  2.8.0
ArModule Class Referenceabstract

Dynamicly loaded module base class, read warning in more. More...

#include <ArModule.h>

Inherited by SimpleMod.

Public Member Functions

 ArModule ()
 Constructor.
 
virtual bool exit ()=0
 Close down the module and have it exit.
 
ArRobotgetRobot ()
 Get the ArRobot pointer the module should be using.
 
virtual bool init (ArRobot *robot, void *argument=NULL)=0
 Initialize the module. The module should use the supplied ArRobot pointer. More...
 
void setRobot (ArRobot *robot)
 Set the ArRobot pointer.
 
virtual ~ArModule ()
 Destructor.
 

Protected Attributes

ArRobotmyRobot
 Stored ArRobot pointer that the module should use.
 

Detailed Description

Dynamicly loaded module base class, read warning in more.

Right now only one module's init will be called, that is the first one, its a bug that I just don't have time to fix at the moment. I'll get to it when I have time or if someone needs it... someone else wrote this code so it'll take me a little longer to fix it.

This class defines a dyanicmly loaded module of code. This is usefull for an application to load piece of code that it does not know about. The ArModule defines and interface in which to invoke that piece of code that the program does not know about. For instance, a module could contain an ArAction and the modules init() could instantiate the ArAction and add it to the supplied ArRobot. The init() takes a reference to an ArRobot. The module should use that robot for its purposes. If the module wants to use more robots, assuming there are multiple robots, it can use Aria::getRobotList() to find all the ArRobot instantiated. The module should do all its clean up in exit().

The user should derive their own class from ArModule and implement the init() and exit() functions. The users code should always clean up when exit() is called. exit() is called right before the module (dynamic library .dll/.so) is closed and removed from the program.

The macro ARDEF_MODULE() must be called within the .cpp file of the users module. A global instance of the users module must be defined and a reference to that instance must be passed to ARDEF_MODULE(). This allows the ArModuleLoader to find the users module class and invoke it.

One thing to note about the use of code wrapped in ArModules and staticly linking in that code. To be able to staticly link .cpp files which contain an ArModule, the ARIA_STATIC preprocessor symbol should be defined. This will cause the ARDEF_MODULE() to do nothing. If it defined its normal functions and variables, the linker would fail to staticly link in multiple modules since they all have symbols with the same name.

Refer to ArModuleLoader to see how to load an ArModule into a program.

For examples, see the programs advanced/simpleMod.cpp and advanced/simpleModule.cpp.

Examples:
moduleExample_Mod.cpp.

Member Function Documentation

◆ init()

virtual bool ArModule::init ( ArRobot robot,
void *  argument = NULL 
)
pure virtual

Initialize the module. The module should use the supplied ArRobot pointer.

Parameters
robotRobot this module should attach to or operate on. Note, may be NULL.
argumentan optional argument passed to the module. Default is NULL. The module can interpret this in any way, it is recommended that you make sure this is documented if used.
Examples:
moduleExample_Mod.cpp.

The documentation for this class was generated from the following files: