Platinum UPnP SDK  1.0.5.13
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
PLT_DeviceHost Class Referenceabstract

UPnP Device Host. More...

#include <PltDeviceHost.h>

Inheritance diagram for PLT_DeviceHost:
PLT_DeviceData PLT_SsdpPacketListener PLT_MediaServer PLT_FileMediaServer

Public Member Functions

 PLT_DeviceHost (const char *description_path="/", const char *uuid="", const char *device_type="", const char *friendly_name="", bool show_ip=false, NPT_UInt16 port=0, bool port_rebind=false)
 Creates a new instance of UPnP Device Host. More...
 
virtual NPT_Result AddIcon (const PLT_DeviceIcon &icon, const char *fileroot, const char *urlroot="/")
 Add UPnP icon information to serve from file system. More...
 
virtual NPT_Result AddIcon (const PLT_DeviceIcon &icon, const void *data, NPT_Size size, bool copy=true)
 Add UPnP icon information to serve using static image. More...
 
virtual NPT_UInt16 GetPort ()
 Returns the port used by the internal HTTP server for all incoming requests. More...
 
virtual void SetByeByeFirst (bool bye_bye_first)
 When a UPnP device comes up, the specifications require that a SSDP bye-bye sequence is sent to force the removal of the device in case it wasn't sent properly during the last shutdown. More...
 
NPT_Result SetLeaseTime (NPT_TimeInterval lease_time)
 Sets the lease time. More...
 

Protected Member Functions

NPT_Result Announce (NPT_HttpRequest &request, NPT_UdpSocket &socket, PLT_SsdpAnnounceType type)
 Called during SSDP announce. More...
 
virtual NPT_Result OnAction (PLT_ActionReference &action, const PLT_HttpRequestContext &context)
 This mehod is called when an action performed by a control point has been received and needs to be answered. More...
 
virtual NPT_Result OnSsdpPacket (const NPT_HttpRequest &request, const NPT_HttpRequestContext &context)
 PLT_SsdpPacketListener method called when a M-SEARCH SSDP packet is received. More...
 
