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

« back to all changes in this revision

Viewing changes to extra/kipi-plugins/dlnaexport/extra/hupnp/src/ssdp/hssdp.h

  • 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) 2010, 2011 Tuomo Penttinen, all rights reserved.
 
3
 *
 
4
 *  Author: Tuomo Penttinen <tp@herqq.org>
 
5
 *
 
6
 *  This file is part of Herqq UPnP (HUPnP) library.
 
7
 *
 
8
 *  Herqq UPnP is free software: you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU Lesser 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 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 Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU Lesser General Public License
 
19
 *  along with Herqq UPnP. If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#ifndef HSSDP_H_
 
23
#define HSSDP_H_
 
24
 
 
25
#include <HUpnpCore/HUpnp>
 
26
 
 
27
#include <QtCore/QObject>
 
28
 
 
29
class QUrl;
 
30
class QString;
 
31
class QHostAddress;
 
32
 
 
33
namespace Herqq
 
34
{
 
35
 
 
36
namespace Upnp
 
37
{
 
38
 
 
39
class HSsdpPrivate;
 
40
 
 
41
/*!
 
42
 * \brief This class is used for sending and receiving SSDP messages defined by the
 
43
 * UPnP Device Architecture specification.
 
44
 *
 
45
 * Simple Service Discovery Protocol (SSDP) is an expired IETF Internet draft
 
46
 * on which the UPnP discovery mechanism is built. This class implements only the
 
47
 * SSDP functionality mandated by the UPnP Device Architecture specification.
 
48
 * \brief This class does not implement the SSDP draft in full.
 
49
 *
 
50
 * To use this class, you only need to instantiate it and connect to the
 
51
 * exposed signals to receive events when SSDP messages are received. You can also
 
52
 * derive a sub-class and override the various virtual member functions to handle
 
53
 * the received messages.
 
54
 *
 
55
 * \headerfile hssdp.h HSsdp
 
56
 *
 
57
 * \ingroup hupnp_ssdp
 
58
 *
 
59
 * \remarks
 
60
 * \li this class requires an event loop for listening incoming messages
 
61
 * \li this class has thread-affinity, which mandates that the instances of this
 
62
 * class has to be used in the thread in which they are located at the time.
 
63
 */
 
64
class H_UPNP_CORE_EXPORT HSsdp :
 
65
    public QObject
 
66
{
 
67
Q_OBJECT
 
68
H_DISABLE_COPY(HSsdp)
 
69
H_DECLARE_PRIVATE(HSsdp)
 
70
 
 
71
public:
 
72
 
 
73
    /*!
 
74
     * \brief This enumeration specifies the different discovery methods the 
 
75
     * HSsdp class can run.
 
76
     */
 
77
    enum DiscoveryRequestMethod
 
78
    {
 
79
        /*!
 
80
         * This is the default multicast discovery supported both UDA v1.0 and 
 
81
         * UDA v1.1.
 
82
         */
 
83
        MulticastDiscovery,
 
84
 
 
85
        /*!
 
86
         * The unicast discovery specified in UDA v1.1.
 
87
         */
 
88
        UnicastDiscovery
 
89
    };
 
90
 
 
91
private Q_SLOTS:
 
92
 
 
93
    void unicastMessageReceived();
 
94
    void multicastMessageReceived();
 
95
 
 
96
protected:
 
97
 
 
98
    HSsdpPrivate* h_ptr;
 
99
    HSsdp(const QByteArray& loggingIdentifier, QObject* parent = 0);
 
100
 
 
101
protected:
 
102
 
 
103
    /*!
 
104
     * This method is called immediately after receiving a discovery request.
 
105
     *
 
106
     * Override this method if you want to handle the message. You can also connect
 
107
     * to the discoveryRequestReceived() signal.
 
108
     *
 
109
     * \param msg specifies the incoming message.
 
110
     * \param source specifies the source TCP/IP endpoint that sent the
 
111
     * message.
 
112
     * \param requestType specifies the type of the incoming discovery request.
 
113
     *
 
114
     * \retval true in case the message was handled successfully and the
 
115
     * discoveryRequestReceived() signal should not be sent.
 
116
     *
 
117
     * \retval false in case the message was not handled and the
 
118
     * discoveryRequestReceived() signal should be sent.
 
119
     *
 
120
     * \sa discoveryRequestReceived()
 
121
     */
 
122
    virtual bool incomingDiscoveryRequest(
 
123
        const HDiscoveryRequest& msg, const HEndpoint& source,
 
124
        DiscoveryRequestMethod requestType);
 
125
 
 
126
    /*!
 
127
     * This method is called immediately after receiving a discovery response.
 
128
     * Override this method if you want to handle message. You can also connect
 
129
     * to the discoveryResponseReceived() signal.
 
130
     *
 
131
     * \param msg specifies the incoming message.
 
132
     * \param source specifies the source TCP/IP endpoint that sent the
 
133
     * message.
 
134
     *
 
135
     * \retval true in case the message was handled successfully and the
 
136
     * discoveryResponseReceived() signal should not be sent.
 
137
     *
 
138
     * \retval false in case the message was not handled and the
 
139
     * discoveryResponseReceived() signal should be sent.
 
140
     *
 
141
     * \sa discoveryResponseReceived()
 
142
     */
 
143
    virtual bool incomingDiscoveryResponse(
 
144
        const HDiscoveryResponse& msg, const HEndpoint& source);
 
145
 
 
146
    /*!
 
147
     * This method is called immediately after receiving a device available announcement.
 
148
     * Override this method if you want to handle message. You can also connect
 
149
     * to the discoveryRequestReceived() signal.
 
150
     *
 
151
     * \param msg specifies the incoming message.
 
152
     * \param source specifies the source TCP/IP endpoint that sent the
 
153
     * message.
 
154
     *
 
155
     * \retval true in case the message was handled successfully and the
 
156
     * resourceAvailableReceived() signal should not be sent.
 
157
     *
 
158
     * \retval false in case the message was not handled and the
 
159
     * resourceAvailableReceived() signal should be sent.
 
160
     *
 
161
     * \sa resourceAvailableReceived()
 
162
     */
 
163
    virtual bool incomingDeviceAvailableAnnouncement(
 
164
        const HResourceAvailable& msg, const HEndpoint& source);
 
165
 
 
166
    /*!
 
167
     * This method is called immediately after receiving a device unavailable announcement.
 
168
     * Override this method if you want to handle message. You can also connect
 
169
     * to the resourceUnavailableReceived() signal.
 
170
     *
 
171
     * \param msg specifies the incoming message.
 
172
     * \param source specifies the source TCP/IP endpoint that sent the
 
173
     * message.
 
174
     *
 
175
     * \retval true in case the message was handled successfully and the
 
176
     * resourceUnavailableReceived() signal should not be sent.
 
177
     *
 
178
     * \retval false in case the message was not handled and the
 
179
     * resourceUnavailableReceived() signal should be sent.
 
180
     *
 
181
     * \sa resourceUnavailableReceived()
 
182
     */
 
183
    virtual bool incomingDeviceUnavailableAnnouncement(
 
184
        const HResourceUnavailable& msg, const HEndpoint& source);
 
185
 
 
186
    /*!
 
187
     * This method is called immediately after receiving a device update announcement.
 
188
     * Override this method if you want to handle message. You can also connect
 
189
     * to the deviceUpdateRecieved() signal.
 
190
     *
 
191
     * \param msg specifies the incoming message.
 
192
     * \param source specifies the source TCP/IP endpoint that sent the
 
193
     * message.
 
194
     *
 
195
     * \retval true in case the message was handled successfully and the
 
196
     * deviceUpdateRecieved() signal should not be sent.
 
197
     *
 
198
     * \retval false in case the message was not handled and the
 
199
     * deviceUpdateRecieved() signal should be sent.
 
200
     *
 
201
     * \sa deviceUpdateRecieved()
 
202
     */
 
203
    virtual bool incomingDeviceUpdateAnnouncement(
 
204
        const HResourceUpdate& msg, const HEndpoint& source);
 
205
 
 
206
public:
 
207
 
 
208
    /*!
 
209
     * \brief Creates a new instance.
 
210
     *
 
211
     * \param parent specifies the parent \c QObject.
 
212
     */
 
213
    HSsdp(QObject* parent=0);
 
214
 
 
215
    /*!
 
216
     * \brief Destroys the instance.
 
217
     */
 
218
    virtual ~HSsdp();
 
219
 
 
220
    /*!
 
221
     * This enum is used to define a "filter", which specifies which message
 
222
     * types are to be processed when encountered.
 
223
     *
 
224
     * \sa filter(), setFilter()
 
225
     */
 
226
    enum AllowedMessage
 
227
    {
 
228
        /*!
 
229
         * No messages are processed.
 
230
         */
 
231
        None = 0x00,
 
232
 
 
233
        /*!
 
234
         * Device available messages are processed.
 
235
         */
 
236
        DeviceAvailable = 0x01,
 
237
 
 
238
        /*!
 
239
         * Device update messages are processed.
 
240
         */
 
241
        DeviceUpdate = 0x02,
 
242
 
 
243
        /*!
 
244
         * Device unavailable messages are processed.
 
245
         */
 
246
        DeviceUnavailable = 0x04,
 
247
 
 
248
        /*!
 
249
         * Discovery request messages are processed.
 
250
         */
 
251
        DiscoveryRequest = 0x08,
 
252
 
 
253
        /*!
 
254
         * Discovery response messages are processed.
 
255
         */
 
256
        DiscoveryResponse = 0x10,
 
257
 
 
258
        /*!
 
259
         * Discovery response messages are processed.
 
260
         */
 
261
        All = 0x1f
 
262
    };
 
263
 
 
264
    Q_DECLARE_FLAGS(AllowedMessages, AllowedMessage)
 
265
 
 
266
    /*!
 
267
     * \brief Sets the filter of what message types are accepted for processing.
 
268
     *
 
269
     * The default is HSsdp::All.
 
270
     *
 
271
     * \param allowedMessages defines the message types the instance should
 
272
     * accept for further processing. Other message types will be silently ignored.
 
273
     *
 
274
     * \sa filter()
 
275
     */
 
276
    void setFilter(AllowedMessages allowedMessages);
 
277
 
 
278
    /*!
 
279
     * \brief Returns the message types that are currently accepted for processing.
 
280
     *
 
281
     * Default is HSsdp::All.
 
282
     *
 
283
     * \return The message types that are currently accepted for processing.
 
284
     *
 
285
     * \sa setFilter()
 
286
     */
 
287
    AllowedMessages filter() const;
 
288
 
 
289
    /*!
 
290
     * \brief Sets the instance to listen the network for SSDP messages and and attempts to
 
291
     * init the unicast socket of the instance to the address of the first
 
292
     * found network address that is up and that is not loopback. If no such
 
293
     * interface is found the loopback address is used.
 
294
     *
 
295
     * \retval true in case the instances was successfully bound to some address.
 
296
     * \retval false in case the instance could not be bound or the instance
 
297
     * was already bound.
 
298
     *
 
299
     * \remarks \c %HSsdp has to be bound to receive messages of any type.
 
300
     */
 
301
    bool init();
 
302
 
 
303
    /*!
 
304
     * \brief Sets the instance to listen the network for SSDP messages and attempts to
 
305
     * init a unicast socket of the instance to the specified address.
 
306
     *
 
307
     * \param unicastAddress specifies the address that should be used for
 
308
     * unicast messaging.
 
309
     *
 
310
     * \retval true in case the instance was successfully bound to the
 
311
     * specified address.
 
312
     *
 
313
     * \retval false in case the instance could not be bound or the instance
 
314
     * was already bound to the specified address.
 
315
     *
 
316
     * \remarks \c %HSsdp has to be bound to receive messages of any type.
 
317
     */
 
318
    bool init(const QHostAddress& unicastAddress);
 
319
 
 
320
    /*!
 
321
     * \brief Indicates if the instance is bound to listen for messages using one
 
322
     * or more network interfaces.
 
323
     *
 
324
     * \return \e true in case the instance is bound to listen for messages
 
325
     * using one or more network interfaces.
 
326
     */
 
327
    bool isInitialized() const;
 
328
 
 
329
    /*!
 
330
     * \brief Returns the UDP endpoint that is used for unicast communication.
 
331
     *
 
332
     * \return The UDP endpoint that is used for unicast communication.
 
333
     */
 
334
    HEndpoint unicastEndpoint() const;
 
335
 
 
336
    /*!
 
337
     * Sends the specified device availability announcement.
 
338
     *
 
339
     * \param msg specifies the announcement to send.
 
340
     * \param count specifies how many times the announcement is send.
 
341
     * The default is 1.
 
342
     *
 
343
     * \return The number of messages sent, 0 in case no messages was sent or
 
344
     * -1 in case the provided message is not valid.
 
345
     */
 
346
    qint32 announcePresence(const HResourceAvailable& msg, qint32 count = 1);
 
347
 
 
348
    /*!
 
349
     * Sends the specified device availability announcement.
 
350
     *
 
351
     * \param msg specifies the announcement to send.
 
352
     * \param count specifies how many times the announcement is send.
 
353
     * The default is 1.
 
354
     *
 
355
     * \return The number of messages sent, 0 in case no messages was sent or
 
356
     * -1 in case the provided message is not valid.
 
357
     */
 
358
    qint32 announcePresence(const HResourceUnavailable& msg, qint32 count = 1);
 
359
 
 
360
    /*!
 
361
     * Sends the specified device update announcement.
 
362
     *
 
363
     * \param msg specifies the message to send.
 
364
     * \param count specifies how many times the announcement is send.
 
365
     * The default is 1.
 
366
     *
 
367
     * \return The number of messages sent, 0 in case no messages was sent or
 
368
     * -1 in case the provided message is not valid.
 
369
     */
 
370
    qint32 announceUpdate(const HResourceUpdate& msg, qint32 count = 1);
 
371
 
 
372
    /*!
 
373
     * Sends the specified discovery request.
 
374
     *
 
375
     * Sends the specified discovery request to a multicast address
 
376
     * 239.255.255.250.
 
377
     *
 
378
     * \param msg specifies the announcement to send.
 
379
     * \param count specifies how many times the announcement is send.
 
380
     * The default is 1.
 
381
     *
 
382
     * \return The number of messages sent, 0 in case no messages was sent or
 
383
     * -1 in case the provided message is not valid.
 
384
     */
 
385
    qint32 sendDiscoveryRequest(const HDiscoveryRequest& msg, qint32 count = 1);
 
386
 
 
387
     /*!
 
388
     * Sends the specified discovery request.
 
389
     *
 
390
     * Sends the specified discovery request to a specified address. The
 
391
     * address can be an unicast address or a multicast address.
 
392
     *
 
393
     * \param msg specifies the announcement to send.
 
394
     * \param destination specifies the target UDP endpoint of the message.
 
395
     * If the port of the specified endpoint is set to zero the message is sent
 
396
     * to the specified host address using the default port 1900.
 
397
     * \param count specifies how many times the announcement is send.
 
398
     * The default is 1.
 
399
     *
 
400
     * \return The number of messages sent, 0 in case no messages was sent or
 
401
     * -1 in case the provided message or the destination is not valid.
 
402
     */
 
403
    qint32 sendDiscoveryRequest(
 
404
        const HDiscoveryRequest& msg, const HEndpoint& destination,
 
405
        qint32 count = 1);
 
406
 
 
407
    /*!
 
408
     * Sends the specified discovery response.
 
409
     *
 
410
     * \param msg specifies the announcement to send.
 
411
     *
 
412
     * \param destination specifies the target of the response.
 
413
     * If the port of the specified endpoint is set to zero the message is sent
 
414
     * to the specified host address using the default port 1900.
 
415
     * \param count specifies how many times the announcement is send.
 
416
     * The default is 1.
 
417
     *
 
418
     * \return The number of messages sent, 0 in case no messages was sent or
 
419
     * -1 in case the provided message is not valid.
 
420
     */
 
421
    qint32 sendDiscoveryResponse(
 
422
        const HDiscoveryResponse& msg, const HEndpoint& destination,
 
423
        qint32 count = 1);
 
424
 
 
425
////
 
426
////////////////////////////////////////////////////////////////////////////////
 
427
Q_SIGNALS:
 
428
 
 
429
    /*!
 
430
     * \brief This signal is emitted when a <em>discovery request</em> is received.
 
431
     *
 
432
     * \param msg specifies the received <em>discovery request</em> message.
 
433
     * \param source specifies the location where the message came.
 
434
     * \param requestType specifies the type of the incoming discovery request.
 
435
     */
 
436
    void discoveryRequestReceived(
 
437
        const Herqq::Upnp::HDiscoveryRequest& msg,
 
438
        const Herqq::Upnp::HEndpoint& source,
 
439
        Herqq::Upnp::HSsdp::DiscoveryRequestMethod requestType);
 
440
 
 
441
    /*!
 
442
     * \brief This signal is emitted when a <em>discovery response</em> is received.
 
443
     *
 
444
     * \param msg specifies the received <em>discovery response</em> message.
 
445
     * \param source specifies the location where the message came.
 
446
     */
 
447
    void discoveryResponseReceived(
 
448
        const Herqq::Upnp::HDiscoveryResponse& msg,
 
449
        const Herqq::Upnp::HEndpoint& source);
 
450
 
 
451
    /*!
 
452
     * \brief This signal is emitted when a <em>device announcement</em> is received.
 
453
     *
 
454
     * \param msg specifies the <em>device announcement</em> message.
 
455
     * \param source specifies the location where the message came.
 
456
     */
 
457
    void resourceAvailableReceived(
 
458
        const Herqq::Upnp::HResourceAvailable& msg,
 
459
        const Herqq::Upnp::HEndpoint& source);
 
460
 
 
461
    /*!
 
462
     * \brief This signal is emitted when a <em>device update</em> is received.
 
463
     *
 
464
     * \param msg specifies the <em>device update</em> message.
 
465
     * \param source specifies the location where the message came.
 
466
     */
 
467
    void deviceUpdateReceived(
 
468
        const Herqq::Upnp::HResourceUpdate& msg,
 
469
        const Herqq::Upnp::HEndpoint& source);
 
470
 
 
471
    /*!
 
472
     * \brief This signal is emitted when a <em>device announcement</em> is received.
 
473
     *
 
474
     * \param msg specifies the <em>device announcement</em> message.
 
475
     * \param source specifies the location where the message came.
 
476
     */
 
477
    void resourceUnavailableReceived(
 
478
        const Herqq::Upnp::HResourceUnavailable& msg,
 
479
        const Herqq::Upnp::HEndpoint& source);
 
480
};
 
481
 
 
482
Q_DECLARE_OPERATORS_FOR_FLAGS(HSsdp::AllowedMessages)
 
483
 
 
484
}
 
485
}
 
486
 
 
487
#endif /* HSSDP_H_ */