Switch to unified view

a/src/ohsndrcv.cxx b/src/ohsndrcv.cxx
...
...
29
29
30
using namespace std;
30
using namespace std;
31
using namespace std::placeholders;
31
using namespace std::placeholders;
32
using namespace UPnPP;
32
using namespace UPnPP;
33
33
34
static const string makesendercmd("scmakempdsender.py");
35
static int mpdport = 6700;
36
37
class SenderReceiver::Internal {
34
class SenderReceiver::Internal {
38
public:
35
public:
39
    Internal(UpMpd *dv)
36
    Internal(UpMpd *dv, const string& starterpath, int port)
40
        : dev(dv), mpd(0), origmpd(0), cmd(0) {
37
        : dev(dv), mpd(0), origmpd(0), sender(0), makesendercmd(starterpath),
38
          mpdport(port) {
41
    }
39
    }
42
    ~Internal() {
40
    ~Internal() {
43
        clear();
41
        clear();
44
    }
42
    }
45
    void clear() {
43
    void clear() {
...
...
52
            if (dev->m_ohpl) {
50
            if (dev->m_ohpl) {
53
                dev->m_ohpl->refreshState();
51
                dev->m_ohpl->refreshState();
54
            }
52
            }
55
        }
53
        }
56
        delete mpd;
54
        delete mpd;
57
        delete cmd;
55
        delete sender;
58
    }
56
    }
59
    UpMpd *dev;
57
    UpMpd *dev;
60
    MPDCli *mpd;
58
    MPDCli *mpd;
61
    MPDCli *origmpd;
59
    MPDCli *origmpd;
62
    ExecCmd *cmd;
60
    ExecCmd *sender;
63
    string uri;
61
    string uri;
64
    string meta;
62
    string meta;
63
    string makesendercmd;
64
    int mpdport;
65
};
65
};
66
66
67
67
68
SenderReceiver::SenderReceiver(UpMpd *dev)
68
SenderReceiver::SenderReceiver(UpMpd *dev, const string& starterpath, int port)
69
{
69
{
70
    m = new Internal(dev);
70
    m = new Internal(dev, starterpath, port);
71
}
71
}
72
72
73
SenderReceiver::~SenderReceiver()
73
SenderReceiver::~SenderReceiver()
74
{
74
{
75
    if (m)
75
    if (m)
...
...
119
    }
119
    }
120
    
120
    
121
    // Stop MPD Play (normally already done)
121
    // Stop MPD Play (normally already done)
122
    m->dev->m_mpdcli->stop();
122
    m->dev->m_mpdcli->stop();
123
123
124
    if (!m->cmd) {
124
    if (!m->sender) {
125
        // First time: Start fifo MPD and Sender
125
        // First time: Start fifo MPD and Sender
126
        m->cmd = new ExecCmd();
126
        m->sender = new ExecCmd();
127
        vector<string> args;
127
        vector<string> args;
128
        args.push_back("-p");
128
        args.push_back("-p");
129
        args.push_back(SoapHelp::i2s(mpdport));
129
        args.push_back(SoapHelp::i2s(m->mpdport));
130
        args.push_back("-f");
130
        args.push_back("-f");
131
        args.push_back(m->dev->m_friendlyname);
131
        args.push_back(m->dev->m_friendlyname);
132
        m->cmd->startExec(makesendercmd, args, false, true);
132
        m->sender->startExec(m->makesendercmd, args, false, true);
133
133
134
        string output;
134
        string output;
135
        if (!m->cmd->getline(output)) {
135
        if (!m->sender->getline(output)) {
136
            LOGERR("SenderReceiver::start: makesender command failed\n");
136
            LOGERR("SenderReceiver::start: makesender command failed\n");
137
            m->clear();
137
            m->clear();
138
            return false;
138
            return false;
139
        }
139
        }
140
        LOGDEB("SenderReceiver::start got [" << output << "] from script\n");
140
        LOGDEB("SenderReceiver::start got [" << output << "] from script\n");
...
...
150
        }
150
        }
151
        m->uri = base64_decode(toks[3]);
151
        m->uri = base64_decode(toks[3]);
152
        m->meta = base64_decode(toks[5]);
152
        m->meta = base64_decode(toks[5]);
153
153
154
        // Connect to the new MPD
154
        // Connect to the new MPD
155
        m->mpd = new MPDCli("localhost", mpdport);
155
        m->mpd = new MPDCli("localhost", m->mpdport);
156
        if (!m->mpd || !m->mpd->ok()) {
156
        if (!m->mpd || !m->mpd->ok()) {
157
            LOGERR("SenderReceiver::start: can't connect to new MPD\n");
157
            LOGERR("SenderReceiver::start: can't connect to new MPD\n");
158
            m->clear();
158
            m->clear();
159
            return false;
159
            return false;
160
        }
160
        }