|
a/src/ohproduct.cxx |
|
b/src/ohproduct.cxx |
|
... |
|
... |
37 |
#include "ohplaylist.hxx"
|
37 |
#include "ohplaylist.hxx"
|
38 |
#include "ohradio.hxx"
|
38 |
#include "ohradio.hxx"
|
39 |
#include "ohreceiver.hxx"
|
39 |
#include "ohreceiver.hxx"
|
40 |
#include "ohsndrcv.hxx"
|
40 |
#include "ohsndrcv.hxx"
|
41 |
#include "ohinfo.hxx"
|
41 |
#include "ohinfo.hxx"
|
|
|
42 |
#include "conftree.hxx"
|
42 |
|
43 |
|
43 |
using namespace std;
|
44 |
using namespace std;
|
44 |
using namespace std::placeholders;
|
45 |
using namespace std::placeholders;
|
45 |
|
46 |
|
|
|
47 |
static void listScripts(vector<pair<string, string> >& sources);
|
|
|
48 |
|
46 |
static const string sTpProduct("urn:av-openhome-org:service:Product:1");
|
49 |
static const string sTpProduct("urn:av-openhome-org:service:Product:1");
|
47 |
static const string sIdProduct("urn:av-openhome-org:serviceId:Product");
|
50 |
static const string sIdProduct("urn:av-openhome-org:serviceId:Product");
|
48 |
|
51 |
|
49 |
static string csxml("<SourceList>\n");
|
52 |
static string csxml("<SourceList>\n");
|
50 |
static string csattrs("Info Time Volume");
|
53 |
static string csattrs("Info Time Volume");
|
|
|
54 |
|
|
|
55 |
// This can be replaced by config data in listScripts()
|
|
|
56 |
static string scripts_dir("/usr/share/upmpdcli/src_scripts");
|
51 |
|
57 |
|
52 |
// (Type, Name) list
|
58 |
// (Type, Name) list
|
53 |
static vector<pair<string, string> > o_sources;
|
59 |
static vector<pair<string, string> > o_sources;
|
54 |
|
60 |
|
55 |
OHProduct::OHProduct(UpMpd *dev, const string& friendlyname)
|
61 |
OHProduct::OHProduct(UpMpd *dev, const string& friendlyname)
|
|
... |
|
... |
78 |
o_sources.push_back(pair<string,string>("Radio",
|
84 |
o_sources.push_back(pair<string,string>("Radio",
|
79 |
"SenderReceiverRD"));
|
85 |
"SenderReceiverRD"));
|
80 |
}
|
86 |
}
|
81 |
}
|
87 |
}
|
82 |
}
|
88 |
}
|
|
|
89 |
|
|
|
90 |
listScripts(o_sources);
|
83 |
|
91 |
|
84 |
for (auto it = o_sources.begin(); it != o_sources.end(); it++) {
|
92 |
for (auto it = o_sources.begin(); it != o_sources.end(); it++) {
|
85 |
string visible = it->first.compare("Receiver") ? "1" : "0";
|
93 |
string visible = it->first.compare("Receiver") ? "1" : "0";
|
86 |
csxml += string(" <Source>\n") +
|
94 |
csxml += string(" <Source>\n") +
|
87 |
" <Name>" + it->second + "</Name>\n" +
|
95 |
" <Name>" + it->second + "</Name>\n" +
|
|
... |
|
... |
249 |
const MpdStatus& mpds = m_dev->getMpdStatus();
|
257 |
const MpdStatus& mpds = m_dev->getMpdStatus();
|
250 |
int savedms = mpds.songelapsedms;
|
258 |
int savedms = mpds.songelapsedms;
|
251 |
|
259 |
|
252 |
m_dev->m_ohif->setMetatext("");
|
260 |
m_dev->m_ohif->setMetatext("");
|
253 |
|
261 |
|
|
|
262 |
string curtp = o_sources[m_sourceIndex].first;
|
254 |
string curnm = o_sources[m_sourceIndex].second;
|
263 |
string curnm = o_sources[m_sourceIndex].second;
|
255 |
if (m_dev->m_ohpl && !curnm.compare("Playlist")) {
|
264 |
if (m_dev->m_ohpl && !curtp.compare("Playlist") &&
|
|
|
265 |
!curnm.compare("Playlist")) {
|
256 |
m_dev->m_ohpl->iStop();
|
266 |
m_dev->m_ohpl->iStop();
|
257 |
m_dev->m_ohpl->setActive(false);
|
267 |
m_dev->m_ohpl->setActive(false);
|
258 |
} else if (m_dev->m_ohrcv && !curnm.compare("Receiver")) {
|
268 |
} else if (m_dev->m_ohrcv && !curtp.compare("Receiver") &&
|
|
|
269 |
!curnm.compare("Receiver")) {
|
259 |
m_dev->m_ohrcv->iStop();
|
270 |
m_dev->m_ohrcv->iStop();
|
260 |
m_dev->m_ohrcv->setActive(false);
|
271 |
m_dev->m_ohrcv->setActive(false);
|
261 |
} else if (m_dev->m_ohrd && !curnm.compare("Radio")) {
|
272 |
} else if (m_dev->m_ohrd && !curtp.compare("Radio") &&
|
|
|
273 |
!curnm.compare("Radio")) {
|
262 |
m_dev->m_ohrd->iStop();
|
274 |
m_dev->m_ohrd->iStop();
|
263 |
m_dev->m_ohrd->setActive(false);
|
275 |
m_dev->m_ohrd->setActive(false);
|
264 |
} else if (m_dev->m_sndrcv && m_dev->m_ohpl &&
|
276 |
} else if (m_dev->m_sndrcv && m_dev->m_ohpl &&
|
|
|
277 |
!curtp.compare("Playlist") &&
|
265 |
!curnm.compare("SenderReceiverPL")) {
|
278 |
!curnm.compare("SenderReceiverPL")) {
|
266 |
m_dev->m_sndrcv->stop();
|
279 |
m_dev->m_sndrcv->stop();
|
267 |
m_dev->m_ohpl->setActive(false);
|
280 |
m_dev->m_ohpl->setActive(false);
|
268 |
} else if (m_dev->m_sndrcv && m_dev->m_ohrd &&
|
281 |
} else if (m_dev->m_sndrcv && m_dev->m_ohrd &&
|
|
|
282 |
!curtp.compare("Radio") &&
|
269 |
!curnm.compare("SenderReceiverRD")) {
|
283 |
!curnm.compare("SenderReceiverRD")) {
|
270 |
m_dev->m_ohrd->setActive(false);
|
284 |
m_dev->m_ohrd->setActive(false);
|
271 |
m_dev->m_sndrcv->stop();
|
285 |
m_dev->m_sndrcv->stop();
|
|
|
286 |
} else {
|
|
|
287 |
// External inputs managed by scripts Analog/Digital/Hdmi etc.
|
|
|
288 |
m_dev->m_sndrcv->stop();
|
272 |
}
|
289 |
}
|
273 |
|
290 |
|
|
|
291 |
string newtp = o_sources[sindex].first;
|
274 |
string newnm = o_sources[sindex].second;
|
292 |
string newnm = o_sources[sindex].second;
|
275 |
if (m_dev->m_ohpl && !newnm.compare("Playlist")) {
|
293 |
if (m_dev->m_ohpl && !newnm.compare("Playlist")) {
|
276 |
m_dev->m_ohpl->setActive(true);
|
294 |
m_dev->m_ohpl->setActive(true);
|
277 |
m_sourceIndex = sindex;
|
|
|
278 |
} else if (m_dev->m_ohrcv && !newnm.compare("Receiver")) {
|
295 |
} else if (m_dev->m_ohrcv && !newnm.compare("Receiver")) {
|
279 |
m_dev->m_ohrcv->setActive(true);
|
296 |
m_dev->m_ohrcv->setActive(true);
|
280 |
m_sourceIndex = sindex;
|
|
|
281 |
} else if (m_dev->m_ohrd && !newnm.compare("Radio")) {
|
297 |
} else if (m_dev->m_ohrd && !newnm.compare("Radio")) {
|
282 |
m_dev->m_ohrd->setActive(true);
|
298 |
m_dev->m_ohrd->setActive(true);
|
283 |
m_sourceIndex = sindex;
|
|
|
284 |
} else if (m_dev->m_ohpl && m_dev->m_sndrcv &&
|
299 |
} else if (m_dev->m_ohpl && m_dev->m_sndrcv &&
|
285 |
!newnm.compare("SenderReceiverPL")) {
|
300 |
!newnm.compare("SenderReceiverPL")) {
|
286 |
// Events are generated by playlist
|
|
|
287 |
m_dev->m_ohpl->setActive(true);
|
301 |
m_dev->m_ohpl->setActive(true);
|
288 |
m_dev->m_sndrcv->start(false, savedms);
|
302 |
m_dev->m_sndrcv->start(string(), savedms);
|
289 |
m_sourceIndex = sindex;
|
|
|
290 |
} else if (m_dev->m_ohrd && m_dev->m_sndrcv &&
|
303 |
} else if (m_dev->m_ohrd && m_dev->m_sndrcv &&
|
291 |
!newnm.compare("SenderReceiverRD")) {
|
304 |
!newnm.compare("SenderReceiverRD")) {
|
292 |
// Events are generated by radio
|
|
|
293 |
m_dev->m_ohrd->setActive(true);
|
305 |
m_dev->m_ohrd->setActive(true);
|
|
|
306 |
m_dev->m_sndrcv->start(string());
|
|
|
307 |
} else {
|
|
|
308 |
string sname = newtp + "-" + newnm;
|
|
|
309 |
string spath = path_cat(scripts_dir, sname);
|
294 |
m_dev->m_sndrcv->start(true, 0);
|
310 |
m_dev->m_sndrcv->start(spath);
|
|
|
311 |
}
|
295 |
m_sourceIndex = sindex;
|
312 |
m_sourceIndex = sindex;
|
296 |
}
|
|
|
297 |
|
313 |
|
298 |
m_dev->loopWakeup();
|
314 |
m_dev->loopWakeup();
|
299 |
}
|
315 |
}
|
300 |
return UPNP_E_SUCCESS;
|
316 |
return UPNP_E_SUCCESS;
|
301 |
}
|
317 |
}
|
|
... |
|
... |
363 |
{
|
379 |
{
|
364 |
LOGDEB("OHProduct::sourceXMLChangeCount" << endl);
|
380 |
LOGDEB("OHProduct::sourceXMLChangeCount" << endl);
|
365 |
data.addarg("Value", "0");
|
381 |
data.addarg("Value", "0");
|
366 |
return UPNP_E_SUCCESS;
|
382 |
return UPNP_E_SUCCESS;
|
367 |
}
|
383 |
}
|
|
|
384 |
|
|
|
385 |
#include <sys/types.h>
|
|
|
386 |
#include <dirent.h>
|
|
|
387 |
|
|
|
388 |
// Script names are like Type-Name
|
|
|
389 |
// Type may be Analog or Digital or Hdmi and is not specially
|
|
|
390 |
// distinguished on value (but must be one of the three).
|
|
|
391 |
//
|
|
|
392 |
// Name is arbitrary
|
|
|
393 |
static void listScripts(vector<pair<string, string> >& sources)
|
|
|
394 |
{
|
|
|
395 |
if (!g_config)
|
|
|
396 |
return;
|
|
|
397 |
|
|
|
398 |
g_config->get("ohsrc_scripts_dir", scripts_dir);
|
|
|
399 |
|
|
|
400 |
DIR *dirp = opendir(scripts_dir.c_str());
|
|
|
401 |
if (dirp == 0) {
|
|
|
402 |
LOGERR("Error opening scripts dir " << scripts_dir << " errno " <<
|
|
|
403 |
errno << endl);
|
|
|
404 |
return;
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
struct dirent *ent;
|
|
|
408 |
while ((ent = readdir(dirp)) != 0) {
|
|
|
409 |
string tpnm(ent->d_name);
|
|
|
410 |
if (tpnm.size() == 0 || tpnm[0] == '.') {
|
|
|
411 |
continue;
|
|
|
412 |
}
|
|
|
413 |
string::size_type dash = tpnm.find_first_of("-");
|
|
|
414 |
if (dash == string::npos)
|
|
|
415 |
continue;
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
string tp(tpnm.substr(0, dash));
|
|
|
419 |
string nm(tpnm.substr(dash+1));
|
|
|
420 |
if (tp.compare("Analog") && tp.compare("Digital") &&
|
|
|
421 |
tp.compare("Hdmi")) {
|
|
|
422 |
LOGERR("listScripts: bad source type: " << tp << endl);
|
|
|
423 |
continue;
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
if (access(path_cat(scripts_dir, tpnm).c_str(), X_OK) != 0) {
|
|
|
427 |
LOGERR("listScripts: script " << tpnm << " is not executable" <<
|
|
|
428 |
endl);
|
|
|
429 |
continue;
|
|
|
430 |
}
|
|
|
431 |
|
|
|
432 |
sources.push_back(pair<string, string>(tp, nm));
|
|
|
433 |
}
|
|
|
434 |
closedir(dirp);
|
|
|
435 |
return;
|
|
|
436 |
}
|