Platinum UPnP SDK
PltHttpClientTask.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | Platinum - HTTP Client 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 
39 #ifndef _PLT_HTTP_CLIENT_TASK_H_
40 #define _PLT_HTTP_CLIENT_TASK_H_
41 
42 /*----------------------------------------------------------------------
43 | includes
44 +---------------------------------------------------------------------*/
45 #include "Neptune.h"
46 #include "PltHttp.h"
47 #include "PltThreadTask.h"
48 
49 /*----------------------------------------------------------------------
50 | PLT_HttpClientSocketTask class
51 +---------------------------------------------------------------------*/
59 {
60 friend class PLT_ThreadTask;
61 
62 public:
63  PLT_HttpClientSocketTask(NPT_HttpRequest* request = NULL,
64  bool wait_forever = false);
65 
66  virtual NPT_Result AddRequest(NPT_HttpRequest* request);
67  virtual NPT_Result SetHttpClientConfig(const NPT_HttpClient::Config& config);
68 
69 protected:
70  virtual ~PLT_HttpClientSocketTask();
71 
72 protected:
73  // PLT_ThreadTask methods
74  virtual void DoAbort();
75  virtual void DoRun();
76 
77  virtual NPT_Result ProcessResponse(NPT_Result res,
78  const NPT_HttpRequest& request,
79  const NPT_HttpRequestContext& context,
80  NPT_HttpResponse* response);
81 
82 private:
83  NPT_Result GetNextRequest(NPT_HttpRequest*& request, NPT_Timeout timeout_ms);
84 
85 protected:
86  NPT_HttpClient m_Client;
87  bool m_WaitForever;
88  NPT_Queue<NPT_HttpRequest> m_Requests;
89 };
90 
91 /*----------------------------------------------------------------------
92 | PLT_HttpClientTask class
93 +---------------------------------------------------------------------*/
98 template <class T>
100 {
101 public:
102  PLT_HttpClientTask<T>(const NPT_HttpUrl& url, T* data) :
103  PLT_HttpClientSocketTask(new NPT_HttpRequest(url,
104  "GET",
105  NPT_HTTP_PROTOCOL_1_1)),
106  m_Data(data) {}
107  protected:
108  virtual ~PLT_HttpClientTask<T>() {}
109 
110 protected:
111  // PLT_HttpClientSocketTask method
112  NPT_Result ProcessResponse(NPT_Result res,
113  const NPT_HttpRequest& request,
114  const NPT_HttpRequestContext& context,
115  NPT_HttpResponse* response) {
116  return m_Data->ProcessResponse(res, request, context, response);
117  }
118 
119 protected:
120  T* m_Data;
121 };
122 
123 #endif /* _PLT_HTTP_CLIENT_TASK_H_ */