Arduino DLNA Server
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tiny_dlna::DLNAControlPoint Class Reference

Lightweight DLNA control point manager. More...

#include <DLNAControlPoint.h>

Inheritance diagram for tiny_dlna::DLNAControlPoint:
Inheritance graph
[legend]

Public Member Functions

 DLNAControlPoint ()
 Default constructor w/o Notifications.
 
 DLNAControlPoint (IHttpRequest &http, IUDPService &udp)
 Constructor wiring HTTP and UDP dependencies; notifications disabled.
 
 DLNAControlPoint (IHttpRequest &http, IUDPService &udp, IHttpServer &server)
 Constructor wiring HTTP and UDP dependencies; notifications disabled.
 
 DLNAControlPoint (IHttpServer &server)
 Constructor supporting Notifications.
 
 ~DLNAControlPoint () override=default
 
void setParseDevice (bool flag) override
 Requests the parsing of the device information.
 
void setLocalURL (Url url) override
 Defines the local url (needed for subscriptions)
 
void setLocalURL (IPAddress url, int port=9001, const char *path="") override
 Set the local callback URL for event subscriptions.
 
void setSearchRepeatMs (int repeatMs) override
 Sets the repeat interval for M-SEARCH requests (define before begin)
 
void setReference (void *ref) override
 Attach an opaque reference pointer (optional, for caller context)
 
void setDeviceIndex (int idx) override
 Selects the default device by index.
 
void setEventSubscriptionCallback (std::function< void(const char *sid, const char *varName, const char *newValue, void *reference)> cb, void *ref=nullptr) override
 Register a callback that will be invoked for incoming event notification.
 
void setHttpServer (IHttpServer &server) override
 Set HttpServer instance and register the notify handler.
 
void onResultNode (std::function< void(const char *nodeName, const char *text, const char *attributes)> cb) override
 
bool begin (const char *searchTarget="ssdp:all", uint32_t minWaitMs=3000, uint32_t maxWaitMs=60000) override
 Start discovery with default HTTP/UDP services.
 
bool begin (IHttpRequest &http, IUDPService &udp, const char *searchTarget="ssdp:all", uint32_t minWaitMs=3000, uint32_t maxWaitMs=60000) override
 Start discovery by sending M-SEARCH requests and process replies.
 
void setTransports (IHttpRequest &http, IUDPService &udp)
 
void end () override
 Stops the processing and releases the resources.
 
ActionRequestaddAction (ActionRequest act) override
 Registers a method that will be called.
 
ActionReplyexecuteActions (XMLCallback xmlProcessor=nullptr) override
 Executes action and parses the reply xml to collect the reply entries. If an XML processor is provided it will be used to process the reply XML instead of the standard processing: This can be useful for large replies where we do not want to store the big data chunks.
 
bool loop () override
 
DLNAServiceInfogetService (const char *id) override
 Provide addess to the service information.
 
DLNADeviceInfogetDevice () override
 Provides the device information of the actually selected device.
 
DLNADeviceInfogetDevice (int idx) override
 Provides the device information by index.
 
DLNADeviceInfogetDevice (DLNAServiceInfo &service) override
 Provides the device for a service.
 
DLNADeviceInfogetDevice (Url location) override
 Get a device for a Url.
 
Vector< DLNADeviceInfo > & getDevices () override
 Get list of all discovered devices.
 
const char * getUrl (DLNADeviceInfo &device, const char *suffix, char *buffer, int len) override
 
bool addDevice (DLNADeviceInfo dev) override
 Adds a new device.
 
bool addDevice (Url url) override
 Adds the device from the device xml url if it does not already exist.
 
void setActive (bool flag) override
 We can activate/deactivate the scheduler.
 
bool isActive () override
 Checks if the scheduler is active.
 
void setAllowLocalhost (bool flag) override
 Defines if localhost devices should be allowed.
 
ActionReplygetLastReply () override
 Provides the last reply.
 
SubscriptionMgrControlPointgetSubscriptionMgr () override
 Provides the subscription manager.
 
void setSubscribeNotificationsActive (bool flag) override
 Activate/deactivate subscription notifications.
 
const char * registerString (const char *s) override
 Register a string in the shared registry and return the stored pointer.
 

Protected Member Functions

bool isDiscoveryAllowed (Url &url)
 
bool matches (const char *usn)
 checks if the usn contains the search target
 
bool processBye (Str &usn)
 processes a bye-bye message
 
size_t createXML (ActionRequest &action)
 
