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

ArServerBase.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 NLSERVERBASE_H
00027 #define NLSERVERBASE_H
00028 
00029 #include "Aria.h"
00030 #include "ArServerClient.h"
00031 #include "ArServerData.h"
00032 #include "ArNetPacket.h"
00033 #include "ArNetPacketReceiverUdp.h"
00034 #include "ArServerUserInfo.h"
00091 class ArServerBase: public ArASyncTask
00092 {
00093 public:
00095   AREXPORT ArServerBase(bool addAriaExitCB = true, 
00096                         const char *serverName = "");
00098   AREXPORT virtual ~ArServerBase();
00099   
00101   AREXPORT bool open(unsigned int port, const char *openOnIP = NULL);
00103   AREXPORT void close(void);
00105   AREXPORT void loopOnce(void);
00106 
00108   AREXPORT bool addData(const char *name, const char *description,
00109                         ArFunctor2<ArServerClient *, ArNetPacket *> *functor,
00110                         const char *argumentDescription,
00111                         const char *returnDescription,
00112                         const char *commandGroup = NULL,
00113                         const char *dataFlags = NULL);
00114 
00116   AREXPORT bool loadUserInfo(const char *fileName, 
00117                              const char *baseDirectory = "");
00118   
00120   AREXPORT void logUserInfo(void);
00121 
00123   AREXPORT void logCommandGroups(void);  
00124 
00126   AREXPORT void logCommandGroupsToFile(const char *fileName);  
00127 
00129   AREXPORT void setGroupDescription(const char *GrpName, const char *GrpDesc);  
00130 
00132   AREXPORT void logGroupDescriptions(void);  
00133 
00135   AREXPORT void logGroupDescriptionsToFile(const char *fileName);  
00136 
00138   AREXPORT void setServerKey(const char *serverKey);
00139 
00141   AREXPORT void rejectSinceUsingCentralServer(
00142           const char *centralServerIPString);
00143 
00145   AREXPORT virtual void run(void);
00146   
00148   AREXPORT virtual void runAsync(void);
00149 
00151   AREXPORT int getNumClients(void);
00152 
00154   AREXPORT unsigned int findCommandFromName(const char *command);
00155 
00157   AREXPORT bool broadcastPacketTcp(ArNetPacket *packet, const char *name);
00158 
00160   AREXPORT bool broadcastPacketTcpWithExclusion(
00161           ArNetPacket *packet, const char *name, 
00162           ArServerClient *excludeClient);
00163 
00165   AREXPORT bool broadcastPacketUdp(ArNetPacket *packet, const char *name);
00166 
00168   AREXPORT bool broadcastPacketUdpWithExclusion(
00169         ArNetPacket *packet, const char *name, ArServerClient *excludeClient);
00170 
00172   AREXPORT void processPacket(ArNetPacket *packet, 
00173                               struct sockaddr_in *sin);
00174 
00176   AREXPORT bool sendUdp(ArNetPacket *packet, 
00177                         struct sockaddr_in *sin);
00178   
00180   AREXPORT void logTracking(bool terse = true);
00181 
00183   AREXPORT void resetTracking(void);
00184 
00185   // the function for the thread
00186   AREXPORT virtual void * runThread(void *arg);
00187 
00189   AREXPORT unsigned int getTcpPort(void);
00191   AREXPORT unsigned int getUdpPort(void);
00192 
00194   AREXPORT void addCycleCallback(ArFunctor* functor);
00195 
00197   AREXPORT void remCycleCallback(ArFunctor* functor);
00198 
00200   AREXPORT void addClientRemovedCallback(ArFunctor1<ArServerClient *> *functor);
00202   AREXPORT void remClientRemovedCallback(ArFunctor1<ArServerClient *> *functor);
00204   AREXPORT void makeNewServerClientFromSocket(ArSocket *socket, 
00205                                               bool doNotReject);
00207   AREXPORT const ArServerUserInfo *getUserInfo(void) const;
00209   AREXPORT void setUserInfo(const ArServerUserInfo *userInfo);
00211   AREXPORT bool addDataAdvanced(
00212           const char *name, const char *description,
00213           ArFunctor2<ArServerClient *, ArNetPacket *> *functor,
00214           const char *argumentDescription, const char *returnDescription,
00215           const char *commandGroup = NULL, const char *dataFlags = NULL, 
00216           unsigned int commandNumber = 0,
00217           ArFunctor2<long, unsigned int> *requestChangedFunctor = NULL, 
00218           ArFunctor2<ArServerClient *, ArNetPacket *> 
00219           *requestOnceFunctor = NULL);
00221   AREXPORT void setAdditionalDataFlags(const char *additionalDataFlags);
00223   AREXPORT long getFrequency(unsigned int command, 
00224                              bool internalCall = false);
00226   AREXPORT bool broadcastPacketTcpByCommand(
00227           ArNetPacket *packet, unsigned int command);
00228 
00230   AREXPORT bool broadcastPacketTcpByCommandWithExclusion(
00231           ArNetPacket *packet, unsigned int command,
00232           ArServerClient *excludeClient);
00233 
00235   AREXPORT bool broadcastPacketUdpByCommand(
00236           ArNetPacket *packet, unsigned int command);
00237 
00239   AREXPORT bool broadcastPacketUdpByCommandWithExclusion(
00240           ArNetPacket *packet, unsigned int command,
00241           ArServerClient *excludeClient);
00242 
00244   AREXPORT bool dataHasFlag(const char *name, const char *dataFlag);
00246   AREXPORT bool dataHasFlagByCommand(unsigned int command, 
00247                                      const char *dataFlag);
00248   
00249 protected:
00250   std::string myServerName;
00251   ArMutex myDataMutex;
00252   ArMutex myClientsMutex;
00253   ArMutex myCycleCallbacksMutex;
00255   void acceptTcpSockets(void);
00257   AREXPORT void finishAcceptingSocket(ArSocket *socket, 
00258                                       bool skipPassword = false, 
00259                                       bool doNotReject = false);
00260 
00261   unsigned int myTcpPort;
00262   unsigned int myUdpPort;
00263   // our mapping of the ints to the serverData
00264   std::map<unsigned int, ArServerData *> myDataMap;
00266   std::map<std::string, std::string> myGroupDescription;                        
00267 
00268   int myRejecting;
00269   std::string myRejectingString;
00270   // the number we're on for the current data
00271   unsigned int myNextDataNumber;
00272   std::string myAdditionalDataFlags;
00273   bool myOpened;
00274   std::list<ArServerClient *> myClients;
00275   ArNetPacketReceiverUdp myUdpReceiver;
00276   ArFunctor2C<ArServerBase, ArNetPacket *, struct sockaddr_in *> myProcessPacketCB;
00277   ArRetFunctor2C<bool, ArServerBase, ArNetPacket *, struct sockaddr_in *> mySendUdpCB;  
00278   ArSocket myTcpSocket;
00279   ArSocket myUdpSocket;
00280   std::list<ArFunctor*> myCycleCallbacks;
00281   std::list<ArFunctor1<ArServerClient *> *> myClientRemovedCallbacks;
00282 
00283   const ArServerUserInfo *myUserInfo;
00284   std::string myServerKey;
00285   ArFunctorC<ArServerBase> myAriaExitCB;
00286   ArRetFunctor2C<long, ArServerBase, unsigned int, bool> myGetFrequencyCB;
00287 };
00288 
00289 #endif

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