Aria  2.7.5.2
Aria Class Reference

This class performs global initialization and deinitialization. More...

#include <ariaInternal.h>

Public Types

enum  SigHandleMethod { SIGHANDLE_SINGLE, SIGHANDLE_THREAD, SIGHANDLE_NONE }
 

Static Public Member Functions

static void addExitCallback (ArFunctor *functor, int position=50)
 Adds a functor to by called before program exit by Aria::exit() More...
 
static void addInitCallBack (ArFunctor *cb, ArListPos::Pos position)
 Adds a callback to call when Aria is initialized using init() More...
 
static void addLogOptionsCB (ArFunctor *functor, int position=50)
 Adds a callback for when we log options.
 
static void addParseArgsCB (ArRetFunctor< bool > *functor, int position=50)
 Adds a callback for when we parse arguments.
 
static void addRobot (ArRobot *robot)
 Add a robot to the global list of robots.
 
static void addUninitCallBack (ArFunctor *cb, ArListPos::Pos position)
 Adds a callback to call when Aria is uninititialized using uninit() More...
 
static void callExitCallbacks (void)
 Internal, calls the exit callbacks.
 
static void delRobot (ArRobot *robot)
 Remove a robot from the global list of robots.
 
static bool deviceConnectionAddCreator (const char *deviceConnectionType, ArRetFunctor3< ArDeviceConnection *, const char *, const char *, const char * > *creator)
 Adds a type of deviceConnection for Aria to be able to create. More...
 
static ArDeviceConnectiondeviceConnectionCreate (const char *deviceConnectionType, const char *port, const char *defaultInfo, const char *prefix="Aria::deviceConnectionCreate")
 Creates a deviceConnection of the given type. More...
 
static const char * deviceConnectionGetTypes (void)
 Gets a list of the possible deviceConnection types. More...
 
static void exit (int exitCode=0)
 Shutdown all Aria processes/threads, call exit callbacks, and exit the program. More...
 
static void exitOld (int exitCode=0)
 Force an exit of all Aria processes/threads (the old way) More...
 
static ArRobotfindRobot (char *name)
 Finds a robot in the global list of robots, by name. More...
 
static ArConfiggetConfig (void)
 Gets the ArConfig for this program. More...
 
static const char * getDirectory (void)
 Gets the directory that ARIA resides in. More...
 
static ArStringInfoGroupgetInfoGroup (void)
 Gets the ArStringInfoGroup for this program. More...
 
static ArJoyHandlergetJoyHandler (void)
 Get a pointer to the joystick handler if one has been set with setJoyHandler() More...
 
static ArKeyHandlergetKeyHandler (void)
 Gets a pointer to the global key handler, if one has been set with setKeyHandler() More...
 
static int getMaxNumLasers (void)
 Gets the maximum number of lasers to use. More...
 
static ArRobotJoyHandlergetRobotJoyHandler (void)
 Gets the robot joystick handler if one has been set. More...
 
static std::list< ArRobot * > * getRobotList ()
 Get a copy of the global robot list.
 
static bool getRunning (void)
 Sees if Aria is still running (mostly for the thread in main) More...
 
static void init (SigHandleMethod method=SIGHANDLE_THREAD, bool initSockets=true, bool sigHandleExitNotShutdown=true)
 Initialize Aria global data struture and perform OS-specific initialization, including adding OS signal handlers on Linux, initializing sockets library on Windows, etc. More...
 
static bool laserAddCreator (const char *laserType, ArRetFunctor2< ArLaser *, int, const char * > *creator)
 Adds a type of laser for Aria to be able to create. More...
 
static ArLaserlaserCreate (const char *laserType, int laserNumber, const char *prefix="Aria::laserCreate")
 Creates a laser of the given type. More...
 
static const char * laserGetTypes (void)
 Gets a list of the possible laser types. More...
 
static void logOptions (void)
 Logs all the options for the program (Calls all the callbacks added with addLogOptionsCB()) More...
 
static bool parseArgs (void)
 Parses the arguments for the program (calls all the callbacks added with addParseArgsCB()) More...
 
static void remExitCallback (ArFunctor *functor)
 Removes a functor to by called before program exit by Aria::exit() More...
 
static void setDirectory (const char *directory)
 Sets the directory that ARIA resides in, to override default. More...
 
static void setExitCallbacksLogLevel (ArLog::LogLevel level)
 Sets the log level for the exit callbacks.
 
static void setJoyHandler (ArJoyHandler *joyHandler)
 Sets the joystick handler, so that other classes can find it using getJoyHandler() More...
 
static void setKeyHandler (ArKeyHandler *keyHandler)
 Sets the key handler, so that other classes can find it using getKeyHandler() More...
 