ActionReplypostAllActions (XMLCallback xmlProcessor=nullptr)
 
ActionReplypostAction (ActionRequest &action, XMLCallback xmlProcessor=nullptr)
 
size_t createSoapXML (ActionRequest &action, Print &out)
 Build the SOAP XML request body for the action into out
 
ActionReplyprocessActionHttpPost (ActionRequest &action, Url &post_url, const char *soapAction, XMLCallback xmlProcessor=nullptr)
 Processes an HTTP POST request for the given action and URL.
 
void parseResult ()
 Parses the XML response from the HTTP client and populates reply arguments.
 
void unEscapeStr (Str &str)
 
const char * getUrlImpl (DLNADeviceInfo &device, const char *suffix, const char *buffer, int len)
 

Static Protected Member Functions

static bool handleNotifyByebye (Str &usn)
 
static bool isUdnKnown (const char *usn_c, DLNADeviceInfo *&outDev)
 
static bool handleNotifyAlive (NotifyReplyCP &data)
 
static bool processDevice (NotifyReplyCP &data)
 
static bool processMSearchReply (MSearchReplyCP &data)
 Processes an M-SEARCH HTTP 200 reply and attempts to add the device.
 

Protected Attributes

DLNADeviceInfo NO_DEVICE {false}
 
Scheduler scheduler
 
IHttpRequestp_http = nullptr
 
IUDPServicep_udp = nullptr
 
SubscriptionMgrControlPoint subscription_mgr
 
Vector< DLNADeviceInfodevices
 
Vector< ActionRequestactions
 
ActionReply reply
 
XMLPrinter xml_printer
 
int default_device_idx = 0
 
int msearch_repeat_ms = 10000
 
bool is_active = false
 
bool is_parse_device = false
 
const char * search_target
 
Url local_url
 
bool allow_localhost = false
 
IHttpServerp_http_server = nullptr
 
void * reference = nullptr
 
std::function< void(const char *nodeName, const char *text, const char *attributes)> result_callback
 

Detailed Description

Lightweight DLNA control point manager.

This class implements a compact, embeddable DLNA/UPnP control point suitable for small devices and emulators. It provides the core responsibilities a control point needs in order to discover devices, subscribe to service events, and invoke actions on services:

Notes and usage:

The class is intentionally small and avoids dynamic STL-heavy constructs so it can run in constrained environments. It is not a full-featured UPnP stack but provides the common features required by many DLNA control point use cases.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ DLNAControlPoint() [1/4]

tiny_dlna::DLNAControlPoint::DLNAControlPoint ( )
inline

Default constructor w/o Notifications.

◆ DLNAControlPoint() [2/4]

tiny_dlna::DLNAControlPoint::DLNAControlPoint ( IHttpRequest http,
IUDPService udp 
)
inline

Constructor wiring HTTP and UDP dependencies; notifications disabled.

◆ DLNAControlPoint() [3/4]

tiny_dlna::DLNAControlPoint::DLNAControlPoint ( IHttpRequest http,
IUDPService udp,
IHttpServer server 
)
inline

Constructor wiring HTTP and UDP dependencies; notifications disabled.

◆ DLNAControlPoint() [4/4]

tiny_dlna::DLNAControlPoint::DLNAControlPoint ( IHttpServer server)
inline

Constructor supporting Notifications.

◆ ~DLNAControlPoint()

tiny_dlna::DLNAControlPoint::~DLNAControlPoint ( )
overridedefault

Member Function Documentation

◆ addAction()

ActionRequest & tiny_dlna::DLNAControlPoint::addAction ( ActionRequest  act)
inlineoverridevirtual

Registers a method that will be called.

Implements tiny_dlna::IControlPoint.

◆ addDevice() [1/2]

bool tiny_dlna::DLNAControlPoint::addDevice ( DLNADeviceInfo  dev)
inlineoverridevirtual

Adds a new device.

Implements tiny_dlna::IControlPoint.

◆ addDevice() [2/2]

bool tiny_dlna::DLNAControlPoint::addDevice ( Url  url)
inlineoverridevirtual

Adds the device from the device xml url if it does not already exist.

Implements tiny_dlna::IControlPoint.

◆ begin() [1/2]

bool tiny_dlna::DLNAControlPoint::begin ( const char *  searchTarget = "ssdp:all",
uint32_t  minWaitMs = 3000,
uint32_t  maxWaitMs = 60000 
)
inlineoverridevirtual

Start discovery with default HTTP/UDP services.

Implements tiny_dlna::IControlPoint.

◆ begin() [2/2]

