forked from HBM/devscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanclientprint.cpp
67 lines (51 loc) · 1.64 KB
/
scanclientprint.cpp
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
// Copyright 2014 Hottinger Baldwin Messtechnik
// Distributed under MIT license
// See file LICENSE provided
#include <iostream>
#include <string>
#include <json/value.h>
#include <json/reader.h>
#include <json/writer.h>
#include "devscan/receiver.h"
void announceCb(const std::string uuid, const std::string& receivingInterfaceName, const std::string& sendingInterfaceName, const std::string& router, const std::string& announcement)
{
std::cout << "announcement: " << uuid;
if(router.empty()==false) {
std::cout <<", via router: " << router;
}
std::cout << std::endl;
// produce output that is structured
Json::Value val;
Json::Reader().parse(announcement, val);
std::cout << Json::StyledWriter().write(val) << std::endl;
}
void expireCb(const std::string uuid, const std::string& receivingInterfaceName, const std::string& sendingInterfaceName, const std::string& router)
{
std::cout << "expired: " << uuid;
if(router.empty()==false) {
std::cout <<", via router: " << router;
}
std::cout << std::endl;
}
int main(int argc, char* argv[])
{
if(argc>1) {
if(std::string(argv[1])=="-h") {
std::cout << "Listens for announcements and prints new/changed announcements as received" << std::endl;
return 0;
}
}
hbm::devscan::Receiver receiver;
// we want to be notified about new or changed announcements
receiver.setAnnounceCb(&announceCb);
// we want to be notified about expired announcements
receiver.setExpireCb(&expireCb);
// start receiving for indefinite time
try {
receiver.start();
} catch(hbm::exception::exception& e) {
std::cerr << "Error starting the receiver: " << e.what() << std::endl;
return 1;
}
return 0;
}