Switch to unified view

a/upexplo/upexplo.cxx b/upexplo/upexplo.cxx
...
...
26
using namespace std;
26
using namespace std;
27
27
28
#include "libupnpp/upnpplib.hxx"
28
#include "libupnpp/upnpplib.hxx"
29
#include "libupnpp/discovery.hxx"
29
#include "libupnpp/discovery.hxx"
30
#include "libupnpp/cdirectory.hxx"
30
#include "libupnpp/cdirectory.hxx"
31
#include "libupnpp/description.hxx"
31
32
32
void listServers(LibUPnP *lib, UPnPDeviceDirectory *superdir)
33
using namespace UPnPClient;
34
35
void listServers(LibUPnP *lib)
33
{
36
{
34
    cerr << "Servers:" << endl;
37
    cerr << "Servers:" << endl;
35
    vector<ContentDirectoryService> dirservices;
38
    vector<ContentDirectoryService> dirservices;
36
  if (!superdir->getDirServices(dirservices)) {
39
  if (!ContentDirectoryService::getServices(dirservices)) {
37
        cerr << "listDirServices failed" << endl;
40
        cerr << "listDirServices failed" << endl;
38
        return;
41
        return;
39
    }
42
    }
40
    for (vector<ContentDirectoryService>::iterator it = dirservices.begin();
43
    for (vector<ContentDirectoryService>::iterator it = dirservices.begin();
41
         it != dirservices.end(); it++) {
44
         it != dirservices.end(); it++) {
42
        cerr << it->getFriendlyName() << endl;
45
        cerr << it->getFriendlyName() << endl;
43
    }
46
    }
44
}
47
}
45
48
46
void readdir(LibUPnP *lib, UPnPDeviceDirectory *superdir,
49
void readdir(LibUPnP *lib, const string& friendlyName, const string& cid)
47
           const string& friendlyName,
48
           const string& cid)
49
{
50
{
50
    cerr << "readdir: [" << friendlyName << "] [" << cid << "]" << endl;
51
    cerr << "readdir: [" << friendlyName << "] [" << cid << "]" << endl;
51
    ContentDirectoryService server;
52
    ContentDirectoryService server;
52
  if (!superdir->getServer(friendlyName, server)) {
53
  if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
53
        cerr << "Server not found" << endl;
54
        cerr << "Server not found" << endl;
54
        return;
55
        return;
55
    }
56
    }
56
    UPnPDirContent dirbuf;
57
    UPnPDirContent dirbuf;
57
    int code = server.readDir(cid, dirbuf);
58
    int code = server.readDir(cid, dirbuf);
...
...
67
    for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
68
    for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
68
        cerr << dirbuf.m_items[i].dump();
69
        cerr << dirbuf.m_items[i].dump();
69
    }
70
    }
70
}
71
}
71
72
72
void getMetadata(LibUPnP *lib, UPnPDeviceDirectory *superdir,
73
void getMetadata(LibUPnP *lib, const string& friendlyName, const string& cid)
73
               const string& friendlyName,
74
               const string& cid)
75
{
74
{
76
    cerr << "getMeta: [" << friendlyName << "] [" << cid << "]" << endl;
75
    cerr << "getMeta: [" << friendlyName << "] [" << cid << "]" << endl;
77
    ContentDirectoryService server;
76
    ContentDirectoryService server;
78
  if (!superdir->getServer(friendlyName, server)) {
77
  if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
79
        cerr << "Server not found" << endl;
78
        cerr << "Server not found" << endl;
80
        return;
79
        return;
81
    }
80
    }
82
    UPnPDirContent dirbuf;
81
    UPnPDirContent dirbuf;
83
    int code = server.getMetadata(cid, dirbuf);
82
    int code = server.getMetadata(cid, dirbuf);
...
...
93
    for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
92
    for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
94
        cerr << dirbuf.m_items[i].dump();
93
        cerr << dirbuf.m_items[i].dump();
95
    }
94
    }
96
}
95
}
97
96
98
void search(LibUPnP *lib, UPnPDeviceDirectory *superdir,
99
          const string& friendlyName, const string& ss)
97
void search(LibUPnP *lib, const string& friendlyName, const string& ss)
100
{
98
{
101
    cerr << "search: [" << friendlyName << "] [" << ss << "]" << endl;
99
    cerr << "search: [" << friendlyName << "] [" << ss << "]" << endl;
102
    ContentDirectoryService server;
100
    ContentDirectoryService server;
103
  if (!superdir->getServer(friendlyName, server)) {
101
  if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
104
        cerr << "Server not found" << endl;
102
        cerr << "Server not found" << endl;
105
        return;
103
        return;
106
    }
104
    }
107
    UPnPDirContent dirbuf;
105
    UPnPDirContent dirbuf;
108
    string cid("0");
106
    string cid("0");
...
...
119
    for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
117
    for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
120
        cerr << dirbuf.m_items[i].dump();
118
        cerr << dirbuf.m_items[i].dump();
121
    }
119
    }
122
}
120
}
123
121
124
void getSearchCaps(LibUPnP *lib, UPnPDeviceDirectory *superdir,
122
void getSearchCaps(LibUPnP *lib, const string& friendlyName)
125
                 const string& friendlyName)
126
{
123
{
127
    cerr << "getSearchCaps: [" << friendlyName << "]" << endl;
124
    cerr << "getSearchCaps: [" << friendlyName << "]" << endl;
128
    ContentDirectoryService server;
125
    ContentDirectoryService server;
129
  if (!superdir->getServer(friendlyName, server)) {
126
  if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
130
        cerr << "Server not found" << endl;
127
        cerr << "Server not found" << endl;
131
        return;
128
        return;
132
    }
129
    }
133
    set<string> capa;
130
    set<string> capa;
134
    int code = server.getSearchCapabilities(capa);
131
    int code = server.getSearchCapabilities(capa);
...
...
226
        return 1;
223
        return 1;
227
    }
224
    }
228
225
229
    if ((op_flags & OPT_l)) {
226
    if ((op_flags & OPT_l)) {
230
        while (true) {
227
        while (true) {
231
            listServers(mylib, superdir);
228
            listServers(mylib);
232
            sleep(5);
229
            sleep(5);
233
        }
230
        }
234
    } else if ((op_flags & OPT_m)) {
231
    } else if ((op_flags & OPT_m)) {
235
        getMetadata(mylib, superdir, fname, arg);
232
        getMetadata(mylib, fname, arg);
236
    } else if ((op_flags & OPT_r)) {
233
    } else if ((op_flags & OPT_r)) {
237
        readdir(mylib, superdir, fname, arg);
234
        readdir(mylib, fname, arg);
238
    } else if ((op_flags & OPT_s)) {
235
    } else if ((op_flags & OPT_s)) {
239
        search(mylib, superdir, fname, arg);
236
        search(mylib, fname, arg);
240
    } else if ((op_flags & OPT_c)) {
237
    } else if ((op_flags & OPT_c)) {
241
        getSearchCaps(mylib, superdir, fname);
238
        getSearchCaps(mylib, fname);
242
    } else {
239
    } else {
243
        Usage();
240
        Usage();
244
    }
241
    }
245
    superdir->terminate();
242
    superdir->terminate();
246
    return 0;
243
    return 0;