bool tiny_dlna::DLNAControlPoint::begin ( IHttpRequest http,
IUDPService udp,
const char *  searchTarget = "ssdp:all",
uint32_t  minWaitMs = 3000,
uint32_t  maxWaitMs = 60000 
)
inlineoverridevirtual

Start discovery by sending M-SEARCH requests and process replies.

searchTarget: the SSDP search target (e.g. "ssdp:all", device/service urn) minWaitMs: minimum time in milliseconds to wait before returning a result (default: 3000 ms) maxWaitMs: maximum time in milliseconds to wait for replies (M-SEARCH window) (default: 60000 ms) Behavior: the function will wait at least minWaitMs and at most maxWaitMs. If a device is discovered after minWaitMs elapsed the function will return early; otherwise it will block until maxWaitMs.

Implements tiny_dlna::IControlPoint.

◆ createSoapXML()

size_t tiny_dlna::DLNAControlPoint::createSoapXML ( ActionRequest action,
Print &  out 
)
inlineprotected

Build the SOAP XML request body for the action into out

◆ createXML()

size_t tiny_dlna::DLNAControlPoint::createXML ( ActionRequest action)
inlineprotected

Creates the Action Soap XML request. E.g "<?xml version=\"1.0\"?>\r\n" "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n" "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" "<s:Body>\r\n" "<u:SetTarget " "xmlns:u=\"urn:schemas-upnp-org:service:SwitchPower:1\">\r\n" "<newTargetValue>1</newTargetValue>\r\n" "</u:SetTarget>\r\n" "</s:Body>\r\n" "</s:Envelope>\r\n";

◆ end()

void tiny_dlna::DLNAControlPoint::end ( )
inlineoverridevirtual

Stops the processing and releases the resources.

Implements tiny_dlna::IControlPoint.

◆ executeActions()

ActionReply & tiny_dlna::DLNAControlPoint::executeActions ( XMLCallback  xmlProcessor = nullptr)
inlineoverridevirtual

Executes action and parses the reply xml to collect the reply entries. If an XML processor is provided it will be used to process the reply XML instead of the standard processing: This can be useful for large replies where we do not want to store the big data chunks.

Parameters
xmlProcessorOptional XML processor callback

Implements tiny_dlna::IControlPoint.

◆ getDevice() [1/4]

DLNADeviceInfo & tiny_dlna::DLNAControlPoint::getDevice ( )
inlineoverridevirtual

Provides the device information of the actually selected device.

Implements tiny_dlna::IControlPoint.

◆ getDevice() [2/4]

DLNADeviceInfo & tiny_dlna::DLNAControlPoint::getDevice ( DLNAServiceInfo service)
inlineoverridevirtual

Provides the device for a service.

Implements tiny_dlna::IControlPoint.

◆ getDevice() [3/4]

DLNADeviceInfo & tiny_dlna::DLNAControlPoint::getDevice ( int  idx)
inlineoverridevirtual

Provides the device information by index.

Implements tiny_dlna::IControlPoint.

◆ getDevice() [4/4]

DLNADeviceInfo & tiny_dlna::DLNAControlPoint::getDevice ( Url  location)
inlineoverridevirtual

Get a device for a Url.

Implements tiny_dlna::IControlPoint.

◆ getDevices()

Vector< DLNADeviceInfo > & tiny_dlna::DLNAControlPoint::getDevices ( )
inlineoverridevirtual

Get list of all discovered devices.

Implements tiny_dlna::IControlPoint.

◆ getLastReply()

ActionReply & tiny_dlna::DLNAControlPoint::getLastReply ( )
inlineoverridevirtual

Provides the last reply.

Implements tiny_dlna::IControlPoint.

◆ getService()

DLNAServiceInfo & tiny_dlna::DLNAControlPoint::getService ( const char *  id)
inlineoverridevirtual

Provide addess to the service information.

Implements tiny_dlna::IControlPoint.

◆ getSubscriptionMgr()

SubscriptionMgrControlPoint * tiny_dlna::DLNAControlPoint::getSubscriptionMgr ( )
inlineoverridevirtual

Provides the subscription manager.

Implements tiny_dlna::IControlPoint.

◆ getUrl()

const char * tiny_dlna::DLNAControlPoint::getUrl ( DLNADeviceInfo device,
const char *  suffix,
char *  buffer,
int  len 
)
inlineoverridevirtual

Public wrapper to build a fully-qualified URL for a device + suffix. This calls the protected getUrl() helper so external helpers can reuse the control point's URL normalization logic without exposing the internal protected method directly.

