PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/libUPnP/Platinum/Targets/universal-apple-macosx/Release/Platinum.framework/Versions/A/Headers/PltCtrlPoint.h

https://gitlab.com/jothow/kodi
C Header | 254 lines | 150 code | 29 blank | 75 comment | 0 complexity | 86aab5e5ae2a21b93ab212e6f5a63595 MD5 | raw file
  1. /*****************************************************************
  2. |
  3. | Platinum - Control Point
  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. | licensing@plutinosoft.com
  21. |
  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.
  26. |
  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
  32. |
  33. ****************************************************************/
  34. /** @file
  35. UPnP ControlPoint
  36. */
  37. #ifndef _PLT_CONTROL_POINT_H_
  38. #define _PLT_CONTROL_POINT_H_
  39. /*----------------------------------------------------------------------
  40. | includes
  41. +---------------------------------------------------------------------*/
  42. #include "Neptune.h"
  43. #include "PltService.h"
  44. #include "PltSsdp.h"
  45. #include "PltDeviceData.h"
  46. #include "PltHttpServer.h"
  47. /*----------------------------------------------------------------------
  48. | forward declarations
  49. +---------------------------------------------------------------------*/
  50. class PLT_CtrlPointHouseKeepingTask;
  51. class PLT_SsdpSearchTask;
  52. class PLT_SsdpListenTask;
  53. class PLT_CtrlPointGetSCPDsTask;
  54. class PLT_CtrlPointGetSCPDRequest;
  55. /*----------------------------------------------------------------------
  56. | PLT_CtrlPointListener class
  57. +---------------------------------------------------------------------*/
  58. /**
  59. The PLT_CtrlPointListener class is an interface used to receive notifications when
  60. devices are found or removed from the network, actions responses and events
  61. are being received.
  62. */
  63. class PLT_CtrlPointListener
  64. {
  65. public:
  66. virtual ~PLT_CtrlPointListener() {}
  67. virtual NPT_Result OnDeviceAdded(PLT_DeviceDataReference& device) = 0;
  68. virtual NPT_Result OnDeviceRemoved(PLT_DeviceDataReference& device) = 0;
  69. virtual NPT_Result OnActionResponse(NPT_Result res, PLT_ActionReference& action, void* userdata) = 0;
  70. virtual NPT_Result OnEventNotify(PLT_Service* service, NPT_List<PLT_StateVariable*>* vars) = 0;
  71. };
  72. typedef NPT_List<PLT_CtrlPointListener*> PLT_CtrlPointListenerList;
  73. /*----------------------------------------------------------------------
  74. | PLT_CtrlPoint class
  75. +---------------------------------------------------------------------*/
  76. /**
  77. The PLT_CtrlPoint class implements the base functionality of a UPnP ControlPoint.
  78. It searches and inpects devices, invoke actions on services and subscribes to
  79. events.
  80. */
  81. class PLT_CtrlPoint : public PLT_SsdpPacketListener,
  82. public PLT_SsdpSearchResponseListener,
  83. public NPT_HttpRequestHandler
  84. {
  85. public:
  86. PLT_CtrlPoint(const char* search_criteria = "upnp:rootdevice"); // pass NULL to prevent repeated automatic search
  87. virtual ~PLT_CtrlPoint();
  88. /**
  89. Returns the port used by the internal HTTP server for all incoming event notifications.
  90. @return port
  91. */
  92. virtual NPT_Result GetPort(NPT_UInt16& port);
  93. // delegation
  94. virtual NPT_Result AddListener(PLT_CtrlPointListener* listener);
  95. virtual NPT_Result RemoveListener(PLT_CtrlPointListener* listener);
  96. // discovery
  97. virtual void IgnoreUUID(const char* uuid);
  98. virtual NPT_Result Search(const NPT_HttpUrl& url = NPT_HttpUrl("239.255.255.250", 1900, "*"),
  99. const char* target = "upnp:rootdevice",
  100. NPT_Cardinal mx = 5,
  101. NPT_TimeInterval frequency = NPT_TimeInterval(50.), // pass NPT_TimeInterval(0.) for one time only
  102. NPT_TimeInterval initial_delay = NPT_TimeInterval(0.));
  103. virtual NPT_Result Discover(const NPT_HttpUrl& url = NPT_HttpUrl("239.255.255.250", 1900, "*"),
  104. const char* target = "ssdp:all",
  105. NPT_Cardinal mx = 5,
  106. NPT_TimeInterval frequency = NPT_TimeInterval(50.), // pass NPT_TimeInterval(0.) for one time only
  107. NPT_TimeInterval initial_delay = NPT_TimeInterval(0.));
  108. virtual NPT_Result InspectDevice(const NPT_HttpUrl& location,
  109. const char* uuid,
  110. NPT_TimeInterval leasetime = *PLT_Constants::GetInstance().GetDefaultDeviceLease());
  111. // actions
  112. virtual NPT_Result FindActionDesc(PLT_DeviceDataReference& device,
  113. const char* service_type,
  114. const char* action_name,
  115. PLT_ActionDesc*& action_desc);
  116. virtual NPT_Result CreateAction(PLT_DeviceDataReference& device,
  117. const char* service_type,
  118. const char* action_name,
  119. PLT_ActionReference& action);
  120. virtual NPT_Result InvokeAction(PLT_ActionReference& action,
  121. void* userdata = NULL);
  122. // events
  123. virtual NPT_Result Subscribe(PLT_Service* service,
  124. bool cancel = false,
  125. void* userdata = NULL);
  126. // NPT_HttpRequestHandler methods
  127. virtual NPT_Result SetupResponse(NPT_HttpRequest& request,
  128. const NPT_HttpRequestContext& context,
  129. NPT_HttpResponse& response);
  130. // PLT_SsdpSearchResponseListener methods
  131. virtual NPT_Result ProcessSsdpSearchResponse(NPT_Result res,
  132. const NPT_HttpRequestContext& context,
  133. NPT_HttpResponse* response);
  134. // PLT_SsdpPacketListener method
  135. virtual NPT_Result OnSsdpPacket(const NPT_HttpRequest& request,
  136. const NPT_HttpRequestContext& context);
  137. protected:
  138. // State Variable Handling
  139. virtual NPT_Result DecomposeLastChangeVar(NPT_List<PLT_StateVariable*>& vars);
  140. // methods
  141. virtual NPT_Result Start(PLT_SsdpListenTask* task);
  142. virtual NPT_Result Stop(PLT_SsdpListenTask* task);
  143. // SSDP & HTTP Notifications handling
  144. virtual NPT_Result ProcessSsdpNotify(const NPT_HttpRequest& request,
  145. const NPT_HttpRequestContext& context);
  146. virtual NPT_Result ProcessSsdpMessage(const NPT_HttpMessage& message,
  147. const NPT_HttpRequestContext& context,
  148. NPT_String& uuid);
  149. virtual NPT_Result ProcessGetDescriptionResponse(NPT_Result res,
  150. const NPT_HttpRequest& request,
  151. const NPT_HttpRequestContext& context,
  152. NPT_HttpResponse* response,
  153. NPT_TimeInterval leasetime,
  154. NPT_String uuid);
  155. virtual NPT_Result ProcessGetSCPDResponse(NPT_Result res,
  156. const NPT_HttpRequest& request,
  157. const NPT_HttpRequestContext& context,
  158. NPT_HttpResponse* response,
  159. PLT_DeviceDataReference& device);
  160. virtual NPT_Result ProcessActionResponse(NPT_Result res,
  161. const NPT_HttpRequest& request,
  162. const NPT_HttpRequestContext& context,
  163. NPT_HttpResponse* response,
  164. PLT_ActionReference& action,
  165. void* userdata);
  166. virtual NPT_Result ProcessSubscribeResponse(NPT_Result res,
  167. const NPT_HttpRequest& request,
  168. const NPT_HttpRequestContext& context,
  169. NPT_HttpResponse* response,
  170. PLT_Service* service,
  171. void* userdata);
  172. virtual NPT_Result ProcessHttpNotify(const NPT_HttpRequest& request,
  173. const NPT_HttpRequestContext& context,
  174. NPT_HttpResponse& response);
  175. // Device management
  176. virtual NPT_Result AddDevice(PLT_DeviceDataReference& data);
  177. virtual NPT_Result RemoveDevice(PLT_DeviceDataReference& data);
  178. private:
  179. // methods
  180. PLT_ThreadTask* RenewSubscriber(PLT_EventSubscriberReference subscriber);
  181. NPT_Result AddPendingEventNotification(PLT_EventNotification *notification);
  182. NPT_Result ProcessPendingEventNotifications();
  183. NPT_Result ProcessEventNotification(PLT_EventSubscriberReference subscriber,
  184. PLT_EventNotification* notification,
  185. NPT_List<PLT_StateVariable*> &vars);
  186. NPT_Result DoHouseKeeping();
  187. NPT_Result FetchDeviceSCPDs(PLT_CtrlPointGetSCPDsTask* task,
  188. PLT_DeviceDataReference& device,
  189. NPT_Cardinal level);
  190. // Device management
  191. NPT_Result FindDevice(const char* uuid, PLT_DeviceDataReference& device, bool return_root = false);
  192. NPT_Result NotifyDeviceReady(PLT_DeviceDataReference& data);
  193. NPT_Result NotifyDeviceRemoved(PLT_DeviceDataReference& data);
  194. NPT_Result CleanupDevice(PLT_DeviceDataReference& data);
  195. NPT_Result ParseFault(PLT_ActionReference& action, NPT_XmlElementNode* fault);
  196. PLT_SsdpSearchTask* CreateSearchTask(const NPT_HttpUrl& url,
  197. const char* target,
  198. NPT_Cardinal mx,
  199. NPT_TimeInterval frequency,
  200. const NPT_IpAddress& address);
  201. private:
  202. friend class NPT_Reference<PLT_CtrlPoint>;
  203. friend class PLT_UPnP;
  204. friend class PLT_UPnP_CtrlPointStartIterator;
  205. friend class PLT_UPnP_CtrlPointStopIterator;
  206. friend class PLT_EventSubscriberRemoverIterator;
  207. friend class PLT_CtrlPointGetDescriptionTask;
  208. friend class PLT_CtrlPointGetSCPDsTask;
  209. friend class PLT_CtrlPointInvokeActionTask;
  210. friend class PLT_CtrlPointHouseKeepingTask;
  211. friend class PLT_CtrlPointSubscribeEventTask;
  212. NPT_List<NPT_String> m_UUIDsToIgnore;
  213. PLT_CtrlPointListenerList m_ListenerList;
  214. PLT_HttpServerReference m_EventHttpServer;
  215. PLT_TaskManagerReference m_TaskManager;
  216. NPT_Mutex m_Lock;
  217. NPT_List<PLT_DeviceDataReference> m_RootDevices;
  218. NPT_List<PLT_EventSubscriberReference> m_Subscribers;
  219. NPT_String m_SearchCriteria;
  220. bool m_Started;
  221. NPT_List<PLT_EventNotification *> m_PendingNotifications;
  222. NPT_List<NPT_String> m_PendingInspections;
  223. };
  224. typedef NPT_Reference<PLT_CtrlPoint> PLT_CtrlPointReference;
  225. #endif /* _PLT_CONTROL_POINT_H_ */