Switch to unified view

a/libupnpp/control/renderingcontrol.cxx b/libupnpp/control/renderingcontrol.cxx
...
...
14
 *       Free Software Foundation, Inc.,
14
 *       Free Software Foundation, Inc.,
15
 *       59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
 *       59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
16
 */
17
17
18
#include <string>
18
#include <string>
19
#include <functional>
20
19
using namespace std;
21
using namespace std;
22
using namespace std::placeholders;
20
23
21
#include <upnp/upnp.h>
24
#include <upnp/upnp.h>
22
25
23
#include "libupnpp/soaphelp.hxx"
26
#include "libupnpp/soaphelp.hxx"
27
#include "libupnpp/upnpp_p.hxx"
24
#include "libupnpp/log.hxx"
28
#include "libupnpp/log.hxx"
25
#include "libupnpp/control/renderingcontrol.hxx"
29
#include "libupnpp/control/renderingcontrol.hxx"
30
#include "libupnpp/control/avlastchg.hxx"
26
31
27
namespace UPnPClient {
32
namespace UPnPClient {
28
33
29
const string 
34
const string 
30
RenderingControl::SType("urn:schemas-upnp-org:service:RenderingControl:1");
35
RenderingControl::SType("urn:schemas-upnp-org:service:RenderingControl:1");
31
36
37
// Check serviceType string (while walking the descriptions. We don't
32
// We don't include a version in comparisons, as we are satisfied with
38
// include a version in comparisons, as we are satisfied with version1
33
// version 1
34
bool RenderingControl::isRDCService(const string& st)
39
bool RenderingControl::isRDCService(const string& st)
35
{
40
{
36
    const string::size_type sz(SType.size()-2);
41
    const string::size_type sz(SType.size()-2);
37
    return !SType.compare(0, sz, st, 0, sz);
42
    return !SType.compare(0, sz, st, 0, sz);
38
}
43
}
39
44
45
void RenderingControl::evtCallback(
46
    const std::unordered_map<std::string, std::string>& props)
47
{
48
    //LOGDEB("RenderingControl::evtCallback:" << endl);
49
    for (auto& entry: props) {
50
        if (!entry.first.compare("LastChange")) {
51
            std::unordered_map<std::string, std::string> props1;
52
            if (!decodeAVLastChange(entry.second, props1)) {
53
                LOGERR("RenderingControl::evtCallback: bad LastChange value: "
54
                       << entry.second << endl);
55
                return;
56
            }
57
            for (auto& entry1: props1) {
58
                //LOGDEB("    " << entry1.first << " -> " << 
59
                //       entry1.second << endl);
60
                if (!entry1.first.compare("Volume")) {
61
                    m_volume = atoi(entry1.second.c_str());
62
                } else if (!entry1.first.compare("Mute")) {
63
                    stringToBool(entry1.second, &m_mute);
64
                }
65
            }
66
        } else {
67
            LOGINF("RenderingControl:event: var not lastchange: "
68
                   << entry.first << " -> " << entry.second << endl;);
69
        }
70
    }
71
    LOGDEB("RenderingControl::evtCallback: m_volume " << m_volume << 
72
           " m_mute " << m_mute << endl);
73
}
40
74
75
void RenderingControl::registerCallback()
76
{
77
    Service::registerCallback(bind(&RenderingControl::evtCallback, this, _1));
78
}
41
79
42
int RenderingControl::setVolume(int volume, const string& channel)
80
int RenderingControl::setVolume(int volume, const string& channel)
43
{
81
{
44
    SoapEncodeInput args(m_serviceType, "SetVolume");
82
    SoapEncodeInput args(m_serviceType, "SetVolume");
45
    args("Channel", channel)("DesiredVolume", SoapEncodeInput::i2s(volume));
83
    args("Channel", channel)("DesiredVolume", SoapHelp::i2s(volume));
46
    SoapDecodeOutput data;
84
    SoapDecodeOutput data;
47
    int ret = runAction(args, data);
85
    int ret = runAction(args, data);
48
    if (ret != UPNP_E_SUCCESS) {
86
    if (ret != UPNP_E_SUCCESS) {
49
        return ret;
87
        return ret;
50
    }
88
    }
...
...
66
        << endl);
104
        << endl);
67
        return UPNP_E_BAD_RESPONSE;
105
        return UPNP_E_BAD_RESPONSE;
68
    }
106
    }
69
    return volume;
107
    return volume;
70
}
108
}
109
int RenderingControl::setMute(bool mute, const string& channel)
110
{
111
    SoapEncodeInput args(m_serviceType, "SetMute");
112
    args("Channel", channel)("DesiredMute", SoapHelp::i2s(mute?1:0));
113
    SoapDecodeOutput data;
114
    int ret = runAction(args, data);
115
    if (ret != UPNP_E_SUCCESS) {
116
        return ret;
117
    }
118
    return 0;
119
}
71
120
72
121
bool RenderingControl::getMute(const string& channel)
73
122
{
74
123
    SoapEncodeInput args(m_serviceType, "GetMute");
75
124
    args("Channel", channel);
76
125
    SoapDecodeOutput data;
77
126
    int ret = runAction(args, data);
78
127
    if (ret != UPNP_E_SUCCESS) {
79
128
        return ret;
129
    }
130
    bool mute;
131
    if (!data.getBool("CurrentMute", &mute)) {
132
        LOGERR("RenderingControl:getMute: missing CurrentMute in response" 
133
        << endl);
134
        return UPNP_E_BAD_RESPONSE;
135
    }
136
    return mute;
137
}
80
138
81
} // End namespace UPnPClient
139
} // End namespace UPnPClient
82
140