Implements tiny_dlna::IControlPoint.

◆ getUrlImpl()

const char * tiny_dlna::DLNAControlPoint::getUrlImpl ( DLNADeviceInfo device,
const char *  suffix,
const char *  buffer,
int  len 
)
inlineprotected

◆ handleNotifyAlive()

static bool tiny_dlna::DLNAControlPoint::handleNotifyAlive ( NotifyReplyCP data)
inlinestaticprotected

◆ handleNotifyByebye()

static bool tiny_dlna::DLNAControlPoint::handleNotifyByebye ( Str usn)
inlinestaticprotected

Processes a NotifyReplyCP message Note: split into smaller helpers for clarity and testability.

◆ isActive()

bool tiny_dlna::DLNAControlPoint::isActive ( )
inlineoverridevirtual

Checks if the scheduler is active.

Implements tiny_dlna::IControlPoint.

◆ isDiscoveryAllowed()

bool tiny_dlna::DLNAControlPoint::isDiscoveryAllowed ( Url url)
inlineprotected

◆ isUdnKnown()

static bool tiny_dlna::DLNAControlPoint::isUdnKnown ( const char *  usn_c,
DLNADeviceInfo *&  outDev 
)
inlinestaticprotected

Returns true and sets outDev if a device with the UDN part of usn_c is already present in the device list.

◆ loop()

bool tiny_dlna::DLNAControlPoint::loop ( )
inlineoverridevirtual

call this method in the Arduino loop as often as possible: the processes all replys

Implements tiny_dlna::IControlPoint.

◆ matches()

bool tiny_dlna::DLNAControlPoint::matches ( const char *  usn)
inlineprotected

checks if the usn contains the search target

◆ onResultNode()

void tiny_dlna::DLNAControlPoint::onResultNode ( std::function< void(const char *nodeName, const char *text, const char *attributes)>  cb)
inlineoverridevirtual

Register a callback that will be invoked when parsing SOAP/Action results Signature: void(const char* nodeName, const char* text, const char* attributes)

Implements tiny_dlna::IControlPoint.

◆ parseResult()

void tiny_dlna::DLNAControlPoint::parseResult ( )
inlineprotected

Parses the XML response from the HTTP client and populates reply arguments.

Parameters
xml_parserXMLParserPrint instance for parsing
bufferTemporary buffer for reading client data

◆ postAction()

ActionReply & tiny_dlna::DLNAControlPoint::postAction ( ActionRequest action,
XMLCallback  xmlProcessor = nullptr 
)
inlineprotected

◆ postAllActions()

ActionReply & tiny_dlna::DLNAControlPoint::postAllActions ( XMLCallback  xmlProcessor = nullptr)
inlineprotected

◆ processActionHttpPost()

ActionReply & tiny_dlna::DLNAControlPoint::processActionHttpPost ( ActionRequest action,
Url post_url,
const char *  soapAction,
XMLCallback  xmlProcessor = nullptr 
)
inlineprotected

Processes an HTTP POST request for the given action and URL.

◆ processBye()

bool tiny_dlna::DLNAControlPoint::processBye ( Str usn)
inlineprotected

processes a bye-bye message

◆ processDevice()

static bool tiny_dlna::DLNAControlPoint::processDevice ( NotifyReplyCP data)
inlinestaticprotected

◆ processMSearchReply()

static bool tiny_dlna::DLNAControlPoint::processMSearchReply ( MSearchReplyCP data)
inlinestaticprotected

Processes an M-SEARCH HTTP 200 reply and attempts to add the device.

◆ registerString()

const char * tiny_dlna::DLNAControlPoint::registerString ( const char *  s)
inlineoverridevirtual

Register a string in the shared registry and return the stored pointer.

Implements tiny_dlna::IControlPoint.

◆ setActive()

void tiny_dlna::DLNAControlPoint::setActive ( bool  flag)
inlineoverridevirtual

We can activate/deactivate the scheduler.

Implements tiny_dlna::IControlPoint.

◆ setAllowLocalhost()

void tiny_dlna::DLNAControlPoint::setAllowLocalhost ( bool  flag)
inlineoverridevirtual

Defines if localhost devices should be allowed.

Implements tiny_dlna::IControlPoint.

◆ setDeviceIndex()

void tiny_dlna::DLNAControlPoint::setDeviceIndex ( int  idx)
inlineoverridevirtual

Selects the default device by index.

Implements tiny_dlna::IControlPoint.

◆ setEventSubscriptionCallback()

