#include <ArServerMode.h>
Inheritance diagram for ArServerMode:
Public Member Functions | |
virtual void | activate (void)=0 |
The function called when the mode is activated, subclass must provide. | |
void | addActivateCallback (ArFunctor *functor, ArListPos::Pos position=ArListPos::LAST) |
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, ArListPos::Pos position=ArListPos::LAST) |
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) |
Adds data to the list of this mode's commands. | |
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, subclass must provide. | |
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. | |
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. | |
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 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) |
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 |
std::string | myStatus |
bool | myStatusSetThisCycle |
ArLog::LogLevel | myVerboseLogLevel |
Static Protected Attributes | |
static ArServerMode * | ourActiveMode = NULL |
static bool | ourActiveModeLocked = false |
static bool | ourActiveModeWillUnlockIfRequested = false |
static std::list< ArServerMode * > | ourDefaultModes |
static ArGlobalFunctor2< ArServerClient *, ArNetPacket * > | ourGetModeDataListCB |
static ArGlobalFunctor2< ArServerClient *, ArNetPacket * > | ourGetModeInfoCB |
static ArServerMode * | ourLastActiveMode = NULL |
static bool | ourLastActiveModeLocked = false |
static bool | ourLastActiveModeWillUnlockIfRequested = false |
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 bool | ourUserTaskAdded = false |
static ArGlobalFunctor | ourUserTaskCB |
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.
Definition at line 61 of file ArServerMode.h.
|
Constructor.
Definition at line 76 of file ArServerMode.cpp. References ArServerBase::addData(), ArRobot::addUserTask(), myHasSetActivityTime, myIsActive, myName, myRobot, myServer, myStatusSetThisCycle, myVerboseLogLevel, ourGetModeDataListCB, ourGetModeInfoCB, ourModes, ourUserTaskAdded, and ourUserTaskCB. |
|
Destructor.
Definition at line 104 of file ArServerMode.cpp. |
|
The function called when the mode is activated, subclass must provide.
Implemented in ArServerModeDrive, ArServerModeRatioDrive, ArServerModeStop, and ArServerModeWander. |
|
Adds a callback for when this class is activated.
Definition at line 135 of file ArServerMode.h. References ArCallbackList::addCallback(), and myActivateCallbacks. |
|
Sets this mode to default (so if a mode deactivates it activates this).
Definition at line 274 of file ArServerMode.cpp. References getName(), ArLog::log(), and ourDefaultModes. Referenced by main(). |
|
Adds a callback for when this class is deactivated.
Definition at line 142 of file ArServerMode.h. References ArCallbackList::addCallback(), and myDeactivateCallbacks. |
|
Adds data to the list of this mode's commands. You should call it only if the addData on the ArServerBase returns true (since otherwise it means that command wasn't added). Definition at line 322 of file ArServerMode.cpp. References ArServerBase::addData(), ArMutex::lock(), ArLog::log(), myName, myServer, ourModeDataMap, ourModeDataMapMutex, and ArMutex::unlock(). Referenced by ArServerModeDrive::ArServerModeDrive(), ArServerModeRatioDrive::ArServerModeRatioDrive(), ArServerModeStop::ArServerModeStop(), and ArServerModeWander::ArServerModeWander(). |
|
Activates this mode if it can (returns true if it can, false otherwise). If this returns false then the mode should just return... note that before calling this a mode should have already made sure it can activate... this also calls the activate callbacks (only if the mode will be allowed to activate of course) 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 Definition at line 158 of file ArServerMode.cpp. References checkBroadcastModeInfoPacket(), ArRobot::clearDirectMotion(), deactivate(), getName(), ArCallbackList::invoke(), ArMutex::lock(), ArLog::log(), myActivateCallbacks, myActivityTime, myActivityTimeMutex, myIsActive, myRobot, myVerboseLogLevel, ourActiveMode, ourActiveModeLocked, ourNextActiveMode, ourRequestedActivateModes, requestUnlock(), ArTime::setToNow(), ArRobot::stop(), and ArMutex::unlock(). Referenced by ArServerModeWander::activate(), ArServerModeStop::activate(), ArServerModeDrive::driveJoystick(), and ArServerModeRatioDrive::ratioDrive(). |
|
Deactivates this mode.
Definition at line 208 of file ArServerMode.cpp. References getName(), ArCallbackList::invoke(), ArLog::log(), myDeactivateCallbacks, myIsActive, myVerboseLogLevel, ourActiveMode, ourActiveModeLocked, ourDefaultModes, ourNextActiveMode, ourRequestedActivateModes, and unlockMode(). Referenced by ArServerModeWander::deactivate(), ArServerModeStop::deactivate(), ArServerModeRatioDrive::deactivate(), and ArServerModeDrive::deactivate(). |
|
Definition at line 376 of file ArServerMode.cpp. References getName(), ourActiveMode, ourActiveModeLocked, and ourActiveModeWillUnlockIfRequested. Referenced by checkBroadcastModeInfoPacket(), and getModeInfo(). |
|
Definition at line 399 of file ArServerMode.cpp. References ArServerBase::broadcastPacketTcp(), buildModeInfoPacket(), myServer, ourActiveMode, ourActiveModeLocked, ourActiveModeWillUnlockIfRequested, ourLastActiveMode, ourLastActiveModeLocked, and ourLastActiveModeWillUnlockIfRequested. Referenced by baseActivate(), lockMode(), and unlockMode(). |
|
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. Definition at line 110 of file ArServerMode.h. Referenced by modeUserTask(). |
|
The function called when the mode is deactivated, subclass must provide.
Implemented in ArServerModeDrive, ArServerModeRatioDrive, ArServerModeStop, and ArServerModeWander. Referenced by baseActivate(). |
|
This function should return the action group this mode uses.
Reimplemented in ArServerModeDrive, ArServerModeRatioDrive, ArServerModeStop, and ArServerModeWander. Definition at line 69 of file ArServerMode.h. |
|
Gets the active mode.
Definition at line 416 of file ArServerMode.cpp. References ourActiveMode. |
|
Gets the seconds since the activity of our active mode.
Definition at line 305 of file ArServerMode.cpp. References getActivityTime(), ourActiveMode, and ArTime::secSince(). |
|
Gets the time of our last activity.
Definition at line 288 of file ArServerMode.cpp. References ArMutex::lock(), myActivityTime, myActivityTimeMutex, and ArMutex::unlock(). Referenced by getActiveModeActivityTimeSecSince(). |
|
Gets a string representing the mode we're in.
Definition at line 83 of file ArServerMode.h. References myMode. Referenced by ArServerInfoRobot::update(). |
|
Gets the list of data for each mode.
Definition at line 348 of file ArServerMode.cpp. References client, ArMutex::lock(), ourModeDataMap, ourModeDataMapMutex, ArClientBase::sendPacketTcp(), ArBasePacket::strToBuf(), ArBasePacket::uByte4ToBuf(), and ArMutex::unlock(). |
|
Gets the info about which mode is active and such.
Definition at line 368 of file ArServerMode.cpp. References buildModeInfoPacket(), client, and ArClientBase::sendPacketTcp(). |
|
Gets the name of the mode we're in.
Definition at line 87 of file ArServerMode.h. References myName. Referenced by addAsDefaultMode(), baseActivate(), baseDeactivate(), buildModeInfoPacket(), ArServerModeRatioDrive::joyUserTask(), ArServerModeDrive::joyUserTask(), lockMode(), and unlockMode(). |
|
Definition at line 419 of file ArServerMode.cpp. References ourRequestedActivateModes. |
|
Gets a string representing the status of the mode we're in.
Definition at line 85 of file ArServerMode.h. References myStatus. Referenced by ArServerInfoRobot::update(). |
|
Gets if we've set our activity time.
Definition at line 95 of file ArServerMode.h. References myHasSetActivityTime. |
|
Gets if this mode is active or not.
Definition at line 89 of file ArServerMode.h. References myIsActive. Referenced by ArServerModeStop::activate(), ArServerModeDrive::driveJoystick(), ArServerModeRatioDrive::joyUserTask(), ArServerModeDrive::joyUserTask(), ArServerModeRatioDrive::ratioDrive(), ArServerModeRatioDrive::setSafeDriving(), and ArServerModeDrive::setSafeDriving(). |
|
Locks this mode in until its unlocked (mode must be the active mode).
Definition at line 109 of file ArServerMode.cpp. References checkBroadcastModeInfoPacket(), getName(), ArLog::log(), myIsActive, myVerboseLogLevel, ourActiveMode, ourActiveModeLocked, and ourActiveModeWillUnlockIfRequested. |
|
Definition at line 52 of file ArServerMode.cpp. References checkDefault(), ArLog::log(), ourActiveMode, ourDefaultModes, and userTask(). |
|
Removes a callback for when this class is activated.
Definition at line 139 of file ArServerMode.h. References myActivateCallbacks, and ArCallbackList::remCallback(). |
|
Removes a callback for when this class is deactivated.
Definition at line 146 of file ArServerMode.h. References myDeactivateCallbacks, and ArCallbackList::remCallback(). |
|
This will be called if another mode wants the lock broken (can ignore).
Definition at line 77 of file ArServerMode.h. Referenced by baseActivate(). |
|
Sets that we're active right now.
Definition at line 297 of file ArServerMode.cpp. References ArMutex::lock(), myActivityTime, myActivityTimeMutex, myHasSetActivityTime, ArTime::setToNow(), and ArMutex::unlock(). Referenced by ArServerModeWander::activate(), ArServerModeStop::activate(), ArServerModeDrive::driveJoystick(), ArServerModeStop::netStop(), ArServerModeWander::netWander(), ArServerModeRatioDrive::ratioDrive(), ArServerModeWander::userTask(), ArServerModeRatioDrive::userTask(), and ArServerModeDrive::userTask(). |
|
This should only be used by careful people and probably not then.
Definition at line 112 of file ArServerMode.h. References myMode. |
|
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. Definition at line 120 of file ArServerMode.h. References myStatus, and myStatusSetThisCycle. |
|
Unlocks the mode so other modes can activate.
Definition at line 123 of file ArServerMode.cpp. References checkBroadcastModeInfoPacket(), getName(), ArLog::log(), myIsActive, myVerboseLogLevel, ourActiveMode, ourActiveModeLocked, and ourActiveModeWillUnlockIfRequested. Referenced by baseDeactivate(). |
|
The ArMode's user task, don't need one, subclass must provide if needed.
Reimplemented in ArServerModeDrive, ArServerModeRatioDrive, ArServerModeStop, and ArServerModeWander. Definition at line 75 of file ArServerMode.h. Referenced by modeUserTask(). |
|
Gets whether we'll unlock if requested or not.
Definition at line 138 of file ArServerMode.cpp. References ourActiveMode, ourActiveModeLocked, and ourActiveModeWillUnlockIfRequested. |
|
Definition at line 158 of file ArServerMode.h. Referenced by addActivateCallback(), baseActivate(), and remActivateCallback(). |
|
Definition at line 176 of file ArServerMode.h. Referenced by baseActivate(), getActivityTime(), and setActivityTimeToNow(). |
|
Definition at line 177 of file ArServerMode.h. Referenced by baseActivate(), getActivityTime(), and setActivityTimeToNow(). |
|
Definition at line 159 of file ArServerMode.h. Referenced by addDeactivateCallback(), baseDeactivate(), and remDeactivateCallback(). |
|
Definition at line 175 of file ArServerMode.h. Referenced by ArServerMode(), hasSetActivityTime(), and setActivityTimeToNow(). |
|
Definition at line 161 of file ArServerMode.h. Referenced by ArServerMode(), baseActivate(), baseDeactivate(), isActive(), lockMode(), and unlockMode(). |
|
Definition at line 167 of file ArServerMode.h. |
|
Definition at line 164 of file ArServerMode.h. Referenced by addModeData(), ArServerMode(), and getName(). |
|
Definition at line 162 of file ArServerMode.h. Referenced by ArServerMode(), and baseActivate(). |
|
Definition at line 163 of file ArServerMode.h. Referenced by addModeData(), ArServerMode(), and checkBroadcastModeInfoPacket(). |
|
Definition at line 168 of file ArServerMode.h. Referenced by getStatus(), and setStatus(). |
|
Definition at line 169 of file ArServerMode.h. Referenced by ArServerMode(), and setStatus(). |
|
Definition at line 198 of file ArServerMode.h. Referenced by ArServerMode(), baseActivate(), baseDeactivate(), lockMode(), and unlockMode(). |
|
Definition at line 32 of file ArServerMode.cpp. Referenced by baseActivate(), baseDeactivate(), buildModeInfoPacket(), checkBroadcastModeInfoPacket(), getActiveMode(), getActiveModeActivityTimeSecSince(), lockMode(), modeUserTask(), unlockMode(), and willUnlockIfRequested(). |
|
Definition at line 30 of file ArServerMode.cpp. Referenced by baseActivate(), baseDeactivate(), buildModeInfoPacket(), checkBroadcastModeInfoPacket(), lockMode(), unlockMode(), and willUnlockIfRequested(). |
|
Definition at line 31 of file ArServerMode.cpp. Referenced by buildModeInfoPacket(), checkBroadcastModeInfoPacket(), lockMode(), unlockMode(), and willUnlockIfRequested(). |
|
Definition at line 34 of file ArServerMode.cpp. Referenced by addAsDefaultMode(), baseDeactivate(), and modeUserTask(). |
|
Referenced by ArServerMode(). |
|
Referenced by ArServerMode(). |
|
Definition at line 48 of file ArServerMode.cpp. Referenced by checkBroadcastModeInfoPacket(). |
|
Definition at line 47 of file ArServerMode.cpp. Referenced by checkBroadcastModeInfoPacket(). |
|
Definition at line 49 of file ArServerMode.cpp. Referenced by checkBroadcastModeInfoPacket(). |
|
Definition at line 39 of file ArServerMode.cpp. Referenced by addModeData(), and getModeDataList(). |
|
Definition at line 40 of file ArServerMode.cpp. Referenced by addModeData(), and getModeDataList(). |
|
Definition at line 36 of file ArServerMode.cpp. Referenced by ArServerMode(). |
|
Definition at line 33 of file ArServerMode.cpp. Referenced by baseActivate(), and baseDeactivate(). |
|
Definition at line 35 of file ArServerMode.cpp. Referenced by baseActivate(), baseDeactivate(), and getRequestedActivateModes(). |
|
Definition at line 37 of file ArServerMode.cpp. Referenced by ArServerMode(). |
|
Referenced by ArServerMode(). |