]> Dogcows Code - chaz/yoink/blobdiff - src/moof/service.cc
the massive refactoring effort
[chaz/yoink] / src / moof / service.cc
diff --git a/src/moof/service.cc b/src/moof/service.cc
new file mode 100644 (file)
index 0000000..869b541
--- /dev/null
@@ -0,0 +1,81 @@
+
+/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
+**]  All rights reserved.
+*
+* vi:ts=4 sw=4 tw=75
+*
+* Distributable under the terms and conditions of the 2-clause BSD license;
+* see the file COPYING for a complete text of the license.
+*
+**************************************************************************/
+
+#include "service.hh"
+#include "socket.hh"
+
+
+#define SOLICIT  0x1234ABCD
+#define RESPONSE 0xABCD1234
+
+
+namespace moof {
+
+
+int service::handle_packet(socket_multiplexer& mux,
+                                                  packet& packet,
+                                                  const socket::address& address)
+{
+       try
+       {
+               uint32_t magic;
+               packet >> magic;
+               if (magic == SOLICIT)
+               {
+                       std::string type;
+                       packet >> type;
+                       if (type == type_)
+                       {
+                               packet.clear();
+                               packet << RESPONSE << type_ << name_ << text_;
+                               mux.socket().write(packet);
+                               return 0;
+                       }
+               }
+       }
+       catch (...) {}
+       return -1;
+}
+
+int service_finder::handle_packet(socket_multiplexer& mux,
+                                                                 packet& packet,
+                                                                 const socket::address& address)
+{
+       try
+       {
+               uint32_t magic;
+               packet >> magic;
+               if (magic == RESPONSE)
+               {
+                       std::string type;
+                       packet >> type;
+                       if (type == type_)
+                       {
+                               std::string name;
+                               std::string     text;
+                               packet >> name >> text;
+                               service service(address, type, name, text);
+                               services_.insert(std::make_pair(name, service));
+                               return 0;
+                       }
+               }
+       }
+       catch (...) {}
+       return -1;
+}
+
+service_finder::service_finder(const std::string& type, int sockType)
+{
+}
+
+
+} // namespace moof
+
This page took 0.022058 seconds and 4 git commands to generate.