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

ArServerMode.h

Go to the documentation of this file.
00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #ifndef ARSERVERMODE_H
00027 #define ARSERVERMODE_H
00028 
00029 #include "Aria.h"
00030 #include "ArServerBase.h"
00031 
00032 class ArServerClient;
00033 
00035 
00061 class ArServerMode
00062 {
00063 public:
00065   AREXPORT ArServerMode(ArRobot *robot, ArServerBase *server, const char *name);
00067   AREXPORT virtual ~ArServerMode();
00069   AREXPORT virtual ArActionGroup *getActionGroup(void) { return NULL; }
00071   AREXPORT virtual void activate(void) = 0;
00073   AREXPORT virtual void deactivate(void) = 0;
00075   AREXPORT virtual void userTask(void) {}
00077   AREXPORT virtual void requestUnlock(void) { }
00079   AREXPORT void lockMode(bool willUnlockIfRequested = false);
00081   AREXPORT void unlockMode(void);      
00083   AREXPORT const char *getMode(void) const { return myMode.c_str(); }
00085   AREXPORT const char *getStatus(void) const { return myStatus.c_str(); }
00087   AREXPORT const char *getName(void) const { return myName.c_str(); }
00089   AREXPORT bool isActive(void) const { return myIsActive; }
00091   AREXPORT static bool willUnlockIfRequested(void);
00093   AREXPORT static ArServerMode *getActiveMode(void);
00095   AREXPORT bool hasSetActivityTime(void) { return myHasSetActivityTime; }
00097   AREXPORT ArTime getActivityTime(void);
00099   AREXPORT void setActivityTimeToNow(void);
00101   AREXPORT static int getActiveModeActivityTimeSecSince(void);
00103   AREXPORT void addAsDefaultMode(ArListPos::Pos pos = ArListPos::LAST);
00105 
00110   AREXPORT virtual void checkDefault(void) {}
00112   AREXPORT void setMode(const char *str) { myMode = str; }
00114 
00120   AREXPORT void setStatus(const char *str) 
00121     { myStatus = str; myStatusSetThisCycle = true; }
00123   AREXPORT bool addModeData(
00124           const char *name, const char *description,
00125           ArFunctor2<ArServerClient *, ArNetPacket *> *functor,
00126           const char *argumentDescription, const char *returnDescription,
00127           const char *commandGroup = NULL, const char *dataFlags = NULL);
00129   AREXPORT static void getModeDataList(ArServerClient *client, 
00130                                        ArNetPacket *packet);
00132   AREXPORT static void getModeInfo(ArServerClient *client, 
00133                                    ArNetPacket *packet);
00135   AREXPORT void addActivateCallback(
00136           ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST) 
00137     { myActivateCallbacks.addCallback(functor, position); }
00139   AREXPORT void remActivateCallback(ArFunctor *functor)
00140     { myActivateCallbacks.remCallback(functor); }
00142   AREXPORT void addDeactivateCallback(
00143           ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST) 
00144     { myDeactivateCallbacks.addCallback(functor, position); }
00146   AREXPORT void remDeactivateCallback(ArFunctor *functor)
00147     { myDeactivateCallbacks.remCallback(functor); }
00148 protected:
00149   AREXPORT static void modeUserTask(void);
00150   AREXPORT static void buildModeInfoPacket(ArNetPacket *packet);
00151   AREXPORT static std::list<ArServerMode *> *getRequestedActivateModes(void);
00152   AREXPORT void checkBroadcastModeInfoPacket(void);
00154   AREXPORT bool baseActivate(void);
00156   AREXPORT void baseDeactivate(void);
00157 
00158   ArCallbackList myActivateCallbacks;
00159   ArCallbackList myDeactivateCallbacks;
00160 
00161   bool myIsActive;
00162   ArRobot *myRobot;
00163   ArServerBase *myServer;
00164   std::string myName;
00165   // inheritors will want to play with these two strings as they are
00166   // what is shown to the user
00167   std::string myMode;
00168   std::string myStatus;
00169   bool myStatusSetThisCycle;
00170 
00171   // variables for activity time (so we can do things if idle) this
00172   // isn't static so that each mode can have its own
00173   // 'myHasSetActivityTime' so that if a mode doesn't use this scheme
00174   // it doesn't get tromped on
00175   bool myHasSetActivityTime;
00176   ArTime myActivityTime;
00177   ArMutex myActivityTimeMutex;
00178   
00179   AREXPORT static bool ourActiveModeLocked;
00180   AREXPORT static bool ourActiveModeWillUnlockIfRequested;
00181   AREXPORT static ArServerMode *ourActiveMode;
00182   AREXPORT static ArServerMode *ourNextActiveMode;
00183   AREXPORT static std::list<ArServerMode *> ourModes;
00184   AREXPORT static std::list<ArServerMode *> ourDefaultModes;
00185   AREXPORT static std::list<ArServerMode *> ourRequestedActivateModes;
00186   AREXPORT static std::multimap<std::string, std::string> ourModeDataMap;
00187   AREXPORT static ArMutex ourModeDataMapMutex;
00188   AREXPORT static ArGlobalFunctor2<ArServerClient *, 
00189                                    ArNetPacket *> ourGetModeDataListCB;
00190   AREXPORT static ArGlobalFunctor2<ArServerClient *, 
00191                                    ArNetPacket *> ourGetModeInfoCB;
00192   AREXPORT static bool ourLastActiveModeLocked;
00193   AREXPORT static ArServerMode *ourLastActiveMode;
00194   AREXPORT static bool ourLastActiveModeWillUnlockIfRequested;
00195   static ArGlobalFunctor ourUserTaskCB;    
00196   static bool ourUserTaskAdded;  
00197   // so we can easily just get the verbose out of this one
00198   ArLog::LogLevel myVerboseLogLevel;
00199 };
00200 
00201 #endif // ARSERVERMODE_H

Generated on Tue Feb 20 10:51:50 2007 for ArNetworking by  doxygen 1.4.0