moduleExample_Mod.cpp

Example demonstrating how to implement a module with ArModule This is a simple example of how to define a module of code that Aria's ArModuleLoader class can dynamically load at runtime. On Windows, loadable modules are DLL files. On Linux, they are shared object (.so) files (ARIA's Makefiles can compile any source file ending in "Mod.cpp" into a .so, so to build this module, run "make moduleExample_Mod.so"). ArModuleLoader knows about these platform conventions, so only the base name (without the .dll or .so suffix) is used to load it. To implement a loadable module, you derive a class from ArModule, instantiate the pure virtual functions init() and exit(), and create an instance of that class. The two functions simply print out the equivalent of Hello World. An important part is the global instance of the class and the call to the macro ARDEF_MODULE(). Without that macro invocation, Aria will never be able to invoke those two functions.

The program moduleExample.cpp is designed to load this module and check the error return.

See also:
moduleExample.cpp.

ArModule in the reference manual.

00001 #include "Aria.h"
00002 
00003 
00028 class SimpleMod : public ArModule
00029 {
00030 public:
00031 
00032   bool init(ArRobot *robot, void *argument = NULL);
00033   bool exit();
00034 };
00035 
00036 SimpleMod aModule;
00037 ARDEF_MODULE(aModule);
00038 
00039 bool SimpleMod::init(ArRobot *robot, void *argument)
00040 {
00041   ArLog::log(ArLog::Terse, "module: init(%p) called in the loaded module!", robot);
00042   if (argument != NULL)
00043     ArLog::log(ArLog::Terse, "module: Argument given to ArModuleLoader::load was the string '%s'.", 
00044        (char *)argument);
00045   else
00046     ArLog::log(ArLog::Terse, "module: No argument was given to ArModuleLoader (this is OK).");
00047     
00048   // Do stuff here...
00049     
00050   return(true);
00051 }
00052 
00053 bool SimpleMod::exit()
00054 {
00055   ArLog::log(ArLog::Terse, "module: exit() called.");
00056 
00057   // Do stuff here...
00058 
00059   return(true);
00060 }

Generated on Fri Jul 31 12:36:37 2009 for Aria by  doxygen 1.4.7