]> Dogcows Code - chaz/yoink/blob - src/Moof/Service.cc
3432ae6ac12c763857fe25d558442a18f192f66f
[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& sock,
24 Packet& packet,
25 const SocketAddress& address)
26 {
27 uint32_t magic = 0;
28
29 try
30 {
31 packet >> magic;
32 }
33 catch (...)
34 {
35 return -1;
36 }
37
38 if (magic == SOLICIT)
39 {
40 Packet out;
41 out << RESPONSE << mType << mName << mText;
42 sock.socket().write(out);
43 return 0;
44 }
45 return -1;
46 }
47
48 int ServiceFinder::handlePacket(SocketMultiplexer& sock,
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 mServices.insert(std::make_pair(name,
66 Service(address, name, text)));
67 return 0;
68 }
69 }
70 }
71 catch (...)
72 {
73 }
74
75 return -1;
76 }
77
78 ServiceFinder::ServiceFinder(const std::string& type, int sockType)
79 {
80 }
81
82
83 } // namespace Mf
84
This page took 0.034811 seconds and 4 git commands to generate.