|
a/upmpd/upmpd.cxx |
|
b/upmpd/upmpd.cxx |
|
... |
|
... |
348 |
<< endl);
|
348 |
<< endl);
|
349 |
return 1;
|
349 |
return 1;
|
350 |
}
|
350 |
}
|
351 |
}
|
351 |
}
|
352 |
|
352 |
|
|
|
353 |
// Initialize MPD client object. Retry until it works or power fail.
|
|
|
354 |
MPDCli *mpdclip = 0;
|
|
|
355 |
int mpdretrysecs = 2;
|
|
|
356 |
for (;;) {
|
|
|
357 |
mpdclip = new MPDCli(mpdhost, mpdport, mpdpassword);
|
|
|
358 |
if (mpdclip == 0) {
|
|
|
359 |
LOGFAT("Can't allocate MPD client object" << endl);
|
|
|
360 |
return 1;
|
|
|
361 |
}
|
|
|
362 |
if (!mpdclip->ok()) {
|
|
|
363 |
LOGERR("MPD connection failed" << endl);
|
|
|
364 |
delete mpdclip;
|
|
|
365 |
mpdclip = 0;
|
|
|
366 |
sleep(mpdretrysecs);
|
|
|
367 |
mpdretrysecs = MIN(2*mpdretrysecs, 120);
|
|
|
368 |
} else {
|
|
|
369 |
break;
|
|
|
370 |
}
|
|
|
371 |
}
|
|
|
372 |
|
353 |
// Initialize libupnpp, and check health
|
373 |
// Initialize libupnpp, and check health
|
354 |
LibUPnP *mylib = 0;
|
374 |
LibUPnP *mylib = 0;
|
355 |
string hwaddr;
|
375 |
string hwaddr;
|
356 |
int libretrysecs = 10;
|
376 |
int libretrysecs = 10;
|
357 |
for (;;) {
|
377 |
for (;;) {
|
|
... |
|
... |
372 |
}
|
392 |
}
|
373 |
|
393 |
|
374 |
//string upnplogfilename("/tmp/upmpdcli_libupnp.log");
|
394 |
//string upnplogfilename("/tmp/upmpdcli_libupnp.log");
|
375 |
//mylib->setLogFileName(upnplogfilename, LibUPnP::LogLevelDebug);
|
395 |
//mylib->setLogFileName(upnplogfilename, LibUPnP::LogLevelDebug);
|
376 |
|
396 |
|
377 |
// Initialize MPD client module
|
|
|
378 |
MPDCli mpdcli(mpdhost, mpdport, mpdpassword);
|
|
|
379 |
if (!mpdcli.ok()) {
|
|
|
380 |
LOGFAT("MPD connection failed" << endl);
|
|
|
381 |
return 1;
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
// Create unique ID
|
397 |
// Create unique ID
|
385 |
string UUID = LibUPnP::makeDevUUID(friendlyname, hwaddr);
|
398 |
string UUID = LibUPnP::makeDevUUID(friendlyname, hwaddr);
|
386 |
|
399 |
|
387 |
// Read our XML data to make it available from the virtual directory
|
400 |
// Read our XML data to make it available from the virtual directory
|
388 |
if (openhome) {
|
401 |
if (openhome) {
|
|
... |
|
... |
421 |
options |= UpMpd::upmpdOwnQueue;
|
434 |
options |= UpMpd::upmpdOwnQueue;
|
422 |
if (openhome)
|
435 |
if (openhome)
|
423 |
options |= UpMpd::upmpdDoOH;
|
436 |
options |= UpMpd::upmpdDoOH;
|
424 |
// Initialize the UPnP device object.
|
437 |
// Initialize the UPnP device object.
|
425 |
UpMpd device(string("uuid:") + UUID, friendlyname,
|
438 |
UpMpd device(string("uuid:") + UUID, friendlyname,
|
426 |
xmlfiles, &mpdcli, options);
|
439 |
xmlfiles, mpdclip, options);
|
427 |
|
440 |
|
428 |
// And forever generate state change events.
|
441 |
// And forever generate state change events.
|
429 |
LOGDEB("Entering event loop" << endl);
|
442 |
LOGDEB("Entering event loop" << endl);
|
430 |
device.eventloop();
|
443 |
device.eventloop();
|
431 |
|
444 |
|