kodi
ControlPoint.h
1 /*****************************************************************
2 |
3 | Platinum - Managed ControlPoint
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 Action;
39 ref class ActionDescription;
40 ref class DeviceData;
41 ref class Service;
42 ref class StateVariable;
43 class ControlPointEventBridge;
44 
45 /*----------------------------------------------------------------------
46 | ControlPoint
47 +---------------------------------------------------------------------*/
48 public ref class ControlPoint
49 {
50 public:
51 
52  delegate void DeviceAddedDelegate(DeviceData^ dev);
53  delegate void DeviceRemovedDelegate(DeviceData^ dev);
54  delegate void ActionResponseDelegate(NeptuneException^ error, Action^ action);
55  delegate void EventNotifyDelegate(Service^ srv, IEnumerable<StateVariable^>^ vars);
56 
57 private:
58 
59  PLT_CtrlPointReference* m_pHandle;
60  ControlPointEventBridge* m_pBridge;
61  List<DeviceData^>^ m_pDevices;
62 
63 public:
64 
65  property array<DeviceData^>^ Devices
66  {
67  array<DeviceData^>^ get()
68  {
69  System::Threading::Monitor::Enter(m_pDevices);
70 
71  return m_pDevices->ToArray();
72 
73  System::Threading::Monitor::Exit(m_pDevices);
74  }
75  }
76 
77 internal:
78 
79  property PLT_CtrlPointReference& Handle
80  {
82  {
83  return *m_pHandle;
84  }
85  }
86 
87 public:
88 
89  event DeviceAddedDelegate^ DeviceAdded;
90  event DeviceRemovedDelegate^ DeviceRemoved;
91  event ActionResponseDelegate^ ActionResponse;
92  event EventNotifyDelegate^ EventNotify;
93 
94 internal:
95 
96  void OnDeviceAdded(DeviceData^ dev)
97  {
98  // add to list
99  System::Threading::Monitor::Enter(m_pDevices);
100 
101  m_pDevices->Add(dev);
102 
103  System::Threading::Monitor::Exit(m_pDevices);
104 
105  // handle events
106  this->DeviceAdded(dev);
107  }
108 
109  void OnDeviceRemoved(DeviceData^ dev)
110  {
111  // handle events
112  this->DeviceRemoved(dev);
113 
114  // remove from list
115  System::Threading::Monitor::Enter(m_pDevices);
116 
117  m_pDevices->Remove(dev);
118 
119  System::Threading::Monitor::Exit(m_pDevices);
120  }
121 
122  void OnActionResponse(NeptuneException^ error, Action^ action)
123  {
124  this->ActionResponse(error, action);
125  }
126 
127  void OnEventNotify(Service^ srv, IEnumerable<StateVariable^>^ vars)
128  {
129  this->EventNotify(srv, vars);
130  }
131 
132 public:
133 
134  Action^ CreateAction(ActionDescription^ desc);
135  void InvokeAction(Action^ action);
136 
137  void Subscribe(Service^ srv);
138  void Unsubscribe(Service^ srv);
139 
140 private:
141 
142  void RegisterEvents();
143 
144 public:
145 
146  virtual Boolean Equals(Object^ obj) override
147  {
148  if (obj == nullptr)
149  return false;
150 
151  if (!this->GetType()->IsInstanceOfType(obj))
152  return false;
153 
154  return (*m_pHandle == *((ControlPoint^)obj)->m_pHandle);
155  }
156 
157 internal:
158 
160  {
161  if (ctlPoint.IsNull())
162  throw gcnew ArgumentNullException("ctlPoint");
163 
164  m_pHandle = new PLT_CtrlPointReference(ctlPoint);
165 
166  RegisterEvents();
167  }
168 
169  ControlPoint(PLT_CtrlPoint& ctlPoint)
170  {
171  m_pHandle = new PLT_CtrlPointReference(&ctlPoint);
172 
173  RegisterEvents();
174  }
175 
176 public:
177 
178  ControlPoint(String^ autoSearcheviceType)
179  {
180  if (String::IsNullOrEmpty(autoSearcheviceType))
181  {
182  throw gcnew ArgumentException("null or empty", "autoSearcheviceType");
183  }
184 
185  marshal_context c;
186 
187  m_pHandle = new PLT_CtrlPointReference(
188  new PLT_CtrlPoint(c.marshal_as<const char*>(autoSearcheviceType))
189  );
190 
191  m_pDevices = gcnew List<DeviceData^>();
192 
193  RegisterEvents();
194  }
195 
196  ControlPoint(bool autoSearch)
197  {
198  if (autoSearch)
199  {
200  m_pHandle = new PLT_CtrlPointReference(new PLT_CtrlPoint());
201  }
202  else
203  {
204  m_pHandle = new PLT_CtrlPointReference(new PLT_CtrlPoint(0));
205  }
206 
207  m_pDevices = gcnew List<DeviceData^>();
208 
209  RegisterEvents();
210  }
211 
212  ~ControlPoint()
213  {
214  // clean-up managed
215 
216  // clean-up unmanaged
217  this->!ControlPoint();
218  }
219 
220  !ControlPoint();
221 
222 };
223 
224 }
225 
226 // marshal wrapper
227 PLATINUM_MANAGED_MARSHAL_AS(Platinum::ControlPoint, PLT_CtrlPoint);
Definition: DeviceData.h:88
Definition: Service.h:45
Definition: ActionDescription.h:44
Definition: ControlPointEventBridge.h:43
Definition: Action.h:45
Definition: NeptuneException.h:42
Definition: ControlPoint.h:48
bool IsNull() const
Returns whether this references a NULL object.
Definition: NptReferences.h:130
The PLT_CtrlPoint class implements the base functionality of a UPnP ControlPoint. ...
Definition: PltCtrlPoint.h:89