Switch to unified view

a/upmpd/ohplaylist.cxx b/upmpd/ohplaylist.cxx
...
...
35
#include "libupnpp/device.hxx"
35
#include "libupnpp/device.hxx"
36
#include "libupnpp/log.hxx"
36
#include "libupnpp/log.hxx"
37
37
38
#include "upmpd.hxx"
38
#include "upmpd.hxx"
39
#include "ohplaylist.hxx"
39
#include "ohplaylist.hxx"
40
#include "ohmetacache.hxx"
40
#include "mpdcli.hxx"
41
#include "mpdcli.hxx"
41
#include "upmpdutils.hxx"
42
#include "upmpdutils.hxx"
42
//#include "renderctl.hxx"
43
#include "base64.hxx"
43
#include "base64.hxx"
44
44
45
static const string sTpProduct("urn:av-openhome-org:service:Playlist:1");
45
static const string sTpProduct("urn:av-openhome-org:service:Playlist:1");
46
static const string sIdProduct("urn:av-openhome-org:serviceId:Playlist");
46
static const string sIdProduct("urn:av-openhome-org:serviceId:Playlist");
47
47
48
OHPlaylist::OHPlaylist(UpMpd *dev, UpMpdRenderCtl *ctl)
48
OHPlaylist::OHPlaylist(UpMpd *dev, UpMpdRenderCtl *ctl)
49
    : UpnpService(sTpProduct, sIdProduct, dev), m_dev(dev), m_ctl(ctl)
49
    : UpnpService(sTpProduct, sIdProduct, dev), m_dev(dev), m_ctl(ctl),
50
      m_cachedirty(false)
50
{
51
{
51
    dev->addActionMapping(this, "Play", 
52
    dev->addActionMapping(this, "Play", 
52
                          bind(&OHPlaylist::play, this, _1, _2));
53
                          bind(&OHPlaylist::play, this, _1, _2));
53
    dev->addActionMapping(this, "Pause", 
54
    dev->addActionMapping(this, "Pause", 
54
                          bind(&OHPlaylist::pause, this, _1, _2));
55
                          bind(&OHPlaylist::pause, this, _1, _2));
...
...
95
    dev->addActionMapping(this, "IdArrayChanged",
96
    dev->addActionMapping(this, "IdArrayChanged",
96
                          bind(&OHPlaylist::idArrayChanged, this, _1, _2));
97
                          bind(&OHPlaylist::idArrayChanged, this, _1, _2));
97
    dev->addActionMapping(this, "ProtocolInfo",
98
    dev->addActionMapping(this, "ProtocolInfo",
98
                          bind(&OHPlaylist::protocolInfo, this, _1, _2));
99
                          bind(&OHPlaylist::protocolInfo, this, _1, _2));
99
    dev->m_mpdcli->consume(false);
100
    dev->m_mpdcli->consume(false);
101
    
102
    dmcacheRestore(dev->getMetaCacheFn().c_str(), m_metacache);
100
}
103
}
101
104
102
static const int tracksmax = 16384;
105
static const int tracksmax = 16384;
103
106
104
static string mpdstatusToTransportState(MpdStatus::State st)
107
static string mpdstatusToTransportState(MpdStatus::State st)
...
...
167
        auto inold = m_metacache.find(usong.uri);
170
        auto inold = m_metacache.find(usong.uri);
168
        if (inold != m_metacache.end()) {
171
        if (inold != m_metacache.end()) {
169
            // Entries already in the metadata array just get
172
            // Entries already in the metadata array just get
170
            // transferred to the new array
173
            // transferred to the new array
171
            nmeta[usong.uri].swap(inold->second);
174
            nmeta[usong.uri].swap(inold->second);
175
            m_metacache.erase(inold);
172
        } else {
176
        } else {
173
            // Entries not in the old array are translated from the
177
            // Entries not in the old array are translated from the
174
            // MPD data to our format. They were probably added by
178
            // MPD data to our format. They were probably added by
175
            // another MPD client. 
179
            // another MPD client. 
176
            nmeta[usong.uri] = didlmake(usong);
180
            nmeta[usong.uri] = didlmake(usong);
181
            m_cachedirty = true;
177
            LOGDEB("OHPlaylist::makeIdArray: set mpd data for " << 
182
            LOGDEB("OHPlaylist::makeIdArray: set mpd data for " << 
178
                   usong.mpdid << endl);
183
                   usong.mpdid << endl);
179
        }
184
        }
185
    }
186
187
    // If we added entries or there are some stale entries, the new
188
    // map differs, save it to cache
189
    if (!m_metacache.empty() || m_cachedirty) {
190
        LOGDEB("OHPlaylist::makeIdArray: saving metacache" << endl);
191
        dmcacheSave(m_dev->getMetaCacheFn().c_str(), nmeta);
192
        m_cachedirty = false;
180
    }
193
    }
181
    m_metacache = nmeta;
194
    m_metacache = nmeta;
182
195
183
    return true;
196
    return true;
184
}
197
}
...
...
416
        if (cached != m_metacache.end()) {
429
        if (cached != m_metacache.end()) {
417
            metadata = SoapArgs::xmlQuote(cached->second);
430
            metadata = SoapArgs::xmlQuote(cached->second);
418
        } else {
431
        } else {
419
            metadata = didlmake(song);
432
            metadata = didlmake(song);
420
            m_metacache[song.uri] = metadata;
433
            m_metacache[song.uri] = metadata;
434
            m_cachedirty = true;
421
            metadata = SoapArgs::xmlQuote(metadata);
435
            metadata = SoapArgs::xmlQuote(metadata);
422
        }
436
        }
423
        data.addarg("Uri", song.uri);
437
        data.addarg("Uri", song.uri);
424
        data.addarg("Metadata", metadata);
438
        data.addarg("Metadata", metadata);
425
    }
439
    }
...
...
461
            } else {
475
            } else {
462
                //LOGDEB("readList: metadata for songid " << id << " uri " 
476
                //LOGDEB("readList: metadata for songid " << id << " uri " 
463
                // << song.uri << " not found " << endl);
477
                // << song.uri << " not found " << endl);
464
                metadata = didlmake(song);
478
                metadata = didlmake(song);
465
                m_metacache[song.uri] = metadata;
479
                m_metacache[song.uri] = metadata;
480
                m_cachedirty = true;
466
                metadata = SoapArgs::xmlQuote(metadata);
481
                metadata = SoapArgs::xmlQuote(metadata);
467
            }
482
            }
468
            out += "<Entry><Id>";
483
            out += "<Entry><Id>";
469
            out += sid.c_str();
484
            out += sid.c_str();
470
            out += "</Id><Uri>";
485
            out += "</Id><Uri>";
...
...
500
           uri << " Metadata " << metadata << endl);
515
           uri << " Metadata " << metadata << endl);
501
    if (ok) {
516
    if (ok) {
502
        int id = m_dev->m_mpdcli->insertAfterId(uri, afterid);
517
        int id = m_dev->m_mpdcli->insertAfterId(uri, afterid);
503
        if ((ok = (id != -1))) {
518
        if ((ok = (id != -1))) {
504
            m_metacache[uri] = metadata;
519
            m_metacache[uri] = metadata;
520
            m_cachedirty = true;
505
            data.addarg("NewId", SoapArgs::i2s(id));
521
            data.addarg("NewId", SoapArgs::i2s(id));
506
        }
522
        }
507
    }
523
    }
508
    maybeWakeUp(ok);
524
    maybeWakeUp(ok);
509
    return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
525
    return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;