1 /*****************************************************************
3 | Platinum - Service State Variable
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
7 | http://www.plutinosoft.com
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
33 ****************************************************************/
39 #ifndef _PLT_STATE_VARIABLE_H_
40 #define _PLT_STATE_VARIABLE_H_
42 /*----------------------------------------------------------------------
44 +---------------------------------------------------------------------*/
47 /*----------------------------------------------------------------------
48 | forward declarations
49 +---------------------------------------------------------------------*/
53 /*----------------------------------------------------------------------
54 | NPT_AllowedValueRange struct
55 +---------------------------------------------------------------------*/
57 The NPT_AllowedValueRange struct holds the min, max and step value allowed of
58 a UPnP Service state variable.
64 } NPT_AllowedValueRange
;
66 /*----------------------------------------------------------------------
67 | PLT_StateVariable class
68 +---------------------------------------------------------------------*/
70 The PLT_StateVariable class maintains the state of a UPnP Service state variable.
71 It is used by a PLT_DeviceHost instance to notify subscribers of a change or by a
72 subscriber (PLT_CtrlPoint) when a service state variable change notification
75 class PLT_StateVariable
78 PLT_StateVariable(PLT_Service
* service
);
82 Populate the SCPD xml document with state variable information.
83 @param node XML Element where to insert the state variable XML Element
85 NPT_Result
GetSCPDXML(NPT_XmlElementNode
* node
);
88 Return the PLT_Service that this state variable is associated with.
89 @return PLT_Service pointer.
91 PLT_Service
* GetService();
94 Return whether the state variable is eventable directly or indirectly. A state
95 variable sends events indirectly when part of the "LastChange" state variable.
96 @param indirectly Boolean to test if the state variable is sending events indirectly
97 @return Whether the state variable sends events according to the input flag specified.
99 bool IsSendingEvents(bool indirectly
= false);
102 Force the state variable to send events directly.
104 void DisableIndirectEventing();
107 Certain state variables notifications must not be sent faster than a certain
108 rate according to the UPnP specs. This sets the rate for a given state variable.
109 @param rate time interval to respect between notifications.
111 NPT_Result
SetRate(NPT_TimeInterval rate
);
114 Set the state variable value. The value is first validated to make sure
115 it is an allowed value. Once the value is validated, it is marked for eventing by
116 calling the PLT_Service AddChanged function.
117 @param value new state variable value. Can be a comma separated list of values.
118 @param clearonsend whether the statevariable should be cleared immediatly after sending
120 NPT_Result
SetValue(const char* value
, const bool clearonsend
= false);
123 Validate the new value of the state variable.
124 @param value new state variable value. Can be a comma separated list of values.
126 NPT_Result
ValidateValue(const char* value
);
129 Certain state variables require extra xml attributes when serialized.
130 @param name the attribute name
131 @param value the attribute value
133 NPT_Result
SetExtraAttribute(const char* name
, const char* value
);
136 Return the state variable name.
137 @return state variable name.
139 const NPT_String
& GetName() const { return m_Name
; }
142 Return the current state variable value.
143 @return state variable current value.
145 const NPT_String
& GetValue() const { return m_Value
; }
148 Return the state variable data type.
149 @return state variable data type.
151 const NPT_String
& GetDataType() const { return m_DataType
; }
154 Return the state variable allowed value range if any.
155 @return state variable value range pointer or null if none.
157 const NPT_AllowedValueRange
* GetAllowedValueRange() const { return m_AllowedValueRange
; }
160 Helper function to return a state variable given a list of state variables
161 and a state variable name.
162 @param vars list of state variables
163 @param name state variable name to look for
164 @return PLT_StateVariable pointer.
166 static PLT_StateVariable
* Find(NPT_List
<PLT_StateVariable
*>& vars
,
171 Return whether the state variable value changed and subscribers need to
174 bool IsReadyToPublish();
177 * If this statevariable should clear after sending to all subscribers, clears the value without
178 * eventing the change
180 void OnSendCompleted();
183 Serialize the state variable into xml.
185 NPT_Result
Serialize(NPT_XmlElementNode
& node
);
188 friend class PLT_Service
;
189 friend class PLT_LastChangeXMLIterator
;
192 PLT_Service
* m_Service
;
193 NPT_AllowedValueRange
* m_AllowedValueRange
;
195 NPT_String m_DataType
;
196 NPT_String m_DefaultValue
;
197 bool m_IsSendingEvents
;
198 bool m_IsSendingEventsIndirectly
;
199 bool m_ShouldClearOnSend
;
200 NPT_TimeInterval m_Rate
;
201 NPT_TimeStamp m_LastEvent
;
202 NPT_Array
<NPT_String
*> m_AllowedValues
;
205 NPT_Map
<NPT_String
,NPT_String
> m_ExtraAttributes
;
208 /*----------------------------------------------------------------------
209 | PLT_StateVariableNameFinder
210 +---------------------------------------------------------------------*/
212 The PLT_StateVariableNameFinder class returns the PLT_StateVariable instance
213 given a state variable name.
215 class PLT_StateVariableNameFinder
219 PLT_StateVariableNameFinder(const char* name
) : m_Name(name
) {}
220 virtual ~PLT_StateVariableNameFinder() {}
222 bool operator()(const PLT_StateVariable
* const & state_variable
) const {
223 return state_variable
->GetName().Compare(m_Name
, true) ? false : true;
231 #endif /* _PLT_STATE_VARIABLE_H_ */