Switch to unified view

a/src/mpdcli.cxx b/src/mpdcli.cxx
...
...
26
#include <string>
26
#include <string>
27
#include <memory>
27
#include <memory>
28
28
29
#include "libupnpp/log.hxx"
29
#include "libupnpp/log.hxx"
30
30
31
#include "upmpd.hxx"
32
#include "conftree.hxx"
31
#include "execmd.h"
33
#include "execmd.h"
32
34
33
struct mpd_status;
35
struct mpd_status;
34
36
35
using namespace std;
37
using namespace std;
36
using namespace UPnPP;
38
using namespace UPnPP;
37
39
38
#define M_CONN ((struct mpd_connection *)m_conn)
40
#define M_CONN ((struct mpd_connection *)m_conn)
39
41
40
MPDCli::MPDCli(const string& host, int port, const string& pass,
42
MPDCli::MPDCli(const string& host, int port, const string& pass)
41
               const string& onstart, const string& onplay,
42
               const string& onstop, const string& onvolumechange,
43
         const string& getexternalvolume, bool externalvolumecontrol)
44
    : m_conn(0), m_ok(false), m_premutevolume(0), m_cachedvolume(50),
43
    : m_conn(0), m_ok(false), m_premutevolume(0), m_cachedvolume(50),
45
      m_host(host), m_port(port), m_password(pass), m_onstart(onstart),
44
      m_host(host), m_port(port), m_password(pass),
46
      m_onplay(onplay), m_onstop(onstop),
47
      m_lastinsertid(-1), m_lastinsertpos(-1), m_lastinsertqvers(-1)
45
      m_lastinsertid(-1), m_lastinsertpos(-1), m_lastinsertqvers(-1)
48
{
46
{
49
    regcomp(&m_tpuexpr, "^[[:alpha:]]+://.+", REG_EXTENDED|REG_NOSUB);
47
    regcomp(&m_tpuexpr, "^[[:alpha:]]+://.+", REG_EXTENDED|REG_NOSUB);
50
    if (!openconn()) {
48
    if (!openconn()) {
51
        return;
49
        return;
52
    }
50
    }
53
    m_have_addtagid = checkForCommand("addtagid");
51
    m_have_addtagid = checkForCommand("addtagid");
54
52
55
    m_ok = true;
53
    m_ok = true;
56
    m_ok = updStatus();
54
    m_ok = updStatus();
55
56
    UPnPP::PTMutexLocker conflock(g_configlock);
57
    g_config->get("onstart", m_onstart);
58
    g_config->get("onplay", m_onplay);
59
    g_config->get("onstop", m_onstop);
60
    g_config->get("onvolumechange", m_stat.onvolumechange);
61
    g_config->get("getexternalvolume", m_stat.getexternalvolume);
57
    m_stat.externalvolumecontrol = externalvolumecontrol;
62
    m_stat.externalvolumecontrol = false;
58
    m_stat.onvolumechange = onvolumechange;
63
    string value;
59
    m_stat.getexternalvolume = getexternalvolume;
64
    if (g_config->get("externalvolumecontrol", value)) {
65
        m_stat.externalvolumecontrol = atoi(value.c_str()) != 0;
66
    }
60
}
67
}
61
68
62
MPDCli::~MPDCli()
69
MPDCli::~MPDCli()
63
{
70
{
64
    if (m_conn) 
71
    if (m_conn) 
65
        mpd_connection_free(M_CONN);
72
        mpd_connection_free(M_CONN);
66
    regfree(&m_tpuexpr);
73
    regfree(&m_tpuexpr);
74
}
75
76
// This is used on the auxiliary songcast mpd in a configuration where
77
// volume is normally controlled by an external script, but we still
78
// want to scale the Songcast stream.
79
void MPDCli::forceInternalVControl()
80
{
81
    m_stat.getexternalvolume.clear();
82
    if (m_stat.externalvolumecontrol)
83
        m_stat.onvolumechange.clear();
84
    m_stat.externalvolumecontrol = false;
67
}
85
}
68
86
69
bool MPDCli::looksLikeTransportURI(const string& path)
87
bool MPDCli::looksLikeTransportURI(const string& path)
70
{
88
{
71
    return (regexec(&m_tpuexpr, path.c_str(), 0, 0, 0) == 0);
89
    return (regexec(&m_tpuexpr, path.c_str(), 0, 0, 0) == 0);