/
beacon.h
95 lines (78 loc) · 2.51 KB
/
beacon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/** @file beacon.h Presence service based on UDP broadcasts.
*
* @authors Copyright © 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBDENG2_BEACON_H
#define LIBDENG2_BEACON_H
#include <QObject>
#include "../Error"
#include "../Block"
#include "../Address"
namespace de {
/**
* UDP-based peer discovery mechanism.
* @ingroup net
*/
class DENG2_PUBLIC Beacon : public QObject
{
Q_OBJECT
public:
/// The UDP port was unavailable. @ingroup errors
DENG2_ERROR(PortError);
public:
Beacon(duint16 port);
virtual ~Beacon();
/**
* Starts the beacon with a message to give out.
*
* @param serviceListenPort
* TCP port that the advertised service listens on. Recipients will
* pair this with the IP address to form a full address.
*/
void start(duint16 serviceListenPort);
/**
* Changes the message to advertise.
*
* @param advertisedMessage Message to send to requesters.
*/
void setMessage(IByteArray const &advertisedMessage);
/**
* Stops the beacon.
*/
void stop();
/**
* Looks for any beacons on all accessible networks.
*
* @param timeOut Maximum time to spend discovering. If the timeout
* is zero or negative, discovery will not end.
* @param interval Interval between query broadcasts.
*/
void discover(TimeDelta const &timeOut, TimeDelta const &interval = TimeDelta(1.0));
QList<Address> foundHosts() const;
Block messageFromHost(Address const &host) const;
protected slots:
void readIncoming();
void readDiscoveryReply();
void continueDiscovery();
signals:
void found(de::Address host, de::Block message);
void finished();
private:
struct Instance;
Instance *d;
};
} // namespace de
#endif // LIBDENG2_BEACON_H