X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FService.hh;h=570a2309e270cb235a7abe7e1b8819d12a7264a6;hp=7c5e6b7b7b440ad4ba9f14fb6ec519eb230633c6;hb=de6942ee1401fea16a171610de779ef0a8c57e38;hpb=c78934a448d0126709fccec3d5a636b3baa87da4 diff --git a/src/Moof/Service.hh b/src/Moof/Service.hh index 7c5e6b7..570a230 100644 --- a/src/Moof/Service.hh +++ b/src/Moof/Service.hh @@ -9,10 +9,15 @@ * **************************************************************************/ +/** + * \file Service.hh + * Classes for publishing and finding network services. + */ + #ifndef _MOOF_SERVICE_HH_ #define _MOOF_SERVICE_HH_ -#include +#include #include #include @@ -29,37 +34,89 @@ class Service public: /** - * Construct a network service. + * 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); + + /** + * 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); + + + /** + * 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; + const SocketAddress& address() const + { + return mAddress; + } /** - * Get the service information. - * \return The service information as a string. + * Get the type of the service. + * \return The service type. */ - const std::string& text() const; + const std::string& type() const + { + return mType; + } + /** + * Get the service name. + * \return The service name. + */ + const std::string& name() const + { + return mName; + } /** - * Publish the service on the network. + * Get the service information. + * \return The service information as a string. */ - void publish(); + const std::string& text() const + { + return mText; + } - void update(Scalar t, Scalar dt); + + ~Service(); private: + int handlePacket(SocketMultiplexer& mux, + Packet& packet, + const SocketAddress& address); + SocketAddress mAddress; + std::string mType; + std::string mName; std::string mText; }; @@ -68,12 +125,23 @@ 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. + */ + explicit ServiceFinder(const SocketAddress& address); - void update(Scalar t, Scalar dt); + /** + * 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 ServiceFinder(const std::string& type, + int sockType = SOCK_STREAM); - const std::vector& services() const + const std::map& services() const { return mServices; } @@ -81,7 +149,12 @@ public: private: - std::vector mServices; + int handlePacket(SocketMultiplexer& mux, + Packet& packet, + const SocketAddress& address); + + std::string mType; + std::map mServices; };