*
**************************************************************************/
+/**
+ * \file Service.hh
+ * Classes for publishing and finding network services.
+ */
+
#ifndef _MOOF_SERVICE_HH_
#define _MOOF_SERVICE_HH_
+#include <map>
+
#include <Moof/Math.hh>
+#include <Moof/Socket.hh>
namespace Mf {
-class ServiceBroadcaster
+/**
+ * Class representing a network service.
+ */
+class Service
{
public:
- ServiceBroadcaster(const std::string& name);
-
- void update(Scalar t, Scalar dt);
+ /**
+ * 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 SocketAddress& address,
+ const std::string& name,
+ const std::string& text);
+
+ /**
+ * 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 SocketAddress& address,
+ const std::string& type,
+ 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 SocketAddress& address() const
+ {
+ return mAddress;
+ }
+
+ /**
+ * Get the type of the service.
+ * \return The service type.
+ */
+ const std::string& type() const
+ {
+ return mType;
+ }
+
+ /**
+ * Get the service name.
+ * \return The service name.
+ */
+ const std::string& name() const
+ {
+ return mName;
+ }
+
+ /**
+ * Get the service information.
+ * \return The service information as a string.
+ */
+ const std::string& text() const
+ {
+ return mText;
+ }
+
+
+ ~Service();
+
+
+private:
+
+ int handlePacket(SocketMultiplexer& sock,
+ Packet& packet,
+ const SocketAddress& address);
+
+ SocketAddress mAddress;
+ std::string mType;
+ std::string mName;
+ std::string mText;
};
-class ServiceLocator
+class ServiceFinder
{
public:
- ServiceLocator(const std::string& name);
+ /**
+ * Construct a service finder to find services of the same type as an
+ * address.
+ * \address The address.
+ */
+ ServiceFinder(const SocketAddress& 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.
+ */
+ ServiceFinder(const std::string& type, int sockType = SOCK_STREAM);
+
+
+ const std::map<std::string,Service>& services() const
+ {
+ return mServices;
+ }
+
+
+private:
+
+ int handlePacket(SocketMultiplexer& sock,
+ Packet& packet,
+ const SocketAddress& address);
- void update(Scalar t, Scalar dt);
+ std::string mType;
+ std::map<std::string,Service> mServices;
};