Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RemoteRouter.h

Go to the documentation of this file.
00001 #ifndef REMOTEROUTER_H_
00002 #define REMOTEROUTER_H_
00003 
00004 #include <string>
00005 #include "Wireless/Socket.h"
00006 #include "Wireless/Wireless.h"
00007 #include "Events/RemoteEvents.h"
00008 #include "Events/EventProxy.h"
00009 #include "Events/EventListener.h"
00010 #include "Shared/RemoteState.h"
00011 
00012 #include <vector>
00013 #include <list>
00014 
00015 class RemoteState;
00016 
00017 /* ! This class allows a client robot to subscribe to events and state updates on a remote robot. It receives events and state from EventProxy on the 
00018   * remote server robot. It is started automatically. Subscribe to events on remote robots using EventRouter::addRemoteListener() and state updates using
00019   * EventRouter::requestRemoteStateUpdates()
00020   */
00021 class RemoteRouter : public RemoteEvents, public EventListener {
00022   public:
00023 
00024   //! constructor
00025   RemoteRouter(int host);
00026   
00027   //! destructor
00028   virtual ~RemoteRouter();
00029 
00030   //! Request state data from a remote robot every 'interval' amount of time. Use EventRouter::requestRemoteStateUpdates() rather than calling this directly.
00031   void requestStateUpdates(RemoteState::StateType type, unsigned int interval);
00032   
00033   //! Cancels state data updates from a remote dog for the given StateType. Use EventRouter::stopRemoteStateUpdates() rather than calling this directly.
00034   void stopStateUpdates(RemoteState::StateType type);
00035 
00036   //! Add remote listener by EGID. Use EventRouter::addRemoteListener() rather than calling this directly.
00037   void addListener(EventBase::EventGeneratorID_t egid);
00038 
00039   //! Add remote listener by EGID and SID. Use EventRouter::addRemoteListener() rather than calling this directly.
00040   void addListener(EventBase::EventGeneratorID_t egid,
00041            size_t sid);
00042 
00043   //! Add remote listener by EGID, SID, and ETID. Use EventRouter::addRemoteListener() rather than calling this directly.
00044   void addListener(EventBase::EventGeneratorID_t egid,
00045            size_t sid,
00046            EventBase::EventTypeID_t etid);
00047 
00048   //! Remove remote listener by EGID. Use EventRouter::removeRemoteListener() rather than calling this directly.
00049   void removeListener(EventBase::EventGeneratorID_t egid);
00050 
00051   //! Remove remote listener by EGID and SID. Use EventRouter::removeRemoteListener() rather than calling this directly.
00052   void removeListener(EventBase::EventGeneratorID_t egid,
00053             size_t sid);
00054 
00055   //! Remove remote listener by EGID, SID, and ETID. Use EventRouter::removeRemoteListener() rather than calling this directly.
00056   void removeListener(EventBase::EventGeneratorID_t egid,
00057             size_t sid,
00058             EventBase::EventTypeID_t etid);
00059 
00060   RemoteState *rstate;
00061 
00062   //! Processes timer events which wait for connections to remote EventProxy.
00063   void processEvent(const EventBase& event);
00064   
00065   //! Receives data from remote EventProxy and forwards it to the correct function according to the data type (Event or State)
00066   int processData(char *data, int bytes);
00067 
00068   protected:
00069 
00070   //! Returns true when robot is connected to remote robot
00071   bool isReady() {
00072     return !waitingForPort && isConnected();
00073   }
00074 
00075   //! Connect robot on specified port
00076   void connect(int port);
00077 
00078   bool waitingForPort;
00079   std::list<RemoteRequest> requestQueue;
00080   bool timerActive;
00081   int waitTime;
00082   
00083   int remoteHost;
00084   
00085   //! Add a remote request to the request queue
00086   void sendRemoteRequest(RemoteRequest& info);
00087   
00088   //! Decode the event from the buffer and post it locally
00089   void forwardEvent(std::vector<char>& event);
00090   
00091   RemoteRouter(RemoteRouter&);
00092   RemoteRouter &operator=(const RemoteRouter&);
00093 };
00094 
00095 #endif /*REMOTEROUTER_H_*/

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:50 2016 by Doxygen 1.6.3