static void setMaxNumLasers (int maxNumLasers)
 Sets the maximum number of lasers to use. More...
 
static void setParseArgLogLevel (ArLog::LogLevel level)
 Sets the log level for the parsing function.
 
static void setRobotJoyHandler (ArRobotJoyHandler *robotJoyHandler)
 Sets the robot joystick handler, so that other classes can find it. More...
 
static void shutdown ()
 Shutdown all Aria processes/threads. More...
 
static void signalHandlerCB (int sig)
 Internal, the callback for the signal handling.
 
static void uninit ()
 Performs OS-specific deinitialization, used by shutdown() and exit(). More...
 

Static Protected Attributes

static ArConfig ourConfig
 
static std::map< std::string,
ArRetFunctor3
< ArDeviceConnection *, const
char *, const char *, const
char * > *, ArStrCaseCmpOp
ourDeviceConnectionCreatorMap
 
static std::string ourDeviceConnectionTypes
 
static std::string ourDirectory =""
 
static std::multimap< int,
ArFunctor * > 
ourExitCallbacks
 
static ArLog::LogLevel ourExitCallbacksLogLevel = ArLog::Verbose
 
static ArMutex ourExitCallbacksMutex
 
static bool ourExiting =false
 
static ArStringInfoGroup ourInfoGroup
 
static std::list< ArFunctor * > ourInitCBs
 
static bool ourInited = false
 
static ArJoyHandlerourJoyHandler = NULL
 
static ArKeyHandlerourKeyHandler = NULL
 
static std::map< std::string,
ArRetFunctor2< ArLaser *, int,
const char * >
*, ArStrCaseCmpOp
ourLaserCreatorMap
 
static std::string ourLaserTypes
 
static std::multimap< int,
ArFunctor * > 
ourLogOptionsCBs
 
static int ourMaxNumLasers = 9
 
static std::multimap< int,
ArRetFunctor< bool > * > 
ourParseArgCBs
 
static ArLog::LogLevel ourParseArgsLogLevel = ArLog::Verbose
 
static ArRobotJoyHandlerourRobotJoyHandler = NULL
 
static std::list< ArRobot * > ourRobots
 
static bool ourRunning = false
 
static bool ourShuttingDown =false
 
static ArMutex ourShuttingDownMutex
 
static bool ourSigHandleExitNotShutdown = true
 
static ArGlobalFunctor1< int > ourSignalHandlerCB
 
static std::list< ArFunctor * > ourUninitCBs
 

Detailed Description

This class performs global initialization and deinitialization.

Member Enumeration Documentation

Enumerator
SIGHANDLE_SINGLE 

Setup signal handlers in a global, non-thread way.

SIGHANDLE_THREAD 

Setup a dedicated signal handling thread.

SIGHANDLE_NONE 

Do no signal handling.

Member Function Documentation

void Aria::addExitCallback ( ArFunctor functor,
int  position = 50 
)
static

Adds a functor to by called before program exit by Aria::exit()

Note, an exit callback may be called at any time; it should not block or wait on any locked mutexes or similar.

Examples:
gpsRobotTaskExample.cpp.
void Aria::addInitCallBack ( ArFunctor cb,
ArListPos::Pos  position 
)
static

Adds a callback to call when Aria is initialized using init()

This will add a callback to the list of callbacks to call when Aria has been initialized. It can be called before anything else.

void Aria::addUninitCallBack ( ArFunctor cb,
ArListPos::Pos  position 
)
static

Adds a callback to call when Aria is uninititialized using uninit()

This will add a callback to the list of callbacks to call right before Aria is un-initialized. It can be called before anything else. This facilitates code that in operating system signal handlers simply calls Aria::uninit() and packages that are based on Aria are unitited as well. It simplifies the entire uninit process.

bool Aria::deviceConnectionAddCreator ( const char *  deviceConnectionType,
ArRetFunctor3< ArDeviceConnection *, const char *, const char *, const char * > *  creator 
)
static

Adds a type of deviceConnection for Aria to be able to create.

This adds a functor which can create a deviceConnection of a given type.

Parameters
deviceConnectionTypeThe deviceConnection type that the creator will make (these are always checked case insensitively). If there is already a creator for this type, then the old one is replaced and the new one is used.
creatorA functor which takes a const char * (port name), a const char * (defaultInfo, for example default tcp port), a const char * (logPrefix) and returns a new deviceConnection of the deviceConnectionType if it can create the desired connection. If the connection failes then it should return NULL.
ArDeviceConnection * Aria::deviceConnectionCreate ( const char *  deviceConnectionType,
const char *  port,
const char *  defaultInfo,
const char *  logPrefix = "Aria::deviceConnectionCreate" 
)
static

Creates a deviceConnection of the given type.

