Fawkes API
Fawkes Development Version
qa_avahi_browser.cpp
1
2
/***************************************************************************
3
* qa_avahi_browser.cpp - QA for AvahiBrowser
4
*
5
* Created: Fri Nov 10 10:19:39 2006 (recreated after stupid delete)
6
* Copyright 2006 Tim Niemueller [www.niemueller.de]
7
*
8
****************************************************************************/
9
10
/* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version. A runtime exception applies to
14
* this software (see LICENSE.GPL_WRE file mentioned below for details).
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Library General Public License for more details.
20
*
21
* Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22
*/
23
24
/// @cond QA
25
26
#include <core/exception.h>
27
#include <netcomm/dns-sd/avahi_thread.h>
28
#include <netcomm/service_discovery/browse_handler.h>
29
#include <utils/system/signal.h>
30
31
#include <cstdio>
32
33
using namespace
fawkes
;
34
35
class
QAAvahiBrowserMain :
public
SignalHandler
,
public
ServiceBrowseHandler
36
{
37
public
:
38
QAAvahiBrowserMain()
39
{
40
at =
new
AvahiThread
();
41
;
42
at->watch_service(
"_fawkes._udp"
,
this
);
43
}
44
45
~QAAvahiBrowserMain()
46
{
47
delete
at;
48
}
49
50
void
51
handle_signal(
int
signum)
52
{
53
at->cancel();
54
}
55
56
void
57
run()
58
{
59
at->start();
60
at->join();
61
}
62
63
virtual
void
64
all_for_now()
65
{
66
printf(
"ALL_FOR_NOW\n"
);
67
}
68
69
virtual
void
70
cache_exhausted()
71
{
72
printf(
"CACHE_EXHAUSTED\n"
);
73
}
74
75
virtual
void
76
browse_failed(
const
char
*name,
const
char
*type,
const
char
*domain)
77
{
78
printf(
"FAILED: name=%s type=%s domain=%s\n"
, name, type, domain);
79
}
80
81
virtual
void
82
service_added(
const
char
* name,
83
const
char
* type,
84
const
char
* domain,
85
const
char
* host_name,
86
const
struct
sockaddr * addr,
87
const
socklen_t addr_size,
88
uint16_t port,
89
std::list<std::string> &txt,
90
int
flags)
91
{
92
printf(
93
"SERVICE_ADDED: name=%s type=%s domain=%s hostname=%s\n"
, name, type, domain, host_name);
94
}
95
96
virtual
void
97
service_removed(
const
char
*name,
const
char
*type,
const
char
*domain)
98
{
99
printf(
"SERVICE_REMOVED: name=%s type=%s domain=%s\n"
, name, type, domain);
100
}
101
102
private
:
103
AvahiThread
*at;
104
};
105
106
int
107
main(
int
argc,
char
**argv)
108
{
109
try
{
110
QAAvahiBrowserMain m;
111
SignalManager::register_handler
(SIGINT, &m);
112
113
m.run();
114
115
}
catch
(
Exception
&e) {
116
e.
print_trace
();
117
}
118
119
SignalManager::finalize
();
120
}
121
122
/// @endcond
fawkes::SignalHandler
Definition:
signal.h:43
fawkes::SignalManager::finalize
static void finalize()
Finalize (and free) the SignalManager instance, this does NOT implicitly delete the signal handlers,...
Definition:
signal.cpp:104
fawkes::SignalManager::register_handler
static SignalHandler * register_handler(int signum, SignalHandler *handler)
Register a SignalHandler for a signal.
Definition:
signal.cpp:121
fawkes::AvahiThread
Definition:
avahi_thread.h:52
fawkes
fawkes::Exception::print_trace
void print_trace()
Prints trace to stderr.
Definition:
exception.cpp:600
fawkes::ServiceBrowseHandler
Definition:
browse_handler.h:50
fawkes::Exception
Definition:
exception.h:39
src
libs
netcomm
qa
qa_avahi_browser.cpp
Generated by
1.8.16