moduleExample.cpp

Example demonstrating how to load an ArModule

This is a simple program that loads the module moduleExample_Mod, which is defined in moduleExample_Mod.cpp. The program simply calls ArModuleLoader::load() with a short message argument and ArModuleLoader::reload with no argument and finally calls ArModuleLoader::close(). The return status of the load(), reload(), and close() are checked and printed out. ArModuleLoader uses the name of the module file without the platform-specific suffix (i.e. ".dll" on Windows and ".so" on Linux) to load the module.

See also:
moduleExample_Mod.cpp.

ArModuleLoader in the reference manual.

00001 #include "Aria.h"
00002 
00003 
00020 void printStatus(ArModuleLoader::Status status)
00021 {
00022   if (status == ArModuleLoader::STATUS_ALREADY_LOADED)
00023     ArLog::log(ArLog::Terse, "moduleExample: Module already loaded.");
00024   else if (status == ArModuleLoader::STATUS_FAILED_OPEN)
00025     ArLog::log(ArLog::Terse, "moduleExample: Failed to find or open the simpleMod module.");
00026   else if (status == ArModuleLoader::STATUS_INVALID)
00027     ArLog::log(ArLog::Terse, "moduleExample: Invalid file.");
00028   else if (status == ArModuleLoader::STATUS_INIT_FAILED)
00029     ArLog::log(ArLog::Terse, "moduleExample: Module Init failed.");
00030   else if (status == ArModuleLoader::STATUS_SUCCESS)
00031     ArLog::log(ArLog::Terse, "moduleExample: Module succedded.");
00032   else if (status == ArModuleLoader::STATUS_EXIT_FAILED)
00033     ArLog::log(ArLog::Terse, "moduleExample: Module exit sequence failed.");
00034   else if (status == ArModuleLoader::STATUS_NOT_FOUND)
00035     ArLog::log(ArLog::Terse, "moduleExample: Module not found.");
00036   else
00037     ArLog::log(ArLog::Terse, "moduleExample: Module returned unknown status!");
00038   ArLog::log(ArLog::Terse, "");
00039 }
00040 
00041 int main(int argc, char **argv)
00042 {
00043 
00044   Aria::init();
00045 
00046   ArArgumentParser parser(&argc, argv);
00047   // set up our simple connector
00048   ArSimpleConnector simpleConnector(&parser);  
00049   ArRobot robot;
00050 
00051   // set up the robot for connecting
00052   if (!simpleConnector.connectRobot(&robot))
00053   {
00054     printf("Could not connect to robot... exiting\n");
00055     Aria::exit(1);
00056   }
00057 
00058   robot.runAsync(true);
00059 
00060   ArModuleLoader::Status status;
00061   std::string str;
00062 
00063   ArLog::log(ArLog::Terse, "moduleExample: Loading the module \"moduleExample_Mod\" with a string argument...");
00064   status=ArModuleLoader::load("./moduleExample_Mod", &robot, (char *)"You've loaded a module!");
00065   printStatus(status);
00066   //ArLog::log(ArLog::Terse, "moduleExample: Reloading the module with no argument...");
00067   //status=ArModuleLoader::reload("./moduleExample_Mod", &robot);
00068   //printStatus(status);
00069 
00070   //ArLog::log(ArLog::Terse, "moduleExample: Closing the module...");
00071   //status=ArModuleLoader::close("./moduleExample_Mod");
00072   //printStatus(status);
00073 
00074   ArUtil::sleep(3000);
00075 
00076   Aria::shutdown();
00077   return(0);
00078 }

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