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::DLNAControlPointMgr Class Reference

Lightweight DLNA control point manager. More...

#include <DLNAControlPointMgr.h>

Collaboration diagram for tiny_dlna::DLNAControlPointMgr:
Collaboration graph
[legend]

Public Member Functions

 DLNAControlPointMgr ()
 Default constructor w/o Notifications.
 
 DLNAControlPointMgr (HttpServer &server, int port=80)
 Constructor supporting Notifications.
 
void setParseDevice (bool flag)
 Requests the parsing of the device information.
 
void setLocalURL (Url url)
 Defines the local url (needed for subscriptions)
 
void setSearchRepeatMs (int repeatMs)
 Sets the repeat interval for M-SEARCH requests (define before begin)
 
bool begin (DLNAHttpRequest &http, IUDPService &udp, const char *searchTarget="ssdp:all", uint32_t minWaitMs=3000, uint32_t maxWaitMs=60000)
 Start discovery by sending M-SEARCH requests and process replies.
 
void end ()
 Stops the processing and releases the resources.
 
ActionRequestaddAction (ActionRequest act)
 Registers a method that will be called.
 
ActionReplyexecuteActions ()
 Executes all registered methods.
 
bool subscribeNotifications (DLNADeviceInfo &device, int timeoutSeconds=60)
 Subscribe to changes for all device services.
 
bool subscribeNotifications (DLNAServiceInfo &service, int timoutSeconds=60)
 Subscribe to changes for defined device service.
 
void onNotification (std::function< void(void *reference, const char *sid, const char *varName, const char *newValue)> cb)
 Register a callback that will be invoked for incoming event notification.
 
void setReference (void *ref)
 Attach an opaque reference pointer (optional, for caller context)
 
void setHttpServer (HttpServer &server, int port=80)
 Set HttpServer instance and register the notify handler.
 
bool loop ()
 
DLNAServiceInfogetService (const char *id)
 Provide addess to the service information.
 
DLNADeviceInfogetDevice (int deviceIdx=0)
 Provides the device information by index.
 
DLNADeviceInfogetDevice (DLNAServiceInfo &service)
 Provides the device for a service.
 
DLNADeviceInfogetDevice (Url location)
 Get a device for a Url.
 
Vector< DLNADeviceInfo > & getDevices ()
 
bool addDevice (DLNADeviceInfo dev)
 Adds a new device.
 
bool addDevice (Url url)
 Adds the device from the device xml url if it does not already exist.
 
void setActive (bool flag)
 We can activate/deactivate the scheduler.
 
bool isActive ()
 Checks if the scheduler is active.
 

Protected Member Functions

void attachHttpServer (HttpServer &server)
 
void parseAndDispatchEvent (NotifyReplyCP &data)
 Parse the xml content of a NotifyReplyCP and dispatch each property.
 
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)
 
ActionReplygetLastReply ()
 
ActionReplypostAllActions ()
 
ActionReplypostAction (ActionRequest &action)
 
void buildActionBody (ActionRequest &action, StrPrint &out)
 Build the SOAP XML request body for the action into out
 
ActionReplyprocessActionHttpPost (Url &post_url, StrPrint &requestBody, const char *soapAction)
 
