X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FService.cc;h=da135c1fea51513a2f7a4f3af2ebf8c02ab46293;hp=a5fae0f33862c05fd0d251e97593baca008ac881;hb=c85b710e7ead9bc417805bb893571a7139f1081c;hpb=c78934a448d0126709fccec3d5a636b3baa87da4 diff --git a/src/Moof/Service.cc b/src/Moof/Service.cc index a5fae0f..da135c1 100644 --- a/src/Moof/Service.cc +++ b/src/Moof/Service.cc @@ -10,16 +10,69 @@ **************************************************************************/ #include "Service.hh" +#include "Socket.hh" + + +#define SOLICIT 0x1234ABCD +#define RESPONSE 0xABCD1234 namespace Mf { -ServiceFinder::ServiceFinder(const std::string& service, int type) +int Service::handlePacket(SocketMultiplexer& mux, + Packet& packet, + const SocketAddress& address) +{ + try + { + uint32_t magic; + packet >> magic; + if (magic == SOLICIT) + { + std::string type; + packet >> type; + if (type == mType) + { + packet.clear(); + packet << RESPONSE << mType << mName << mText; + mux.socket().write(packet); + return 0; + } + } + } + catch (...) {} + return -1; +} + +int ServiceFinder::handlePacket(SocketMultiplexer& mux, + Packet& packet, + const SocketAddress& address) { + try + { + uint32_t magic; + packet >> magic; + if (magic == RESPONSE) + { + std::string type; + packet >> type; + if (type == mType) + { + std::string name; + std::string text; + packet >> name >> text; + Service service(address, type, name, text); + mServices.insert(std::make_pair(name, service)); + return 0; + } + } + } + catch (...) {} + return -1; } -void ServiceFinder::update(Scalar t, Scalar dt) +ServiceFinder::ServiceFinder(const std::string& type, int sockType) { }