2
* Copyright (C) 2011 Tuomo Penttinen, all rights reserved.
4
* Author: Tuomo Penttinen <tp@herqq.org>
6
* This file is part of Herqq UPnP Av (HUPnPAv) library.
8
* Herqq UPnP Av is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation, either version 3 of the License, or
11
* (at your option) any later version.
13
* Herqq UPnP Av is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with Herqq UPnP Av. If not, see <http://www.gnu.org/licenses/>.
22
#include "hconnectionmanager_adapter.h"
23
#include "hconnectionmanager_adapter_p.h"
25
#include "hconnectioninfo.h"
26
#include "hprotocolinforesult.h"
27
#include "hconnectionmanager_id.h"
28
#include "hprepareforconnection_result.h"
30
#include "../common/hprotocolinfo.h"
31
#include "../hav_devicemodel_infoprovider.h"
33
#include <HUpnpCore/private/hlogger_p.h>
35
#include <HUpnpCore/HActionInfo>
36
#include <HUpnpCore/HClientAction>
37
#include <HUpnpCore/HClientService>
38
#include <HUpnpCore/HClientActionOp>
39
#include <HUpnpCore/HActionArguments>
40
#include <HUpnpCore/HClientAdapterOp>
41
#include <HUpnpCore/HStateVariableEvent>
42
#include <HUpnpCore/HClientStateVariable>
55
HProtocolInfos parse(const QString& protocolInfos)
57
HProtocolInfos retVal;
58
QStringList sourceCsv = protocolInfos.split(',');
59
foreach(const QString& str, sourceCsv)
61
HProtocolInfo pi = str;
70
QList<quint32> parseIDs(const QString& ids)
72
QList<quint32> retVal;
73
QStringList idsCsv = ids.split(",");
74
foreach(const QString& str, idsCsv)
77
quint32 id = str.toUInt(&ok);
87
/*******************************************************************************
88
* HConnectionManagerAdapterPrivate
89
******************************************************************************/
90
HConnectionManagerAdapterPrivate::HConnectionManagerAdapterPrivate() :
91
HClientServiceAdapterPrivate(HConnectionManagerInfo::supportedServiceType()),
96
HConnectionManagerAdapterPrivate::~HConnectionManagerAdapterPrivate()
100
bool HConnectionManagerAdapterPrivate::getProtocolInfo(
101
HClientAction*, const HClientActionOp& op)
103
H_Q(HConnectionManagerAdapter);
105
QList<HProtocolInfo> source, sink;
106
if (op.returnValue() == UpnpSuccess)
108
HActionArguments outArgs = op.outputArguments();
110
QString sourceStr = outArgs.value("Source").toString();
111
QString sinkStr = outArgs.value("Sink").toString();
113
source = parse(sourceStr);
114
sink = parse(sinkStr);
117
HProtocolInfoResult result(source, sink);
118
emit q->getProtocolInfoCompleted(q, takeOp(op, result));
123
bool HConnectionManagerAdapterPrivate::prepareForConnection(
124
HClientAction*, const HClientActionOp& op)
126
H_Q(HConnectionManagerAdapter);
128
HPrepareForConnectionResult result;
129
if (op.returnValue() == UpnpSuccess)
131
HActionArguments outArgs = op.outputArguments();
133
qint32 connectionId = outArgs.value("ConnectionID").toInt();
134
qint32 avTransportId = outArgs.value("AVTransportID").toInt();
135
qint32 rcsId = outArgs.value("RcsID").toInt();
137
result.setConnectionId(connectionId);
138
result.setAvTransportId(avTransportId);
139
result.setRcsId(rcsId);
141
emit q->prepareForConnectionCompleted(q, takeOp(op, result));
146
bool HConnectionManagerAdapterPrivate::connectionComplete(
147
HClientAction*, const HClientActionOp& op)
149
H_Q(HConnectionManagerAdapter);
150
emit q->connectionCompleteCompleted(q, takeOp(op));
154
bool HConnectionManagerAdapterPrivate::getCurrentConnectionIDs(
155
HClientAction*, const HClientActionOp& op)
157
H_Q(HConnectionManagerAdapter);
159
QList<quint32> connectionIds;
160
if (op.returnValue() == UpnpSuccess)
162
connectionIds = parseIDs(op.outputArguments().value("ConnectionIDs").toString());
164
emit q->getCurrentConnectionIDsCompleted(q, takeOp(op, connectionIds));
169
bool HConnectionManagerAdapterPrivate::getCurrentConnectionInfo(
170
HClientAction*, const HClientActionOp& op)
173
H_Q(HConnectionManagerAdapter);
175
HConnectionInfo connectionInfo;
176
if (op.returnValue() == UpnpSuccess)
178
HActionArguments outArgs = op.outputArguments();
180
qint32 rcsId = outArgs.value("RcsID").toInt();
181
qint32 avTransportId = outArgs.value("AVTransportID").toInt();
182
QString protocolInfo = outArgs.value("ProtocolInfo").toString();
183
QString peerCm = outArgs.value("PeerConnectionManager").toString();
184
qint32 peerCid = outArgs.value("PeerConnectionID").toInt();
185
QString dirStr = outArgs.value("Direction").toString();
186
QString statusStr = outArgs.value("Status").toString();
188
qint32 connectionId = m_connectionIds.value(op.id());
190
HProtocolInfo pinfo(protocolInfo);
191
if (!pinfo.isValid())
194
"Received invalid ProtocolInfo information. Assuming all fields were "
195
"meant to be wild-cards");
196
pinfo = HProtocolInfo::createUsingWildcards();
205
HConnectionManagerId(peerCm),
207
HConnectionManagerInfo::directionFromString(dirStr),
208
HConnectionManagerInfo::statusFromString(statusStr));
210
emit q->getCurrentConnectionInfoCompleted(
211
q, takeOp(op, connectionInfo));
216
/*******************************************************************************
217
* HConnectionManagerAdapter
218
******************************************************************************/
219
HConnectionManagerAdapter::HConnectionManagerAdapter(QObject* parent) :
220
HClientServiceAdapter(*new HConnectionManagerAdapterPrivate(), parent)
222
HAvDeviceModelInfoProvider infoProvider;
223
setDeviceModelInfoProvider(infoProvider);
226
HConnectionManagerAdapter::~HConnectionManagerAdapter()
230
void HConnectionManagerAdapter::sourceProtocolInfoChanged_(
231
const HClientStateVariable* source, const HStateVariableEvent& event)
234
emit sourceProtocolInfoChanged(this, parse(event.newValue().toString()));
237
void HConnectionManagerAdapter::sinkProtocolInfoChanged_(
238
const HClientStateVariable* source, const HStateVariableEvent& event)
241
emit sinkProtocolInfoChanged(this, parse(event.newValue().toString()));
244
void HConnectionManagerAdapter::currentConnectionIDsChanged_(
245
const HClientStateVariable* source, const HStateVariableEvent& event)
248
emit currentConnectionIdsChanged(this, parseIDs(event.newValue().toString()));
251
bool HConnectionManagerAdapter::prepareService(HClientService* service)
253
const HClientStateVariable* source =
254
service->stateVariables().value("SourceProtocolInfo");
259
const Herqq::Upnp::HClientStateVariable*,
260
Herqq::Upnp::HStateVariableEvent)),
262
SLOT(sourceProtocolInfoChanged_(
263
const Herqq::Upnp::HClientStateVariable*,
264
Herqq::Upnp::HStateVariableEvent)));
265
Q_ASSERT(ok); Q_UNUSED(ok)
267
const HClientStateVariable* sink =
268
service->stateVariables().value("SinkProtocolInfo");
273
const Herqq::Upnp::HClientStateVariable*,
274
Herqq::Upnp::HStateVariableEvent)),
276
SLOT(sinkProtocolInfoChanged_(
277
const Herqq::Upnp::HClientStateVariable*,
278
Herqq::Upnp::HStateVariableEvent)));
281
const HClientStateVariable* cids =
282
service->stateVariables().value("CurrentConnectionIDs");
287
const Herqq::Upnp::HClientStateVariable*,
288
Herqq::Upnp::HStateVariableEvent)),
290
SLOT(currentConnectionIDsChanged_(
291
const Herqq::Upnp::HClientStateVariable*,
292
Herqq::Upnp::HStateVariableEvent)));
298
HClientAdapterOp<HProtocolInfoResult> HConnectionManagerAdapter::getProtocolInfo()
300
H_D(HConnectionManagerAdapter);
302
qint32 rc = UpnpUndefinedFailure;
303
HClientAction* action = h_ptr->getAction("GetProtocolInfo", &rc);
306
return HClientAdapterOp<HProtocolInfoResult>::createInvalid(rc, "");
309
HActionArguments inArgs = action->info().inputArguments();
310
return h_ptr->beginInvoke<HProtocolInfoResult>(
312
HActionInvokeCallback(h, &HConnectionManagerAdapterPrivate::getProtocolInfo));
315
HClientAdapterOp<QList<quint32> > HConnectionManagerAdapter::getCurrentConnectionIDs()
317
H_D(HConnectionManagerAdapter);
319
qint32 rc = UpnpUndefinedFailure;
320
HClientAction* action = h_ptr->getAction("GetCurrentConnectionIDs", &rc);
323
return HClientAdapterOp<QList<quint32> >::createInvalid(rc, "");
326
HActionArguments inArgs = action->info().inputArguments();
327
return h_ptr->beginInvoke<QList<quint32> >(
329
HActionInvokeCallback(h, &HConnectionManagerAdapterPrivate::getCurrentConnectionIDs));
332
HClientAdapterOp<HConnectionInfo>
333
HConnectionManagerAdapter::getCurrentConnectionInfo(qint32 connectionId)
335
H_D(HConnectionManagerAdapter);
337
qint32 rc = UpnpUndefinedFailure;
338
HClientAction* action = h_ptr->getAction("GetCurrentConnectionInfo", &rc);
341
return HClientAdapterOp<HConnectionInfo>::createInvalid(rc, "");
344
HActionArguments inArgs = action->info().inputArguments();
345
inArgs.setValue("ConnectionID", QString::number(connectionId));
347
HClientActionOp op = action->beginInvoke(inArgs,
348
HActionInvokeCallback(h, &HConnectionManagerAdapterPrivate::getCurrentConnectionInfo));
350
h->m_connectionIds.insert(op.id(), connectionId);
352
return h_ptr->addOp<HConnectionInfo>(op);
355
HClientAdapterOp<HPrepareForConnectionResult> HConnectionManagerAdapter::prepareForConnection(
356
const HProtocolInfo& remoteProtocolInfo,
357
const HConnectionManagerId& peerConnectionManager,
358
qint32 peerConnectionId,
359
HConnectionManagerInfo::Direction direction)
361
H_D(HConnectionManagerAdapter);
363
qint32 rc = UpnpUndefinedFailure;
364
HClientAction* action = h_ptr->getAction("PrepareForConnection", &rc);
367
return HClientAdapterOp<HPrepareForConnectionResult>::createInvalid(rc, "");
370
HActionArguments inArgs = action->info().inputArguments();
371
if (!inArgs.setValue("RemoteProtocolInfo", remoteProtocolInfo.toString()))
373
return HClientAdapterOp<HPrepareForConnectionResult>::createInvalid(UpnpInvalidArgs, "");
375
if (!inArgs.setValue("PeerConnectionManager", peerConnectionManager.toString()))
377
return HClientAdapterOp<HPrepareForConnectionResult>::createInvalid(UpnpInvalidArgs, "");
379
if (!inArgs.setValue("PeerConnectionID", QString::number(peerConnectionId)))
381
return HClientAdapterOp<HPrepareForConnectionResult>::createInvalid(UpnpInvalidArgs, "");
383
if (!inArgs.setValue("Direction", HConnectionManagerInfo::directionToString(direction)))
385
return HClientAdapterOp<HPrepareForConnectionResult>::createInvalid(UpnpInvalidArgs, "");
388
return h_ptr->beginInvoke<HPrepareForConnectionResult>(
390
HActionInvokeCallback(h, &HConnectionManagerAdapterPrivate::prepareForConnection));
393
HClientAdapterOpNull HConnectionManagerAdapter::connectionComplete(qint32 connectionId)
395
H_D(HConnectionManagerAdapter);
397
qint32 rc = UpnpUndefinedFailure;
398
HClientAction* action = h_ptr->getAction("ConnectionComplete", &rc);
401
return HClientAdapterOpNull::createInvalid(rc, "");
404
HActionArguments inArgs = action->info().inputArguments();
405
inArgs.setValue("ConnectionID", QString::number(connectionId));
407
return h_ptr->beginInvoke(
409
HActionInvokeCallback(h, &HConnectionManagerAdapterPrivate::connectionComplete));