RemoteEvents.cc
Go to the documentation of this file.00001 #include "Events/RemoteEvents.h"
00002 #include "Events/EventRouter.h"
00003 #include "Shared/string_util.h"
00004
00005 RemoteEvents::RemoteEvents() : sck(NULL),
00006 sizeLeft(0), vecbuf(), bufType(Invalid) {
00007
00008 }
00009
00010 RemoteEvents::~RemoteEvents() {
00011
00012 }
00013
00014 std::string RemoteEvents::remoteIPString() {
00015 return string_util::intToStringIP(remoteIPInt());
00016 }
00017
00018 int RemoteEvents::remoteIPInt() {
00019 return sck->getPeerAddress();
00020 }
00021
00022
00023
00024
00025 bool RemoteEvents::readType(char* &data, int &bytes) {
00026
00027 if ((unsigned)bytes < sizeof(BufferType))
00028 return false;
00029
00030 bufType = *(BufferType *)data;
00031 data += sizeof(BufferType);
00032 bytes -= sizeof(BufferType);
00033 return true;
00034 }
00035
00036
00037 bool RemoteEvents::readSize(char* &data, int &bytes) {
00038
00039 if ((unsigned)bytes < sizeof(int))
00040 return false;
00041
00042
00043 vecbuf.clear();
00044
00045
00046 sizeLeft = *(int *)data;
00047 data += sizeof(int);
00048 bytes -= sizeof(int);
00049 return true;
00050 }
00051
00052
00053
00054
00055 bool RemoteEvents::readData(char* &data, int &bytes) {
00056 while (bytes) {
00057
00058 if (!sizeLeft)
00059 return true;
00060
00061
00062 vecbuf.push_back(*data++);
00063 bytes--;
00064 sizeLeft--;
00065 }
00066
00067 return !sizeLeft;
00068 }
00069
00070
00071 bool RemoteEvents::isConnected() {
00072 return sck==NULL ? false : wireless->isConnected(sck->sock);
00073 }
00074
00075 std::ostream& operator<<(std::ostream &os, const RemoteRequest &req) {
00076 os << "RemoteRequest[type=" << req.type
00077 << ",elts=" << req.numElements
00078 << ",egid=" << req.egid
00079 << ",sid=" << req.sid
00080 << ",etid=" << req.etid
00081 << ",sType=" << req.sType
00082 << ",interval=" << req.interval
00083 << "]";
00084 return os;
00085 }