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
|
/***************************************************************************
* Copyright (C) 2006 by Lesly Weyts and Kevin Andre *
* *
* 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef AVAHI_SERVICE_HH
#define AVAHI_SERVICE_HH
/**
* @author Lesly Weyts and Kevin Andre
* @brief Handles everything directly related to Avahi
*
* This set of functions provide a simple way to use Avahi inside the KTorrent source code.
*/
#include <cstdlib>
#include <tqstring.h>
#include <avahi-client/client.h>
#include <avahi-client/publish.h>
#include <avahi-client/lookup.h>
#include <avahi-common/thread-watch.h>
#include <avahi-common/malloc.h>
#include <util/sha1hash.h>
#include <interfaces/peersource.h>
namespace kt
{
class AvahiService : public kt::PeerSource
{
Q_OBJECT
public:
AvahiService(const bt::PeerID&, bt::Uint16, const bt::SHA1Hash&);
virtual ~AvahiService();
virtual void stop(bt::WaitJob* wjob = 0);
virtual void start();
virtual void aboutToBeDestroyed();
void emitPeersReady();
signals:
void serviceDestroyed(AvahiService* av);
private:
bool startPublishing();
bool startBrowsing();
friend void group_callback(AvahiEntryGroup*, AvahiEntryGroupState, void*);
friend void publish_service(AvahiService*, AvahiClient*);
friend void publisher_callback(AvahiClient*, AvahiClientState, void*);
friend void listener_callback(AvahiClient*, AvahiClientState, void*);
friend void resolve_callback(
AvahiServiceResolver*,
AvahiIfIndex,
AvahiProtocol,
AvahiResolverEvent,
const char*,
const char*,
const char*,
const char*,
const AvahiAddress*,
uint16_t,
AvahiStringList*,
AvahiLookupResultFlags,
void*
);
friend void browser_callback(
AvahiServiceBrowser*,
AvahiIfIndex,
AvahiProtocol,
AvahiBrowserEvent,
const char*,
const char*,
const char*,
AvahiLookupResultFlags,
void*
);
TQString id;
int port;
TQString infoHash;
bool started;
AvahiEntryGroup *group;
const AvahiPoll* publisher_poll;
const AvahiPoll* listener_poll;
AvahiClient* publisher;
AvahiClient* listener;
AvahiServiceBrowser *browser;
};
}
#endif
|