ArServerMode Class Reference

#include <ArServerMode.h>

Inheritance diagram for ArServerMode:

ArServerModeIdle List of all members.

Detailed Description

A mode for controlling the robot (only one active).

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.


Public Member Functions

virtual void activate (void)=0
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)
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)
 Sees if this wants to become the default mode.
virtual void deactivate (void)=0
virtual void forceUnlock (void)
 This will be called if another mode has to break the lock.
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.
virtual bool isAutoResumeAfterInterrupt ()
 Returns whether the mode should be automatically resumed after it was interrupted.
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 should only be used by careful people and probably not then.
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 ArServerModeIdlegetIdleMode (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)
void baseDeactivate (void)
void checkBroadcastModeInfoPacket (void)
ArServerModegetLastActiveMode ()

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
ArCallbackList mySingleShotDeactivateCallbacks
std::string myStatus
bool myStatusSetThisCycle
ArLog::LogLevel myVerboseLogLevel

Static Protected Attributes

static ArServerModeourActiveMode
static bool ourActiveModeLocked
static bool ourActiveModeWillUnlockIfRequested
static ArServerModeourBroadcastActiveMode
static bool ourBroadcastActiveModeLocked
static bool ourBroadcastActiveModeWillUnlockIfRequested
static std::list< ArServerMode * > ourDefaultModes
static ArGlobalFunctor2< ArServerClient *,
ArNetPacket * > 
ourGetModeBusyCB
static ArGlobalFunctor2< ArServerClient *,
ArNetPacket * > 
ourGetModeDataListCB
static ArGlobalFunctor2< ArServerClient *,
ArNetPacket * > 
ourGetModeInfoCB
static ArServerModeIdleourIdleMode
static bool ourIdleModeCreated
static ArMutex ourIdleModeMutex
static bool ourIsBusy
static ArServerModeourLastActiveMode
static std::multimap< std::string,
std::string > 
ourModeDataMap
static ArMutex ourModeDataMapMutex
static std::list< ArServerMode * > ourModes
static ArServerModeourNextActiveMode
static std::list< ArServerMode * > ourRequestedActivateModes
static ArServerBaseourServerBase
static bool ourUserTaskAdded
static ArGlobalFunctor ourUserTaskCB


Member Function Documentation

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

The function called when the mode is activated. Subclasses must implement this, but also call baseActivate().-

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.

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)

virtual void ArServerMode::checkDefault ( void   )  [inline, virtual]

Sees if this wants to become the default mode.

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 ArServerMode::deactivate ( void   )  [pure virtual]

The function called when the mode is deactivated. Subclasses must implement this, and also call baseDeactivate().

virtual bool ArServerMode::isAutoResumeAfterInterrupt (  )  [virtual]

Returns whether the mode should be automatically resumed after it was interrupted.

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::setStatus ( const char *  str  )  [inline]

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

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.


The documentation for this class was generated from the following file:
Generated on Thu Aug 6 09:40:12 2009 for ArNetworking by  doxygen 1.5.1