~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to extra/kipi-plugins/dlnaexport/extra/hupnp_av/src/connectionmanager/hconnectionmanager_adapter.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2011 Tuomo Penttinen, all rights reserved.
 
3
 *
 
4
 *  Author: Tuomo Penttinen <tp@herqq.org>
 
5
 *
 
6
 *  This file is part of Herqq UPnP Av (HUPnPAv) library.
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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/>.
 
20
 */
 
21
 
 
22
#include "hconnectionmanager_adapter.h"
 
23
#include "hconnectionmanager_adapter_p.h"
 
24
 
 
25
#include "hconnectioninfo.h"
 
26
#include "hprotocolinforesult.h"
 
27
#include "hconnectionmanager_id.h"
 
28
#include "hprepareforconnection_result.h"
 
29
 
 
30
#include "../common/hprotocolinfo.h"
 
31
#include "../hav_devicemodel_infoprovider.h"
 
32
 
 
33
#include <HUpnpCore/private/hlogger_p.h>
 
34
 
 
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>
 
43
 
 
44
namespace Herqq
 
45
{
 
46
 
 
47
namespace Upnp
 
48
{
 
49
 
 
50
namespace Av
 
51
{
 
52
 
 
53
namespace
 
54
{
 
55
HProtocolInfos parse(const QString& protocolInfos)
 
56
{
 
57
    HProtocolInfos retVal;
 
58
    QStringList sourceCsv = protocolInfos.split(',');
 
59
    foreach(const QString& str, sourceCsv)
 
60
    {
 
61
        HProtocolInfo pi = str;
 
62
        if (!pi.isEmpty())
 
63
        {
 
64
            retVal.append(pi);
 
65
        }
 
66
    }
 
67
    return retVal;
 
68
}
 
69
 
 
70
QList<quint32> parseIDs(const QString& ids)
 
71
{
 
72
    QList<quint32> retVal;
 
73
    QStringList idsCsv = ids.split(",");
 
74
    foreach(const QString& str, idsCsv)
 
75
    {
 
76
        bool ok = false;
 
77
        quint32 id = str.toUInt(&ok);
 
78
        if (ok)
 
79
        {
 
80
            retVal.append(id);
 
81
        }
 
82
    }
 
83
    return retVal;
 
84
}
 
85
}
 
86
 
 
87
/*******************************************************************************
 
88
 * HConnectionManagerAdapterPrivate
 
89
 ******************************************************************************/
 
90
HConnectionManagerAdapterPrivate::HConnectionManagerAdapterPrivate() :
 
91
    HClientServiceAdapterPrivate(HConnectionManagerInfo::supportedServiceType()),
 
92
        m_connectionIds()
 
93
{
 
94
}
 
95
 
 
96
HConnectionManagerAdapterPrivate::~HConnectionManagerAdapterPrivate()
 
97
{
 
98
}
 
99
 
 
100
bool HConnectionManagerAdapterPrivate::getProtocolInfo(
 
101
    HClientAction*, const HClientActionOp& op)
 
102
{
 
103
    H_Q(HConnectionManagerAdapter);
 
104
 
 
105
    QList<HProtocolInfo> source, sink;
 
106
    if (op.returnValue() == UpnpSuccess)
 
107
    {
 
108
        HActionArguments outArgs = op.outputArguments();
 
109
 
 
110
        QString sourceStr = outArgs.value("Source").toString();
 
111
        QString sinkStr   = outArgs.value("Sink").toString();
 
112
 
 
113
        source = parse(sourceStr);
 
114
        sink = parse(sinkStr);
 
115
    }
 
116
 
 
117
    HProtocolInfoResult result(source, sink);
 
118
    emit q->getProtocolInfoCompleted(q, takeOp(op, result));
 
119
 
 
120
    return false;
 
121
}
 
122
 
 
123
bool HConnectionManagerAdapterPrivate::prepareForConnection(
 
124
    HClientAction*, const HClientActionOp& op)
 
125
{
 
126
    H_Q(HConnectionManagerAdapter);
 
127
 
 
128
    HPrepareForConnectionResult result;
 
129
    if (op.returnValue() == UpnpSuccess)
 
130
    {
 
131
        HActionArguments outArgs = op.outputArguments();
 
132
 
 
133
        qint32 connectionId = outArgs.value("ConnectionID").toInt();
 
134
        qint32 avTransportId = outArgs.value("AVTransportID").toInt();
 
135
        qint32 rcsId = outArgs.value("RcsID").toInt();
 
136
 
 
137
        result.setConnectionId(connectionId);
 
138
        result.setAvTransportId(avTransportId);
 
139
        result.setRcsId(rcsId);
 
140
    }
 
141
    emit q->prepareForConnectionCompleted(q, takeOp(op, result));
 
142
 
 
143
    return false;
 
144
}
 
145
 
 
146
bool HConnectionManagerAdapterPrivate::connectionComplete(
 
147
    HClientAction*, const HClientActionOp& op)
 
148
{
 
149
    H_Q(HConnectionManagerAdapter);
 
150
    emit q->connectionCompleteCompleted(q, takeOp(op));
 
151
    return false;
 
152
}
 
153
 
 
154
bool HConnectionManagerAdapterPrivate::getCurrentConnectionIDs(
 
155
    HClientAction*, const HClientActionOp& op)
 
156
{
 
157
    H_Q(HConnectionManagerAdapter);
 
158
 
 
159
    QList<quint32> connectionIds;
 
160
    if (op.returnValue() == UpnpSuccess)
 
161
    {
 
162
        connectionIds = parseIDs(op.outputArguments().value("ConnectionIDs").toString());
 
163
    }
 
164
    emit q->getCurrentConnectionIDsCompleted(q, takeOp(op, connectionIds));
 
165
 
 
166
    return false;
 
167
}
 
168
 
 
169
bool HConnectionManagerAdapterPrivate::getCurrentConnectionInfo(
 
170
    HClientAction*, const HClientActionOp& op)
 
171
{
 
172
    HLOG(H_AT, H_FUN);
 
173
    H_Q(HConnectionManagerAdapter);
 
174
 
 
175
    HConnectionInfo connectionInfo;
 
176
    if (op.returnValue() == UpnpSuccess)
 
177
    {
 
178
        HActionArguments outArgs = op.outputArguments();
 
179
 
 
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();
 
187
 
 
188
        qint32 connectionId = m_connectionIds.value(op.id());
 
189
 
 
190
        HProtocolInfo pinfo(protocolInfo);
 
191
        if (!pinfo.isValid())
 
192
        {
 
193
            HLOG_WARN_NONSTD(
 
194
                "Received invalid ProtocolInfo information. Assuming all fields were "
 
195
                "meant to be wild-cards");
 
196
            pinfo = HProtocolInfo::createUsingWildcards();
 
197
        }
 
198
 
 
199
        connectionInfo =
 
200
            HConnectionInfo(
 
201
                connectionId,
 
202
                rcsId,
 
203
                avTransportId,
 
204
                pinfo,
 
205
                HConnectionManagerId(peerCm),
 
206
                peerCid,
 
207
                HConnectionManagerInfo::directionFromString(dirStr),
 
208
                HConnectionManagerInfo::statusFromString(statusStr));
 
209
    }
 
210
    emit q->getCurrentConnectionInfoCompleted(
 
211
        q, takeOp(op, connectionInfo));
 
212
 
 
213
    return false;
 
214
}
 
215
 
 
216
/*******************************************************************************
 
217
 * HConnectionManagerAdapter
 
218
 ******************************************************************************/
 
219
HConnectionManagerAdapter::HConnectionManagerAdapter(QObject* parent) :
 
220
    HClientServiceAdapter(*new HConnectionManagerAdapterPrivate(), parent)
 
221
{
 
222
    HAvDeviceModelInfoProvider infoProvider;
 
223
    setDeviceModelInfoProvider(infoProvider);
 
224
}
 
225
 
 
226
HConnectionManagerAdapter::~HConnectionManagerAdapter()
 
227
{
 
228
}
 
229
 
 
230
void HConnectionManagerAdapter::sourceProtocolInfoChanged_(
 
231
    const HClientStateVariable* source, const HStateVariableEvent& event)
 
232
{
 
233
    Q_UNUSED(source)
 
234
    emit sourceProtocolInfoChanged(this, parse(event.newValue().toString()));
 
235
}
 
236
 
 
237
void HConnectionManagerAdapter::sinkProtocolInfoChanged_(
 
238
    const HClientStateVariable* source, const HStateVariableEvent& event)
 
239
{
 
240
    Q_UNUSED(source)
 
241
    emit sinkProtocolInfoChanged(this, parse(event.newValue().toString()));
 
242
}
 
243
 
 
244
void HConnectionManagerAdapter::currentConnectionIDsChanged_(
 
245
    const HClientStateVariable* source, const HStateVariableEvent& event)
 
246
{
 
247
    Q_UNUSED(source)
 
248
    emit currentConnectionIdsChanged(this, parseIDs(event.newValue().toString()));
 
249
}
 
250
 
 
251
bool HConnectionManagerAdapter::prepareService(HClientService* service)
 
252
{
 
253
    const HClientStateVariable* source =
 
254
        service->stateVariables().value("SourceProtocolInfo");
 
255
 
 
256
    bool ok = connect(
 
257
        source,
 
258
        SIGNAL(valueChanged(
 
259
            const Herqq::Upnp::HClientStateVariable*,
 
260
            Herqq::Upnp::HStateVariableEvent)),
 
261
        this,
 
262
        SLOT(sourceProtocolInfoChanged_(
 
263
            const Herqq::Upnp::HClientStateVariable*,
 
264
            Herqq::Upnp::HStateVariableEvent)));
 
265
    Q_ASSERT(ok); Q_UNUSED(ok)
 
266
 
 
267
    const HClientStateVariable* sink =
 
268
        service->stateVariables().value("SinkProtocolInfo");
 
269
 
 
270
    ok = connect(
 
271
        sink,
 
272
        SIGNAL(valueChanged(
 
273
            const Herqq::Upnp::HClientStateVariable*,
 
274
            Herqq::Upnp::HStateVariableEvent)),
 
275
        this,
 
276
        SLOT(sinkProtocolInfoChanged_(
 
277
            const Herqq::Upnp::HClientStateVariable*,
 
278
            Herqq::Upnp::HStateVariableEvent)));
 
279
    Q_ASSERT(ok);
 
280
 
 
281
    const HClientStateVariable* cids =
 
282
        service->stateVariables().value("CurrentConnectionIDs");
 
283
 
 
284
    ok = connect(
 
285
        cids,
 
286
        SIGNAL(valueChanged(
 
287
            const Herqq::Upnp::HClientStateVariable*,
 
288
            Herqq::Upnp::HStateVariableEvent)),
 
289
        this,
 
290
        SLOT(currentConnectionIDsChanged_(
 
291
            const Herqq::Upnp::HClientStateVariable*,
 
292
            Herqq::Upnp::HStateVariableEvent)));
 
293
    Q_ASSERT(ok);
 
294
 
 
295
    return true;
 
296
}
 
297
 
 
298
HClientAdapterOp<HProtocolInfoResult> HConnectionManagerAdapter::getProtocolInfo()
 
299
{
 
300
    H_D(HConnectionManagerAdapter);
 
301
 
 
302
    qint32 rc = UpnpUndefinedFailure;
 
303
    HClientAction* action = h_ptr->getAction("GetProtocolInfo", &rc);
 
304
    if (!action)
 
305
    {
 
306
        return HClientAdapterOp<HProtocolInfoResult>::createInvalid(rc, "");
 
307
    }
 
308
 
 
309
    HActionArguments inArgs = action->info().inputArguments();
 
310
    return h_ptr->beginInvoke<HProtocolInfoResult>(
 
311
        action, inArgs,
 
312
        HActionInvokeCallback(h, &HConnectionManagerAdapterPrivate::getProtocolInfo));
 
313
}
 
314
 
 
315
HClientAdapterOp<QList<quint32> > HConnectionManagerAdapter::getCurrentConnectionIDs()
 
316
{
 
317
    H_D(HConnectionManagerAdapter);
 
318
 
 
319
    qint32 rc = UpnpUndefinedFailure;
 
320
    HClientAction* action = h_ptr->getAction("GetCurrentConnectionIDs", &rc);
 
321
    if (!action)
 
322
    {
 
323
        return HClientAdapterOp<QList<quint32> >::createInvalid(rc, "");
 
324
    }
 
325
 
 
326
    HActionArguments inArgs = action->info().inputArguments();
 
327
    return h_ptr->beginInvoke<QList<quint32> >(
 
328
        action, inArgs,
 
329
        HActionInvokeCallback(h, &HConnectionManagerAdapterPrivate::getCurrentConnectionIDs));
 
330
}
 
331
 
 
332
HClientAdapterOp<HConnectionInfo>
 
333
    HConnectionManagerAdapter::getCurrentConnectionInfo(qint32 connectionId)
 
334
{
 
335
    H_D(HConnectionManagerAdapter);
 
336
 
 
337
    qint32 rc = UpnpUndefinedFailure;
 
338
    HClientAction* action = h_ptr->getAction("GetCurrentConnectionInfo", &rc);
 
339
    if (!action)
 
340
    {
 
341
        return HClientAdapterOp<HConnectionInfo>::createInvalid(rc, "");
 
342
    }
 
343
 
 
344
    HActionArguments inArgs = action->info().inputArguments();
 
345
    inArgs.setValue("ConnectionID", QString::number(connectionId));
 
346
 
 
347
    HClientActionOp op = action->beginInvoke(inArgs,
 
348
        HActionInvokeCallback(h, &HConnectionManagerAdapterPrivate::getCurrentConnectionInfo));
 
349
 
 
350
    h->m_connectionIds.insert(op.id(), connectionId);
 
351
 
 
352
    return h_ptr->addOp<HConnectionInfo>(op);
 
353
}
 
354
 
 
355
HClientAdapterOp<HPrepareForConnectionResult> HConnectionManagerAdapter::prepareForConnection(
 
356
    const HProtocolInfo& remoteProtocolInfo,
 
357
    const HConnectionManagerId& peerConnectionManager,
 
358
    qint32 peerConnectionId,
 
359
    HConnectionManagerInfo::Direction direction)
 
360
{
 
361
    H_D(HConnectionManagerAdapter);
 
362
 
 
363
    qint32 rc = UpnpUndefinedFailure;
 
364
    HClientAction* action = h_ptr->getAction("PrepareForConnection", &rc);
 
365
    if (!action)
 
366
    {
 
367
        return HClientAdapterOp<HPrepareForConnectionResult>::createInvalid(rc, "");
 
368
    }
 
369
 
 
370
    HActionArguments inArgs = action->info().inputArguments();
 
371
    if (!inArgs.setValue("RemoteProtocolInfo", remoteProtocolInfo.toString()))
 
372
    {
 
373
        return HClientAdapterOp<HPrepareForConnectionResult>::createInvalid(UpnpInvalidArgs, "");
 
374
    }
 
375
    if (!inArgs.setValue("PeerConnectionManager", peerConnectionManager.toString()))
 
376
    {
 
377
        return HClientAdapterOp<HPrepareForConnectionResult>::createInvalid(UpnpInvalidArgs, "");
 
378
    }
 
379
    if (!inArgs.setValue("PeerConnectionID", QString::number(peerConnectionId)))
 
380
    {
 
381
        return HClientAdapterOp<HPrepareForConnectionResult>::createInvalid(UpnpInvalidArgs, "");
 
382
    }
 
383
    if (!inArgs.setValue("Direction", HConnectionManagerInfo::directionToString(direction)))
 
384
    {
 
385
        return HClientAdapterOp<HPrepareForConnectionResult>::createInvalid(UpnpInvalidArgs, "");
 
386
    }
 
387
 
 
388
    return h_ptr->beginInvoke<HPrepareForConnectionResult>(
 
389
        action, inArgs,
 
390
        HActionInvokeCallback(h, &HConnectionManagerAdapterPrivate::prepareForConnection));
 
391
}
 
392
 
 
393
HClientAdapterOpNull HConnectionManagerAdapter::connectionComplete(qint32 connectionId)
 
394
{
 
395
    H_D(HConnectionManagerAdapter);
 
396
 
 
397
    qint32 rc = UpnpUndefinedFailure;
 
398
    HClientAction* action = h_ptr->getAction("ConnectionComplete", &rc);
 
399
    if (!action)
 
400
    {
 
401
        return HClientAdapterOpNull::createInvalid(rc, "");
 
402
    }
 
403
 
 
404
    HActionArguments inArgs = action->info().inputArguments();
 
405
    inArgs.setValue("ConnectionID", QString::number(connectionId));
 
406
 
 
407
    return h_ptr->beginInvoke(
 
408
        action, inArgs,
 
409
        HActionInvokeCallback(h, &HConnectionManagerAdapterPrivate::connectionComplete));
 
410
}
 
411
 
 
412
}
 
413
}
 
414
}