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

ArCentralForwarder.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 ARCENTRALFORWARDER_H
00027 #define ARCENTRALFORWARDER_H
00028 
00029 #include "Aria.h"
00030 #include "ArServerBase.h"
00031 #include "ArClientBase.h"
00032 
00036 class ArCentralForwarder 
00037 {
00038 public:
00039   AREXPORT ArCentralForwarder(
00040           ArServerBase *mainServer, ArSocket *socket,
00041           const char *robotName, int startingPort, std::set<int> *usedPorts);
00042   AREXPORT ~ArCentralForwarder();
00043   ArServerBase *getServer(void) { return myServer; }
00044   ArClientBase *getClient(void) { return myClient; }
00045   int getPort(void) { return myPort; }
00046   const char *getRobotName(void) { return myRobotName.c_str(); }
00047   AREXPORT void netCentralHeartbeat(ArNetPacket *packet);
00048   AREXPORT bool callOnce(double heartbeatTimeout);
00049   AREXPORT bool isConnected(void) { return myState == STATE_CONNECTED; }
00050 protected:
00051   void serverClientRemoved(ArServerClient *client);
00052   void receiveData(ArNetPacket *packet);
00053   void requestChanged(long interval, unsigned int command);
00054   void requestOnce(ArServerClient *client, ArNetPacket *packet);
00055 
00056   AREXPORT bool startingCallOnce(double heartbeatTimeout);
00057   AREXPORT bool connectingCallOnce(double heartbeatTimeout);
00058   AREXPORT bool connectedCallOnce(double heartbeatTimeout);
00059 
00060   ArServerBase *myMainServer;
00061   ArSocket *mySocket;
00062   std::string myRobotName;
00063   int myStartingPort;
00064   std::set<int> *myUsedPorts;
00065 
00066   enum State
00067   {
00068     STATE_STARTING,
00069     STATE_CONNECTING,
00070     STATE_CONNECTED
00071   };
00072 
00073   ArServerBase *myServer;
00074   ArClientBase *myClient;
00075   State myState;
00076   int myPort;
00077   ArServerBase *server;
00078   ArClientBase *client;
00079   
00080   enum ReturnType
00081   {
00082     RETURN_NONE,
00083     RETURN_SINGLE,
00084     RETURN_VIDEO,
00085     RETURN_UNTIL_EMPTY,
00086     RETURN_COMPLEX
00087   };
00088 
00089   std::map<unsigned int, ReturnType> myReturnTypes;
00090   std::map<unsigned int, std::list<ArServerClient *> *> myRequestOnces;
00091   std::map<unsigned int, ArTime *> myLastRequest;
00092   std::map<unsigned int, ArTime *> myLastBroadcast;
00093 
00094   ArTime myLastHeartbeat;
00095 
00096   ArFunctor1C<ArCentralForwarder, ArNetPacket *> myReceiveDataFunctor;
00097   ArFunctor2C<ArCentralForwarder, 
00098               long, unsigned int> myRequestChangedFunctor;
00099   ArFunctor2C<ArCentralForwarder, 
00100               ArServerClient *, ArNetPacket *> myRequestOnceFunctor;
00101   ArFunctor1C<ArCentralForwarder, 
00102       ArServerClient *> myServerClientRemovedCB;
00103   ArFunctor1C<ArCentralForwarder, 
00104       ArNetPacket *> myNetCentralHeartbeatCB;
00105 
00106 };
00107 
00108 
00109 #endif // ARSERVERSWITCHFORWARDER

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