summaryrefslogtreecommitdiffstats
path: root/lib/libUPnP/patches/0008-platinum-allow-some-statevariables-to-reset-to-defau.patch
blob: 8841447ad7ce60e67b94182dfa6bc180e37648bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
From 73a60837afb1a0ddf03ac500665c28853d95dca8 Mon Sep 17 00:00:00 2001
From: Alasdair Campbell <alcoheca@gmail.com>
Date: Tue, 9 Oct 2012 10:14:39 +0100
Subject: [PATCH 08/24] platinum: allow some statevariables to reset to
 default value after sending completed (needed for
 ContainerUpdateIDs usage)

---
 lib/libUPnP/Platinum/Source/Core/PltService.cpp       | 11 +++++++++--
 lib/libUPnP/Platinum/Source/Core/PltService.h         |  3 ++-
 lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp | 16 ++++++++++++++--
 lib/libUPnP/Platinum/Source/Core/PltStateVariable.h   | 10 +++++++++-
 4 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/lib/libUPnP/Platinum/Source/Core/PltService.cpp b/lib/libUPnP/Platinum/Source/Core/PltService.cpp
index b1fec51..b86fb23 100644
--- a/lib/libUPnP/Platinum/Source/Core/PltService.cpp
+++ b/lib/libUPnP/Platinum/Source/Core/PltService.cpp
@@ -459,14 +459,14 @@ PLT_Service::IsSubscribable()
 |   PLT_Service::SetStateVariable
 +---------------------------------------------------------------------*/
 NPT_Result
-PLT_Service::SetStateVariable(const char* name, const char* value)
+PLT_Service::SetStateVariable(const char* name, const char* value, const bool clearonsend /*=false*/)
 {
     PLT_StateVariable* stateVariable = NULL;
     NPT_ContainerFind(m_StateVars, PLT_StateVariableNameFinder(name), stateVariable);
     if (stateVariable == NULL)
         return NPT_FAILURE;
 
-    return stateVariable->SetValue(value);
+    return stateVariable->SetValue(value, clearonsend);
 }
 
 /*----------------------------------------------------------------------
@@ -835,6 +835,13 @@ PLT_Service::NotifyChanged()
         m_Subscribers.Erase(sub_iter++);
     }
 
+    // some state variables must be cleared immediatly after sending
+    iter = vars_ready.GetFirstItem();
+    while (iter) {
+      PLT_StateVariable* var = *iter;
+      var->OnSendCompleted();
+      ++iter;
+    }
     return NPT_SUCCESS;
 }
 
diff --git a/lib/libUPnP/Platinum/Source/Core/PltService.h b/lib/libUPnP/Platinum/Source/Core/PltService.h
index 84959f2..0401ea2 100644
--- a/lib/libUPnP/Platinum/Source/Core/PltService.h
+++ b/lib/libUPnP/Platinum/Source/Core/PltService.h
@@ -216,8 +216,9 @@ public:
      when necessary.
      @param name state variable name
      @param value new State Variable value.
+     @param clearonsend whether the State Variable should clear immediatly in ::OnSendingCompleted
      */
-    NPT_Result SetStateVariable(const char* name, const char* value);
+    NPT_Result SetStateVariable(const char* name, const char* value, const bool clearonsend = false);
     
     /**
      Certain state variables notifications must not be sent faster than a certain 
diff --git a/lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp b/lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp
index c3eb7cc..d38392e 100644
--- a/lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp
+++ b/lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp
@@ -49,7 +49,8 @@ PLT_StateVariable::PLT_StateVariable(PLT_Service* service) :
     m_Service(service), 
     m_AllowedValueRange(NULL),
     m_IsSendingEvents(false),
-    m_IsSendingEventsIndirectly(true)
+    m_IsSendingEventsIndirectly(true),
+    m_ShouldClearOnSend(false)
 {
 }
 
@@ -146,7 +147,7 @@ PLT_StateVariable::SetRate(NPT_TimeInterval rate)
 |   PLT_StateVariable::SetValue
 +---------------------------------------------------------------------*/
 NPT_Result
-PLT_StateVariable::SetValue(const char* value)
+PLT_StateVariable::SetValue(const char* value, const bool clearonsend /*=false*/)
 {
     if (value == NULL) {
         return NPT_FAILURE;
@@ -160,6 +161,7 @@ PLT_StateVariable::SetValue(const char* value)
         }
 
         m_Value = value;
+        m_ShouldClearOnSend = clearonsend;
         m_Service->AddChanged(this); 
     }
 
@@ -184,6 +186,16 @@ PLT_StateVariable::IsReadyToPublish()
 }
 
 /*----------------------------------------------------------------------
+|   PLT_StateVariable::OnSendCompleted
++---------------------------------------------------------------------*/
+void
+PLT_StateVariable::OnSendCompleted()
+{
+  if(m_ShouldClearOnSend)
+      m_Value = m_DefaultValue;
+}
+
+/*----------------------------------------------------------------------
 |   PLT_StateVariable::ValidateValue
 +---------------------------------------------------------------------*/
 NPT_Result
diff --git a/lib/libUPnP/Platinum/Source/Core/PltStateVariable.h b/lib/libUPnP/Platinum/Source/Core/PltStateVariable.h
index 46ec9e9..465e95c 100644
--- a/lib/libUPnP/Platinum/Source/Core/PltStateVariable.h
+++ b/lib/libUPnP/Platinum/Source/Core/PltStateVariable.h
@@ -115,8 +115,9 @@ public:
      it is an allowed value. Once the value is validated, it is marked for eventing by
      calling the PLT_Service AddChanged function.
      @param value new state variable value. Can be a comma separated list of values.
+     @param clearonsend whether the statevariable should be cleared immediatly after sending
      */
-    NPT_Result SetValue(const char* value);
+    NPT_Result SetValue(const char* value, const bool clearonsend = false);
     
     /**
      Validate the new value of the state variable.
@@ -173,6 +174,12 @@ protected:
     bool IsReadyToPublish();
     
     /**
+     * If this statevariable should clear after sending to all subscribers, clears the value without
+     * eventing the change
+     */
+    void OnSendCompleted();
+
+    /**
      Serialize the state variable into xml.
      */
 	NPT_Result Serialize(NPT_XmlElementNode& node);
@@ -189,6 +196,7 @@ protected:
     NPT_String              m_DefaultValue;
     bool                    m_IsSendingEvents;
     bool                    m_IsSendingEventsIndirectly;
+    bool                    m_ShouldClearOnSend;
     NPT_TimeInterval        m_Rate;
     NPT_TimeStamp           m_LastEvent;
     NPT_Array<NPT_String*>  m_AllowedValues;
-- 
1.7.11.msysgit.0