Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

ArServerMode Class Reference

This is a lot like ArMode but for net control instead... More...

#include <ArServerMode.h>

Inheritance diagram for ArServerMode:

ArServerModeDrive ArServerModeRatioDrive ArServerModeStop ArServerModeWander List of all members.

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 ArActionGroupgetActionGroup (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 ArServerModegetActiveMode (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
ArRobotmyRobot
ArServerBasemyServer
std::string myStatus
bool myStatusSetThisCycle
ArLog::LogLevel myVerboseLogLevel

Static Protected Attributes

static ArServerModeourActiveMode = 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 ArServerModeourLastActiveMode = 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 ArServerModeourNextActiveMode = NULL
static std::list< ArServerMode * > ourRequestedActivateModes
static bool ourUserTaskAdded = false
static ArGlobalFunctor ourUserTaskCB

Detailed Description

This is a lot like ArMode but for net control instead...

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 & Destructor Documentation

ArServerMode::ArServerMode ArRobot robot,
ArServerBase server,
const char *  name
 

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.

ArServerMode::~ArServerMode  )  [virtual]
 

Destructor.

Definition at line 104 of file ArServerMode.cpp.


Member Function Documentation

virtual void ArServerMode::activate void   )  [pure virtual]
 

The function called when the mode is activated, subclass must provide.

Implemented in ArServerModeDrive, ArServerModeRatioDrive, ArServerModeStop, and ArServerModeWander.

void ArServerMode::addActivateCallback ArFunctor functor,
ArListPos::Pos  position = ArListPos::LAST
[inline]
 

Adds a callback for when this class is activated.

Definition at line 135 of file ArServerMode.h.

References ArCallbackList::addCallback(), and myActivateCallbacks.

void ArServerMode::addAsDefaultMode ArListPos::Pos  pos = ArListPos::LAST  ) 
 

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().

void ArServerMode::addDeactivateCallback ArFunctor functor,
ArListPos::Pos  position = ArListPos::LAST
[inline]
 

Adds a callback for when this class is deactivated.

Definition at line 142 of file ArServerMode.h.

References ArCallbackList::addCallback(), and myDeactivateCallbacks.

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
 

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().

bool ArServerMode::baseActivate void   )  [protected]
 

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().

void ArServerMode::baseDeactivate void   )  [protected]
 

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().

void ArServerMode::buildModeInfoPacket ArNetPacket packet  )  [static, protected]
 

Definition at line 376 of file ArServerMode.cpp.

References getName(), ourActiveMode, ourActiveModeLocked, and ourActiveModeWillUnlockIfRequested.

Referenced by checkBroadcastModeInfoPacket(), and getModeInfo().

void ArServerMode::checkBroadcastModeInfoPacket void   )  [protected]
 

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().

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.

Definition at line 110 of file ArServerMode.h.

Referenced by modeUserTask().

virtual void ArServerMode::deactivate void   )  [pure virtual]
 

The function called when the mode is deactivated, subclass must provide.

Implemented in ArServerModeDrive, ArServerModeRatioDrive, ArServerModeStop, and ArServerModeWander.

Referenced by baseActivate().

virtual ArActionGroup* ArServerMode::getActionGroup void   )  [inline, virtual]
 

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.

ArServerMode * ArServerMode::getActiveMode void   )  [static]
 

Gets the active mode.

Definition at line 416 of file ArServerMode.cpp.

References ourActiveMode.

int ArServerMode::getActiveModeActivityTimeSecSince void   )  [static]
 

Gets the seconds since the activity of our active mode.

Definition at line 305 of file ArServerMode.cpp.

References getActivityTime(), ourActiveMode, and ArTime::secSince().

ArTime ArServerMode::getActivityTime void   ) 
 

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().

const char* ArServerMode::getMode void   )  const [inline]
 

Gets a string representing the mode we're in.

Definition at line 83 of file ArServerMode.h.

References myMode.

Referenced by ArServerInfoRobot::update().

void ArServerMode::getModeDataList ArServerClient client,
ArNetPacket packet
[static]
 

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().

void ArServerMode::getModeInfo ArServerClient client,
ArNetPacket packet
[static]
 

Gets the info about which mode is active and such.

Definition at line 368 of file ArServerMode.cpp.

References buildModeInfoPacket(), client, and ArClientBase::sendPacketTcp().

const char* ArServerMode::getName void   )  const [inline]
 

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().

std::list< ArServerMode * > * ArServerMode::getRequestedActivateModes void   )  [static, protected]
 

Definition at line 419 of file ArServerMode.cpp.

References ourRequestedActivateModes.

const char* ArServerMode::getStatus void   )  const [inline]
 

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().

bool ArServerMode::hasSetActivityTime void   )  [inline]
 

Gets if we've set our activity time.

Definition at line 95 of file ArServerMode.h.

References myHasSetActivityTime.

bool ArServerMode::isActive void   )  const [inline]
 

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().

void ArServerMode::lockMode bool  willUnlockIfRequested = false  ) 
 

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.

void ArServerMode::modeUserTask void   )  [static, protected]
 

Definition at line 52 of file ArServerMode.cpp.

References checkDefault(), ArLog::log(), ourActiveMode, ourDefaultModes, and userTask().

void ArServerMode::remActivateCallback ArFunctor functor  )  [inline]
 

Removes a callback for when this class is activated.

Definition at line 139 of file ArServerMode.h.

References myActivateCallbacks, and ArCallbackList::remCallback().

void ArServerMode::remDeactivateCallback ArFunctor functor  )  [inline]
 

Removes a callback for when this class is deactivated.

Definition at line 146 of file ArServerMode.h.

References myDeactivateCallbacks, and ArCallbackList::remCallback().

virtual void ArServerMode::requestUnlock void   )  [inline, virtual]
 

This will be called if another mode wants the lock broken (can ignore).

Definition at line 77 of file ArServerMode.h.

Referenced by baseActivate().

void ArServerMode::setActivityTimeToNow void   ) 
 

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().

void ArServerMode::setMode const char *  str  )  [inline]
 

This should only be used by careful people and probably not then.

Definition at line 112 of file ArServerMode.h.

References myMode.

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.

Definition at line 120 of file ArServerMode.h.

References myStatus, and myStatusSetThisCycle.

void ArServerMode::unlockMode void   ) 
 

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().

virtual void ArServerMode::userTask void   )  [inline, virtual]
 

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().

bool ArServerMode::willUnlockIfRequested void   )  [static]
 

Gets whether we'll unlock if requested or not.

Definition at line 138 of file ArServerMode.cpp.

References ourActiveMode, ourActiveModeLocked, and ourActiveModeWillUnlockIfRequested.


Member Data Documentation

ArCallbackList ArServerMode::myActivateCallbacks [protected]
 

Definition at line 158 of file ArServerMode.h.

Referenced by addActivateCallback(), baseActivate(), and remActivateCallback().

ArTime ArServerMode::myActivityTime [protected]
 

Definition at line 176 of file ArServerMode.h.

Referenced by baseActivate(), getActivityTime(), and setActivityTimeToNow().

ArMutex ArServerMode::myActivityTimeMutex [protected]
 

Definition at line 177 of file ArServerMode.h.

Referenced by baseActivate(), getActivityTime(), and setActivityTimeToNow().

ArCallbackList ArServerMode::myDeactivateCallbacks [protected]
 

Definition at line 159 of file ArServerMode.h.

Referenced by addDeactivateCallback(), baseDeactivate(), and remDeactivateCallback().

bool ArServerMode::myHasSetActivityTime [protected]
 

Definition at line 175 of file ArServerMode.h.

Referenced by ArServerMode(), hasSetActivityTime(), and setActivityTimeToNow().

bool ArServerMode::myIsActive [protected]
 

Definition at line 161 of file ArServerMode.h.

Referenced by ArServerMode(), baseActivate(), baseDeactivate(), isActive(), lockMode(), and unlockMode().

std::string ArServerMode::myMode [protected]
 

Definition at line 167 of file ArServerMode.h.

Referenced by getMode(), and setMode().

std::string ArServerMode::myName [protected]
 

Definition at line 164 of file ArServerMode.h.

Referenced by addModeData(), ArServerMode(), and getName().

ArRobot* ArServerMode::myRobot [protected]
 

Definition at line 162 of file ArServerMode.h.

Referenced by ArServerMode(), and baseActivate().

ArServerBase* ArServerMode::myServer [protected]
 

Definition at line 163 of file ArServerMode.h.

