Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitab37647

Browse files
committed
setNotificationCallback() for CP
1 parent7aba6a7 commitab37647

File tree

7 files changed

+57
-20
lines changed

7 files changed

+57
-20
lines changed

‎examples/control-point-media-renderer/control-point-media-renderer.ino‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void setup() {
4747
// Use first discovered renderer device
4848
renderer.setDeviceIndex(0);
4949
// Subscribe to event notifications
50-
renderer.setSubscribeNotificationsActive(true);
50+
renderer.setNotificationsActive(true);
5151

5252
// Starting playback
5353
Serial.println("Starting playback...");

‎src/dlna/clients/DLNAControlPoint.h‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ class DLNAControlPoint : public IControlPoint {
293293
return reply;
294294
}
295295

296-
/// call this method in the Arduino loop as often as possible:the processes
297-
/// allreplys
296+
/// call this method in the Arduino loop as often as possible:it processes
297+
/// allsubscriptions and scheduled tasks for udp requests
298298
boolloop()override {
299299
if (!is_active)returnfalse;
300300
DLNAControlPointRequestParser parser;
@@ -494,13 +494,8 @@ class DLNAControlPoint : public IControlPoint {
494494
}
495495

496496
/// Activate/deactivate subscription notifications
497-
voidsetSubscribeNotificationsActive(bool flag)override {
498-
subscription_mgr.setEventSubscriptionActive(flag);
499-
}
500-
501-
/// Register a string in the shared registry and return the stored pointer
502-
constchar*registerString(constchar* s)override {
503-
return s;// registry removed
497+
voidsetNotificationsActive(bool flag)override {
498+
subscription_mgr.setNotificationsActive(flag);
504499
}
505500

506501
protected:

‎src/dlna/clients/DLNAControlPointMediaRenderer.h‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,18 @@ class DLNAControlPointMediaRenderer {
116116
constchar* newValue);
117117

118118
/// Activate/deactivate subscription notifications
119-
voidsetSubscribeNotificationsActive(bool flag) {
120-
p_mgr->setSubscribeNotificationsActive(flag);
119+
voidsetNotificationsActive(bool flag) {
120+
p_mgr->setNotificationsActive(flag);
121+
}
122+
123+
/// Register a callback for notifications and activate subscriptions
124+
voidsetNotificationCallback(
125+
std::function<void(constchar* sid,constchar* varName,
126+
constchar* newValue,void* reference)>
127+
cb,
128+
void* ref = nullptr) {
129+
p_mgr->setNotificationsActive(true);
130+
p_mgr->setEventSubscriptionCallback(cb, ref);
121131
}
122132

123133
/**

‎src/dlna/clients/DLNAControlPointMediaServer.h‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,18 @@ class DLNAControlPointMediaServer {
104104
voidsetDeviceIndex(int idx) { p_mgr->setDeviceIndex(idx); }
105105

106106
/// Activate/deactivate subscription notifications
107-
voidsetSubscribeNotificationsActive(bool flag) {
108-
p_mgr->setSubscribeNotificationsActive(flag);
107+
voidsetNotificationsActive(bool flag) {
108+
p_mgr->setNotificationsActive(flag);
109+
}
110+
111+
/// Register a callback for notifications and activate subscriptions
112+
voidsetNotificationCallback(
113+
std::function<void(constchar* sid,constchar* varName,
114+
constchar* newValue,void* reference)>
115+
cb,
116+
void* ref = nullptr) {
117+
p_mgr->setNotificationsActive(true);
118+
p_mgr->setEventSubscriptionCallback(cb, ref);
109119
}
110120

111121
/**

‎src/dlna/clients/IControlPoint.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ class IControlPoint {
115115
/// Get subscription manager for event handling
116116
virtual SubscriptionMgrControlPoint*getSubscriptionMgr() = 0;
117117
/// Enable/disable event subscription notifications
118-
virtualvoidsetSubscribeNotificationsActive(bool flag) = 0;
119-
/// Register string for memory management
120-
virtualconstchar*registerString(constchar* s) = 0;
118+
virtualvoidsetNotificationsActive(bool flag) = 0;
121119
};
122120

123121
}// namespace tiny_dlna

‎src/dlna/clients/SubscriptionMgrControlPoint.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SubscriptionMgrControlPoint {
6868
p_device = &device;
6969
is_setup =true;
7070
// Initialize event subscription state
71-
setEventSubscriptionActive(event_subscription_active);
71+
setNotificationsActive(event_subscription_active);
7272
}
7373
/**
7474
* @brief Attach an HttpServer instance and register the internal
@@ -169,7 +169,7 @@ class SubscriptionMgrControlPoint {
169169
* @param active true to maintain subscriptions automatically; false to
170170
* stop and attempt unsubscription.
171171
*/
172-
voidsetEventSubscriptionActive(bool active) {
172+
voidsetNotificationsActive(bool active) {
173173
event_subscription_active = active;
174174

175175
// if not setup, ignore

‎src/dlna/common/Schedule.h‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class MSearchReplySchedule : public Schedule {
112112

113113
boolisValid()override {
114114
// check if the search target is valid for this device
115-
if (!isValidSearchTarget(*p_device, search_target.c_str())){
115+
if (!isValidSearchTarget(*p_device, search_target.c_str())){
116116
returnfalse;
117117
}
118118
returnisValidIP();
@@ -422,4 +422,28 @@ class PostSubscribe : public Schedule {
422422
voidsetDuration(uint32_t sec) { durationSec = sec; }
423423
};
424424

425+
/**
426+
* @brief Generic Schedule that invokes a callback function
427+
* @author Phil Schatzmann
428+
*/
429+
classCallbackSchedule :publicSchedule {
430+
public:
431+
CallbackSchedule(std::function<bool(void* ref)> cb,void* ref) {
432+
callback = cb;
433+
reference = ref;
434+
}
435+
constchar*name()override {return"Callback"; }
436+
void* reference =nullptr;
437+
438+
boolprocess(IUDPService& udp)override {
439+
if (callback) {
440+
returncallback(reference);
441+
}
442+
returnfalse;
443+
}
444+
445+
protected:
446+
std::function<bool(void* ref)> callback;
447+
};
448+
425449
}// namespace tiny_dlna

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp