Switch to unified view

a/src/upmpd.cxx b/src/upmpd.cxx
...
...
98
//        urn:upnp-org:serviceId:ConnectionManager
98
//        urn:upnp-org:serviceId:ConnectionManager
99
// The solution would be to have a separate init call to start the
99
// The solution would be to have a separate init call to start the
100
// device at the end of the constructor code.
100
// device at the end of the constructor code.
101
UpMpd::UpMpd(const string& deviceid, const string& friendlyname,
101
UpMpd::UpMpd(const string& deviceid, const string& friendlyname,
102
             const unordered_map<string, VDirContent>& files,
102
             const unordered_map<string, VDirContent>& files,
103
             MPDCli *mpdcli, unsigned int opts, const string& cachefn,
103
             MPDCli *mpdcli, Options opts)
104
             int schttpport
105
    )
106
    : UpnpDevice(deviceid, files), m_mpdcli(mpdcli), m_mpds(0),
104
    : UpnpDevice(deviceid, files), m_mpdcli(mpdcli), m_mpds(0),
107
      m_options(opts),
105
      m_options(opts.options),
108
      m_mcachefn(cachefn)
106
      m_mcachefn(opts.cachefn)
109
{
107
{
110
    // Note: the order is significant here as it will be used when
108
    // Note: the order is significant here as it will be used when
111
    // calling the getStatus() methods, and we want AVTransport to
109
    // calling the getStatus() methods, and we want AVTransport to
112
    // update the mpd status for OHInfo
110
    // update the mpd status for OHInfo
113
    UpMpdRenderCtl *rdctl = new UpMpdRenderCtl(this);
111
    UpMpdRenderCtl *rdctl = new UpMpdRenderCtl(this);
...
...
118
    if (m_options & upmpdDoOH) {
116
    if (m_options & upmpdDoOH) {
119
        m_services.push_back(new OHProduct(this, friendlyname, has_scmpdcli));
117
        m_services.push_back(new OHProduct(this, friendlyname, has_scmpdcli));
120
        m_services.push_back(new OHInfo(this));
118
        m_services.push_back(new OHInfo(this));
121
        m_services.push_back(new OHTime(this));
119
        m_services.push_back(new OHTime(this));
122
        m_services.push_back(new OHVolume(this, rdctl));
120
        m_services.push_back(new OHVolume(this, rdctl));
123
        OHPlaylist *ohp = new OHPlaylist(this, rdctl);
121
        OHPlaylist *ohp = new OHPlaylist(this, rdctl, opts.ohmetasleep);
124
        m_services.push_back(ohp);
122
        m_services.push_back(ohp);
125
        if (avt)
123
        if (avt)
126
            avt->setOHP(ohp);
124
            avt->setOHP(ohp);
127
        if (has_scmpdcli) {
125
        if (has_scmpdcli) {
128
            m_services.push_back(new OHReceiver(this, ohp, schttpport));
126
            m_services.push_back(new OHReceiver(this, ohp, opts.schttpport));
129
        }
127
        }
130
    }
128
    }
131
}
129
}
132
130
133
UpMpd::~UpMpd()
131
UpMpd::~UpMpd()
...
...
337
    }
335
    }
338
336
339
    if (argc != 0)
337
    if (argc != 0)
340
        Usage();
338
        Usage();
341
339
342
    int schttpport(8888);
340
    UpMpd::Options opts;
341
343
    string iconpath;
342
    string iconpath;
344
    if (!configfile.empty()) {
343
    if (!configfile.empty()) {
345
        ConfSimple config(configfile.c_str(), 1, true);
344
        ConfSimple config(configfile.c_str(), 1, true);
346
        if (!config.ok()) {
345
        if (!config.ok()) {
347
            cerr << "Could not open config: " << configfile << endl;
346
            cerr << "Could not open config: " << configfile << endl;
...
...
378
        }
377
        }
379
        if (!(op_flags & OPT_P) && config.get("upnpport", value)) {
378
        if (!(op_flags & OPT_P) && config.get("upnpport", value)) {
380
            upport = atoi(value.c_str());
379
            upport = atoi(value.c_str());
381
        }
380
        }
382
        if (config.get("schttpport", value))
381
        if (config.get("schttpport", value))
383
            schttpport = atoi(value.c_str());
382
            opts.schttpport = atoi(value.c_str());
383
        if (config.get("ohmetasleep", value))
384
            opts.ohmetasleep = atoi(value.c_str());
384
    }
385
    }
385
386
386
    if (Logger::getTheLog(logfilename) == 0) {
387
    if (Logger::getTheLog(logfilename) == 0) {
387
        cerr << "Can't initialize log" << endl;
388
        cerr << "Can't initialize log" << endl;
388
        return 1;
389
        return 1;
...
...
417
        cachedir = "/var/cache/upmpdcli";
418
        cachedir = "/var/cache/upmpdcli";
418
    } else {
419
    } else {
419
        cachedir = path_cat(path_tildexpand("~") , "/.cache/upmpdcli");
420
        cachedir = path_cat(path_tildexpand("~") , "/.cache/upmpdcli");
420
    }
421
    }
421
422
422
    string mcfn;
423
    string& mcfn = opts.cachefn;
423
    if (ohmetapersist) {
424
    if (ohmetapersist) {
424
        mcfn = path_cat(cachedir, "/metacache");
425
        opts.cachefn = path_cat(cachedir, "/metacache");
425
        if (!path_makepath(cachedir, 0755)) {
426
        if (!path_makepath(cachedir, 0755)) {
426
            LOGERR("makepath("<< cachedir << ") : errno : " << errno << endl);
427
            LOGERR("makepath("<< cachedir << ") : errno : " << errno << endl);
427
        } else {
428
        } else {
428
            int fd;
429
            int fd;
429
            if ((fd = open(mcfn.c_str(), O_CREAT|O_RDWR, 0644)) < 0) {
430
            if ((fd = open(mcfn.c_str(), O_CREAT|O_RDWR, 0644)) < 0) {
...
...
583
    if (!icondata.empty()) {
584
    if (!icondata.empty()) {
584
        files.insert(pair<string, VDirContent>
585
        files.insert(pair<string, VDirContent>
585
                     ("icon.png", VDirContent(icondata, "image/png")));
586
                     ("icon.png", VDirContent(icondata, "image/png")));
586
    }
587
    }
587
588
588
    unsigned int options = UpMpd::upmpdNone;
589
    if (ownqueue)
589
    if (ownqueue)
590
        options |= UpMpd::upmpdOwnQueue;
590
        opts.options |= UpMpd::upmpdOwnQueue;
591
    if (openhome)
591
    if (openhome)
592
        options |= UpMpd::upmpdDoOH;
592
        opts.options |= UpMpd::upmpdDoOH;
593
    if (ohmetapersist)
593
    if (ohmetapersist)
594
        options |= UpMpd::upmpdOhMetaPersist;
594
        opts.options |= UpMpd::upmpdOhMetaPersist;
595
595
596
    // Initialize the UPnP device object.
596
    // Initialize the UPnP device object.
597
    UpMpd device(string("uuid:") + UUID, friendlyname, 
597
    UpMpd device(string("uuid:") + UUID, friendlyname, 
598
                 files, mpdclip, options, mcfn, schttpport);
598
                 files, mpdclip, opts);
599
    dev = &device;
599
    dev = &device;
600
600
601
    // And forever generate state change events.
601
    // And forever generate state change events.
602
    LOGDEB("Entering event loop" << endl);
602
    LOGDEB("Entering event loop" << endl);
603
    setupsigs();
603
    setupsigs();