Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RemoteEvents.h

Go to the documentation of this file.
00001 #ifndef _REMOTEEVENTS_H_
00002 #define _REMOTEEVENTS_H_
00003 
00004 #include "Wireless/Socket.h"
00005 #include "Wireless/Wireless.h"
00006 #include "Wireless/SocketListener.h"
00007 #include "Events/EventBase.h"
00008 #include "Events/NetworkBuffer.h"
00009 #include "Shared/RemoteState.h"
00010 #include <vector>
00011 #include <string>
00012 
00013 
00014 /*! This class contains the network code common between RemoteRouter
00015  *  and EventProxy. It contains methods for sending and receiving
00016  *  events, state updates, and requests to recieve the former two
00017  *  things. */
00018 class RemoteEvents : public SocketListener {
00019     public:
00020 
00021   //! This is sent in the header of any data sent over the wireless,
00022   //it indicates what type of data it is
00023     enum BufferType {
00024         Invalid,
00025         StateData,
00026         EventData,
00027         RequestData
00028     };
00029 
00030   //! This is sent in the header of any requests for remote events
00031   //or state updates
00032   enum RequestType {
00033     EventListenerRequest,
00034     StateUpdateRequest,
00035     RemoveEventListenerRequest,
00036     StopStateUpdateRequest
00037   };
00038   
00039   //! Returns true of the socket is connected
00040     bool isConnected();
00041 
00042   //! Returns the remote IP address as a string
00043   std::string remoteIPString();
00044 
00045   //! Returns the remote IP address as an int
00046   int remoteIPInt();
00047 
00048   
00049   static const int defaultBufferSize = 1024;
00050   
00051     protected:
00052 
00053     //This is so the class can't be instantiated by itself
00054     RemoteEvents();
00055     virtual ~RemoteEvents();
00056     
00057     Socket *sck;
00058     
00059     //Methods and variables for receiving data------------------
00060     int sizeLeft;
00061     std::vector<char> vecbuf;
00062     BufferType bufType;
00063     
00064     bool readSize(char* &data, int &bytes);
00065     bool readType(char* &data, int &bytes);
00066     bool readData(char* &data, int &bytes);
00067     //-------------------------------------------------------
00068   
00069     RemoteEvents(RemoteEvents&);
00070     RemoteEvents &operator=(const RemoteEvents&);
00071 };
00072 
00073 /*! This struct holds the information required for a request to a
00074  *  server robot for events for state updates.  */
00075 struct RemoteRequest {
00076   RemoteEvents::RequestType type;
00077 
00078   //Event subscription
00079   int numElements;
00080   EventBase::EventGeneratorID_t egid;
00081   size_t sid;
00082   EventBase::EventTypeID_t etid;
00083 
00084   //State updates
00085   RemoteState::StateType sType;
00086   unsigned int interval;
00087 };
00088 
00089 std::ostream& operator<<(std::ostream &os, const RemoteRequest &req);
00090 
00091 #endif

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