]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Service.cc
more explicit constructors
[chaz/yoink] / src / Moof / Service.cc
index 43689afdee09a0c62975f2ce92298d581b5f3613..da135c1fea51513a2f7a4f3af2ebf8c02ab46293 100644 (file)
 **************************************************************************/
 
 #include "Service.hh"
+#include "Socket.hh"
 
 
-namespace Mf {
+#define SOLICIT  0x1234ABCD
+#define RESPONSE 0xABCD1234
 
 
-ServiceBroadcaster::ServiceBroadcaster(const std::string& name)
-{
-}
+namespace Mf {
+
 
-void ServiceBroadcaster::update(Scalar t, Scalar dt)
+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;
 }
 
-
-ServiceLocator::ServiceLocator(const std::string& name)
+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 ServiceLocator::update(Scalar t, Scalar dt)
+ServiceFinder::ServiceFinder(const std::string& type, int sockType)
 {
 }
 
This page took 0.02088 seconds and 4 git commands to generate.