Creates a device connection of a given type, connecting to a given port, with the given defaultInfo, logging messages with the given prefix. This is mostly for internal use by ArLaserConnector

Parameters
deviceConnectionTypeThe type of device connection to create
portThe port to connect to (for serial, an example is COM1 or /dev/ttyS0, for tcp an example is p3dx:8101)
defaultInfoDefault info to use, the only use for this right now is for a default port for a tcp connection (so that if it doesn't have hostname:port format but only hostname then it will use this port)
logPrefixThe prefix to use when logging
const char * Aria::deviceConnectionGetTypes ( void  )
static

Gets a list of the possible deviceConnection types.

Gets a string that is the types of device connections that can be created separated by | characters. Mostly for internal use by ArLaserConnector.

void Aria::exit ( int  exitCode = 0)
static
void Aria::exitOld ( int  exitCode = 0)
static

Force an exit of all Aria processes/threads (the old way)

This method is roughly obsolete, it simply forces all the threads to die immediately and then exits... The new method exit() is preferred.

This calls cancel() on all AtThread's and ArASyncTask's. It forces each thread to exit and should only be used in the case of a thread hanging or getting stuck in an infinite loop. This works fine in Linux. In Windows it is not recommended at all that this function be called. Windows can not handle cleanly killing off a thread. See the help in the VC++ compiler on the WIN32 function TerminateThread. The biggest problem is that the state of DLL's can be destroyed.

Deprecated:
ArRobot * Aria::findRobot ( char *  name)
static

Finds a robot in the global list of robots, by name.

Parameters
namethe name of the robot you want to find
Returns
NULL if there is no robot of that name, otherwise the robot with that name
ArConfig * Aria::getConfig ( void  )
static

Gets the ArConfig for this program.

This gets the global config aria uses.

Examples:
configExample.cpp.
const char * Aria::getDirectory ( void  )
static

Gets the directory that ARIA resides in.

This gets the directory that ARIA is located in, this is so ARIA can find param files and the like.

Returns
the directory ARIA is located in
See Also
setDirectory
ArStringInfoGroup * Aria::getInfoGroup ( void  )
static

Gets the ArStringInfoGroup for this program.

This gets the global string group aria uses.

ArJoyHandler * Aria::getJoyHandler ( void  )
static

Get a pointer to the joystick handler if one has been set with setJoyHandler()

Gets the joy handler if one has been set.

ArKeyHandler * Aria::getKeyHandler ( void  )
static

Gets a pointer to the global key handler, if one has been set with setKeyHandler()

Gets the key handler if one has been set.

Examples:
actionGroupExample.cpp, dpptuExample.cpp, gripperExample.cpp, gyroExample.cpp, rvisionCameraExample.cpp, sonyPTZDemo.cpp, and vcc4CameraExample.cpp.
int Aria::getMaxNumLasers ( void  )
static

Gets the maximum number of lasers to use.

Gets the maximum number of lasers to check for and use

ArRobotJoyHandler * Aria::getRobotJoyHandler ( void  )
static

Gets the robot joystick handler if one has been set.

Gets the robot joy handler if one has been set.

bool Aria::getRunning ( void  )
static

Sees if Aria is still running (mostly for the thread in main)

returns true if ARIA is initialized (Aria::init() has been called) and has not been shut down by a call to Aria::shutdown() or Aria::exit() and an operating system signal has not occured (e.g. external KILL signal)

Examples:
gotoActionExample.cpp, netServerExample.cpp, socketServerExample.cpp, and soundsQueueExample.cpp.
void Aria::init ( SigHandleMethod  method = SIGHANDLE_THREAD,
bool  initSockets = true,
bool  sigHandleExitNotShutdown = true 
)
static

Initialize Aria global data struture and perform OS-specific initialization, including adding OS signal handlers on Linux, initializing sockets library on Windows, etc.

This must be called first before any other Aria functions. It initializes the thread layer and the signal handling method. For Windows it iniatializes the socket layer as well. This also sets the directory Aria is located in using ARIA environmental variable (or Aria registry key on Windows). For more about Aria's directory see getDirectory() and setDirectory().

For Linux the default signal handling method is to intercept OS signals in a dedicated "signal handling thread", which cleanly closes down the program, causes all the instances of ArRobot to stop their run loop and disconnect from their robot. The program will exit on the following signals: SIGHUP, SIGINT, SIGQUIT, and SIGTERM.

For Windows, there is no signal handling.

This method also adds the file /etc/Aria.args and the environment variable ARIAARGS as locations for ArArgumentParser to obtain default argument values from.

Parameters
methodthe method in which to handle signals. Defaulted to SIGHANDLE_SINGLE, or the method indicated by the ARIA_SIGHANDLE_METHOD environment variable (NONE, SINGLE or THREAD), if it exists.
initSocketsspecify whether or not to initialize the socket layer. This is only meaningfull for Windows. Defaulted to true.
sigHandleExitNotShutdownif this is true and a signal happens Aria will use exit() to quit instead of shutdown(), false will still use shutdown which is the old behavior.
See Also
ArSignalHandler
ArSocket
Examples:
actionExample.cpp, actionGroupExample.cpp, actsColorFollowingExample.cpp, armExample.cpp, auxSerialExample.cpp, configExample.cpp, demo.cpp, directMotionExample.cpp, dpptuExample.cpp, gotoActionExample.cpp, gpsExample.cpp, gpsRobotTaskExample.cpp, gripperExample.cpp, gyroExample.cpp, imuExample.cpp, joydriveActionExample.cpp, lasers.cpp, lineFinderExample.cpp, moduleExample.cpp, netServerExample.cpp, robotConnectionCallbacks.cpp, robotSyncTaskExample.cpp, rvisionCameraExample.cpp, seekurPower.cpp, simpleConnect.cpp, simpleMotionCommands.cpp, socketClientExample.cpp, socketServerExample.cpp, sonyPTZDemo.cpp, soundsQueueExample.cpp, teleopActionsExample.cpp, threadExample.cpp, triangleDriveToActionExample.cpp, vcc4CameraExample.cpp, and wander.cpp.
bool Aria::laserAddCreator ( const char *  laserType,
ArRetFunctor2< ArLaser *, int, const char * > *  creator 
)
static

Adds a type of laser for Aria to be able to create.

This adds a functor which can create a laser of a given type.

Parameters
laserTypeThe laser type that the creator will make (these are always checked case insensitively). If there is already a creator for this type, then the old one is replaced and the new one is used.
creatorA functor which takes an int (laser number) and a const char * (logPrefix) and returns a new laser of the laserType
ArLaser * Aria::laserCreate ( const char *  laserType,
int  laserNumber,
const char *  logPrefix = "Aria::laserCreate" 
)
static

Creates a laser of the given type.

Creates a laser of a given type, with the given laserNumber, and uses the logPrefix for logging what happens. This is mostly for internal use by ArLaserConnector.

Parameters
laserTypeThe type of laser to create
laserNumberThe laser number to use for the created laser
logPrefixThe prefix to use when logging
const char * Aria::laserGetTypes ( void  )
static

Gets a list of the possible laser types.

Gets a string that is the types of lasers that can be created separated by | characters. Mostly for internal use by ArLaserConnector.

void Aria::remExitCallback ( ArFunctor functor)
static

Removes a functor to by called before program exit by Aria::exit()

Note, an exit callback may be called at any time; it should not * block or wait on any locked mutexes or similar.

Also note that this will not actually happen if it is called while aria is exiting (ie it is walking through the list).

Since
2.7.0
void Aria::setDirectory ( const char *  directory)
static

Sets the directory that ARIA resides in, to override default.

This sets the directory that ARIA is located in, so ARIA can find param files and the like. This can also be controlled by the environment variable ARIA, which this is set to (if it exists) when Aria::init is done. So for setDirectory to be effective, it must be done after the Aria::init.

Parameters
directorythe directory Aria is located in
See Also
getDirectory
void Aria::setJoyHandler ( ArJoyHandler joyHandler)
static

Sets the joystick handler, so that other classes can find it using getJoyHandler()

Sets the joy handler, so that other classes can find it.

void Aria::setKeyHandler ( ArKeyHandler keyHandler)
static
void Aria::setMaxNumLasers ( int  maxNumLasers)
static

Sets the maximum number of lasers to use.

Sets the maximum number of lasers to check for and use, if you are going to set this you should do it after the Aria::init before you start making laser connectors or robots or robot params.

void Aria::setRobotJoyHandler ( ArRobotJoyHandler robotJoyHandler)
static

Sets the robot joystick handler, so that other classes can find it.

Sets the robot joy handler, so that other classes can find it.

void Aria::shutdown ( )
static

Shutdown all Aria processes/threads.

Use this function to clean up or uninitialize Aria, in particular, to stop background threads. This calls stop() on all ArThread's and ArASyncTask's. It will block until all ArThread's and ArASyncTask's exit. It is expected that all the tasks will obey the ArThread::myRunning variable and exit when it is false. (Note, this only stop Aria's background threads, it does not exit the program. Use exit() to do some cleanup and exit the program.)

See Also
Aria::exit()
Examples:
imuExample.cpp.
void Aria::uninit ( )
static

Performs OS-specific deinitialization, used by shutdown() and exit().

This must be called last, after all other Aria functions. For both Linux and Windows, it closes all the open ArModules. For Windows it deinitializes the socket layer as well.


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