#include <ArServerMode.h>
Inheritance diagram for ArServerMode:

..
Only one mode can control the robot at once, this is made to be subclassed. Each subclass needs to implement activate and deactivate, activate MUST call baseActivate and if baseActivate returns false then the mode is NOT active and shouldn't do anything. Further each class should set myMode and myStatus to the mode its in and the things its doing... You can lock your mode in with lockMode and unlock it with unlockMode but you should redefine the inherited requestUnlock and unlock yourself and deactivate gracefully.
If you want to implement a server mode as a default mode then you also need to implement checkDefault which will be called when nothing else is active
Note that there's a new mechanism in place where if you use addModeData instead of addData on the ArServerBase the command will be placed into a map of available modes with commands that can be gotten by the client. The active mode and whether its locked and will unlock and such can now be gotten too... this is all so that different commands can be disabled in client GUIs when they aren't available.
Public Member Functions | |
| virtual void | activate (void)=0 |
| The function called when the mode is activated. | |
| virtual void | activationDenied (void) |
| The function called if the mode is not activated because another mode superceded it. | |
| void | addActivateCallback (ArFunctor *functor, int position=50) |
| Adds a callback for when this class is activated. | |
| void | addAsDefaultMode (ArListPos::Pos pos=ArListPos::LAST) |
| Sets this mode to default (so if a mode deactivates it activates this). | |
| void | addDeactivateCallback (ArFunctor *functor, int position=50) |
| Adds a callback for when this class is deactivated. | |
| bool | addModeData (const char *name, const char *description, ArFunctor2< ArServerClient *, ArNetPacket * > *functor, const char *argumentDescription, const char *returnDescription, const char *commandGroup=NULL, const char *dataFlags=NULL) |
| This basically just notes the commands associated with a mode so that clients can know what can and can't happen based on what mode is active/locked/etc. | |
| void | addSingleShotDeactivateCallback (ArFunctor *functor, int position=50) |
| Adds a single shot callback for when this class is deactivated. | |
| ArServerMode (ArRobot *robot, ArServerBase *server, const char *name) | |
| Constructor. | |
| virtual void | checkDefault (void) |
| This will be called when there would be no other modes, if this mode wants to take over it should activate itself, if it doesn't want to take over it shouldn't activate. | |
| virtual void | deactivate (void)=0 |
| The function called when the mode is deactivated. | |
| virtual void | forceUnlock (void) |
| This will be called if another mode has to break the lock. | |
| virtual ArActionGroup * | getActionGroup (void) |
| This function should return the action group this mode uses. | |
| ArTime | getActivityTime (void) |
| Gets the time of our last activity. | |
| const char * | getMode (void) const |
| Gets a string representing the mode we're in. | |
| const char * | getName (void) const |
| Gets the name of the mode we're in. | |
| const char * | getStatus (void) const |
| Gets a string representing the status of the mode we're in. | |
| bool | hasSetActivityTime (void) |
| Gets if we've set our activity time. | |
| bool | isActive (void) const |
| Gets if this mode is active or not. | |
| virtual bool | isAutoResumeAfterInterrupt () |
| This method primarily applies when the mode has been interrupted by a forced docking situation. | |
| void | lockMode (bool willUnlockIfRequested=false) |
| Locks this mode in until its unlocked (mode must be the active mode). | |
| void | remActivateCallback (ArFunctor *functor) |
| Removes a callback for when this class is activated. | |
| void | remDeactivateCallback (ArFunctor *functor) |
| Removes a callback for when this class is deactivated. | |
| void | remSingleShotDeactivateCallback (ArFunctor *functor) |
| Removes a single shot callback for when this class is deactivated. | |
| virtual void | requestUnlock (void) |
| This will be called if another mode wants the lock broken (can ignore). | |
| void | setActivityTimeToNow (void) |
| Sets that we're active right now. | |
| void | setMode (const char *str) |
| This should only be used by careful people and probably not then. | |
| void | setStatus (const char *str) |
| This changes the status of the mode and sets the myStatusSetThisCycle to true. | |
| void | unlockMode (void) |
| Unlocks the mode so other modes can activate. | |
| virtual void | userTask (void) |
| The ArMode's user task, don't need one, subclass must provide if needed. | |
| virtual | ~ArServerMode () |
| Destructor. | |
Static Public Member Functions | |
| static ArServerMode * | getActiveMode (void) |
| Gets the active mode. | |
| static int | getActiveModeActivityTimeSecSince (void) |
| Gets the seconds since the activity of our active mode. | |
| static ArServerModeIdle * | getIdleMode (void) |
| Call that gets our idle mode. | |
| static void | getModeBusy (ArServerClient *client, ArNetPacket *packet) |
| Handles the packet request for the mode busy state. | |
| static void | getModeDataList (ArServerClient *client, ArNetPacket *packet) |
| Gets the list of data for each mode. | |
| static void | getModeInfo (ArServerClient *client, ArNetPacket *packet) |
| Gets the info about which mode is active and such. | |
| static bool | willUnlockIfRequested (void) |
| Gets whether we'll unlock if requested or not. | |
Protected Member Functions | |
| bool | baseActivate (void) |
| Activates this mode if it can (returns true if it can, false otherwise). | |
| void | baseDeactivate (void) |
| Deactivates this mode. | |
| void | checkBroadcastModeInfoPacket (void) |
| ArServerMode * | getLastActiveMode () |
Static Protected Member Functions | |
| static void | buildModeInfoPacket (ArNetPacket *packet) |
| static std::list< ArServerMode * > * | getRequestedActivateModes (void) |
| static void | modeUserTask (void) |
Protected Attributes | |
| ArCallbackList | myActivateCallbacks |
| ArTime | myActivityTime |
| ArMutex | myActivityTimeMutex |
| ArCallbackList | myDeactivateCallbacks |
| bool | myHasSetActivityTime |
| bool | myIsActive |
| std::string | myMode |
| std::string | myName |
| ArRobot * | myRobot |
| ArServerBase * | myServer |
| ArCallbackList | mySingleShotDeactivateCallbacks |
| std::string | myStatus |
| bool | myStatusSetThisCycle |
| ArLog::LogLevel | myVerboseLogLevel |
Static Protected Attributes | |
| static ArServerMode * | ourActiveMode = NULL |
| static bool | ourActiveModeLocked = false |
| static bool | ourActiveModeWillUnlockIfRequested = false |
| static ArServerMode * | ourBroadcastActiveMode = NULL |
| static bool | ourBroadcastActiveModeLocked = false |
| static bool | ourBroadcastActiveModeWillUnlockIfRequested = false |
| static std::list< ArServerMode * > | ourDefaultModes |
| static ArGlobalFunctor2< ArServerClient *, ArNetPacket * > | ourGetModeBusyCB |
| static ArGlobalFunctor2< ArServerClient *, ArNetPacket * > | ourGetModeDataListCB |
| static ArGlobalFunctor2< ArServerClient *, ArNetPacket * > | ourGetModeInfoCB |
| static ArServerModeIdle * | ourIdleMode = NULL |
| static bool | ourIdleModeCreated = false |
| static ArMutex | ourIdleModeMutex |
| static bool | ourIsBusy = false |
| static ArServerMode * | ourLastActiveMode = NULL |
| static std::multimap< std::string, std::string > | ourModeDataMap |
| static ArMutex | ourModeDataMapMutex |
| static std::list< ArServerMode * > | ourModes |
| static ArServerMode * | ourNextActiveMode = NULL |
| static std::list< ArServerMode * > | ourRequestedActivateModes |
| static ArServerBase * | ourServerBase = NULL |
| static bool | ourUserTaskAdded = false |
| static ArGlobalFunctor | ourUserTaskCB |
| ArServerMode::ArServerMode | ( | ArRobot * | robot, | |
| ArServerBase * | server, | |||
| const char * | name | |||
| ) |
Constructor.
| ArServerMode::~ArServerMode | ( | ) | [virtual] |
Destructor.
| virtual void ArServerMode::activate | ( | void | ) | [pure virtual] |
The function called when the mode is activated.
Subclasses must implement this, but also call baseActivate().-
Implemented in ArServerModeDrive, ArServerModeIdle, ArServerModeRatioDrive, ArServerModeStop, and ArServerModeWander.
| virtual void ArServerMode::activationDenied | ( | void | ) | [inline, virtual] |
The function called if the mode is not activated because another mode superceded it.
| void ArServerMode::addActivateCallback | ( | ArFunctor * | functor, | |
| int | position = 50 | |||
| ) | [inline] |
Adds a callback for when this class is activated.
| void ArServerMode::addAsDefaultMode | ( | ArListPos::Pos | pos = ArListPos::LAST |
) |
| void ArServerMode::addDeactivateCallback | ( | ArFunctor * | functor, | |
| int | position = 50 | |||
| ) | [inline] |
Adds a callback for when this class is deactivated.
| bool ArServerMode::addModeData | ( | const char * | name, | |
| const char * | description, | |||
| ArFunctor2< ArServerClient *, ArNetPacket * > * | functor, | |||
| const char * | argumentDescription, | |||
| const char * | returnDescription, | |||
| const char * | commandGroup = NULL, |
|||
| const char * | dataFlags = NULL | |||
| ) |
This basically just notes the commands associated with a mode so that clients can know what can and can't happen based on what mode is active/locked/etc.
You should call it only if the addData on the ArServerBase returns true (since otherwise it means that command wasn't added).
| void ArServerMode::addSingleShotDeactivateCallback | ( | ArFunctor * | functor, | |
| int | position = 50 | |||
| ) | [inline] |
Adds a single shot callback for when this class is deactivated.
| bool ArServerMode::baseActivate | ( | void | ) | [protected] |
Activates this mode if it can (returns true if it can, false otherwise).
If we have an ArRobot instance (myRobot), then robot motion is stopped. Activity time is reset, and activate callbacks are called.
Call our activate callbacks
Set the activity time to now, but do NOT set the flag, since that flag is used to determine if a particular mode has used it or not
| void ArServerMode::baseDeactivate | ( | void | ) | [protected] |
Deactivates this mode.
Deactivation callbacks are called. The next mode to be activated is activated, if any. (E.g. the global default mode)
| void ArServerMode::buildModeInfoPacket | ( | ArNetPacket * | packet | ) | [static, protected] |
| void ArServerMode::checkBroadcastModeInfoPacket | ( | void | ) | [protected] |
| virtual void ArServerMode::checkDefault | ( | void | ) | [inline, virtual] |
This will be called when there would be no other modes, if this mode wants to take over it should activate itself, if it doesn't want to take over it shouldn't activate.
Reimplemented in ArServerModeStop, and ArServerModeWander.
| virtual void ArServerMode::deactivate | ( | void | ) | [pure virtual] |
The function called when the mode is deactivated.
Subclasses must implement this, and also call baseDeactivate().
Implemented in ArServerModeDrive, ArServerModeIdle, ArServerModeRatioDrive, ArServerModeStop, and ArServerModeWander.
| void ArServerMode::forceUnlock | ( | void | ) | [virtual] |
This will be called if another mode has to break the lock.
| virtual ArActionGroup* ArServerMode::getActionGroup | ( | void | ) | [inline, virtual] |
This function should return the action group this mode uses.
Reimplemented in ArServerModeDrive, ArServerModeIdle, ArServerModeRatioDrive, ArServerModeStop, and ArServerModeWander.
| ArServerMode * ArServerMode::getActiveMode | ( | void | ) | [static] |
Gets the active mode.
| int ArServerMode::getActiveModeActivityTimeSecSince | ( | void | ) | [static] |
Gets the seconds since the activity of our active mode.
| ArTime ArServerMode::getActivityTime | ( | void | ) |
Gets the time of our last activity.
| ArServerModeIdle * ArServerMode::getIdleMode | ( | void | ) | [static] |
Call that gets our idle mode.
| ArServerMode * ArServerMode::getLastActiveMode | ( | ) | [protected] |
| const char* ArServerMode::getMode | ( | void | ) | const [inline] |
Gets a string representing the mode we're in.
| void ArServerMode::getModeBusy | ( | ArServerClient * | client, | |
| ArNetPacket * | packet | |||
| ) | [static] |
Handles the packet request for the mode busy state.
| void ArServerMode::getModeDataList | ( | ArServerClient * | client, | |
| ArNetPacket * | packet | |||
| ) | [static] |
Gets the list of data for each mode.
| void ArServerMode::getModeInfo | ( | ArServerClient * | client, | |
| ArNetPacket * | packet | |||
| ) | [static] |
Gets the info about which mode is active and such.
| const char* ArServerMode::getName | ( | void | ) | const [inline] |
Gets the name of the mode we're in.
| std::list< ArServerMode * > * ArServerMode::getRequestedActivateModes | ( | void | ) | [static, protected] |
| const char* ArServerMode::getStatus | ( | void | ) | const [inline] |
Gets a string representing the status of the mode we're in.
| bool ArServerMode::hasSetActivityTime | ( | void | ) | [inline] |
Gets if we've set our activity time.
| bool ArServerMode::isActive | ( | void | ) | const [inline] |
Gets if this mode is active or not.
| bool ArServerMode::isAutoResumeAfterInterrupt | ( | ) | [virtual] |
This method primarily applies when the mode has been interrupted by a forced docking situation.
In that case, when the docking mode is complete, it will resume the interrupted mode -- if this method returns true. This would primarily be applicable to very long, complex modes.
The default return value is false.
| void ArServerMode::lockMode | ( | bool | willUnlockIfRequested = false |
) |
Locks this mode in until its unlocked (mode must be the active mode).
| void ArServerMode::modeUserTask | ( | void | ) | [static, protected] |
| void ArServerMode::remActivateCallback | ( | ArFunctor * | functor | ) | [inline] |
Removes a callback for when this class is activated.
| void ArServerMode::remDeactivateCallback | ( | ArFunctor * | functor | ) | [inline] |
Removes a callback for when this class is deactivated.
| void ArServerMode::remSingleShotDeactivateCallback | ( | ArFunctor * | functor | ) | [inline] |
Removes a single shot callback for when this class is deactivated.
| virtual void ArServerMode::requestUnlock | ( | void | ) | [inline, virtual] |
This will be called if another mode wants the lock broken (can ignore).
| void ArServerMode::setActivityTimeToNow | ( | void | ) |
Sets that we're active right now.
| void ArServerMode::setMode | ( | const char * | str | ) | [inline] |
This should only be used by careful people and probably not then.
| void ArServerMode::setStatus | ( | const char * | str | ) | [inline] |
This changes the status of the mode and sets the myStatusSetThisCycle to true.
If the mode inheriting is setting the status in cycles then it should use this status instead and then clear the myStatusSetThisFlag to false.
| void ArServerMode::unlockMode | ( | void | ) |
Unlocks the mode so other modes can activate.
| virtual void ArServerMode::userTask | ( | void | ) | [inline, virtual] |
The ArMode's user task, don't need one, subclass must provide if needed.
Reimplemented in ArServerModeDrive, ArServerModeIdle, ArServerModeRatioDrive, ArServerModeStop, and ArServerModeWander.
| bool ArServerMode::willUnlockIfRequested | ( | void | ) | [static] |
Gets whether we'll unlock if requested or not.
ArCallbackList ArServerMode::myActivateCallbacks [protected] |
ArTime ArServerMode::myActivityTime [protected] |
ArMutex ArServerMode::myActivityTimeMutex [protected] |
ArCallbackList ArServerMode::myDeactivateCallbacks [protected] |
bool ArServerMode::myHasSetActivityTime [protected] |
bool ArServerMode::myIsActive [protected] |
std::string ArServerMode::myMode [protected] |
std::string ArServerMode::myName [protected] |
ArRobot* ArServerMode::myRobot [protected] |
ArServerBase* ArServerMode::myServer [protected] |
std::string ArServerMode::myStatus [protected] |
bool ArServerMode::myStatusSetThisCycle [protected] |
ArLog::LogLevel ArServerMode::myVerboseLogLevel [protected] |
ArServerMode * ArServerMode::ourActiveMode = NULL [static, protected] |
bool ArServerMode::ourActiveModeLocked = false [static, protected] |
bool ArServerMode::ourActiveModeWillUnlockIfRequested = false [static, protected] |
ArServerMode * ArServerMode::ourBroadcastActiveMode = NULL [static, protected] |
bool ArServerMode::ourBroadcastActiveModeLocked = false [static, protected] |
bool ArServerMode::ourBroadcastActiveModeWillUnlockIfRequested = false [static, protected] |
std::list< ArServerMode * > ArServerMode::ourDefaultModes [static, protected] |
ArGlobalFunctor2< ArServerClient *, ArNetPacket * > ArServerMode::ourGetModeBusyCB [static, protected] |
ArGlobalFunctor2< ArServerClient *, ArNetPacket * > ArServerMode::ourGetModeDataListCB [static, protected] |
ArGlobalFunctor2< ArServerClient *, ArNetPacket * > ArServerMode::ourGetModeInfoCB [static, protected] |
ArServerModeIdle * ArServerMode::ourIdleMode = NULL [static, protected] |
bool ArServerMode::ourIdleModeCreated = false [static, protected] |
ArMutex ArServerMode::ourIdleModeMutex [static, protected] |
bool ArServerMode::ourIsBusy = false [static, protected] |
ArServerMode * ArServerMode::ourLastActiveMode = NULL [static, protected] |
std::multimap< std::string, std::string > ArServerMode::ourModeDataMap [static, protected] |
ArMutex ArServerMode::ourModeDataMapMutex [static, protected] |
std::list< ArServerMode * > ArServerMode::ourModes [static, protected] |
ArServerMode * ArServerMode::ourNextActiveMode = NULL [static, protected] |
std::list< ArServerMode * > ArServerMode::ourRequestedActivateModes [static, protected] |
ArServerBase * ArServerMode::ourServerBase = NULL [static, protected] |
bool ArServerMode::ourUserTaskAdded = false [static, protected] |
ArGlobalFunctor ArServerMode::ourUserTaskCB [static, protected] |
1.4.7