]> Dogcows Code - chaz/yoink/blobdiff - src/moof/service.hh
the massive refactoring effort
[chaz/yoink] / src / moof / service.hh
diff --git a/src/moof/service.hh b/src/moof/service.hh
new file mode 100644 (file)
index 0000000..6db1d96
--- /dev/null
@@ -0,0 +1,164 @@
+
+/*]  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.
+*
+**************************************************************************/
+
+#ifndef _MOOF_SERVICE_HH_
+#define _MOOF_SERVICE_HH_
+
+/**
+ * \file service.hh
+ * Classes for publishing and finding network services.
+ */
+
+#include <map>
+
+#include <moof/math.hh>
+#include <moof/socket.hh>
+
+
+namespace moof {
+
+
+/**
+ * Class representing a network service.
+ */
+class service
+{
+public:
+
+       /**
+        * Construct a network service with an explicit type.
+        * \param address The address of the host.
+        * \param type The type of service.
+        * \param name The service name.
+        * \param text The service information.
+        */
+       service(const socket::address& address,
+                       const std::string& type,
+                       const std::string& name,
+                       const std::string& text);
+
+       /**
+        * Construct a network service.  The type of service will be inferred
+        * from the address.
+        * \param address The address of the host.
+        * \param name The service name.
+        * \param text The service information.
+        */
+       service(const socket::address& address,
+                       const std::string& name,
+                       const std::string& text);
+
+
+       /**
+        * Publish the service on the network.
+        */
+       void publish();
+
+       /**
+        * Stop publishing the service on the network.
+        */
+       void stop();
+
+
+       /**
+        * Get the host address.
+        * \return The address.
+        */
+       const socket::address& address() const
+       {
+               return address_;
+       }
+
+       /**
+        * Get the type of the service.
+        * \return The service type.
+        */
+       const std::string& type() const
+       {
+               return type_;
+       }
+
+       /**
+        * Get the service name.
+        * \return The service name.
+        */
+       const std::string& name() const
+       {
+               return name_;
+       }
+
+       /**
+        * Get the service information.
+        * \return The service information as a string.
+        */
+       const std::string& text() const
+       {
+               return text_;
+       }
+
+
+       ~service();
+
+
+private:
+
+       int handle_packet(socket_multiplexer& mux,
+                                        packet& packet,
+                                        const socket::address& address);
+
+       socket::address address_;
+       std::string             type_;
+       std::string             name_;
+       std::string             text_;
+};
+
+
+class service_finder
+{
+public:
+
+       /**
+        * Construct a service finder to find services of the same type as an
+        * address.
+        * \address The address.
+        */
+       explicit service_finder(const socket::address& address);
+
+       /**
+        * Construct a service finder to find services of a certain type.
+        * \param type The type of the service.
+        * \param sockType The type of socket.
+        */
+       explicit service_finder(const std::string& type,
+                                                       int sockType = SOCK_STREAM);
+
+
+       const std::map<std::string,service>& services() const
+       {
+               return services_;
+       }
+
+
+private:
+
+       int handle_packet(socket_multiplexer& mux,
+                                         packet& packet,
+                                         const socket::address& address);
+
+       std::string                                             type_;
+       std::map<std::string,service>   services_;
+};
+
+
+} // namespace moof
+
+#endif // _MOOF_SERVICE_HH_
+
This page took 0.024268 seconds and 4 git commands to generate.