Switch to unified view

a b/upmpd/conman.cxx
1
/* Copyright (C) 2014 J.F.Dockes
2
 *     This program is free software; you can redistribute it and/or modify
3
 *     it under the terms of the GNU General Public License as published by
4
 *     the Free Software Foundation; either version 2 of the License, or
5
 *     (at your option) any later version.
6
 *
7
 *     This program is distributed in the hope that it will be useful,
8
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *     GNU General Public License for more details.
11
 *
12
 *     You should have received a copy of the GNU General Public License
13
 *     along with this program; if not, write to the
14
 *     Free Software Foundation, Inc.,
15
 *     59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
17
18
#include <stdio.h>
19
#include <stdlib.h>
20
#include <unistd.h>
21
#include <sys/types.h>
22
#include <pwd.h>
23
24
#include <string>
25
#include <iostream>
26
#include <sstream>
27
#include <vector>
28
#include <functional>
29
#include <set>
30
using namespace std;
31
using namespace std::placeholders;
32
33
#include "libupnpp/upnpplib.hxx"
34
#include "libupnpp/soaphelp.hxx"
35
#include "libupnpp/device.hxx"
36
#include "libupnpp/log.hxx"
37
38
#include "upmpd.hxx"
39
#include "conman.hxx"
40
#include "mpdcli.hxx"
41
#include "upmpdutils.hxx"
42
43
static const string serviceIdCM("urn:upnp-org:serviceId:ConnectionManager");
44
45
UpMpdConMan::UpMpdConMan(UpMpd *dev)
46
    : UpnpService(dev)
47
{
48
    dev->addService(this, serviceIdCM);
49
    dev->addActionMapping("GetCurrentConnectionIDs", 
50
                          bind(&UpMpdConMan::getCurrentConnectionIDs, 
51
                               this, _1,_2));
52
    dev->addActionMapping("GetCurrentConnectionInfo", 
53
                          bind(&UpMpdConMan::getCurrentConnectionInfo, 
54
                               this,_1,_2));
55
    dev->addActionMapping("GetProtocolInfo", 
56
                          bind(&UpMpdConMan::getProtocolInfo, this, _1, _2));
57
}
58
59
const std::string& UpMpdConMan::getServiceType()
60
{
61
    return serviceIdCM;
62
}
63
64
// "http-get:*:audio/mpeg:DLNA.ORG_PN=MP3,"
65
// "http-get:*:audio/L16:DLNA.ORG_PN=LPCM,"
66
// "http-get:*:audio/x-flac:DLNA.ORG_PN=FLAC"
67
static const string 
68
myProtocolInfo(
69
    "http-get:*:audio/wav:*,"
70
    "http-get:*:audio/wave:*,"
71
    "http-get:*:audio/x-wav:*,"
72
    "http-get:*:audio/x-aiff:*,"
73
    "http-get:*:audio/mpeg:*,"
74
    "http-get:*:audio/x-mpeg:*,"
75
    "http-get:*:audio/mp1:*,"
76
    "http-get:*:audio/aac:*,"
77
    "http-get:*:audio/flac:*,"
78
    "http-get:*:audio/x-flac:*,"
79
    "http-get:*:audio/m4a:*,"
80
    "http-get:*:audio/mp4:*,"
81
    "http-get:*:audio/x-m4a:*,"
82
    "http-get:*:audio/vorbis:*,"
83
    "http-get:*:audio/ogg:*,"
84
    "http-get:*:audio/x-ogg:*,"
85
    "http-get:*:audio/x-scpls:*,"
86
    "http-get:*:audio/L16;rate=11025;channels=1:*,"
87
    "http-get:*:audio/L16;rate=22050;channels=1:*,"
88
    "http-get:*:audio/L16;rate=44100;channels=1:*,"
89
    "http-get:*:audio/L16;rate=48000;channels=1:*,"
90
    "http-get:*:audio/L16;rate=88200;channels=1:*,"
91
    "http-get:*:audio/L16;rate=96000;channels=1:*,"
92
    "http-get:*:audio/L16;rate=176400;channels=1:*,"
93
    "http-get:*:audio/L16;rate=192000;channels=1:*,"
94
    "http-get:*:audio/L16;rate=11025;channels=2:*,"
95
    "http-get:*:audio/L16;rate=22050;channels=2:*,"
96
    "http-get:*:audio/L16;rate=44100;channels=2:*,"
97
    "http-get:*:audio/L16;rate=48000;channels=2:*,"
98
    "http-get:*:audio/L16;rate=88200;channels=2:*,"
99
    "http-get:*:audio/L16;rate=96000;channels=2:*,"
100
    "http-get:*:audio/L16;rate=176400;channels=2:*,"
101
    "http-get:*:audio/L16;rate=192000;channels=2:*"
102
    );
103
104
bool UpMpdConMan::getEventData(bool all, std::vector<std::string>& names, 
105
                                 std::vector<std::string>& values)
106
{
107
    //LOGDEB("UpMpd:getEventDataCM" << endl);
108
109
    // Our data never changes, so if this is not an unconditional request,
110
    // we return nothing.
111
    if (all) {
112
        names.push_back("SinkProtocolInfo");
113
        values.push_back(myProtocolInfo);
114
    }
115
    return true;
116
}
117
118
int UpMpdConMan::getCurrentConnectionIDs(const SoapArgs& sc, SoapData& data)
119
{
120
    LOGDEB("UpMpd:getCurrentConnectionIDs" << endl);
121
    data.addarg("ConnectionIDs", "0");
122
    return UPNP_E_SUCCESS;
123
}
124
125
int UpMpdConMan::getCurrentConnectionInfo(const SoapArgs& sc, SoapData& data)
126
{
127
    LOGDEB("UpMpdConMan:getCurrentConnectionInfo" << endl);
128
    map<string, string>::const_iterator it;
129
    it = sc.args.find("ConnectionID");
130
    if (it == sc.args.end() || it->second.empty()) {
131
        return UPNP_E_INVALID_PARAM;
132
    }
133
    if (it->second.compare("0")) {
134
        return UPNP_E_INVALID_PARAM;
135
    }
136
137
    data.addarg("RcsID", "0");
138
    data.addarg("AVTransportID", "0");
139
    data.addarg("ProtocolInfo", "");
140
    data.addarg("PeerConnectionManager", "");
141
    data.addarg("PeerConnectionID", "-1");
142
    data.addarg("Direction", "Input");
143
    data.addarg("Status", "Unknown");
144
145
    return UPNP_E_SUCCESS;
146
}
147
148
int UpMpdConMan::getProtocolInfo(const SoapArgs& sc, SoapData& data)
149
{
150
    LOGDEB("UpMpdConMan::getProtocolInfo" << endl);
151
    data.addarg("Source", "");
152
    data.addarg("Sink", myProtocolInfo);
153
154
    return UPNP_E_SUCCESS;
155
}