]> Dogcows Code - chaz/yoink/blob - src/Moof/Service.cc
more explicit constructors
[chaz/yoink] / src / Moof / Service.cc
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 #include "Service.hh"
13 #include "Socket.hh"
14
15
16 #define SOLICIT 0x1234ABCD
17 #define RESPONSE 0xABCD1234
18
19
20 namespace Mf {
21
22
23 int Service::handlePacket(SocketMultiplexer& mux,
24 Packet& packet,
25 const SocketAddress& address)
26 {
27 try
28 {
29 uint32_t magic;
30 packet >> magic;
31 if (magic == SOLICIT)
32 {
33 std::string type;
34 packet >> type;
35 if (type == mType)
36 {
37 packet.clear();
38 packet << RESPONSE << mType << mName << mText;
39 mux.socket().write(packet);
40 return 0;
41 }
42 }
43 }
44 catch (...) {}
45 return -1;
46 }
47
48 int ServiceFinder::handlePacket(SocketMultiplexer& mux,
49 Packet& packet,
50 const SocketAddress& address)
51 {
52 try
53 {
54 uint32_t magic;
55 packet >> magic;
56 if (magic == RESPONSE)
57 {
58 std::string type;
59 packet >> type;
60 if (type == mType)
61 {
62 std::string name;
63 std::string text;
64 packet >> name >> text;
65 Service service(address, type, name, text);
66 mServices.insert(std::make_pair(name, service));
67 return 0;
68 }
69 }
70 }
71 catch (...) {}
72 return -1;
73 }
74
75 ServiceFinder::ServiceFinder(const std::string& type, int sockType)
76 {
77 }
78
79
80 } // namespace Mf
81
This page took 0.030768 seconds and 4 git commands to generate.