109 std::function<
void(
const char* sid,
const char* varName,
110 const char* newValue,
void* reference)>
112 void* ref =
nullptr) {
235 std::function<void(
const char* sid,
const char* varName,
const char* newValue,
238 const char* newValue,
void* reference) {
241 "- Event notification: SID='%s' var='%s' value='%s'",
242 sid ? sid :
"", varName ? varName :
"",
243 newValue ? newValue :
"");
308 if (ssid !=
nullptr && strcmp(ssid, sid) == 0)
return service;
329 "DLNAControlPointMgr::attachHttpServer");
333 const char* path =
"/dlna/events";
355 if (
p_device ==
nullptr)
return false;
397 "Unsubscribe from service %s failed",
431 char seconds_txt[80] = {0};
432 snprintf(seconds_txt,
sizeof(seconds_txt),
"Second-%d",
445 if (sid !=
nullptr) {
457 "Subscribe %s succeeded but no SID returned", url.
url());
463 "Failed to subscribe to service %s, rc=%d",
503 "Failed to unsubscribe from service %s, rc=%d",
532 if (handlerLine ==
nullptr || handlerLine->
contextCount < 1)
return;
533 void* ctx0 = handlerLine->
context[0];
556 Client& client = server->
client();
558 while (client.available()) {
560 xml_parser.
write(buffer, read);
562 while (xml_parser.
parse(nodeName, path, text, attrs)) {
569 const char* sid_c = sid ? sid :
"";
Device Attributes and generation of XML using urn:schemas-upnp-org:device-1-0. We could just return a...
Definition: DLNADeviceInfo.h:25
Vector< DLNAServiceInfo > & getServices()
Provides all service definitions.
Definition: DLNADeviceInfo.h:203
Attributes needed for the DLNA Service Definition.
Definition: DLNAServiceInfo.h:18
uint64_t time_subscription_confirmed
timestamp when subscription was confirmed
Definition: DLNAServiceInfo.h:51
SubscriptionState subscription_state
Definition: DLNAServiceInfo.h:49
uint64_t time_subscription_expires
timestamp when subscription expires
Definition: DLNAServiceInfo.h:52
Str subscription_id
for subscriptions
Definition: DLNAServiceInfo.h:48
Str event_sub_url
Definition: DLNAServiceInfo.h:41
Str service_id
Definition: DLNAServiceInfo.h:38
uint64_t time_subscription_started
timestamp when subscription started
Definition: DLNAServiceInfo.h:50
Used to register and process callbacks.
Definition: HttpRequestHandlerLine.h:15
void ** context
Definition: HttpRequestHandlerLine.h:40
int contextCount
Definition: HttpRequestHandlerLine.h:41
Abstract interface for HTTP client request functionality.
Definition: IHttpRequest.h:21
virtual HttpRequestHeader & request()=0
Get reference to request header.
virtual HttpReplyHeader & reply()=0
Get reference to reply header.
virtual int subscribe(Url &url)=0
Send SUBSCRIBE request for UPnP events.
virtual int unsubscribe(Url &url, const char *sid)=0
Send UNSUBSCRIBE request for UPnP events.
Abstract interface for HTTP server functionality.
Definition: IHttpServer.h:30
virtual void on(const char *url, TinyMethodID method, web_callback_fn fn, void *ctx[]=nullptr, int ctxCount=0)=0
Register callback for HTTP request with context.
virtual void replyOK()=0
Send 200 OK response.
virtual Client & client()=0
Get reference to current client.
virtual HttpRequestHeader & requestHeader()=0
Get reference to request header.
Abstract Interface for UDP API.
Definition: IUDPService.h:33
A simple wrapper to provide string functions on char*. If the underlying char* is a const we do not a...
Definition: StrView.h:18
virtual bool isEmpty()
checks if the string is empty
Definition: StrView.h:383
Heap-backed string utility used throughout tiny_dlna.
Definition: Str.h:27
bool isEmpty() const
True if empty.
Definition: Str.h:54
const char * c_str() const
C-string pointer to internal buffer.
Definition: Str.h:88
Standalone manager for UPnP/DLNA event subscriptions used by control points and devices.
Definition: SubscriptionMgrControlPoint.h:44
uint64_t getLastEventNotifyMs()
Get the timestamp of the last received NOTIFY message.
Definition: SubscriptionMgrControlPoint.h:188
bool event_subscription_active
Definition: SubscriptionMgrControlPoint.h:226
std::function< void(const char *sid, const char *varName, const char *newValue, void *reference)> event_callback
Definition: SubscriptionMgrControlPoint.h:237
void updateReceived(const char *sid)
Update internal and service metadata when a NOTIFY is received.
Definition: SubscriptionMgrControlPoint.h:290
uint64_t last_event_notify_ms
Definition: SubscriptionMgrControlPoint.h:227
void setEventSubscriptionCallback(std::function< void(const char *sid, const char *varName, const char *newValue, void *reference)> callback, void *ref=nullptr)
Register a callback invoked when event properties change.
Definition: SubscriptionMgrControlPoint.h:108
bool subscribeToDevice(DLNADeviceInfo &device)
Subscribe to all services exposed by device.
Definition: SubscriptionMgrControlPoint.h:370
bool subscribeToService(DLNAServiceInfo &service)
Subscribe to a single eventing service described by service.
Definition: SubscriptionMgrControlPoint.h:419
IHttpRequest * p_http
Definition: SubscriptionMgrControlPoint.h:228
bool isActive()
Query whether the manager is currently active.
Definition: SubscriptionMgrControlPoint.h:216
DLNADeviceInfo * p_device
Definition: SubscriptionMgrControlPoint.h:232
void setEventSubscriptionRetryMs(int ms)
Set the retry threshold in milliseconds.
Definition: SubscriptionMgrControlPoint.h:159
bool is_setup
Definition: SubscriptionMgrControlPoint.h:222
bool subscribeNotifications(bool subscribe=true)
Convenience to subscribe or unsubscribe all services of the currently selected device.
Definition: SubscriptionMgrControlPoint.h:354
Url * p_local_url
Definition: SubscriptionMgrControlPoint.h:231
bool hasEventSubscriptionCallback()
Return true when an application notification callback is set.
Definition: SubscriptionMgrControlPoint.h:93
IUDPService * p_udp
Definition: SubscriptionMgrControlPoint.h:229
void * event_callback_ref
Definition: SubscriptionMgrControlPoint.h:219
DLNAServiceInfo NO_SERVICE
Definition: SubscriptionMgrControlPoint.h:233
bool unsubscribeFromDevice(DLNADeviceInfo &device)
Unsubscribe from all services of device.
Definition: SubscriptionMgrControlPoint.h:392
IHttpServer * p_http_server
Definition: SubscriptionMgrControlPoint.h:230
bool loop()
Periodic work to manage subscription renewals and retries.
Definition: SubscriptionMgrControlPoint.h:198
static void notifyHandler(IHttpServer *server, const char *requestPath, HttpRequestHandlerLine *handlerLine)
HTTP NOTIFY handler registered with HttpServer.
Definition: SubscriptionMgrControlPoint.h:530
bool is_active
Definition: SubscriptionMgrControlPoint.h:220
bool unsubscribeFromService(DLNAServiceInfo &service)
Unsubscribe from a single service.
Definition: SubscriptionMgrControlPoint.h:481
SubscriptionState subscription_state
Definition: SubscriptionMgrControlPoint.h:221
void attachHttpServer(IHttpServer &server)
Locate a DLNAServiceInfo by its stored SID.
Definition: SubscriptionMgrControlPoint.h:327
void updateSubscriptions()
Evaluate and apply subscription state transitions.
Definition: SubscriptionMgrControlPoint.h:265
void setHttpServer(IHttpServer &server)
Attach an HttpServer instance and register the internal NOTIFY handler.
Definition: SubscriptionMgrControlPoint.h:84
void end()
Tear down the manager. This clears the internal setup state but does not perform network unsubscribe ...
Definition: SubscriptionMgrControlPoint.h:121
DLNAServiceInfo & getServiceInfoBySID(const char *sid)
Definition: SubscriptionMgrControlPoint.h:301
void setEventSubscriptionDurationSec(int seconds=3600)
Configure desired subscription duration in seconds.
Definition: SubscriptionMgrControlPoint.h:146
uint32_t event_subscription_retry_ms
Definition: SubscriptionMgrControlPoint.h:225
uint32_t event_subscription_duration_sec
Definition: SubscriptionMgrControlPoint.h:224
void setup(IHttpRequest &http, IUDPService &udp, Url &localCallbackUrl, DLNADeviceInfo &device)
Inject required dependencies and initialize the manager.
Definition: SubscriptionMgrControlPoint.h:62
void setEventSubscriptionActive(bool active)
Turn automatic event subscription on or off.
Definition: SubscriptionMgrControlPoint.h:172
uint64_t processing_timeout
Definition: SubscriptionMgrControlPoint.h:234
uint64_t subscribe_timeout
Definition: SubscriptionMgrControlPoint.h:223
URL parser which breaks a full url string up into its individual parts.
Definition: Url.h:18
const char * url()
Definition: Url.h:39
const char * path()
Definition: Url.h:40
Lightweight wrapper around std::vector with Arduino-friendly helpers and a pluggable allocator.
Definition: Vector.h:39
Helper class that implements a Print interface to accumulate XML data and then parse it using XMLPars...
Definition: XMLParserPrint.h:16
size_t write(uint8_t ch) override
Writes a single byte to the buffer (Print interface)
Definition: XMLParserPrint.h:32
void setExpandEncoded(bool flag)
Forwards expand-entities setting to the underlying XMLParser.
Definition: XMLParserPrint.h:48
bool parse(Str &outNodeName, Vector< Str > &outPath, Str &outText, Str &outAttributes)
Parses the accumulated XML data and returns results via output parameters.
Definition: XMLParserPrint.h:59
#define XML_PARSER_BUFFER_SIZE
Define XML parse buffer size.
Definition: dlna_config.h:25
Definition: Allocator.h:13
@ T_NOTIFY
Definition: HttpHeader.h:48
SubscriptionState
Subscription State for DLNA eventing.
Definition: DLNACommon.h:13