|
a/src/ohproduct.cxx |
|
b/src/ohproduct.cxx |
|
... |
|
... |
24 |
#include <iostream> // for endl, etc
|
24 |
#include <iostream> // for endl, etc
|
25 |
#include <map> // for _Rb_tree_const_iterator, etc
|
25 |
#include <map> // for _Rb_tree_const_iterator, etc
|
26 |
#include <string> // for string, operator<<, etc
|
26 |
#include <string> // for string, operator<<, etc
|
27 |
#include <utility> // for pair
|
27 |
#include <utility> // for pair
|
28 |
#include <vector> // for vector
|
28 |
#include <vector> // for vector
|
29 |
|
29 |
#include <utility>
|
30 |
|
30 |
|
31 |
#include "libupnpp/device/device.hxx" // for UpnpService
|
31 |
#include "libupnpp/device/device.hxx" // for UpnpService
|
32 |
#include "libupnpp/log.hxx" // for LOGDEB
|
32 |
#include "libupnpp/log.hxx" // for LOGDEB
|
33 |
#include "libupnpp/soaphelp.hxx" // for SoapOutgoing, SoapIncoming
|
33 |
#include "libupnpp/soaphelp.hxx" // for SoapOutgoing, SoapIncoming
|
34 |
|
34 |
|
35 |
#include "upmpd.hxx" // for UpMpd
|
35 |
#include "upmpd.hxx" // for UpMpd
|
|
|
36 |
#include "ohplaylist.hxx"
|
|
|
37 |
#include "ohreceiver.hxx"
|
|
|
38 |
#include "ohsndrcv.hxx"
|
36 |
|
39 |
|
37 |
using namespace std;
|
40 |
using namespace std;
|
38 |
using namespace std::placeholders;
|
41 |
using namespace std::placeholders;
|
39 |
|
42 |
|
40 |
static const string sTpProduct("urn:av-openhome-org:service:Product:1");
|
43 |
static const string sTpProduct("urn:av-openhome-org:service:Product:1");
|
41 |
static const string sIdProduct("urn:av-openhome-org:serviceId:Product");
|
44 |
static const string sIdProduct("urn:av-openhome-org:serviceId:Product");
|
42 |
|
45 |
|
43 |
static string csxml("<SourceList>\n");
|
46 |
static string csxml("<SourceList>\n");
|
|
|
47 |
|
|
|
48 |
// (Type, Name) list
|
44 |
static vector<string> o_sources;
|
49 |
static vector<pair<string, string> > o_sources;
|
45 |
|
50 |
|
46 |
OHProduct::OHProduct(UpMpd *dev, const string& friendlyname, bool hasRcv)
|
51 |
OHProduct::OHProduct(UpMpd *dev, const string& friendlyname, bool hasRcv)
|
47 |
: UpnpService(sTpProduct, sIdProduct, dev), m_dev(dev),
|
52 |
: UpnpService(sTpProduct, sIdProduct, dev), m_dev(dev),
|
|
|
53 |
m_sndrcv(new SenderReceiver(dev)),
|
48 |
m_roomOrName(friendlyname), m_sourceIndex(0)
|
54 |
m_roomOrName(friendlyname), m_sourceIndex(0)
|
49 |
{
|
55 |
{
|
50 |
// Playlist must stay first.
|
56 |
// Playlist must stay first.
|
51 |
o_sources.push_back("Playlist");
|
57 |
o_sources.push_back(pair<string,string>("Playlist","Playlist"));
|
52 |
//o_sources.push_back("UpnpAv");
|
58 |
//o_sources.push_back("UpnpAv");
|
53 |
if (hasRcv)
|
59 |
if (hasRcv) {
|
54 |
o_sources.push_back("Receiver");
|
60 |
o_sources.push_back(pair<string,string>("Receiver","Receiver"));
|
|
|
61 |
o_sources.push_back(pair<string,string>("Playlist", "Sender"));
|
|
|
62 |
}
|
55 |
|
63 |
|
56 |
for (auto it = o_sources.begin(); it != o_sources.end(); it++) {
|
64 |
for (auto it = o_sources.begin(); it != o_sources.end(); it++) {
|
57 |
csxml += string(" <Source>\n") +
|
65 |
csxml += string(" <Source>\n") +
|
58 |
" <Name>" + *it + "</Name>\n" +
|
66 |
" <Name>" + it->second + "</Name>\n" +
|
59 |
" <Type>" + *it + "</Type>\n" +
|
67 |
" <Type>" + it->first + "</Type>\n" +
|
60 |
" <Visible>1</Visible>\n" +
|
68 |
" <Visible>1</Visible>\n" +
|
61 |
" </Source>\n";
|
69 |
" </Source>\n";
|
62 |
}
|
70 |
}
|
63 |
csxml += string("</SourceList>\n");
|
71 |
csxml += string("</SourceList>\n");
|
64 |
LOGDEB("OHProduct::OHProduct: sources: " << csxml << endl);
|
72 |
LOGDEB("OHProduct::OHProduct: sources: " << csxml << endl);
|
|
... |
|
... |
88 |
bind(&OHProduct::attributes, this, _1, _2));
|
96 |
bind(&OHProduct::attributes, this, _1, _2));
|
89 |
dev->addActionMapping(this, "SourceXmlChangeCount",
|
97 |
dev->addActionMapping(this, "SourceXmlChangeCount",
|
90 |
bind(&OHProduct::sourceXMLChangeCount, this, _1, _2));
|
98 |
bind(&OHProduct::sourceXMLChangeCount, this, _1, _2));
|
91 |
}
|
99 |
}
|
92 |
|
100 |
|
|
|
101 |
OHProduct::~OHProduct()
|
|
|
102 |
{
|
|
|
103 |
delete m_sndrcv;
|
|
|
104 |
}
|
93 |
|
105 |
|
94 |
static const string csattrs("Info Time Volume");
|
106 |
static const string csattrs("Info Time Volume");
|
95 |
static const string csversion(PACKAGE_VERSION);
|
107 |
static const string csversion(PACKAGE_VERSION);
|
96 |
static const string csmanname("UpMPDCli heavy industries Co.");
|
108 |
static const string csmanname("UpMPDCli heavy industries Co.");
|
97 |
static const string csmaninfo("Such nice guys and gals");
|
109 |
static const string csmaninfo("Such nice guys and gals");
|
|
... |
|
... |
198 |
LOGDEB("OHProduct::sourceIndex" << endl);
|
210 |
LOGDEB("OHProduct::sourceIndex" << endl);
|
199 |
data.addarg("Value", SoapHelp::i2s(m_sourceIndex));
|
211 |
data.addarg("Value", SoapHelp::i2s(m_sourceIndex));
|
200 |
return UPNP_E_SUCCESS;
|
212 |
return UPNP_E_SUCCESS;
|
201 |
}
|
213 |
}
|
202 |
|
214 |
|
|
|
215 |
int OHProduct::iSrcNameToIndex(const string& nm)
|
|
|
216 |
{
|
|
|
217 |
for (unsigned int i = 0; i < o_sources.size(); i++) {
|
|
|
218 |
if (!nm.compare(o_sources[i].second)) {
|
|
|
219 |
return int(i);
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
return -1;
|
|
|
223 |
}
|
|
|
224 |
|
203 |
int OHProduct::iSetSourceIndex(int sindex)
|
225 |
int OHProduct::iSetSourceIndex(int sindex)
|
204 |
{
|
226 |
{
|
205 |
LOGDEB("OHProduct::iSetSourceIndex: " << sindex << endl);
|
227 |
LOGDEB("OHProduct::iSetSourceIndex: current " << m_sourceIndex <<
|
|
|
228 |
" new " << sindex << endl);
|
206 |
if (sindex < 0 || sindex >= int(o_sources.size())) {
|
229 |
if (sindex < 0 || sindex >= int(o_sources.size())) {
|
207 |
LOGERR("OHProduct::setSourceIndex: bad index: " << sindex << endl);
|
230 |
LOGERR("OHProduct::setSourceIndex: bad index: " << sindex << endl);
|
208 |
return UPNP_E_INVALID_PARAM;
|
231 |
return UPNP_E_INVALID_PARAM;
|
209 |
}
|
232 |
}
|
|
|
233 |
if (m_sourceIndex != sindex) {
|
|
|
234 |
|
|
|
235 |
const MpdStatus& mpds = m_dev->getMpdStatus();
|
|
|
236 |
int savedms = mpds.songelapsedms;
|
|
|
237 |
|
|
|
238 |
string curnm = o_sources[m_sourceIndex].second;
|
|
|
239 |
if (!curnm.compare("Playlist") && m_dev->m_ohpl) {
|
|
|
240 |
LOGDEB("OHProduct::iSetSourceIndex: stopping OHPL\n");
|
|
|
241 |
m_dev->m_ohpl->iStop();
|
|
|
242 |
} else if (!curnm.compare("Receiver") && m_dev->m_ohrcv) {
|
|
|
243 |
LOGDEB("OHProduct::iSetSourceIndex: stopping Receiver\n");
|
|
|
244 |
m_dev->m_ohrcv->iStop();
|
|
|
245 |
} else if (!curnm.compare("Sender") && m_sndrcv) {
|
|
|
246 |
LOGDEB("OHProduct::iSetSourceIndex: stopping Sender/Receiver\n");
|
|
|
247 |
m_sndrcv->stop();
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
string newnm = o_sources[sindex].second;
|
|
|
251 |
if (!newnm.compare("Playlist")) {
|
|
|
252 |
} else if (!newnm.compare("Receiver")) {
|
|
|
253 |
} else if (!newnm.compare("Sender")) {
|
|
|
254 |
m_sndrcv->start(savedms);
|
|
|
255 |
}
|
|
|
256 |
|
210 |
m_sourceIndex = sindex;
|
257 |
m_sourceIndex = sindex;
|
211 |
m_dev->loopWakeup();
|
258 |
m_dev->loopWakeup();
|
|
|
259 |
}
|
212 |
return UPNP_E_SUCCESS;
|
260 |
return UPNP_E_SUCCESS;
|
213 |
}
|
261 |
}
|
|
|
262 |
|
214 |
int OHProduct::setSourceIndex(const SoapIncoming& sc, SoapOutgoing&)
|
263 |
int OHProduct::setSourceIndex(const SoapIncoming& sc, SoapOutgoing&)
|
215 |
{
|
264 |
{
|
216 |
LOGDEB("OHProduct::setSourceIndex" << endl);
|
265 |
LOGDEB("OHProduct::setSourceIndex" << endl);
|
217 |
int sindex;
|
266 |
int sindex;
|
218 |
if (!sc.get("Value", &sindex)) {
|
267 |
if (!sc.get("Value", &sindex)) {
|
219 |
return UPNP_E_INVALID_PARAM;
|
268 |
return UPNP_E_INVALID_PARAM;
|
220 |
}
|
269 |
}
|
221 |
return iSetSourceIndex(sindex);
|
270 |
return iSetSourceIndex(sindex);
|
222 |
}
|
271 |
}
|
223 |
|
272 |
|
|
|
273 |
int OHProduct::iSetSourceIndexByName(const string& name)
|
|
|
274 |
{
|
|
|
275 |
LOGDEB("OHProduct::iSetSourceIndexByName: " << name << endl);
|
|
|
276 |
int i = iSrcNameToIndex(name);
|
|
|
277 |
if (i >= 0) {
|
|
|
278 |
return iSetSourceIndex(i);
|
|
|
279 |
}
|
|
|
280 |
LOGERR("OHProduct::iSetSourceIndexByName: no such name: " << name << endl);
|
|
|
281 |
return UPNP_E_INVALID_PARAM;
|
|
|
282 |
}
|
|
|
283 |
|
224 |
int OHProduct::setSourceIndexByName(const SoapIncoming& sc, SoapOutgoing& data)
|
284 |
int OHProduct::setSourceIndexByName(const SoapIncoming& sc, SoapOutgoing& data)
|
225 |
{
|
285 |
{
|
226 |
|
286 |
|
227 |
string name;
|
287 |
string name;
|
228 |
if (!sc.get("Value", &name)) {
|
288 |
if (!sc.get("Value", &name)) {
|
229 |
LOGERR("OHProduct::setSourceIndexByName: no Value" << endl);
|
289 |
LOGERR("OHProduct::setSourceIndexByName: no Value" << endl);
|
230 |
return UPNP_E_INVALID_PARAM;
|
290 |
return UPNP_E_INVALID_PARAM;
|
231 |
}
|
291 |
}
|
232 |
LOGDEB("OHProduct::setSourceIndexByName: " << name << endl);
|
|
|
233 |
for (unsigned int i = 0; i < o_sources.size(); i++) {
|
|
|
234 |
if (o_sources[i] == name) {
|
|
|
235 |
return iSetSourceIndex(i);
|
292 |
return iSetSourceIndexByName(name);
|
236 |
}
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
LOGERR("OHProduct::setSoaurceIndexByName: no such name: " << name << endl);
|
|
|
240 |
return UPNP_E_INVALID_PARAM;
|
|
|
241 |
}
|
293 |
}
|
242 |
|
294 |
|
243 |
int OHProduct::source(const SoapIncoming& sc, SoapOutgoing& data)
|
295 |
int OHProduct::source(const SoapIncoming& sc, SoapOutgoing& data)
|
244 |
{
|
296 |
{
|
245 |
LOGDEB("OHProduct::source" << endl);
|
297 |
LOGDEB("OHProduct::source" << endl);
|
|
... |
|
... |
251 |
if (sindex < 0 || sindex >= int(o_sources.size())) {
|
303 |
if (sindex < 0 || sindex >= int(o_sources.size())) {
|
252 |
LOGERR("OHProduct::source: bad index: " << sindex << endl);
|
304 |
LOGERR("OHProduct::source: bad index: " << sindex << endl);
|
253 |
return UPNP_E_INVALID_PARAM;
|
305 |
return UPNP_E_INVALID_PARAM;
|
254 |
}
|
306 |
}
|
255 |
data.addarg("SystemName", m_roomOrName);
|
307 |
data.addarg("SystemName", m_roomOrName);
|
256 |
data.addarg("Type", o_sources[sindex]);
|
308 |
data.addarg("Type", o_sources[sindex].first);
|
257 |
data.addarg("Name", o_sources[sindex]);
|
309 |
data.addarg("Name", o_sources[sindex].second);
|
258 |
data.addarg("Visible", "1");
|
310 |
data.addarg("Visible", "1");
|
259 |
return UPNP_E_SUCCESS;
|
311 |
return UPNP_E_SUCCESS;
|
260 |
}
|
312 |
}
|
261 |
|
313 |
|
262 |
int OHProduct::attributes(const SoapIncoming& sc, SoapOutgoing& data)
|
314 |
int OHProduct::attributes(const SoapIncoming& sc, SoapOutgoing& data)
|