]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Service.hh
tcp socket disconnecting by remote
[chaz/yoink] / src / Moof / Service.hh
index 77cee183f9b3346c8563dbafff75105b00e9ee76..b26f4cfb375a01433eb9f1c3c5c59a371f0f4028 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef _MOOF_SERVICE_HH_
 #define _MOOF_SERVICE_HH_
 
-#include <vector>
+#include <map>
 
 #include <Moof/Math.hh>
 #include <Moof/Socket.hh>
@@ -34,18 +34,37 @@ class Service
 public:
 
        /**
-        * Construct a network service.
+        * 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& text);
+       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 local network.
+        * Publish the service on the network.
         */
        void publish();
 
+       /**
+        * Stop publishing the service on the network.
+        */
        void stop();
 
 
@@ -58,6 +77,24 @@ public:
                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.
@@ -68,6 +105,9 @@ public:
        }
 
 
+       ~Service();
+
+
 private:
 
        int handlePacket(SocketMultiplexer& sock,
@@ -75,6 +115,8 @@ private:
                                         const SocketAddress& address);
 
        SocketAddress   mAddress;
+       std::string             mType;
+       std::string             mName;
        std::string             mText;
 };
 
@@ -83,10 +125,22 @@ class ServiceFinder
 {
 public:
 
-       ServiceFinder(const std::string& service, int type = SOCK_STREAM);
+       /**
+        * 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::vector<Service>& services() const
+       const std::map<std::string,Service>& services() const
        {
                return mServices;
        }
@@ -98,8 +152,8 @@ private:
                                         Packet& packet,
                                         const SocketAddress& address);
 
-       std::string                             mService;
-       std::vector<Service>    mServices;
+       std::string                                             mType;
+       std::map<std::string,Service>   mServices;
 };
 
 
This page took 0.022036 seconds and 4 git commands to generate.