void tiny_dlna::DLNAControlPoint::setEventSubscriptionCallback ( std::function< void(const char *sid, const char *varName, const char *newValue, void *reference)>  cb,
void *  ref = nullptr 
)
inlineoverridevirtual

Register a callback that will be invoked for incoming event notification.

Implements tiny_dlna::IControlPoint.

◆ setHttpServer()

void tiny_dlna::DLNAControlPoint::setHttpServer ( IHttpServer server)
inlineoverridevirtual

Set HttpServer instance and register the notify handler.

Implements tiny_dlna::IControlPoint.

◆ setLocalURL() [1/2]

void tiny_dlna::DLNAControlPoint::setLocalURL ( IPAddress  url,
int  port = 9001,
const char *  path = "" 
)
inlineoverridevirtual

Set the local callback URL for event subscriptions.

Implements tiny_dlna::IControlPoint.

◆ setLocalURL() [2/2]

void tiny_dlna::DLNAControlPoint::setLocalURL ( Url  url)
inlineoverridevirtual

Defines the local url (needed for subscriptions)

Implements tiny_dlna::IControlPoint.

◆ setParseDevice()

void tiny_dlna::DLNAControlPoint::setParseDevice ( bool  flag)
inlineoverridevirtual

Requests the parsing of the device information.

Implements tiny_dlna::IControlPoint.

◆ setReference()

void tiny_dlna::DLNAControlPoint::setReference ( void *  ref)
inlineoverridevirtual

Attach an opaque reference pointer (optional, for caller context)

Implements tiny_dlna::IControlPoint.

◆ setSearchRepeatMs()

void tiny_dlna::DLNAControlPoint::setSearchRepeatMs ( int  repeatMs)
inlineoverridevirtual

Sets the repeat interval for M-SEARCH requests (define before begin)

Implements tiny_dlna::IControlPoint.

◆ setSubscribeNotificationsActive()

void tiny_dlna::DLNAControlPoint::setSubscribeNotificationsActive ( bool  flag)
inlineoverridevirtual

Activate/deactivate subscription notifications.

Implements tiny_dlna::IControlPoint.

◆ setTransports()

void tiny_dlna::DLNAControlPoint::setTransports ( IHttpRequest http,
IUDPService udp 
)
inline

◆ unEscapeStr()

void tiny_dlna::DLNAControlPoint::unEscapeStr ( Str str)
inlineprotected

Member Data Documentation

◆ actions

Vector<ActionRequest> tiny_dlna::DLNAControlPoint::actions
protected

◆ allow_localhost

bool tiny_dlna::DLNAControlPoint::allow_localhost = false
protected

◆ default_device_idx

int tiny_dlna::DLNAControlPoint::default_device_idx = 0
protected

◆ devices

Vector<DLNADeviceInfo> tiny_dlna::DLNAControlPoint::devices
protected

◆ is_active

bool tiny_dlna::DLNAControlPoint::is_active = false
protected

◆ is_parse_device

bool tiny_dlna::DLNAControlPoint::is_parse_device = false
protected

◆ local_url

Url tiny_dlna::DLNAControlPoint::local_url
protected

◆ msearch_repeat_ms

int tiny_dlna::DLNAControlPoint::msearch_repeat_ms = 10000
protected

◆ NO_DEVICE

DLNADeviceInfo tiny_dlna::DLNAControlPoint::NO_DEVICE {false}
protected

◆ p_http

IHttpRequest* tiny_dlna::DLNAControlPoint::p_http = nullptr
protected

◆ p_http_server

IHttpServer* tiny_dlna::DLNAControlPoint::p_http_server = nullptr
protected

◆ p_udp

IUDPService* tiny_dlna::DLNAControlPoint::p_udp = nullptr
protected

◆ reference

void* tiny_dlna::DLNAControlPoint::reference = nullptr
protected

◆ reply

ActionReply tiny_dlna::DLNAControlPoint::reply
protected

◆ result_callback

std::function<void(const char* nodeName, const char* text, const char* attributes)> tiny_dlna::DLNAControlPoint::result_callback
protected

◆ scheduler

Scheduler tiny_dlna::DLNAControlPoint::scheduler
protected

◆ search_target

const char* tiny_dlna::DLNAControlPoint::search_target
protected

◆ subscription_mgr

SubscriptionMgrControlPoint tiny_dlna::DLNAControlPoint::subscription_mgr
protected

◆ xml_printer

XMLPrinter tiny_dlna::DLNAControlPoint::xml_printer
protected

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