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