kodi
StateVariable.h
1 /*****************************************************************
2 |
3 | Platinum - Managed StateVariable
4 |
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
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.
13 |
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 |
21 | This program is distributed in the hope that it will be useful,
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | GNU General Public License for more details.
25 |
26 | You should have received a copy of the GNU General Public License
27 | along with this program; see the file LICENSE.txt. If not, write to
28 | the Free Software Foundation, Inc.,
29 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 | http://www.gnu.org/licenses/gpl-2.0.html
31 |
32 ****************************************************************/
33 #pragma once
34 
35 namespace Platinum
36 {
37 
38 ref class Service;
39 
40 /*----------------------------------------------------------------------
41 | StateVariable
42 +---------------------------------------------------------------------*/
43 public ref class StateVariable
44 {
45 private:
46 
47  PLT_StateVariable* m_pHandle;
48 
49 public:
50 
51  property String^ Name
52  {
53  String^ get()
54  {
55  return gcnew String(m_pHandle->GetName());
56  }
57  }
58 
59  property Service^ ParentService
60  {
61  Service^ get();
62  }
63 
64  property Type^ DataType
65  {
66  Type^ get()
67  {
68  return Helpers::ParseType(m_pHandle->GetDataType());
69  }
70  }
71 
72  property String^ DataTypeString
73  {
74  String^ get()
75  {
76  return gcnew String(m_pHandle->GetDataType());
77  }
78  }
79 
80  property Object^ Value
81  {
82  Object^ get()
83  {
84  return Helpers::ConvertValue(
85  m_pHandle->GetDataType(),
86  m_pHandle->GetValue()
87  );
88  }
89  }
90 
91  property String^ ValueString
92  {
93  String^ get()
94  {
95  return gcnew String(m_pHandle->GetValue());
96  }
97 
98  void set (String^ value)
99  {
100  if (value == nullptr)
101  throw gcnew ArgumentNullException("value");
102 
103  marshal_context c;
104 
105  Helpers::ThrowOnError(m_pHandle->SetValue(
106  c.marshal_as<const char*>(value)
107  ));
108  }
109  }
110 
111 public:
112 
113  void ValidateValue(String^ value)
114  {
115  if (value == nullptr)
116  throw gcnew ArgumentNullException("value");
117 
118  marshal_context c;
119 
120  Helpers::ThrowOnError(m_pHandle->ValidateValue(
121  c.marshal_as<const char*>(value)
122  ));
123  }
124 
125 public:
126 
127  virtual Boolean Equals(Object^ obj) override
128  {
129  if (obj == nullptr)
130  return false;
131 
132  if (!this->GetType()->IsInstanceOfType(obj))
133  return false;
134 
135  return (m_pHandle == ((StateVariable^)obj)->m_pHandle);
136  }
137 
138 internal:
139 
141  {
142  m_pHandle = &devData;
143  }
144 
145 public:
146 
147  ~StateVariable()
148  {
149  // clean-up managed
150 
151  // clean-up unmanaged
152  this->!StateVariable();
153  }
154 
155  !StateVariable()
156  {
157  // clean-up unmanaged
158  }
159 
160 };
161 
162 }
163 
164 // marshal wrapper
165 PLATINUM_MANAGED_MARSHAL_AS(Platinum::StateVariable, PLT_StateVariable);
const NPT_String & GetValue() const
Return the current state variable value.
Definition: PltStateVariable.h:145
Definition: Service.h:45
NPT_Result SetValue(const char *value, const bool clearonsend=false)
Set the state variable value.
Definition: PltStateVariable.cpp:150
const NPT_String & GetName() const
Return the state variable name.
Definition: PltStateVariable.h:139
The PLT_StateVariable class maintains the state of a UPnP Service state variable. ...
Definition: PltStateVariable.h:75
NPT_Result ValidateValue(const char *value)
Validate the new value of the state variable.
Definition: PltStateVariable.cpp:202
Definition: StateVariable.h:43
const NPT_String & GetDataType() const
Return the state variable data type.
Definition: PltStateVariable.h:151