|
a |
|
b/src/uplistdir.cpp |
|
|
1 |
// This libupnpp sample program lists all devices and services found
|
|
|
2 |
// on the local network
|
|
|
3 |
|
|
|
4 |
#include <string>
|
|
|
5 |
#include <iostream>
|
|
|
6 |
|
|
|
7 |
#include "libupnpp/upnpplib.hxx"
|
|
|
8 |
#include "libupnpp/log.hxx"
|
|
|
9 |
#include "libupnpp/control/description.hxx"
|
|
|
10 |
#include "libupnpp/control/discovery.hxx"
|
|
|
11 |
|
|
|
12 |
using namespace std;
|
|
|
13 |
using namespace UPnPClient;
|
|
|
14 |
using namespace UPnPP;
|
|
|
15 |
|
|
|
16 |
static bool traverser(const UPnPDeviceDesc& device, const UPnPServiceDesc& srv)
|
|
|
17 |
{
|
|
|
18 |
cout << device.friendlyName <<" ("<< device.deviceType << ") " <<
|
|
|
19 |
srv.serviceType << endl;
|
|
|
20 |
return true;
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
int main(int argc, char *argv[])
|
|
|
24 |
{
|
|
|
25 |
// Initialize libupnpp logging
|
|
|
26 |
Logger::getTheLog("")->setLogLevel(Logger::LLERR);
|
|
|
27 |
|
|
|
28 |
// Get a handle to the main lib object. You don't really need to
|
|
|
29 |
// do this actually. We just do it to check that the lib
|
|
|
30 |
// initialized ok, but there are other possible uses, see the doc
|
|
|
31 |
// in the include file.
|
|
|
32 |
LibUPnP *mylib = LibUPnP::getLibUPnP();
|
|
|
33 |
if (!mylib) {
|
|
|
34 |
cerr << "Can't get LibUPnP" << endl;
|
|
|
35 |
return 1;
|
|
|
36 |
}
|
|
|
37 |
if (!mylib->ok()) {
|
|
|
38 |
cerr << "Lib init failed: " <<
|
|
|
39 |
mylib->errAsString("main", mylib->getInitError()) << endl;
|
|
|
40 |
return 1;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
// Get a handle to the device directory. You can call this
|
|
|
44 |
// multiple times, only the first call does something, any further
|
|
|
45 |
// call will just return the pointer to the singleton.
|
|
|
46 |
UPnPDeviceDirectory *superdir = UPnPDeviceDirectory::getTheDir();
|
|
|
47 |
if (superdir == 0) {
|
|
|
48 |
cerr << "Cant access device directory\n";
|
|
|
49 |
return 1;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
// Call the directory traversal. This will wait for the initial
|
|
|
53 |
// time window. It's possible to see the devices as they appear
|
|
|
54 |
// instead by using UPnPDeviceDirectory::addCallback(). See for
|
|
|
55 |
// example rdcvolume.cpp
|
|
|
56 |
superdir->traverse(traverser);
|
|
|
57 |
|
|
|
58 |
return 0;
|
|
|
59 |
}
|