-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathannouncer.h
144 lines (119 loc) · 4.72 KB
/
announcer.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
This file is part of the Kapotah project.
Copyright (C) 2010 Shantanu Tushar <[email protected]>
Copyright (C) 2010 Sudhendu Kumar <[email protected]>
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 3 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/>.
*/
#ifndef KAPOTAH_ANNOUNCER_H
#define KAPOTAH_ANNOUNCER_H
#include "singleton.h"
#include "peer.h"
#include <QHostAddress>
namespace Kapotah
{
/**
*\brief This class processes user name announces, peer status, search, additional broadcasts
*
* The class can can get datagrams from the lower UdpManager layer and
* process it to determine announces, peer statuses.
* You can also use Announcer to add or remove additional broadcast addresses.
* Can be also used to send search requests to the network and receive requests.
*/
class Announcer : public Singleton<Announcer>
{
Q_OBJECT
public:
Announcer();
virtual ~Announcer();
/**
* Returns the currently set username
*
* @return the current username
*/
QString username();
/**
* Set the current username
*
* @param username the username to set
*/
void setUserName (const QString &username);
protected:
virtual void timerEvent (QTimerEvent* t);
private:
int m_timerId;
QString m_username;
public slots:
/**
* Process datagram that was collected from UdpManager
*
* @param datagram datagram received
* @param host hostname
* @param port port
*/
void processDatagram (const QByteArray &datagram, const QHostAddress &host, quint16 port);
/**
* Called to send user's status to peer
*
* @param address peer's address
*/
void peerStatus(QHostAddress address);
/**
* Called when the UI sends a request to search for a file
*
* @param pattern the pattern to use while searching
*/
void searchPeersForFile(const QString &pattern);
/**
* Call to add additional broadcast addresses
*
* @param broadcastAddress the address to broadcast to
*/
void addAdditionalBroadcastAddress(const QHostAddress &broadcastAddress);
/**
* Call to remove additional broadcast addresses
*
* @param broadcastAddress the address to stop broadcasting to
*/
void removeAdditionalBroadcastAddress(const QHostAddress &broadcastAddress);
signals:
/**
* Emitted when a new peer has become online
*
* @param peer details about the peer
*/
void gotAnnounce (const Peer &peer);
/**
* Emitted when a peer's typing status has been received
*
* @param peer details about the peer
*/
void peerTyping (const QHostAddress &peer);
/**
* Emitted when a receiving progress has been received from the receipient
*
* @param peer details about the peer
* @param id id of the Transfer
* @param bytesDone bytes of transfer completed
* @param total total size
* @param speed transfer speed
*/
void gotProgress (const QHostAddress &peer, QString id, quint64 bytesDone, quint64 total, quint64 speed);
/**
* Emitted when a search request has been received on the network
*
* @param pattern the search request pattern
* @param host details of the host who sent the request
*/
void gotSearchRequest (const QString &pattern, const QHostAddress &host);
};
}
#endif // KAPOTAH_ANNOUNCER_H