|
a |
|
b/libupnpp/control/ohinfo.cxx |
|
|
1 |
/* Copyright (C) 2014 J.F.Dockes
|
|
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
* (at your option) any later version.
|
|
|
6 |
*
|
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
* GNU General Public License for more details.
|
|
|
11 |
*
|
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
|
13 |
* along with this program; if not, write to the
|
|
|
14 |
* Free Software Foundation, Inc.,
|
|
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
#include "libupnpp/config.h"
|
|
|
19 |
|
|
|
20 |
#include <string.h> // for strcmp
|
|
|
21 |
#include <upnp/upnp.h> // for UPNP_E_BAD_RESPONSE, etc
|
|
|
22 |
#include <ostream> // for endl
|
|
|
23 |
#include <string> // for string
|
|
|
24 |
#include <vector> // for vector
|
|
|
25 |
|
|
|
26 |
#include "libupnpp/control/ohinfo.hxx"
|
|
|
27 |
#include "libupnpp/control/ohradio.hxx"
|
|
|
28 |
#include "libupnpp/log.hxx" // for LOGERR
|
|
|
29 |
#include "libupnpp/soaphelp.hxx" // for SoapIncoming, etc
|
|
|
30 |
#include "libupnpp/upnpp_p.hxx" // for stringToBool, trimstring
|
|
|
31 |
|
|
|
32 |
using namespace std;
|
|
|
33 |
using namespace STD_PLACEHOLDERS;
|
|
|
34 |
using namespace UPnPP;
|
|
|
35 |
|
|
|
36 |
namespace UPnPClient {
|
|
|
37 |
const string OHInfo::SType("urn:av-openhome-org:service:Info:1");
|
|
|
38 |
|
|
|
39 |
// Check serviceType string (while walking the descriptions. We don't
|
|
|
40 |
// include a version in comparisons, as we are satisfied with version1
|
|
|
41 |
bool OHInfo::isOHInfoService(const string& st)
|
|
|
42 |
{
|
|
|
43 |
const string::size_type sz(SType.size()-2);
|
|
|
44 |
return !SType.compare(0, sz, st, 0, sz);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
void OHInfo::evtCallback(
|
|
|
48 |
const STD_UNORDERED_MAP<std::string, std::string>& props)
|
|
|
49 |
{
|
|
|
50 |
LOGDEB1("OHInfo::evtCallback: getReporter(): " << getReporter() << endl);
|
|
|
51 |
for (STD_UNORDERED_MAP<std::string, std::string>::const_iterator it =
|
|
|
52 |
props.begin(); it != props.end(); it++) {
|
|
|
53 |
if (!getReporter()) {
|
|
|
54 |
LOGDEB1("OHInfo::evtCallback: " << it->first << " -> "
|
|
|
55 |
<< it->second << endl);
|
|
|
56 |
continue;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
if (!it->first.compare("Metatext")) {
|
|
|
60 |
/* Metadata is a didl-lite string */
|
|
|
61 |
UPnPDirObject dirent;
|
|
|
62 |
if (OHRadio::decodeMetadata(it->second, &dirent) == 0) {
|
|
|
63 |
getReporter()->changed(it->first.c_str(), dirent);
|
|
|
64 |
} else {
|
|
|
65 |
LOGDEB("OHInfo:evtCallback: bad metadata in event\n");
|
|
|
66 |
}
|
|
|
67 |
} else {
|
|
|
68 |
LOGDEB1("OHInfo event: unknown variable: name [" <<
|
|
|
69 |
it->first << "] value [" << it->second << endl);
|
|
|
70 |
getReporter()->changed(it->first.c_str(), it->second.c_str());
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
void OHInfo::registerCallback()
|
|
|
76 |
{
|
|
|
77 |
Service::registerCallback(bind(&OHInfo::evtCallback, this, _1));
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
int OHInfo::metatext(UPnPDirObject *dirent)
|
|
|
81 |
{
|
|
|
82 |
SoapOutgoing args(getServiceType(), "Metatext");
|
|
|
83 |
SoapIncoming data;
|
|
|
84 |
int ret = runAction(args, data);
|
|
|
85 |
if (ret != UPNP_E_SUCCESS) {
|
|
|
86 |
LOGERR("OHInfo::metatext: runAction failed\n");
|
|
|
87 |
return ret;
|
|
|
88 |
}
|
|
|
89 |
string didl;
|
|
|
90 |
if (!data.get("Value", &didl)) {
|
|
|
91 |
LOGERR("OHInfo::Read: missing Value in response" << endl);
|
|
|
92 |
return UPNP_E_BAD_RESPONSE;
|
|
|
93 |
}
|
|
|
94 |
return OHRadio::decodeMetadata(didl, dirent);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
} // End namespace UPnPClient
|