X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmoof%2Fservice.hh;fp=src%2Fmoof%2Fservice.hh;h=6db1d964b1e47a76c0cfc2c77af0fb9962a8f374;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hp=0000000000000000000000000000000000000000;hpb=299af4f2047e767e5d79501c26444473bda64c64;p=chaz%2Fyoink diff --git a/src/moof/service.hh b/src/moof/service.hh new file mode 100644 index 0000000..6db1d96 --- /dev/null +++ b/src/moof/service.hh @@ -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 + +#include +#include + + +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& services() const + { + return services_; + } + + +private: + + int handle_packet(socket_multiplexer& mux, + packet& packet, + const socket::address& address); + + std::string type_; + std::map services_; +}; + + +} // namespace moof + +#endif // _MOOF_SERVICE_HH_ +