|
Arduino DLNA Server
|
Lightweight DLNA control point manager. More...
#include <DLNAControlPoint.h>
Public Member Functions | |
| DLNAControlPoint () | |
| Default constructor w/o Notifications. | |
| DLNAControlPoint (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) | |
| void | setReference (void *ref) |
| Attach an opaque reference pointer (optional, for caller context) | |
| void | setDeviceIndex (int idx) |
| Selects the default device by index. | |
| void | setSubscribeInterval (int repeatSec=3600) |
| Activates event notification subscription with repeat interval in seconds. | |
| 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 | setHttpServer (HttpServer &server, int port=80) |
| Set HttpServer instance and register the notify handler. | |
| void | onResultNode (std::function< void(const char *nodeName, const char *text, const char *attributes)> cb) |
| 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. | |
| bool | subscribeNotifications () |
| Subscribes to event notifications for the selected device. | |
| void | end () |
| Stops the processing and releases the resources. | |
| ActionRequest & | addAction (ActionRequest act) |
| Registers a method that will be called. | |
| ActionReply & | executeActions () |
| Executes all registered methods. | |
| bool | loop () |
| DLNAServiceInfo & | getService (const char *id) |
| Provide addess to the service information. | |
| DLNADeviceInfo & | getDevice () |
| Provides the device information of the actually selected device. | |
| DLNADeviceInfo & | getDevice (int idx) |
| Provides the device information by index. | |
| DLNADeviceInfo & | getDevice (DLNAServiceInfo &service) |
| Provides the device for a service. | |
| DLNADeviceInfo & | getDevice (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. | |
| void | setAllowLocalhost (bool flag) |
| Defines if localhost devices should be allowed. | |
| ActionReply & | getLastReply () |
| Provides the last reply. | |
Protected Member Functions | |
| void | attachHttpServer (HttpServer &server) |
| 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) |
| ActionReply & | postAllActions () |
| ActionReply & | postAction (ActionRequest &action) |
| void | buildActionBody (ActionRequest &action, StrPrint &out) |
Build the SOAP XML request body for the action into out | |
| const char * | nullStr (const char *str, const char *empty="(null)") |
| const char * | nullStr (Str &str, const char *empty="(null)") |
| ActionReply & | processActionHttpPost (Url &post_url, StrPrint &requestBody, const char *soapAction) |
| const char * | getUrl (DLNADeviceInfo &device, const char *suffix, const char *buffer, int len) |
| bool | subscribeNotifications (DLNADeviceInfo &device, int timeoutSeconds=1800) |
| Subscribe to changes for all device services. | |
| bool | subscribeNotifications (DLNAServiceInfo &service, int timoutSeconds=1800) |
| Subscribe to changes for defined device service. | |
Static Protected Member Functions | |
| static void | notifyHandler (HttpServer *server, const char *requestPath, HttpRequestHandlerLine *hl) |
| 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 |
| DLNAHttpRequest * | p_http = nullptr |
| IUDPService * | p_udp = nullptr |
| Vector< DLNADeviceInfo > | devices |
| Vector< ActionRequest > | actions |
| ActionReply | reply |
| XMLPrinter | xml |
| int | default_device_idx = 0 |
| int | msearch_repeat_ms = 10000 |
| uint64_t | subscribe_timeout = 0 |
| int | subscribe_repeat_sec = 3600 |
| bool | is_active = false |
| bool | is_parse_device = false |
| DLNADeviceInfo | NO_DEVICE {false} |
| const char * | search_target |
| StringRegistry | strings |
| Url | local_url |
| bool | allow_localhost = false |
| HttpServer * | p_http_server = nullptr |
| int | http_server_port = 0 |
| void * | reference = nullptr |
| std::function< void(const char *nodeName, const char *text, const char *attributes)> | result_callback |
| std::function< void(void *reference, const char *sid, const char *varName, const char *newValue)> | event_callback |
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:
DLNADevice objects and their DLNAServiceInfo entries.HttpServer.onNotification).Notes and usage:
HttpServer with setHttpServer() (or construct with a server). The server's request handler will forward NOTIFY bodies to this manager.onNotification() to receive parsed property updates. An opaque reference pointer may be stored with setReference() and will be passed back with the callback.begin() to start discovery and loop() frequently (e.g. from the device main loop) to process incoming network events and scheduled tasks.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.
|
inline |
Default constructor w/o Notifications.
|
inline |
Constructor supporting Notifications.
|
inline |
Registers a method that will be called.
|
inline |
Adds a new device.
|
inline |
Adds the device from the device xml url if it does not already exist.
|
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.
|
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.
|
inlineprotected |
Build the SOAP XML request body for the action into out
|
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";
|
inline |
Stops the processing and releases the resources.
|
inline |
Executes all registered methods.
|
inline |
Provides the device information of the actually selected device.
|
inline |
Provides the device for a service.
|
inline |
Provides the device information by index.
|
inline |
Get a device for a Url.
|
inline |
|
inline |
Provides the last reply.
|
inline |
Provide addess to the service information.
|
inlineprotected |
|
inlinestaticprotected |
|
inlinestaticprotected |
Processes a NotifyReplyCP message Note: split into smaller helpers for clarity and testability.
|
inline |
Checks if the scheduler is active.
|
inlinestaticprotected |
Returns true and sets outDev if a device with the UDN part of usn_c is already present in the device list.
|
inline |
call this method in the Arduino loop as often as possible: the processes all replys
|
inlineprotected |
checks if the usn contains the search target
|
inlinestaticprotected |
Static HTTP handler for incoming NOTIFY event callbacks. The HttpServer will pass the control point instance as context[0] so we can retrieve the instance and forward the event to parseAndDispatchEvent().
Parse body
Activate callback
|
inlineprotected |
|
inlineprotected |
|
inline |
Register a callback that will be invoked for incoming event notification.
|
inline |
Register a callback that will be invoked when parsing SOAP/Action results Signature: void(const char* nodeName, const char* text, const char* attributes)
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
response body is written into responseOut (an XMLParserPrint). Returns the HTTP rc.
|
inlineprotected |
processes a bye-bye message
|
inlinestaticprotected |
|
inlinestaticprotected |
Processes an M-SEARCH HTTP 200 reply and attempts to add the device.
|
inline |
We can activate/deactivate the scheduler.
|
inline |
Defines if localhost devices should be allowed.
|
inline |
Selects the default device by index.
|
inline |
Set HttpServer instance and register the notify handler.
|
inline |
Defines the local url (needed for subscriptions)
|
inline |
Requests the parsing of the device information.
|
inline |
Attach an opaque reference pointer (optional, for caller context)
|
inline |
Sets the repeat interval for M-SEARCH requests (define before begin)
|
inline |
Activates event notification subscription with repeat interval in seconds.
|
inline |
Subscribes to event notifications for the selected device.
|
inlineprotected |
Subscribe to changes for all device services.
|
inlineprotected |
Subscribe to changes for defined device service.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |