Merge pull request #4314 from MartijnKaijser/beta1
[vuplus_xbmc] / lib / libUPnP / patches / 0008-Platinum-allow-some-statevariables-to-reset-to-defau.patch
1 From ad0db59a112ff4cf62ffc18c9565e48b90c4e4e2 Mon Sep 17 00:00:00 2001
2 From: Alasdair Campbell <alcoheca@gmail.com>
3 Date: Tue, 9 Oct 2012 10:14:39 +0100
4 Subject: [PATCH 04/21] Platinum: allow some statevariables to reset to
5  default value after sending completed (needed for
6  ContainerUpdateIDs usage)
7
8 ---
9  lib/libUPnP/Platinum/Source/Core/PltService.cpp       | 11 +++++++++--
10  lib/libUPnP/Platinum/Source/Core/PltService.h         |  3 ++-
11  lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp | 16 ++++++++++++++--
12  lib/libUPnP/Platinum/Source/Core/PltStateVariable.h   | 10 +++++++++-
13  4 files changed, 34 insertions(+), 6 deletions(-)
14
15 diff --git a/lib/libUPnP/Platinum/Source/Core/PltService.cpp b/lib/libUPnP/Platinum/Source/Core/PltService.cpp
16 index 3280b15..62bdc49 100644
17 --- a/lib/libUPnP/Platinum/Source/Core/PltService.cpp
18 +++ b/lib/libUPnP/Platinum/Source/Core/PltService.cpp
19 @@ -460,14 +460,14 @@ PLT_Service::IsSubscribable()
20  |   PLT_Service::SetStateVariable
21  +---------------------------------------------------------------------*/
22  NPT_Result
23 -PLT_Service::SetStateVariable(const char* name, const char* value)
24 +PLT_Service::SetStateVariable(const char* name, const char* value, const bool clearonsend /*=false*/)
25  {
26      PLT_StateVariable* stateVariable = NULL;
27      NPT_ContainerFind(m_StateVars, PLT_StateVariableNameFinder(name), stateVariable);
28      if (stateVariable == NULL)
29          return NPT_FAILURE;
30  
31 -    return stateVariable->SetValue(value);
32 +    return stateVariable->SetValue(value, clearonsend);
33  }
34  
35  /*----------------------------------------------------------------------
36 @@ -838,6 +838,13 @@ PLT_Service::NotifyChanged()
37          delete sub;
38      }
39  
40 +    // some state variables must be cleared immediatly after sending
41 +    iter = vars_ready.GetFirstItem();
42 +    while (iter) {
43 +      PLT_StateVariable* var = *iter;
44 +      var->OnSendCompleted();
45 +      ++iter;
46 +    }
47      return NPT_SUCCESS;
48  }
49  
50 diff --git a/lib/libUPnP/Platinum/Source/Core/PltService.h b/lib/libUPnP/Platinum/Source/Core/PltService.h
51 index c03a552..9bd4d12 100644
52 --- a/lib/libUPnP/Platinum/Source/Core/PltService.h
53 +++ b/lib/libUPnP/Platinum/Source/Core/PltService.h
54 @@ -216,8 +216,9 @@ public:
55       when necessary.
56       @param name state variable name
57       @param value new State Variable value.
58 +     @param clearonsend whether the State Variable should clear immediatly in ::OnSendingCompleted
59       */
60 -    NPT_Result SetStateVariable(const char* name, const char* value);
61 +    NPT_Result SetStateVariable(const char* name, const char* value, const bool clearonsend = false);
62      
63      /**
64       Certain state variables notifications must not be sent faster than a certain 
65 diff --git a/lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp b/lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp
66 index 229e304..47aeb5a 100644
67 --- a/lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp
68 +++ b/lib/libUPnP/Platinum/Source/Core/PltStateVariable.cpp
69 @@ -48,7 +48,8 @@ NPT_SET_LOCAL_LOGGER("platinum.core.statevariable")
70  PLT_StateVariable::PLT_StateVariable(PLT_Service* service) : 
71      m_Service(service), 
72      m_AllowedValueRange(NULL),
73 -    m_IsSendingEventsIndirectly(true)
74 +    m_IsSendingEventsIndirectly(true),
75 +    m_ShouldClearOnSend(false)
76  {
77  }
78  
79 @@ -145,7 +146,7 @@ PLT_StateVariable::SetRate(NPT_TimeInterval rate)
80  |   PLT_StateVariable::SetValue
81  +---------------------------------------------------------------------*/
82  NPT_Result
83 -PLT_StateVariable::SetValue(const char* value)
84 +PLT_StateVariable::SetValue(const char* value, const bool clearonsend /*=false*/)
85  {
86      if (value == NULL) {
87          return NPT_FAILURE;
88 @@ -159,6 +160,7 @@ PLT_StateVariable::SetValue(const char* value)
89          }
90  
91          m_Value = value;
92 +        m_ShouldClearOnSend = clearonsend;
93          m_Service->AddChanged(this); 
94      }
95  
96 @@ -183,6 +185,16 @@ PLT_StateVariable::IsReadyToPublish()
97  }
98  
99  /*----------------------------------------------------------------------
100 +|   PLT_StateVariable::OnSendCompleted
101 ++---------------------------------------------------------------------*/
102 +void
103 +PLT_StateVariable::OnSendCompleted()
104 +{
105 +  if(m_ShouldClearOnSend)
106 +      m_Value = m_DefaultValue;
107 +}
108 +
109 +/*----------------------------------------------------------------------
110  |   PLT_StateVariable::ValidateValue
111  +---------------------------------------------------------------------*/
112  NPT_Result
113 diff --git a/lib/libUPnP/Platinum/Source/Core/PltStateVariable.h b/lib/libUPnP/Platinum/Source/Core/PltStateVariable.h
114 index 46ec9e9..465e95c 100644
115 --- a/lib/libUPnP/Platinum/Source/Core/PltStateVariable.h
116 +++ b/lib/libUPnP/Platinum/Source/Core/PltStateVariable.h
117 @@ -115,8 +115,9 @@ public:
118       it is an allowed value. Once the value is validated, it is marked for eventing by
119       calling the PLT_Service AddChanged function.
120       @param value new state variable value. Can be a comma separated list of values.
121 +     @param clearonsend whether the statevariable should be cleared immediatly after sending
122       */
123 -    NPT_Result SetValue(const char* value);
124 +    NPT_Result SetValue(const char* value, const bool clearonsend = false);
125      
126      /**
127       Validate the new value of the state variable.
128 @@ -173,6 +174,12 @@ protected:
129      bool IsReadyToPublish();
130      
131      /**
132 +     * If this statevariable should clear after sending to all subscribers, clears the value without
133 +     * eventing the change
134 +     */
135 +    void OnSendCompleted();
136 +
137 +    /**
138       Serialize the state variable into xml.
139       */
140         NPT_Result Serialize(NPT_XmlElementNode& node);
141 @@ -189,6 +196,7 @@ protected:
142      NPT_String              m_DefaultValue;
143      bool                    m_IsSendingEvents;
144      bool                    m_IsSendingEventsIndirectly;
145 +    bool                    m_ShouldClearOnSend;
146      NPT_TimeInterval        m_Rate;
147      NPT_TimeStamp           m_LastEvent;
148      NPT_Array<NPT_String*>  m_AllowedValues;
149 -- 
150 1.7.11.msysgit.0
151