Referenced by addModeData(), ArServerMode(), and checkBroadcastModeInfoPacket().

std::string ArServerMode::myStatus [protected]
 

Definition at line 168 of file ArServerMode.h.

Referenced by getStatus(), and setStatus().

bool ArServerMode::myStatusSetThisCycle [protected]
 

Definition at line 169 of file ArServerMode.h.

Referenced by ArServerMode(), and setStatus().

ArLog::LogLevel ArServerMode::myVerboseLogLevel [protected]
 

Definition at line 198 of file ArServerMode.h.

Referenced by ArServerMode(), baseActivate(), baseDeactivate(), lockMode(), and unlockMode().

ArServerMode * ArServerMode::ourActiveMode = NULL [static, protected]
 

Definition at line 32 of file ArServerMode.cpp.

Referenced by baseActivate(), baseDeactivate(), buildModeInfoPacket(), checkBroadcastModeInfoPacket(), getActiveMode(), getActiveModeActivityTimeSecSince(), lockMode(), modeUserTask(), unlockMode(), and willUnlockIfRequested().

bool ArServerMode::ourActiveModeLocked = false [static, protected]
 

Definition at line 30 of file ArServerMode.cpp.

Referenced by baseActivate(), baseDeactivate(), buildModeInfoPacket(), checkBroadcastModeInfoPacket(), lockMode(), unlockMode(), and willUnlockIfRequested().

bool ArServerMode::ourActiveModeWillUnlockIfRequested = false [static, protected]
 

Definition at line 31 of file ArServerMode.cpp.

Referenced by buildModeInfoPacket(), checkBroadcastModeInfoPacket(), lockMode(), unlockMode(), and willUnlockIfRequested().

std::list< ArServerMode * > ArServerMode::ourDefaultModes [static, protected]
 

Definition at line 34 of file ArServerMode.cpp.

Referenced by addAsDefaultMode(), baseDeactivate(), and modeUserTask().

ArGlobalFunctor2< ArServerClient *, ArNetPacket * > ArServerMode::ourGetModeDataListCB [static, protected]
 

Referenced by ArServerMode().

ArGlobalFunctor2< ArServerClient *, ArNetPacket * > ArServerMode::ourGetModeInfoCB [static, protected]
 

Referenced by ArServerMode().

ArServerMode * ArServerMode::ourLastActiveMode = NULL [static, protected]
 

Definition at line 48 of file ArServerMode.cpp.

Referenced by checkBroadcastModeInfoPacket().

bool ArServerMode::ourLastActiveModeLocked = false [static, protected]
 

Definition at line 47 of file ArServerMode.cpp.

Referenced by checkBroadcastModeInfoPacket().

bool ArServerMode::ourLastActiveModeWillUnlockIfRequested = false [static, protected]
 

Definition at line 49 of file ArServerMode.cpp.

Referenced by checkBroadcastModeInfoPacket().

std::multimap< std::string, std::string > ArServerMode::ourModeDataMap [static, protected]
 

Definition at line 39 of file ArServerMode.cpp.

Referenced by addModeData(), and getModeDataList().

ArMutex ArServerMode::ourModeDataMapMutex [static, protected]
 

Definition at line 40 of file ArServerMode.cpp.

Referenced by addModeData(), and getModeDataList().

std::list< ArServerMode * > ArServerMode::ourModes [static, protected]
 

Definition at line 36 of file ArServerMode.cpp.

Referenced by ArServerMode().

ArServerMode * ArServerMode::ourNextActiveMode = NULL [static, protected]
 

Definition at line 33 of file ArServerMode.cpp.

Referenced by baseActivate(), and baseDeactivate().

std::list< ArServerMode * > ArServerMode::ourRequestedActivateModes [static, protected]
 

Definition at line 35 of file ArServerMode.cpp.

Referenced by baseActivate(), baseDeactivate(), and getRequestedActivateModes().

bool ArServerMode::ourUserTaskAdded = false [static, protected]
 

Definition at line 37 of file ArServerMode.cpp.

Referenced by ArServerMode().

ArGlobalFunctor ArServerMode::ourUserTaskCB [static, protected]
 

Referenced by ArServerMode().


The documentation for this class was generated from the following files:
Generated on Tue Feb 20 10:51:52 2007 for ArNetworking by  doxygen 1.4.0