Switch to unified view

a/src/mpdcli.cxx b/src/mpdcli.cxx
...
...
93
        return false;
93
        return false;
94
    }
94
    }
95
95
96
    int error = mpd_connection_get_error(M_CONN);
96
    int error = mpd_connection_get_error(M_CONN);
97
    if (error == MPD_ERROR_SUCCESS) {
97
    if (error == MPD_ERROR_SUCCESS) {
98
        //LOGDEB("MPDCli::showError: " << who << " success !" << endl;);
98
        //LOGDEB("MPDCli::showError: " << who << " success !" << endl);
99
        return false;
99
        return false;
100
    }
100
    }
101
    LOGERR(who << " failed: " <<  mpd_connection_get_error_message(M_CONN) 
101
    LOGERR(who << " failed: " <<  mpd_connection_get_error_message(M_CONN) 
102
           << endl);
102
           << endl);
103
    if (error == MPD_ERROR_SERVER) {
103
    if (error == MPD_ERROR_SERVER) {
...
...
165
165
166
    switch (mpd_status_get_state(mpds)) {
166
    switch (mpd_status_get_state(mpds)) {
167
    case MPD_STATE_STOP:
167
    case MPD_STATE_STOP:
168
        // Only execute onstop command if mpd was playing or paused
168
        // Only execute onstop command if mpd was playing or paused
169
        if (m_stat.state != MpdStatus::MPDS_STOP && !m_onstop.empty()) {
169
        if (m_stat.state != MpdStatus::MPDS_STOP && !m_onstop.empty()) {
170
            system(m_onstop.c_str());
170
            if (system(m_onstop.c_str())) {
171
                LOGERR("MPDCli::updStatus: " << m_onstop << " failed "<< endl);
172
            }
171
        }
173
        }
172
        m_stat.state = MpdStatus::MPDS_STOP;
174
        m_stat.state = MpdStatus::MPDS_STOP;
173
        break;
175
        break;
174
    case MPD_STATE_PLAY: m_stat.state = MpdStatus::MPDS_PLAY;break;
176
    case MPD_STATE_PLAY: m_stat.state = MpdStatus::MPDS_PLAY;break;
175
    case MPD_STATE_PAUSE: m_stat.state = MpdStatus::MPDS_PAUSE;break;
177
    case MPD_STATE_PAUSE: m_stat.state = MpdStatus::MPDS_PAUSE;break;
...
...
241
    return found;
243
    return found;
242
}
244
}
243
245
244
bool MPDCli::statSong(UpSong& upsong, int pos, bool isid)
246
bool MPDCli::statSong(UpSong& upsong, int pos, bool isid)
245
{
247
{
246
    //LOGDEB("MPDCli::statSong. isid " << isid << " val " << pos << endl);
248
    //LOGDEB("MPDCli::statSong. isid " << isid << " id/pos " << pos << endl);
247
    if (!ok())
249
    if (!ok())
248
        return false;
250
        return false;
249
251
250
    struct mpd_song *song;
252
    struct mpd_song *song;
251
    if (isid == false) {
253
    if (isid == false) {
...
...
267
    return true;
269
    return true;
268
}    
270
}    
269
271
270
UpSong&  MPDCli::mapSong(UpSong& upsong, struct mpd_song *song)
272
UpSong&  MPDCli::mapSong(UpSong& upsong, struct mpd_song *song)
271
{
273
{
274
    LOGDEB1("MPDCli::mapSong" << endl);
272
    const char *cp;
275
    const char *cp;
273
276
274
    cp = mpd_song_get_uri(song);
277
    cp = mpd_song_get_uri(song);
275
    if (cp != 0)
278
    if (cp != 0)
276
        upsong.uri = cp;
279
        upsong.uri = cp;
...
...
313
        upsong.genre.clear();
316
        upsong.genre.clear();
314
317
315
    upsong.duration_secs = mpd_song_get_duration(song);
318
    upsong.duration_secs = mpd_song_get_duration(song);
316
    upsong.mpdid = mpd_song_get_id(song);
319
    upsong.mpdid = mpd_song_get_id(song);
317
320
321
    LOGDEB1("MPDCli::mapSong: got mpdid " << upsong.mpdid << " " << 
322
            upsong.dump() << endl);
318
    return upsong;
323
    return upsong;
319
}
324
}
320
325
321
bool MPDCli::setVolume(int volume, bool isMute)
326
bool MPDCli::setVolume(int volume, bool isMute)
322
{
327
{
328
    LOGDEB1("MPDCli::setVolume" << endl);
323
    if (!ok()) {
329
    if (!ok()) {
324
        return false;
330
        return false;
325
    }
331
    }
326
332
327
    // MPD does not want to set the volume if not active.
333
    // MPD does not want to set the volume if not active.
...
...
364
    return true;
370
    return true;
365
}
371
}
366
372
367
int MPDCli::getVolume()
373
int MPDCli::getVolume()
368
{
374
{
375
    LOGDEB1("MPDCli::getVolume" << endl);
369
    return m_stat.volume >= 0 ? m_stat.volume : m_cachedvolume;
376
    return m_stat.volume >= 0 ? m_stat.volume : m_cachedvolume;
370
}
377
}
371
378
372
bool MPDCli::togglePause()
379
bool MPDCli::togglePause()
373
{
380
{
...
...
391
{
398
{
392
    LOGDEB("MPDCli::play(pos=" << pos << ")" << endl);
399
    LOGDEB("MPDCli::play(pos=" << pos << ")" << endl);
393
    if (!ok())
400
    if (!ok())
394
        return false;
401
        return false;
395
    if (!m_onstart.empty()) {
402
    if (!m_onstart.empty()) {
396
        system(m_onstart.c_str());
403
        if (system(m_onstart.c_str())) {
404
            LOGERR("MPDCli::play: " << m_onstart << " failed "<< endl);
405
        }
397
    }
406
    }
398
    if (pos >= 0) {
407
    if (pos >= 0) {
399
        RETRY_CMD(mpd_run_play_pos(M_CONN, (unsigned int)pos));
408
        RETRY_CMD(mpd_run_play_pos(M_CONN, (unsigned int)pos));
400
    } else {
409
    } else {
401
        RETRY_CMD(mpd_run_play(M_CONN));
410
        RETRY_CMD(mpd_run_play(M_CONN));
...
...
407
{
416
{
408
    LOGDEB("MPDCli::playId(id=" << id << ")" << endl);
417
    LOGDEB("MPDCli::playId(id=" << id << ")" << endl);
409
    if (!ok())
418
    if (!ok())
410
        return false;
419
        return false;
411
    if (!m_onstart.empty()) {
420
    if (!m_onstart.empty()) {
412
        system(m_onstart.c_str());
421
        if (system(m_onstart.c_str())) {
422
            LOGERR("MPDCli::playId: " << m_onstart << " failed "<< endl);
423
        }
413
    }
424
    }
414
    RETRY_CMD(mpd_run_play_id(M_CONN, (unsigned int)id));
425
    RETRY_CMD(mpd_run_play_id(M_CONN, (unsigned int)id));
415
    return updStatus();
426
    return updStatus();
416
}
427
}
417
bool MPDCli::stop()
428
bool MPDCli::stop()
...
...
489
                          data.c_str(), NULL)) {
500
                          data.c_str(), NULL)) {
490
        LOGERR("MPDCli::send_tag: mpd_send_command failed" << endl);
501
        LOGERR("MPDCli::send_tag: mpd_send_command failed" << endl);
491
        return false;
502
        return false;
492
    }
503
    }
493
504
494
    return mpd_response_finish(M_CONN);
505
    if (!mpd_response_finish(M_CONN)) {
506
        LOGERR("MPDCli::send_tag: mpd_response_finish failed\n");
507
        showError("MPDCli::send_tag");
508
        return false;
509
    }
510
    return true;
495
}
511
}
496
512
497
static const string upmpdcli_comment("client=upmpdcli;");
513
static const string upmpdcli_comment("client=upmpdcli;");
498
514
499
bool MPDCli::send_tag_data(int id, const UpSong& meta)
515
bool MPDCli::send_tag_data(int id, const UpSong& meta)
500
{
516
{
517
    LOGDEB1("MPDCli::send_tag_data" << endl);
501
    if (!m_have_addtagid)
518
    if (!m_have_addtagid)
502
        return false;
519
        return false;
503
520
504
    char cid[30];
521
    char cid[30];
505
    sprintf(cid, "%d", id);
522
    sprintf(cid, "%d", id);
...
...
618
    return false;
635
    return false;
619
}
636
}
620
637
621
bool MPDCli::getQueueSongs(vector<mpd_song*>& songs)
638
bool MPDCli::getQueueSongs(vector<mpd_song*>& songs)
622
{
639
{
640
    LOGDEB1("MPDCli::getQueueSongs" << endl);
623
    songs.clear();
641
    songs.clear();
624
642
625
    RETRY_CMD(mpd_send_list_queue_meta(M_CONN));
643
    RETRY_CMD(mpd_send_list_queue_meta(M_CONN));
626
644
627
    struct mpd_song *song;
645
    struct mpd_song *song;
...
...
637
    return true;
655
    return true;
638
}
656
}
639
657
640
void MPDCli::freeSongs(vector<mpd_song*>& songs)
658
void MPDCli::freeSongs(vector<mpd_song*>& songs)
641
{
659
{
660
    LOGDEB1("MPDCli::freeSongs" << endl);
642
    for (vector<mpd_song*>::iterator it = songs.begin();
661
    for (vector<mpd_song*>::iterator it = songs.begin();
643
         it != songs.end(); it++) {
662
         it != songs.end(); it++) {
644
        mpd_song_free(*it);
663
        mpd_song_free(*it);
645
    }
664
    }
646
}
665
}
...
...
667
        return -1;
686
        return -1;
668
    LOGDEB("MPDCli::curpos: pos: " << m_stat.songpos << " id " 
687
    LOGDEB("MPDCli::curpos: pos: " << m_stat.songpos << " id " 
669
           << m_stat.songid << endl);
688
           << m_stat.songid << endl);
670
    return m_stat.songpos;
689
    return m_stat.songpos;
671
}
690
}
672
673
691
674
692
675
693
676
#ifdef MPDCLI_TEST
694
#ifdef MPDCLI_TEST
677
695