Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArNetServer.h

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
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 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 
00025 */
00026 
00027 #ifndef ARNETSERVER_H
00028 #define ARNETSERVER_H
00029 
00030 #include "ariaTypedefs.h"
00031 #include "ArSocket.h"
00032 #include "ArFunctor.h"
00033 #include "ariaUtil.h"
00034 #include <list>
00035 
00036 
00037 class ArRobot;
00038 
00039 class ArArgumentBuilder;
00040 
00042 
00055 class ArNetServer
00056 {
00057 public:
00059   ArNetServer(bool addAriaExitCB = true);
00061   ~ArNetServer();
00062   
00064   bool open(ArRobot *robot, unsigned int port, 
00065                      const char *password, bool multipleClients = true);
00066 
00068   void close(void);
00069 
00071   bool addCommand(const char *command, 
00072                            ArFunctor3<char **, int, ArSocket *> *functor, 
00073                            const char *help);
00074 
00076   bool remCommand(const char *command);
00077 
00078 #ifndef SWIG
00079 
00080   void sendToAllClients(const char *str, ...);
00081 #endif
00082 
00083   void sendToAllClientsPlain(const char *str);
00084 
00086   bool isOpen(void);
00087 
00089   void setLoggingDataSent(bool loggingData);
00090   
00092   bool getLoggingDataSent(void);
00093 
00095   void setLoggingDataReceived(bool loggingData);
00096   
00098   bool getLoggingDataReceived(void);
00099 
00100 
00102   void runOnce(void);
00103 
00105   void internalGreeting(ArSocket *socket);
00106   
00108   void internalHelp(ArSocket *socket);
00110   void internalHelp(char **argv, int argc, ArSocket *socket);
00112   void internalEcho(char **argv, int argc, ArSocket *socket);
00114   void internalQuit(char **argv, int argc, ArSocket *socket);
00116   void internalShutdownServer(char **argv, int argc, 
00117                                        ArSocket *socket);
00119   void parseCommandOnSocket(ArArgumentBuilder *args, 
00120                                      ArSocket *socket, bool allowLog = true);
00122   void internalAddSocketToList(ArSocket *socket);
00124   void internalAddSocketToDeleteList(ArSocket *socket);
00126   void squelchNormal(void);
00128   void setExtraString(const char *str) { myExtraString = str; }
00130   const char *getExtraString(void) { return myExtraString.c_str(); }
00132   int lock() {return(myMutex.lock());}
00134   int tryLock() {return(myMutex.tryLock());}
00136   int unlock() {return(myMutex.unlock());}
00137 
00138 protected:
00139   ArMutex myMutex;
00140   std::map<std::string, ArFunctor3<char **, int, ArSocket *> *, ArStrCaseCmpOp> myFunctorMap;
00141   std::map<std::string, std::string, ArStrCaseCmpOp> myHelpMap;
00142   bool myLoggingDataSent;
00143   bool myLoggingDataReceived;
00144   bool myOpened;
00145   bool myWantToClose;
00146   bool mySquelchNormal;
00147   ArSocket myServerSocket;
00148   ArRobot *myRobot;
00149   std::string myPassword;
00150   bool myMultipleClients;
00151   unsigned int myPort;
00152   std::string myExtraString;
00153   std::list<ArSocket *> myConns;
00154   std::list<ArSocket *> myConnectingConns;
00155   std::list<ArSocket *> myDeleteList;
00156   ArFunctorC<ArNetServer> myTaskCB;
00157   ArFunctor3C<ArNetServer, char **, int, ArSocket *> myHelpCB;
00158   ArFunctor3C<ArNetServer, char **, int, ArSocket *> myEchoCB;
00159   ArFunctor3C<ArNetServer, char **, int, ArSocket *> myQuitCB;
00160   ArFunctor3C<ArNetServer, char **, int, ArSocket *> myShutdownServerCB;
00161   ArFunctorC<ArNetServer> myAriaExitCB;
00162 };
00163 
00164 #endif // ARNETSERVER_H

Generated on Wed Oct 19 12:56:36 2005 for Aria by  doxygen 1.4.0