exception-aware packets; other misc socket changes
[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 <vector>
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.
38 * \param address The address of the host.
39 * \param text The service information.
40 */
41 Service(const SocketAddress& address, const std::string& text);
42
43
44 /**
45 * Publish the service on the local network.
46 */
47 void publish();
48
49 void stop();
50
51
52 /**
53 * Get the host address.
54 * \return The address.
55 */
56 const SocketAddress& address() const
57 {
58 return mAddress;
59 }
60
61 /**
62 * Get the service information.
63 * \return The service information as a string.
64 */
65 const std::string& text() const
66 {
67 return mText;
68 }
69
70
71 private:
72
73 int handlePacket(SocketMultiplexer& sock,
74 Packet& packet,
75 const SocketAddress& address);
76
77 SocketAddress mAddress;
78 std::string mText;
79 };
80
81
82 class ServiceFinder
83 {
84 public:
85
86 ServiceFinder(const std::string& service, int type = SOCK_STREAM);
87
88
89 const std::vector<Service>& services() const
90 {
91 return mServices;
92 }
93
94
95 private:
96
97 int handlePacket(SocketMultiplexer& sock,
98 Packet& packet,
99 const SocketAddress& address);
100
101 std::string mService;
102 std::vector<Service> mServices;
103 };
104
105
106 } // namespace Mf
107
108 #endif // _MOOF_SERVICE_HH_
109
This page took 0.032877 seconds and 4 git commands to generate.