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

ArServerClient.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 NLSERVERCLIENT_H
00027 #define NLSERVERCLIENT_H
00028 
00029 #include "ArNetPacket.h"
00030 #include "ArNetPacketReceiverTcp.h"
00031 #include "ArNetPacketSenderTcp.h"
00032 
00033 class ArServerData;
00034 class ArServerUserInfo;
00035 
00036 #include "ArServerClientData.h"
00037 
00038 
00045 class ArServerClient
00046 {
00047 public:
00049   enum ServerState {
00050     STATE_SENT_INTRO, 
00051     STATE_REJECTED, 
00052     STATE_CONNECTED, 
00053     STATE_DISCONNECTED 
00054   };
00055 
00056 
00058   AREXPORT ArServerClient(ArSocket *tcpSocket, unsigned int udpPort, 
00059                           long authKey, long introKey, 
00060                           ArRetFunctor2<bool, ArNetPacket *, 
00061                           struct sockaddr_in *> *sendUdpCallback,
00062                           std::map<unsigned int, ArServerData *> *dataMap,
00063                           const char *passwordKey, const char *serverKey,
00064                           const ArServerUserInfo *userInfo = NULL,
00065                           int rejecting = 0, 
00066                           const char *rejectingString = "");
00068   AREXPORT virtual ~ArServerClient();
00069   
00071   AREXPORT bool tcpCallback(void);
00072   
00074   AREXPORT void processPacket(ArNetPacket *packet, bool tcp = true);
00075   
00079   AREXPORT bool sendPacketTcp(ArNetPacket *packet);
00083   AREXPORT bool sendPacketUdp(ArNetPacket *packet);
00084 
00086   AREXPORT bool hasGroupAccess(const char *group);
00087 
00092   AREXPORT void broadcastPacketTcp(ArNetPacket *packet); 
00093 
00097   AREXPORT void broadcastPacketUdp(ArNetPacket *packet);
00098 
00100   AREXPORT void logTracking(bool terse);
00101   
00103   AREXPORT void resetTracking(void);
00104 
00106   AREXPORT const char *getIPString(void) const;
00107 
00109   AREXPORT void shutdown(void);
00110 
00112   AREXPORT void setUdpAddress(struct sockaddr_in *sin);
00113 
00115   AREXPORT struct sockaddr_in *getUdpAddress(void);
00116  
00118   AREXPORT long getAuthKey(void);
00119 
00121   AREXPORT void processAuthPacket(ArNetPacket *packet, struct sockaddr_in *sin);
00122   
00124   AREXPORT void handleRequests(void);
00125 
00127   AREXPORT ArSocket *getTcpSocket(void) { return &myTcpSocket; }
00129   AREXPORT void forceDisconnect(bool quiet);
00131   AREXPORT long getFrequency(ArTypes::UByte2 command);
00132 protected:
00133   // Some members so that we don't have to pass the number around
00134   std::list<unsigned int> myCommandStack;
00135   AREXPORT bool setupPacket(ArNetPacket *packet);
00136   // Pushes a new number onto our little stack of numbers
00137   void pushCommand(unsigned int num);
00138   // Pops the command off the stack
00139   void popCommand(void);
00140   // Gets the command we're on
00141   unsigned int getCommand();
00142 
00143   // this sends a list packet to our client
00144   void sendListPacket(void);
00145 
00146   // this could just be dealth with by seeing if myUserInfo is NULL,
00147   // but that may be confusing
00148   const ArServerUserInfo *myUserInfo;
00149   std::set<std::string, ArStrCaseCmpOp> myGroups;  
00150   ArNetPacketSenderTcp myTcpSender;
00151   std::map<unsigned int, ArServerData *> *myDataMap;
00152   std::list<ArServerClientData *> myRequested;
00153   void internalSwitchState(ServerState state);
00154   ServerState myState;
00155   ArTime myStateStart;
00156   bool myUdpConfirmedFrom;
00157   bool myUdpConfirmedTo;
00158   ArSocket myTcpSocket;
00159   ArNetPacketReceiverTcp myTcpReceiver;
00160   ArFunctor2C<ArServerClient, ArNetPacket *, bool> myProcessPacketCB;
00161   ArRetFunctor2<bool, ArNetPacket *, struct sockaddr_in *> *mySendUdpCB;
00162   struct sockaddr_in mySin;
00163   long myAuthKey;
00164   long myIntroKey;
00165   bool myTcpOnly;
00166   std::string myPasswordKey;
00167   std::string myServerKey;
00168 
00169   int myRejecting;
00170   std::string myRejectingString;
00171 
00172 
00173   ArTime myTrackingStarted;
00174   class Tracker
00175   {
00176   public:
00177     Tracker() { reset(); }
00178     virtual ~Tracker() {}
00179     void reset(void) 
00180       { myPacketsTcp = 0; myBytesTcp = 0; myPacketsUdp = 0; myBytesUdp = 0; }
00181     long myPacketsTcp;
00182     long myBytesTcp;
00183     long myPacketsUdp;
00184     long myBytesUdp;
00185   };
00186   AREXPORT void trackPacketSent(ArNetPacket *packet, bool tcp);
00187   AREXPORT void trackPacketReceived(ArNetPacket *packet, ArTypes::UByte2, bool tcp);
00188   std::map<ArTypes::UByte2, Tracker *> myTrackingSentMap;
00189   std::map<ArTypes::UByte2, Tracker *> myTrackingReceivedMap;
00190   
00191 };
00192 
00193 #endif

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