1 /***************************************************************** 2 | 3 | Platinum - Control Point Tasks 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 35 /** @file 36 UPnP ControlPoint Tasks 37 */ 38 39 #ifndef _PLT_CONTROL_POINT_TASK_H_ 40 #define _PLT_CONTROL_POINT_TASK_H_ 41 42 /*---------------------------------------------------------------------- 43 | includes 44 +---------------------------------------------------------------------*/ 45 #include "Neptune.h" 46 #include "PltHttpClientTask.h" 47 #include "PltDatagramStream.h" 48 #include "PltDeviceData.h" 49 #include "PltCtrlPoint.h" 50 51 /*---------------------------------------------------------------------- 52 | forward declarations 53 +---------------------------------------------------------------------*/ 54 class PLT_Action; 55 56 /*---------------------------------------------------------------------- 57 | PLT_CtrlPointGetDescriptionTask class 58 +---------------------------------------------------------------------*/ 59 /** 60 The PLT_CtrlPointGetDescriptionTask class fetches the description xml document 61 from a UPnP device 62 */ 63 class PLT_CtrlPointGetDescriptionTask : public PLT_HttpClientSocketTask 64 { 65 public: 66 PLT_CtrlPointGetDescriptionTask(const NPT_HttpUrl& url, 67 PLT_CtrlPoint* ctrl_point, 68 NPT_TimeInterval leasetime, 69 NPT_String uuid); 70 virtual ~PLT_CtrlPointGetDescriptionTask(); 71 72 protected: 73 // PLT_HttpClientSocketTask methods 74 NPT_Result ProcessResponse(NPT_Result res, 75 const NPT_HttpRequest& request, 76 const NPT_HttpRequestContext& context, 77 NPT_HttpResponse* response); 78 79 protected: 80 PLT_CtrlPoint* m_CtrlPoint; 81 NPT_TimeInterval m_LeaseTime; 82 NPT_String m_UUID; 83 }; 84 85 /*---------------------------------------------------------------------- 86 | PLT_CtrlPointGetSCPDRequest class 87 +---------------------------------------------------------------------*/ 88 /** 89 The PLT_CtrlPointGetSCPDRequest class is used by a PLT_CtrlPointGetSCPDsTask task 90 to fetch a specific SCPD xml document for a given service of a given device. 91 */ 92 class PLT_CtrlPointGetSCPDRequest : public NPT_HttpRequest 93 { 94 public: 95 PLT_CtrlPointGetSCPDRequest(PLT_DeviceDataReference& device, 96 const char* url, 97 const char* method = "GET", 98 const char* protocol = NPT_HTTP_PROTOCOL_1_1) : // 1.1 for pipelining NPT_HttpRequest(url,method,protocol)99 NPT_HttpRequest(url, method, protocol), m_Device(device) {} ~PLT_CtrlPointGetSCPDRequest()100 virtual ~PLT_CtrlPointGetSCPDRequest() {} 101 102 // members 103 PLT_DeviceDataReference m_Device; 104 }; 105 106 /*---------------------------------------------------------------------- 107 | PLT_CtrlPointGetSCPDsTask class 108 +---------------------------------------------------------------------*/ 109 /** 110 The PLT_CtrlPointGetSCPDsTask class fetches the SCPD xml document of one or more 111 services for a given device. 112 */ 113 class PLT_CtrlPointGetSCPDsTask : public PLT_HttpClientSocketTask 114 { 115 public: 116 PLT_CtrlPointGetSCPDsTask(PLT_CtrlPoint* ctrl_point, PLT_DeviceDataReference& root_device); ~PLT_CtrlPointGetSCPDsTask()117 virtual ~PLT_CtrlPointGetSCPDsTask() {} 118 AddSCPDRequest(PLT_CtrlPointGetSCPDRequest * request)119 NPT_Result AddSCPDRequest(PLT_CtrlPointGetSCPDRequest* request) { 120 return PLT_HttpClientSocketTask::AddRequest((NPT_HttpRequest*)request); 121 } 122 123 // override to prevent calling this directly AddRequest(NPT_HttpRequest *)124 NPT_Result AddRequest(NPT_HttpRequest*) { 125 // only queuing PLT_CtrlPointGetSCPDRequest allowed 126 return NPT_ERROR_NOT_SUPPORTED; 127 } 128 129 protected: 130 // PLT_HttpClientSocketTask methods 131 NPT_Result ProcessResponse(NPT_Result res, 132 const NPT_HttpRequest& request, 133 const NPT_HttpRequestContext& context, 134 NPT_HttpResponse* response); 135 136 protected: 137 PLT_CtrlPoint* m_CtrlPoint; 138 PLT_DeviceDataReference m_RootDevice; 139 }; 140 141 /*---------------------------------------------------------------------- 142 | PLT_CtrlPointInvokeActionTask class 143 +---------------------------------------------------------------------*/ 144 /** 145 The PLT_CtrlPointInvokeActionTask class is used by a PLT_CtrlPoint to invoke 146 a specific action of a given service for a given device. 147 */ 148 class PLT_CtrlPointInvokeActionTask : public PLT_HttpClientSocketTask 149 { 150 public: 151 PLT_CtrlPointInvokeActionTask(NPT_HttpRequest* request, 152 PLT_CtrlPoint* ctrl_point, 153 PLT_ActionReference& action, 154 void* userdata); 155 virtual ~PLT_CtrlPointInvokeActionTask(); 156 157 protected: 158 // PLT_HttpClientSocketTask methods 159 NPT_Result ProcessResponse(NPT_Result res, 160 const NPT_HttpRequest& request, 161 const NPT_HttpRequestContext& context, 162 NPT_HttpResponse* response); 163 164 protected: 165 PLT_CtrlPoint* m_CtrlPoint; 166 PLT_ActionReference m_Action; 167 void* m_Userdata; 168 }; 169 170 /*---------------------------------------------------------------------- 171 | PLT_CtrlPointHouseKeepingTask class 172 +---------------------------------------------------------------------*/ 173 /** 174 The PLT_CtrlPointHouseKeepingTask class is used by a PLT_CtrlPoint to keep 175 track of expired devices and autmatically renew event subscribers. 176 */ 177 class PLT_CtrlPointHouseKeepingTask : public PLT_ThreadTask 178 { 179 public: 180 PLT_CtrlPointHouseKeepingTask(PLT_CtrlPoint* ctrl_point, 181 NPT_TimeInterval timer = NPT_TimeInterval(5.)); 182 183 protected: ~PLT_CtrlPointHouseKeepingTask()184 ~PLT_CtrlPointHouseKeepingTask() {} 185 186 // PLT_ThreadTask methods 187 virtual void DoRun(); 188 189 protected: 190 PLT_CtrlPoint* m_CtrlPoint; 191 NPT_TimeInterval m_Timer; 192 }; 193 194 /*---------------------------------------------------------------------- 195 | PLT_CtrlPointSubscribeEventTask class 196 +---------------------------------------------------------------------*/ 197 /** 198 The PLT_CtrlPointSubscribeEventTask class is used to subscribe, renew or cancel 199 a subscription for a given service of a given device. 200 */ 201 class PLT_CtrlPointSubscribeEventTask : public PLT_HttpClientSocketTask 202 { 203 public: 204 PLT_CtrlPointSubscribeEventTask(NPT_HttpRequest* request, 205 PLT_CtrlPoint* ctrl_point, 206 PLT_DeviceDataReference& device, 207 PLT_Service* service, 208 void* userdata = NULL); 209 virtual ~PLT_CtrlPointSubscribeEventTask(); 210 211 protected: 212 // PLT_HttpClientSocketTask methods 213 NPT_Result ProcessResponse(NPT_Result res, 214 const NPT_HttpRequest& request, 215 const NPT_HttpRequestContext& context, 216 NPT_HttpResponse* response); 217 218 protected: 219 PLT_CtrlPoint* m_CtrlPoint; 220 PLT_Service* m_Service; 221 PLT_DeviceDataReference m_Device; // force to keep a reference to device owning m_Service 222 void* m_Userdata; 223 }; 224 225 #endif /* _PLT_CONTROL_POINT_TASK_H_ */ 226