const char * getUrl (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

Scheduler scheduler
 
DLNAHttpRequestp_http = nullptr
 
IUDPServicep_udp = nullptr
 
Vector< DLNADeviceInfodevices
 
Vector< ActionRequestactions
 
ActionReply reply
 
XMLPrinter xml
 
int msearch_repeat_ms = 10000
 
bool is_active = false
 
bool is_parse_device = false
 
DLNADeviceInfo NO_DEVICE {false}
 
const char * search_target
 
StringRegistry strings
 
Url local_url
 
HttpServerp_http_server = nullptr
 
int http_server_port = 0
 
void * reference = nullptr
 
std::function< void(void *reference, const char *sid, const char *varName, const char *newValue)> eventCallback
 

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

◆ DLNAControlPointMgr() [1/2]

tiny_dlna::DLNAControlPointMgr::DLNAControlPointMgr ( )
inline

Default constructor w/o Notifications.

◆ DLNAControlPointMgr() [2/2]

tiny_dlna::DLNAControlPointMgr::DLNAControlPointMgr ( HttpServer server,
int  port = 80 
)
inline

Constructor supporting Notifications.

Member Function Documentation

◆ addAction()

ActionRequest & tiny_dlna::DLNAControlPointMgr::addAction ( ActionRequest  act)
inline

Registers a method that will be called.

◆ addDevice() [1/2]

bool tiny_dlna::DLNAControlPointMgr::addDevice ( DLNADeviceInfo  dev)
inline

Adds a new device.

◆ addDevice() [2/2]

bool tiny_dlna::DLNAControlPointMgr::addDevice ( Url  url)
inline

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

◆ attachHttpServer()

void tiny_dlna::DLNAControlPointMgr::attachHttpServer ( HttpServer server)
inlineprotected

Attach an HttpServer so the control point can receive HTTP NOTIFY event messages. This registers a handler at the configured local URL path (see local_url) which will extract the SID header and body and call parseAndDispatchEvent() to dispatch property changes.

◆ begin()

bool tiny_dlna::DLNAControlPointMgr::begin ( DLNAHttpRequest http,
IUDPService udp,
const char *  searchTarget = "ssdp:all",
uint32_t  minWaitMs = 3000,
uint32_t  maxWaitMs = 60000 
)
inline

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.

◆ buildActionBody()

void tiny_dlna::DLNAControlPointMgr::buildActionBody ( ActionRequest action,
StrPrint out 
)
inlineprotected

Build the SOAP XML request body for the action into out

◆ createXML()

size_t tiny_dlna::DLNAControlPointMgr::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::DLNAControlPointMgr::end ( )
inline

Stops the processing and releases the resources.

◆ executeActions()

ActionReply & tiny_dlna::DLNAControlPointMgr::executeActions ( )
inline

Executes all registered methods.

◆ getDevice() [1/3]

DLNADeviceInfo & tiny_dlna::DLNAControlPointMgr::getDevice ( DLNAServiceInfo service)
inline

Provides the device for a service.

◆ getDevice() [2/3]

DLNADeviceInfo & tiny_dlna::DLNAControlPointMgr::getDevice ( int  deviceIdx = 0)
inline

Provides the device information by index.

◆ getDevice() [3/3]

DLNADeviceInfo & tiny_dlna::DLNAControlPointMgr::getDevice ( Url  location)
inline

Get a device for a Url.

◆ getDevices()

Vector< DLNADeviceInfo > & tiny_dlna::DLNAControlPointMgr::getDevices ( )
inline

◆ getLastReply()

ActionReply & tiny_dlna::DLNAControlPointMgr::getLastReply ( )
inlineprotected

◆ getService()

DLNAServiceInfo & tiny_dlna::DLNAControlPointMgr::getService ( const char *  id)
inline

Provide addess to the service information.

◆ getUrl()

const char * tiny_dlna::DLNAControlPointMgr::getUrl ( DLNADeviceInfo device,
const char *  suffix,
const char *  buffer,
int  len 
)
inlineprotected

◆ handleNotifyAlive()

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

◆ handleNotifyByebye()

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

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

◆ isActive()

bool tiny_dlna::DLNAControlPointMgr::isActive ( )
inline

Checks if the scheduler is active.

◆ isUdnKnown()

static bool tiny_dlna::DLNAControlPointMgr::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::DLNAControlPointMgr::loop ( )
inline

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

◆ matches()

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

checks if the usn contains the search target

◆ onNotification()

void tiny_dlna::DLNAControlPointMgr::onNotification ( std::function< void(void *reference, const char *sid, const char *varName, const char *newValue)>  cb)
inline

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

◆ parseAndDispatchEvent()

void tiny_dlna::DLNAControlPointMgr::parseAndDispatchEvent ( NotifyReplyCP data)
inlineprotected

Parse the xml content of a NotifyReplyCP and dispatch each property.

◆ postAction()

ActionReply & tiny_dlna::DLNAControlPointMgr::postAction ( ActionRequest action)
inlineprotected

◆ postAllActions()

ActionReply & tiny_dlna::DLNAControlPointMgr::postAllActions ( )
inlineprotected

◆ processActionHttpPost()

ActionReply & tiny_dlna::DLNAControlPointMgr::processActionHttpPost ( Url post_url,
StrPrint requestBody,
const char *  soapAction 
)
inlineprotected

response body is written into responseOut (an XMLParserPrint). Returns the HTTP rc.

◆ processBye()

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

processes a bye-bye message

◆ processDevice()

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

◆ processMSearchReply()

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

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

◆ setActive()

void tiny_dlna::DLNAControlPointMgr::setActive ( bool  flag)
inline

We can activate/deactivate the scheduler.

◆ setHttpServer()

void tiny_dlna::DLNAControlPointMgr::setHttpServer ( HttpServer server,
int  port = 80 
)
inline

Set HttpServer instance and register the notify handler.

◆ setLocalURL()

void tiny_dlna::DLNAControlPointMgr::setLocalURL ( Url  url)
inline

Defines the local url (needed for subscriptions)

◆ setParseDevice()

void tiny_dlna::DLNAControlPointMgr::setParseDevice ( bool  flag)
inline

Requests the parsing of the device information.

◆ setReference()

void tiny_dlna::DLNAControlPointMgr::setReference ( void *  ref)
inline

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

◆ setSearchRepeatMs()

void tiny_dlna::DLNAControlPointMgr::setSearchRepeatMs ( int  repeatMs)
inline

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

◆ subscribeNotifications() [1/2]

bool tiny_dlna::DLNAControlPointMgr::subscribeNotifications ( DLNADeviceInfo device,
int  timeoutSeconds = 60 
)
inline

Subscribe to changes for all device services.

◆ subscribeNotifications() [2/2]

bool tiny_dlna::DLNAControlPointMgr::subscribeNotifications ( DLNAServiceInfo service,
int  timoutSeconds = 60 
)
inline

Subscribe to changes for defined device service.

Member Data Documentation

◆ actions

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

◆ devices

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

◆ eventCallback

std::function<void(void* reference, const char* sid, const char* varName, const char* newValue)> tiny_dlna::DLNAControlPointMgr::eventCallback
protected

◆ http_server_port

int tiny_dlna::DLNAControlPointMgr::http_server_port = 0
protected

◆ is_active

bool tiny_dlna::DLNAControlPointMgr::is_active = false
protected

◆ is_parse_device

bool tiny_dlna::DLNAControlPointMgr::is_parse_device = false
protected

◆ local_url

Url tiny_dlna::DLNAControlPointMgr::local_url
protected

◆ msearch_repeat_ms

int tiny_dlna::DLNAControlPointMgr::msearch_repeat_ms = 10000
protected

◆ NO_DEVICE

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

◆ p_http

DLNAHttpRequest* tiny_dlna::DLNAControlPointMgr::p_http = nullptr
protected

◆ p_http_server

HttpServer* tiny_dlna::DLNAControlPointMgr::p_http_server = nullptr
protected

◆ p_udp

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

◆ reference

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

◆ reply

ActionReply tiny_dlna::DLNAControlPointMgr::reply
protected

◆ scheduler

Scheduler tiny_dlna::DLNAControlPointMgr::scheduler
protected

◆ search_target

const char* tiny_dlna::DLNAControlPointMgr::search_target
protected

◆ strings

StringRegistry tiny_dlna::DLNAControlPointMgr::strings
protected

◆ xml

XMLPrinter tiny_dlna::DLNAControlPointMgr::xml
protected

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