]> Dogcows Code - chaz/yoink/blob - src/moof/service.hh
fixed documentation about where to find licenses
[chaz/yoink] / src / moof / service.hh
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #ifndef _MOOF_SERVICE_HH_
11 #define _MOOF_SERVICE_HH_
12
13 #include <map>
14
15 #include <moof/math.hh>
16 #include <moof/socket.hh>
17
18
19 /**
20 * \file service.hh
21 * Classes for publishing and finding network services.
22 */
23
24 namespace moof {
25
26
27 /**
28 * Class representing a network service.
29 */
30 class service
31 {
32 public:
33
34 /**
35 * Construct a network service with an explicit type.
36 * \param address The address of the host.
37 * \param type The type of service.
38 * \param name The service name.
39 * \param text The service information.
40 */
41 service(const socket::address& address,
42 const std::string& type,
43 const std::string& name,
44 const std::string& text);
45
46 /**
47 * Construct a network service. The type of service will be inferred
48 * from the address.
49 * \param address The address of the host.
50 * \param name The service name.
51 * \param text The service information.
52 */
53 service(const socket::address& address,
54 const std::string& name,
55 const std::string& text);
56
57 /**
58 * Publish the service on the network.
59 */
60 void publish();
61
62 /**
63 * Stop publishing the service on the network.
64 */
65 void stop();
66
67 /**
68 * Get the host address.
69 * \return The address.
70 */
71 const socket::address& address() const
72 {
73 return address_;
74 }
75
76 /**
77 * Get the type of the service.
78 * \return The service type.
79 */
80 const std::string& type() const
81 {
82 return type_;
83 }
84
85 /**
86 * Get the service name.
87 * \return The service name.
88 */
89 const std::string& name() const
90 {
91 return name_;
92 }
93
94 /**
95 * Get the service information.
96 * \return The service information as a string.
97 */
98 const std::string& text() const
99 {
100 return text_;
101 }
102
103 ~service();
104
105 private:
106
107 int handle_packet(socket_multiplexer& mux,
108 packet& packet, const socket::address& address);
109
110 socket::address address_;
111 std::string type_;
112 std::string name_;
113 std::string text_;
114 };
115
116
117 class service_finder
118 {
119 public:
120
121 /**
122 * Construct a service finder to find services of the same type as an
123 * address.
124 * \address The address.
125 */
126 explicit service_finder(const socket::address& address);
127
128 /**
129 * Construct a service finder to find services of a certain type.
130 * \param type The type of the service.
131 * \param sockType The type of socket.
132 */
133 explicit service_finder(const std::string& type,
134 int sockType = SOCK_STREAM);
135
136 const std::map<std::string,service>& services() const
137 {
138 return services_;
139 }
140
141 private:
142
143 int handle_packet(socket_multiplexer& mux,
144 packet& packet, const socket::address& address);
145
146 std::string type_;
147 std::map<std::string,service> services_;
148 };
149
150
151 } // namespace moof
152
153 #endif // _MOOF_SERVICE_HH_
154
This page took 0.036203 seconds and 4 git commands to generate.