virtual NPT_Result ProcessGetDescription (NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
 This method is called when a control point is requesting the device description. More...
 
virtual NPT_Result ProcessGetSCPD (PLT_Service *service, NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
 This method is called when a control point is requesting a service SCPD. More...
 
virtual NPT_Result ProcessHttpGetRequest (NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
 This method is called when a "GET" request for a resource other than the device description, SCPD, or icons has been received. More...
 
virtual NPT_Result ProcessHttpPostRequest (NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
 This method is called when a "POST" request has been received. More...
 
virtual NPT_Result ProcessHttpSubscriberRequest (NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
 This method is called when a request from a subscriber has been received. More...
 
virtual NPT_Result SendSsdpSearchResponse (NPT_HttpResponse &response, NPT_UdpSocket &socket, const char *st, const NPT_SocketAddress *addr=NULL)
 Called by PLT_SsdpDeviceSearchResponseTask when responding to a M-SEARCH SSDP request. More...
 
virtual NPT_Result SetupDevice ()
 Default implementation for setting up device host. More...
 
virtual NPT_Result SetupIcons ()
 Default implementation for registering device icon resources. More...
 
virtual NPT_Result SetupResponse (NPT_HttpRequest &request, const NPT_HttpRequestContext &context, NPT_HttpResponse &response)
 NPT_HttpRequestHandler method for setting up the response of an incoming HTTP request. More...
 
virtual NPT_Result SetupServices ()=0
 Required method for setting up UPnP services of device host (and any embedded). More...
 
virtual NPT_Result Start (PLT_SsdpListenTask *task)
 Called by PLT_TaskManager when the device is started. More...
 
virtual NPT_Result Stop (PLT_SsdpListenTask *task)
 Called by PLT_TaskManager when the device is stoped. More...
 

Static Protected Member Functions

static NPT_Result Announce (PLT_DeviceData *device, NPT_HttpRequest &request, NPT_UdpSocket &socket, PLT_SsdpAnnounceType type)
 Static method similar to Announce. More...
 
static NPT_Result SendSsdpSearchResponse (PLT_DeviceData *device, NPT_HttpResponse &response, NPT_UdpSocket &socket, const char *st, const NPT_SocketAddress *addr=NULL)
 Static method similar to SendSsdpSearchResponse. More...
 

Friends

class PLT_Service
 
class PLT_SsdpAnnounceInterfaceIterator
 
class PLT_SsdpDeviceSearchResponseInterfaceIterator
 
class PLT_SsdpDeviceSearchResponseTask
 
class PLT_UPnP
 

Detailed Description

UPnP Device Host.

The PLT_DeviceHost class is a base class for implementing a UPnP Device. It handles network announcements and responses to searches from ControlPoints. ControlPoint action invocations are also received and delegated to derived classes. A PLT_DeviceHost also takes care of eventing when services state variables change.

Constructor & Destructor Documentation

PLT_DeviceHost::PLT_DeviceHost ( const char *  description_path = "/",
const char *  uuid = "",
const char *  device_type = "",
const char *  friendly_name = "",
bool  show_ip = false,
NPT_UInt16  port = 0,
bool  port_rebind = false 
)

Creates a new instance of UPnP Device Host.

Parameters
description_pathRelative path for description url
uuidUPnP device unique id
device_typeUPnP device type
friendly_nameName advertised for UPnP device
show_ipFlag to indicate if device IP should be appended to friendly name
portlocal port for the device host internal HTTP server, 0 for randomly selected.
port_rebindFlag to indicate if device host should automatically try to look for another port if failing to choose the one passed.

Member Function Documentation

virtual NPT_Result PLT_DeviceHost::AddIcon ( const PLT_DeviceIcon icon,
const char *  fileroot,
const char *  urlroot = "/" 
)
virtual

Add UPnP icon information to serve from file system.

Parameters
iconthe icon information including url path
filerootthe file system root path
urlrootthe url root path of the icon url to match to fileroot Note: As an exemple, if the icon url path is "/images/icon1.jpg", the fileroot is "/Users/joe/www" and the urlroot is "/", when a request is made for "/images/icon1.jpg", the file is expected to be found at "/Users/joe/www/images/icon1.jpg". If the urlroot were "/images", the file would be expected to be found at "/Users/joe/www/icon1.jpg".
virtual NPT_Result PLT_DeviceHost::AddIcon ( const PLT_DeviceIcon icon,
const void *  data,
NPT_Size  size,
bool  copy = true 
)
virtual

Add UPnP icon information to serve using static image.

Parameters
iconthe icon information including url path
datathe image data
sizethe image data size
copyboolean to indicate the data should be copied internally
static NPT_Result PLT_DeviceHost::Announce ( PLT_DeviceData device,
NPT_HttpRequest &  request,
NPT_UdpSocket &  socket,
PLT_SsdpAnnounceType  type 
)
staticprotected

Static method similar to Announce.

Parameters
devicethe device to announce
requestthe SSDP pre formatted request
socketthe network socket to use to send the request
typePLT_SsdpAnnounceType enum if the announce is a SSDP bye-bye, update or alive.

Referenced by Announce().

NPT_Result PLT_DeviceHost::Announce ( NPT_HttpRequest &  request,
NPT_UdpSocket &  socket,
PLT_SsdpAnnounceType  type 
)
inlineprotected

Called during SSDP announce.

The HTTP request is already configured with the right method and host.

Parameters
requestthe SSDP pre formatted request
socketthe network socket to use to send the request
typePLT_SsdpAnnounceType enum if the announce is a SSDP bye-bye, update or alive.

References Announce().

virtual NPT_UInt16 PLT_DeviceHost::GetPort ( )
inlinevirtual

Returns the port used by the internal HTTP server for all incoming requests.

Returns
port
virtual NPT_Result PLT_DeviceHost::OnAction ( PLT_ActionReference &  action,
const PLT_HttpRequestContext context 
)
protectedvirtual

This mehod is called when an action performed by a control point has been received and needs to be answered.

Parameters
actionthe action information to answer
contextthe context information including the HTTP request and local and remote socket information (IP & port).

Reimplemented in PLT_MediaServer.

virtual NPT_Result PLT_DeviceHost::OnSsdpPacket ( const NPT_HttpRequest &  request,
const NPT_HttpRequestContext &  context 
)
protectedvirtual

PLT_SsdpPacketListener method called when a M-SEARCH SSDP packet is received.

Parameters
requestSSDP packet
contextthe context of the request

Implements PLT_SsdpPacketListener.

virtual NPT_Result PLT_DeviceHost::ProcessGetDescription ( NPT_HttpRequest &  request,
const NPT_HttpRequestContext &  context,
NPT_HttpResponse &  response 
)
protectedvirtual

This method is called when a control point is requesting the device description.

Parameters
requestthe HTTP request
contextthe context information including local and remote socket information.
responsethe response to setup.
virtual NPT_Result PLT_DeviceHost::ProcessGetSCPD ( PLT_Service service,
NPT_HttpRequest &  request,
const NPT_HttpRequestContext &  context,
NPT_HttpResponse &  response 
)
protectedvirtual

This method is called when a control point is requesting a service SCPD.

Parameters
servicethe service
requestthe HTTP request
contextthe context information including local and remote socket information.
responsethe response to setup.
virtual NPT_Result PLT_DeviceHost::ProcessHttpGetRequest ( NPT_HttpRequest &  request,
const NPT_HttpRequestContext &  context,
NPT_HttpResponse &  response 
)
protectedvirtual

This method is called when a "GET" request for a resource other than the device description, SCPD, or icons has been received.

Parameters
requestthe HTTP request
contextthe context information including local and remote socket information.
responsethe response to setup.

Reimplemented in PLT_MediaServer.

virtual NPT_Result PLT_DeviceHost::ProcessHttpPostRequest ( NPT_HttpRequest &  request,
const NPT_HttpRequestContext &  context,
NPT_HttpResponse &  response 
)
protectedvirtual

This method is called when a "POST" request has been received.

This is usually an UPnP service action invocation. This will deserialize the request and call the OnAction method.

Parameters
requestthe HTTP request
contextthe context information including local and remote socket information.
responsethe response to setup.
virtual NPT_Result PLT_DeviceHost::ProcessHttpSubscriberRequest ( NPT_HttpRequest &  request,
const NPT_HttpRequestContext &  context,
NPT_HttpResponse &  response 
)
protectedvirtual

This method is called when a request from a subscriber has been received.

This is for any new subscritions, existing subscrition renewal or cancellation.

Parameters
requestthe HTTP request
contextthe context information including local and remote socket information.
responsethe response to setup.
static NPT_Result PLT_DeviceHost::SendSsdpSearchResponse ( PLT_DeviceData device,
NPT_HttpResponse &  response,
NPT_UdpSocket &  socket,
const char *  st,
const NPT_SocketAddress *  addr = NULL 
)
staticprotected

Static method similar to SendSsdpSearchResponse.

Parameters
devicethe device to announce
responsethe SSDP pre formatted response
socketthe network socket to use to send the request
stthe original request search target
addrthe remote address to send the response back to in case the socket is not already connected.

Referenced by SendSsdpSearchResponse().

virtual NPT_Result PLT_DeviceHost::SendSsdpSearchResponse ( NPT_HttpResponse &  response,
NPT_UdpSocket &  socket,
const char *  st,
const NPT_SocketAddress *  addr = NULL 
)
inlineprotectedvirtual

Called by PLT_SsdpDeviceSearchResponseTask when responding to a M-SEARCH SSDP request.

Parameters
responsethe SSDP pre formatted response
socketthe network socket to use to send the request
stthe original request search target
addrthe remote address to send the response back to in case the socket is not already connected.

References SendSsdpSearchResponse().

virtual void PLT_DeviceHost::SetByeByeFirst ( bool  bye_bye_first)
inlinevirtual

When a UPnP device comes up, the specifications require that a SSDP bye-bye sequence is sent to force the removal of the device in case it wasn't sent properly during the last shutdown.

Parameters
bye_bye_firstBoolean to indicate that SSDP bye-bye sequence should be sent first or not.
NPT_Result PLT_DeviceHost::SetLeaseTime ( NPT_TimeInterval  lease_time)
inline

Sets the lease time.

Parameters
lease_timeLease Time
virtual NPT_Result PLT_DeviceHost::SetupDevice ( )
protectedvirtual

Default implementation for setting up device host.

This calls SetupServices and SetupIcons when device starts.

virtual NPT_Result PLT_DeviceHost::SetupIcons ( )
protectedvirtual

Default implementation for registering device icon resources.

Override to use different ones. Called when device starts.

virtual NPT_Result PLT_DeviceHost::SetupResponse ( NPT_HttpRequest &  request,
const NPT_HttpRequestContext &  context,
NPT_HttpResponse &  response 
)
protectedvirtual

NPT_HttpRequestHandler method for setting up the response of an incoming HTTP request.

Parameters
requestthe request received
contextthe context of the request
responsethe response to set up
virtual NPT_Result PLT_DeviceHost::SetupServices ( )
protectedpure virtual

Required method for setting up UPnP services of device host (and any embedded).

Called when device starts.

Implemented in PLT_MediaServer.

virtual NPT_Result PLT_DeviceHost::Start ( PLT_SsdpListenTask task)
protectedvirtual

Called by PLT_TaskManager when the device is started.

Parameters
taskthe SSDP listening task to attach to for receiving SSDP M-SEARCH messages.
virtual NPT_Result PLT_DeviceHost::Stop ( PLT_SsdpListenTask task)
protectedvirtual

Called by PLT_TaskManager when the device is stoped.

Parameters
taskthe SSDP listening task to detach from to stop receiving SSDP M-SEARCH messages.

The documentation for this class was generated from the following file: