Arduino DLNA Server
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tiny_dlna::DLNADevice< ClientType > Class Template Reference

Setup of a Basic DLNA Device service. The device registers itself to the network and answers to the DLNA queries and requests. A DLNA device uses UDP, Http, XML and Soap to discover and manage a service, so there is quite some complexity involved: More...

#include <DLNADevice.h>

Inheritance diagram for tiny_dlna::DLNADevice< ClientType >:
Inheritance graph
[legend]

Public Member Functions

 DLNADevice ()
 
bool begin (DLNADeviceInfo &device, IUDPService &udp, IHttpServer &server) override
 start the
 
ISubscriptionMgrDevicegetSubscriptionMgr () override
 Get subscription manager for event handling.
 
void end () override
 Stops the processing and releases the resources.
 
bool loop (int loopAction=RUN_ALL) override
 
int loopPublishSubscriptions ()
 Publish pending subscription notifications.
 
bool loopServer () override
 Process http server loop.
 
int loopUDPMessages ()
 Process incoming UDP and execute scheduled replies.
 
DLNAServiceInfogetService (const char *id) override
 Provide addess to the service information.
 
DLNAServiceInfogetServiceByAbbrev (const char *abbrev) override
 Get Service by subscription ns abbrev.
 
DLNAServiceInfogetServiceByEventPath (const char *requestPath) override
 
void addChange (const char *serviceAbbrev, std::function< size_t(Print &, void *)> changeWriter, void *ref) override
 Record a state variable change for subscription notifications.
 
DLNADeviceInfogetDeviceInfo () override
 Provides the device.
 
void setSchedulerActive (bool flag) override
 We can activate/deactivate the scheduler.
 
bool isSchedulerActive () override
 Checks if the scheduler is active.
 
void setPostAliveRepeatMs (uint32_t ms) override
 
void setSubscriptionsActive (bool flag) override
 Enable or disable subscription notifications: call before begin.
 
bool isSubscriptionsActive () const override
 Check if subscription notifications are active.
 
void setReference (void *ref) override
 Sets a reference pointer that can be used to associate application.
 
void * getReference () override
 Gets the reference pointer.
 
void logStatus ()
 

Static Public Member Functions

static void parseActionRequest (IHttpServer *server, const char *requestPath, HttpRequestHandlerLine *hl, ActionRequest &action)
 Parses the SOAP content of a DLNA action request.
 
static size_t printReplyXML (Print &out, const char *replyName, const char *serviceId, std::function< size_t(Print &, void *)> valuesWriter=nullptr, void *ref=nullptr)
 Builds a standard SOAP reply envelope.
 
static size_t replyGetProtocolInfo (Print &out, const char *source="", const char *sink="")
 
static size_t replyGetCurrentConnectionIDs (Print &out, const char *ids)
 
static size_t replyGetCurrentConnectionInfo (Print &out, const char *protocolInfo, const char *connectionID, const char *direction)
 
static bool handleSubscription (IHttpServer *server, const char *requestPath, HttpRequestHandlerLine *hl, bool &is_subscribe)
 Static handler for SUBSCRIBE/UNSUBSCRIBE requests on service event URLs.
 

Protected Member Functions

void setDeviceInfo (DLNADeviceInfo &device)
 
void setSchedulerIntervalMs (uint32_t ms)
 Set scheduler interval in milliseconds.
 
uint32_t getSchedulerIntervalMs () const
 Get scheduler interval in milliseconds.
 
void setSubscriptionsIntervalMs (uint32_t ms)
 Set subscription publish interval in milliseconds.
 
uint32_t getSubscriptionsIntervalMs () const
 Get subscription publish interval in milliseconds.
 
void logScheduledStatus (bool runImmediately=false)
 
bool setupParser ()
 
bool setupScheduler ()
 Schedule PostAlive messages.
 
bool validateServiceInfo (const DLNAServiceInfo &service)
 Validates that all required service URLs and callbacks are defined.
 
virtual bool setupDLNAServer (IHttpServer &srv)
 set up Web Server to handle Service Addresses
 

Static Protected Member Functions

static void deviceXMLCallback (IHttpServer *server, const char *requestPath, HttpRequestHandlerLine *hl)
 callback to provide device XML
 
static bool handleSubscribe (IHttpServer *server, const char *requestPath, HttpRequestHandlerLine *hl)
 Handle SUBSCRIBE requests.
 
static bool handleUnsubscribe (IHttpServer *server, const char *requestPath, HttpRequestHandlerLine *hl)
 Handle UNSUBSCRIBE requests.
 

Protected Attributes

bool is_active = false
 
bool is_subscriptions_active = true
 
uint32_t post_alive_repeat_ms = 0
 
Scheduler scheduler
 
SubscriptionMgrDevice< ClientType > subscription_mgr
 
DLNADeviceRequestParser parser
 
DLNADeviceInfop_device_info = nullptr
 
IUDPServicep_udp = nullptr
 
IHttpServerp_server = nullptr
 
uint64_t scheduler_interval_ms = (uint64_t)DLNA_RUN_SCHEDULER_EVERY_MS
 
uint64_t subscriptions_interval_ms
 
uint64_t next_scheduler_timeout_ms = 0
 
uint64_t next_subscriptions_timeout_ms = 0
 
void * reference = nullptr
 

Detailed Description

template<typename ClientType>
class tiny_dlna::DLNADevice< ClientType >

Setup of a Basic DLNA Device service. The device registers itself to the network and answers to the DLNA queries and requests. A DLNA device uses UDP, Http, XML and Soap to discover and manage a service, so there is quite some complexity involved:

The template parameter selects the HTTP client implementation (for example WiFiClient) that will be used by all internal helpers; choose the one that matches your platform.

Template Parameters
ClientTypeArduino Client implementation used for outbound HTTP traffic (e.g. WiFiClient, EthernetClient).
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ DLNADevice()

template<typename ClientType >
tiny_dlna::DLNADevice< ClientType >::DLNADevice ( )
inline

Member Function Documentation

◆ addChange()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::addChange ( const char *  serviceAbbrev,
std::function< size_t(Print &, void *)>  changeWriter,
void *  ref 
)
inlineoverridevirtual

Record a state variable change for subscription notifications.

Implements tiny_dlna::IDevice.

◆ begin()

template<typename ClientType >
bool tiny_dlna::DLNADevice< ClientType >::begin ( DLNADeviceInfo device,
IUDPService udp,
IHttpServer server 
)
inlineoverridevirtual

start the

Implements tiny_dlna::IDevice.

◆ deviceXMLCallback()

template<typename ClientType >
static void tiny_dlna::DLNADevice< ClientType >::deviceXMLCallback ( IHttpServer server,
const char *  requestPath,
HttpRequestHandlerLine hl 
)
inlinestaticprotected

callback to provide device XML

◆ end()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::end ( )
inlineoverridevirtual

Stops the processing and releases the resources.

Implements tiny_dlna::IDevice.

◆ getDeviceInfo()

template<typename ClientType >
DLNADeviceInfo & tiny_dlna::DLNADevice< ClientType >::getDeviceInfo ( )
inlineoverridevirtual

Provides the device.

Implements tiny_dlna::IDevice.

◆ getReference()

template<typename ClientType >
void * tiny_dlna::DLNADevice< ClientType >::getReference ( )
inlineoverridevirtual

Gets the reference pointer.

Implements tiny_dlna::IDevice.

◆ getSchedulerIntervalMs()

template<typename ClientType >
uint32_t tiny_dlna::DLNADevice< ClientType >::getSchedulerIntervalMs ( ) const
inlineprotected

Get scheduler interval in milliseconds.

◆ getService()

template<typename ClientType >
DLNAServiceInfo & tiny_dlna::DLNADevice< ClientType >::getService ( const char *  id)
inlineoverridevirtual

Provide addess to the service information.

Implements tiny_dlna::IDevice.

◆ getServiceByAbbrev()

template<typename ClientType >
DLNAServiceInfo & tiny_dlna::DLNADevice< ClientType >::getServiceByAbbrev ( const char *  abbrev)
inlineoverridevirtual

Get Service by subscription ns abbrev.

Implements tiny_dlna::IDevice.

◆ getServiceByEventPath()

template<typename ClientType >
DLNAServiceInfo * tiny_dlna::DLNADevice< ClientType >::getServiceByEventPath ( const char *  requestPath)
inlineoverridevirtual

Find a service by its event subscription URL (returns nullptr if not found). This encapsulates the lookup that was previously done inline in the static subscription handler.

Implements tiny_dlna::IDevice.

◆ getSubscriptionMgr()

template<typename ClientType >
ISubscriptionMgrDevice & tiny_dlna::DLNADevice< ClientType >::getSubscriptionMgr ( )
inlineoverridevirtual

Get subscription manager for event handling.

Implements tiny_dlna::IDevice.

◆ getSubscriptionsIntervalMs()

template<typename ClientType >
uint32_t tiny_dlna::DLNADevice< ClientType >::getSubscriptionsIntervalMs ( ) const
inlineprotected

Get subscription publish interval in milliseconds.

◆ handleSubscribe()

template<typename ClientType >
static bool tiny_dlna::DLNADevice< ClientType >::handleSubscribe ( IHttpServer server,
const char *  requestPath,
HttpRequestHandlerLine hl 
)
inlinestaticprotected

Handle SUBSCRIBE requests.

◆ handleSubscription()

template<typename ClientType >
static bool tiny_dlna::DLNADevice< ClientType >::handleSubscription ( IHttpServer server,
const char *  requestPath,
HttpRequestHandlerLine hl,
bool &  is_subscribe 
)
inlinestatic

Static handler for SUBSCRIBE/UNSUBSCRIBE requests on service event URLs.

◆ handleUnsubscribe()

template<typename ClientType >
static bool tiny_dlna::DLNADevice< ClientType >::handleUnsubscribe ( IHttpServer server,
const char *  requestPath,
HttpRequestHandlerLine hl 
)
inlinestaticprotected

Handle UNSUBSCRIBE requests.

◆ isSchedulerActive()

template<typename ClientType >
bool tiny_dlna::DLNADevice< ClientType >::isSchedulerActive ( )
inlineoverridevirtual

Checks if the scheduler is active.

Implements tiny_dlna::IDevice.

◆ isSubscriptionsActive()

template<typename ClientType >
bool tiny_dlna::DLNADevice< ClientType >::isSubscriptionsActive ( ) const
inlineoverridevirtual

Check if subscription notifications are active.

Implements tiny_dlna::IDevice.

◆ logScheduledStatus()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::logScheduledStatus ( bool  runImmediately = false)
inlineprotected

Periodic platform-specific diagnostics. Kept as a separate method so it can be tested or stubbed easily. Currently logs ESP32 heap/psram every 10s.

◆ logStatus()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::logStatus ( )
inline

◆ loop()

template<typename ClientType >
bool tiny_dlna::DLNADevice< ClientType >::loop ( int  loopAction = RUN_ALL)
inlineoverridevirtual

Call this method in the Arduino loop as often as possible. It calls loopServer, loopUDP and loopPublishSubscriptions in defined intervals..

Implements tiny_dlna::IDevice.

◆ loopPublishSubscriptions()

template<typename ClientType >
int tiny_dlna::DLNADevice< ClientType >::loopPublishSubscriptions ( )
inline

Publish pending subscription notifications.

◆ loopServer()

template<typename ClientType >
bool tiny_dlna::DLNADevice< ClientType >::loopServer ( )
inlineoverridevirtual

Process http server loop.

Implements tiny_dlna::IDevice.

◆ loopUDPMessages()

template<typename ClientType >
int tiny_dlna::DLNADevice< ClientType >::loopUDPMessages ( )
inline

Process incoming UDP and execute scheduled replies.

◆ parseActionRequest()

template<typename ClientType >
static void tiny_dlna::DLNADevice< ClientType >::parseActionRequest ( IHttpServer server,
const char *  requestPath,
HttpRequestHandlerLine hl,
ActionRequest action 
)
inlinestatic

Parses the SOAP content of a DLNA action request.

◆ printReplyXML()

template<typename ClientType >
static size_t tiny_dlna::DLNADevice< ClientType >::printReplyXML ( Print &  out,
const char *  replyName,
const char *  serviceId,
std::function< size_t(Print &, void *)>  valuesWriter = nullptr,
void *  ref = nullptr 
)
inlinestatic

Builds a standard SOAP reply envelope.

This helper prints a SOAP envelope and calls the provided valuesWriter to emit the inner XML fragment. The valuesWriter receives the output Print and a void* ref for caller-provided context and shall return the number of bytes written.

◆ replyGetCurrentConnectionIDs()

template<typename ClientType >
static size_t tiny_dlna::DLNADevice< ClientType >::replyGetCurrentConnectionIDs ( Print &  out,
const char *  ids 
)
inlinestatic

◆ replyGetCurrentConnectionInfo()

template<typename ClientType >
static size_t tiny_dlna::DLNADevice< ClientType >::replyGetCurrentConnectionInfo ( Print &  out,
const char *  protocolInfo,
const char *  connectionID,
const char *  direction 
)
inlinestatic

◆ replyGetProtocolInfo()

template<typename ClientType >
static size_t tiny_dlna::DLNADevice< ClientType >::replyGetProtocolInfo ( Print &  out,
const char *  source = "",
const char *  sink = "" 
)
inlinestatic

Parameterized variants that allow callers to pass dynamic values from devices (e.g. source/sink protocol lists or current connection IDs).

◆ setDeviceInfo()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::setDeviceInfo ( DLNADeviceInfo device)
inlineprotected

◆ setPostAliveRepeatMs()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::setPostAliveRepeatMs ( uint32_t  ms)
inlineoverridevirtual

Repeat the post-alive messages (default: 0 = no repeat). Call this method before calling begin!

Implements tiny_dlna::IDevice.

◆ setReference()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::setReference ( void *  ref)
inlineoverridevirtual

Sets a reference pointer that can be used to associate application.

Implements tiny_dlna::IDevice.

◆ setSchedulerActive()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::setSchedulerActive ( bool  flag)
inlineoverridevirtual

We can activate/deactivate the scheduler.

Implements tiny_dlna::IDevice.

◆ setSchedulerIntervalMs()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::setSchedulerIntervalMs ( uint32_t  ms)
inlineprotected

Set scheduler interval in milliseconds.

◆ setSubscriptionsActive()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::setSubscriptionsActive ( bool  flag)
inlineoverridevirtual

Enable or disable subscription notifications: call before begin.

Implements tiny_dlna::IDevice.

◆ setSubscriptionsIntervalMs()

template<typename ClientType >
void tiny_dlna::DLNADevice< ClientType >::setSubscriptionsIntervalMs ( uint32_t  ms)
inlineprotected

Set subscription publish interval in milliseconds.

◆ setupDLNAServer()

template<typename ClientType >
virtual bool tiny_dlna::DLNADevice< ClientType >::setupDLNAServer ( IHttpServer srv)
inlineprotectedvirtual

set up Web Server to handle Service Addresses

◆ setupParser()

template<typename ClientType >
bool tiny_dlna::DLNADevice< ClientType >::setupParser ( )
inlineprotected

MSearch requests reply to upnp:rootdevice and the device type defined in the device

◆ setupScheduler()

template<typename ClientType >
bool tiny_dlna::DLNADevice< ClientType >::setupScheduler ( )
inlineprotected

Schedule PostAlive messages.

◆ validateServiceInfo()

template<typename ClientType >
bool tiny_dlna::DLNADevice< ClientType >::validateServiceInfo ( const DLNAServiceInfo service)
inlineprotected

Validates that all required service URLs and callbacks are defined.

Member Data Documentation

◆ is_active

template<typename ClientType >
bool tiny_dlna::DLNADevice< ClientType >::is_active = false
protected

◆ is_subscriptions_active

template<typename ClientType >
bool tiny_dlna::DLNADevice< ClientType >::is_subscriptions_active = true
protected

◆ next_scheduler_timeout_ms

template<typename ClientType >
uint64_t tiny_dlna::DLNADevice< ClientType >::next_scheduler_timeout_ms = 0
protected

◆ next_subscriptions_timeout_ms

template<typename ClientType >
uint64_t tiny_dlna::DLNADevice< ClientType >::next_subscriptions_timeout_ms = 0
protected

◆ p_device_info

template<typename ClientType >
DLNADeviceInfo* tiny_dlna::DLNADevice< ClientType >::p_device_info = nullptr
protected

◆ p_server

template<typename ClientType >
IHttpServer* tiny_dlna::DLNADevice< ClientType >::p_server = nullptr
protected

◆ p_udp

template<typename ClientType >
IUDPService* tiny_dlna::DLNADevice< ClientType >::p_udp = nullptr
protected

◆ parser

template<typename ClientType >
DLNADeviceRequestParser tiny_dlna::DLNADevice< ClientType >::parser
protected

◆ post_alive_repeat_ms

template<typename ClientType >
uint32_t tiny_dlna::DLNADevice< ClientType >::post_alive_repeat_ms = 0
protected

◆ reference

template<typename ClientType >
void* tiny_dlna::DLNADevice< ClientType >::reference = nullptr
protected

◆ scheduler

template<typename ClientType >
Scheduler tiny_dlna::DLNADevice< ClientType >::scheduler
protected

◆ scheduler_interval_ms

template<typename ClientType >
uint64_t tiny_dlna::DLNADevice< ClientType >::scheduler_interval_ms = (uint64_t)DLNA_RUN_SCHEDULER_EVERY_MS
protected

◆ subscription_mgr

template<typename ClientType >
SubscriptionMgrDevice<ClientType> tiny_dlna::DLNADevice< ClientType >::subscription_mgr
protected

◆ subscriptions_interval_ms

template<typename ClientType >
uint64_t tiny_dlna::DLNADevice< ClientType >::subscriptions_interval_ms
protected
Initial value:
=
#define DLNA_RUN_SUBSCRIPTIONS_EVERY_MS
Define subscription publish interval in ms.
Definition: dlna_config.h:15

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