Public Types | Signals | Public Member Functions | Protected Member Functions

HSsdp Class Reference
[Ssdp]

This class is used for sending and receiving SSDP messages defined by the UPnP Device Architecture specification. More...

#include <HSsdp>

Inherited by HControlPointSsdpHandler, and HDeviceHostSsdpHandler.

List of all members.

Public Types

enum  AllowedMessage

Signals

void discoveryRequestReceived (const Herqq::Upnp::HDiscoveryRequest &msg, const Herqq::Upnp::HEndpoint &source, Herqq::Upnp::HSsdp::DiscoveryRequestMethod requestType)
void discoveryResponseReceived (const Herqq::Upnp::HDiscoveryResponse &msg, const Herqq::Upnp::HEndpoint &source)
void resourceAvailableReceived (const Herqq::Upnp::HResourceAvailable &msg, const Herqq::Upnp::HEndpoint &source)
void deviceUpdateReceived (const Herqq::Upnp::HResourceUpdate &msg, const Herqq::Upnp::HEndpoint &source)
void resourceUnavailableReceived (const Herqq::Upnp::HResourceUnavailable &msg, const Herqq::Upnp::HEndpoint &source)

Public Member Functions

 HSsdp (QObject *parent=0)
void setFilter (AllowedMessages allowedMessages)
AllowedMessages filter () const
bool init ()
bool init (const QHostAddress &unicastAddress)
bool isInitialized () const
HEndpoint unicastEndpoint () const
qint32 announcePresence (const HResourceAvailable &msg, qint32 count=1)
qint32 announcePresence (const HResourceUnavailable &msg, qint32 count=1)
qint32 announceUpdate (const HResourceUpdate &msg, qint32 count=1)
qint32 sendDiscoveryRequest (const HDiscoveryRequest &msg, qint32 count=1)
qint32 sendDiscoveryRequest (const HDiscoveryRequest &msg, const HEndpoint &destination, qint32 count=1)
qint32 sendDiscoveryResponse (const HDiscoveryResponse &msg, const HEndpoint &destination, qint32 count=1)

Protected Member Functions

virtual bool incomingDiscoveryRequest (const HDiscoveryRequest &msg, const HEndpoint &source, DiscoveryRequestMethod requestType)
virtual bool incomingDiscoveryResponse (const HDiscoveryResponse &msg, const HEndpoint &source)
virtual bool incomingDeviceAvailableAnnouncement (const HResourceAvailable &msg, const HEndpoint &source)
virtual bool incomingDeviceUnavailableAnnouncement (const HResourceUnavailable &msg, const HEndpoint &source)
virtual bool incomingDeviceUpdateAnnouncement (const HResourceUpdate &msg, const HEndpoint &source)

Detailed Description

Simple Service Discovery Protocol (SSDP) is an expired IETF Internet draft on which the UPnP discovery mechanism is built. This class implements only the SSDP functionality mandated by the UPnP Device Architecture specification. This class does not implement the SSDP draft in full.

To use this class, you only need to instantiate it and connect to the exposed signals to receive events when SSDP messages are received. You can also derive a sub-class and override the various virtual member functions to handle the received messages.

Remarks:
  • this class requires an event loop for listening incoming messages
  • this class has thread-affinity, which mandates that the instances of this class has to be used in the thread in which they are located at the time.

Member Enumeration Documentation

This enumeration specifies the different discovery methods the HSsdp class can run.

Enumerator:
MulticastDiscovery 

This is the default multicast discovery supported both UDA v1.0 and UDA v1.1.

UnicastDiscovery 

The unicast discovery specified in UDA v1.1.

This enum is used to define a "filter", which specifies which message types are to be processed when encountered.

See also:
filter(), setFilter()
Enumerator:
None 

No messages are processed.

DeviceAvailable 

Device available messages are processed.

DeviceUpdate 

Device update messages are processed.

DeviceUnavailable 

Device unavailable messages are processed.

DiscoveryRequest 

Discovery request messages are processed.

DiscoveryResponse 

Discovery response messages are processed.

All 

Discovery response messages are processed.


Constructor & Destructor Documentation

HSsdp ( QObject *  parent = 0 )

Creates a new instance.

Parameters:
parentspecifies the parent QObject.

Member Function Documentation

bool incomingDiscoveryRequest ( const HDiscoveryRequest msg,
const HEndpoint source,
DiscoveryRequestMethod  requestType 
) [protected, virtual]

This method is called immediately after receiving a discovery request.

Override this method if you want to handle the message. You can also connect to the discoveryRequestReceived() signal.

Parameters:
msgspecifies the incoming message.
sourcespecifies the source TCP/IP endpoint that sent the message.
requestTypespecifies the type of the incoming discovery request.
Return values:
truein case the message was handled successfully and the discoveryRequestReceived() signal should not be sent.
falsein case the message was not handled and the discoveryRequestReceived() signal should be sent.
See also:
discoveryRequestReceived()
bool incomingDiscoveryResponse ( const HDiscoveryResponse msg,
const HEndpoint source 
) [protected, virtual]

This method is called immediately after receiving a discovery response.

Override this method if you want to handle message. You can also connect to the discoveryResponseReceived() signal.

Parameters:
msgspecifies the incoming message.
sourcespecifies the source TCP/IP endpoint that sent the message.
Return values:
truein case the message was handled successfully and the discoveryResponseReceived() signal should not be sent.
falsein case the message was not handled and the discoveryResponseReceived() signal should be sent.
See also:
discoveryResponseReceived()
bool incomingDeviceAvailableAnnouncement ( const HResourceAvailable msg,
const HEndpoint source 
) [protected, virtual]

This method is called immediately after receiving a device available announcement.

Override this method if you want to handle message. You can also connect to the discoveryRequestReceived() signal.

Parameters:
msgspecifies the incoming message.
sourcespecifies the source TCP/IP endpoint that sent the message.
Return values:
truein case the message was handled successfully and the resourceAvailableReceived() signal should not be sent.
falsein case the message was not handled and the resourceAvailableReceived() signal should be sent.
See also:
resourceAvailableReceived()
bool incomingDeviceUnavailableAnnouncement ( const HResourceUnavailable msg,
const HEndpoint source 
) [protected, virtual]

This method is called immediately after receiving a device unavailable announcement.

Override this method if you want to handle message. You can also connect to the resourceUnavailableReceived() signal.

Parameters:
msgspecifies the incoming message.
sourcespecifies the source TCP/IP endpoint that sent the message.
Return values:
truein case the message was handled successfully and the resourceUnavailableReceived() signal should not be sent.
falsein case the message was not handled and the resourceUnavailableReceived() signal should be sent.
See also:
resourceUnavailableReceived()
bool incomingDeviceUpdateAnnouncement ( const HResourceUpdate msg,
const HEndpoint source 
) [protected, virtual]

This method is called immediately after receiving a device update announcement.

Override this method if you want to handle message. You can also connect to the deviceUpdateRecieved() signal.

Parameters:
msgspecifies the incoming message.
sourcespecifies the source TCP/IP endpoint that sent the message.
Return values:
truein case the message was handled successfully and the deviceUpdateRecieved() signal should not be sent.
falsein case the message was not handled and the deviceUpdateRecieved() signal should be sent.
See also:
deviceUpdateRecieved()
void setFilter ( AllowedMessages  allowedMessages )

Sets the filter of what message types are accepted for processing.

The default is HSsdp::All.

Parameters:
allowedMessagesdefines the message types the instance should accept for further processing. Other message types will be silently ignored.
See also:
filter()
HSsdp::AllowedMessages filter (  ) const

Returns the message types that are currently accepted for processing.

Default is HSsdp::All.

Returns:
the message types that are currently accepted for processing.
See also:
setFilter()
bool init (  )

Sets the instance to listen the network for SSDP messages and and attempts to init the unicast socket of the instance to the address of the first found network address that is up and that is not loopback.

If no such interface is found the loopback address is used.

Return values:
truein case the instances was successfully bound to some address.
falsein case the instance could not be bound or the instance was already bound.
Remarks:
HSsdp has to be bound to receive messages of any type.
bool init ( const QHostAddress &  unicastAddress )

Sets the instance to listen the network for SSDP messages and attempts to init a unicast socket of the instance to the specified address.

Parameters:
unicastAddressspecifies the address that should be used for unicast messaging.
Return values:
truein case the instance was successfully bound to the specified address.
falsein case the instance could not be bound or the instance was already bound to the specified address.
Remarks:
HSsdp has to be bound to receive messages of any type.
bool isInitialized (  ) const

Indicates if the instance is bound to listen for messages using one or more network interfaces.

Returns:
true in case the instance is bound to listen for messages using one or more network interfaces.
HEndpoint unicastEndpoint (  ) const

Returns the UDP endpoint that is used for unicast communication.

Returns:
the UDP endpoint that is used for unicast communication.
qint32 announcePresence ( const HResourceAvailable msg,
qint32  count = 1 
)

Sends the specified device availability announcement.

Parameters:
msgspecifies the announcement to send.
countspecifies how many times the announcement is send. The default is 1.
Returns:
the number of messages sent, 0 in case no messages was sent or -1 in case the provided message is not valid.
qint32 announcePresence ( const HResourceUnavailable msg,
qint32  count = 1 
)

Sends the specified device availability announcement.

Parameters:
msgspecifies the announcement to send.
countspecifies how many times the announcement is send. The default is 1.
Returns:
the number of messages sent, 0 in case no messages was sent or -1 in case the provided message is not valid.
qint32 announceUpdate ( const HResourceUpdate msg,
qint32  count = 1 
)

Sends the specified device update announcement.

Parameters:
msgspecifies the message to send.
countspecifies how many times the announcement is send. The default is 1.
Returns:
the number of messages sent, 0 in case no messages was sent or -1 in case the provided message is not valid.
qint32 sendDiscoveryRequest ( const HDiscoveryRequest msg,
qint32  count = 1 
)

Sends the specified discovery request.

Sends the specified discovery request to a multicast address 239.255.255.250.

Parameters:
msgspecifies the announcement to send.
countspecifies how many times the announcement is send. The default is 1.
Returns:
the number of messages sent, 0 in case no messages was sent or -1 in case the provided message is not valid.
qint32 sendDiscoveryRequest ( const HDiscoveryRequest msg,
const HEndpoint destination,
qint32  count = 1 
)

Sends the specified discovery request.

Sends the specified discovery request to a specified address. The address can be an unicast address or a multicast address.

Parameters:
msgspecifies the announcement to send.
destinationspecifies the target UDP endpoint of the message. If the port of the specified endpoint is set to zero the message is sent to the specified host address using the default port 1900.
countspecifies how many times the announcement is send. The default is 1.
Returns:
the number of messages sent, 0 in case no messages was sent or -1 in case the provided message or the destination is not valid.
qint32 sendDiscoveryResponse ( const HDiscoveryResponse msg,
const HEndpoint destination,
qint32  count = 1 
)

Sends the specified discovery response.

Parameters:
msgspecifies the announcement to send.
destinationspecifies the target of the response. If the port of the specified endpoint is set to zero the message is sent to the specified host address using the default port 1900.
countspecifies how many times the announcement is send. The default is 1.
Returns:
the number of messages sent, 0 in case no messages was sent or -1 in case the provided message is not valid.
void discoveryRequestReceived ( const Herqq::Upnp::HDiscoveryRequest msg,
const Herqq::Upnp::HEndpoint source,
Herqq::Upnp::HSsdp::DiscoveryRequestMethod  requestType 
) [signal]

This signal is emitted when a discovery request is received.

Parameters:
msgspecifies the received discovery request message.
sourcespecifies the location where the message came.
requestTypespecifies the type of the incoming discovery request.
void discoveryResponseReceived ( const Herqq::Upnp::HDiscoveryResponse msg,
const Herqq::Upnp::HEndpoint source 
) [signal]

This signal is emitted when a discovery response is received.

Parameters:
msgspecifies the received discovery response message.
sourcespecifies the location where the message came.
void resourceAvailableReceived ( const Herqq::Upnp::HResourceAvailable msg,
const Herqq::Upnp::HEndpoint source 
) [signal]

This signal is emitted when a device announcement is received.

Parameters:
msgspecifies the device announcement message.
sourcespecifies the location where the message came.
void deviceUpdateReceived ( const Herqq::Upnp::HResourceUpdate msg,
const Herqq::Upnp::HEndpoint source 
) [signal]

This signal is emitted when a device update is received.

Parameters:
msgspecifies the device update message.
sourcespecifies the location where the message came.
void resourceUnavailableReceived ( const Herqq::Upnp::HResourceUnavailable msg,
const Herqq::Upnp::HEndpoint source 
) [signal]

This signal is emitted when a device announcement is received.

Parameters:
msgspecifies the device announcement message.
sourcespecifies the location where the message came.