Platinum UPnP SDK  1.0.5.13
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  virtual ~PLT_HttpClientSocketTask();
66 
67  virtual NPT_Result AddRequest(NPT_HttpRequest* request);
68  virtual NPT_Result SetHttpClientConfig(const NPT_HttpClient::Config& config);
69 
70 protected:
71  // PLT_ThreadTask methods
72  virtual void DoAbort();
73  virtual void DoRun();
74 
75  virtual NPT_Result ProcessResponse(NPT_Result res,
76  const NPT_HttpRequest& request,
77  const NPT_HttpRequestContext& context,
78  NPT_HttpResponse* response);
79 
80 private:
81  NPT_Result GetNextRequest(NPT_HttpRequest*& request, NPT_Timeout timeout_ms);
82 
83 protected:
84  NPT_HttpClient m_Client;
85  bool m_WaitForever;
86  NPT_Queue<NPT_HttpRequest> m_Requests;
87 };
88 
89 /*----------------------------------------------------------------------
90 | PLT_HttpClientTask class
91 +---------------------------------------------------------------------*/
96 template <class T>
98 {
99 public:
100  PLT_HttpClientTask<T>(const NPT_HttpUrl& url, T* data) :
101  PLT_HttpClientSocketTask(new NPT_HttpRequest(url,
102  "GET",
103  NPT_HTTP_PROTOCOL_1_1)),
104  m_Data(data) {}
105  protected:
106  virtual ~PLT_HttpClientTask<T>() {}
107 
108 protected:
109  // PLT_HttpClientSocketTask method
110  NPT_Result ProcessResponse(NPT_Result res,
111  const NPT_HttpRequest& request,
112  const NPT_HttpRequestContext& context,
113  NPT_HttpResponse* response) {
114  return m_Data->ProcessResponse(res, request, context, response);
115  }
116 
117 protected:
118  T* m_Data;
119 };
120 
121 #endif /* _PLT_HTTP_CLIENT_TASK_H_ */
Runnable Task.
The PLT_HttpClientSocketTask class is the base class used to send a HTTP request asynchronously using...
Definition: PltHttpClientTask.h:58
virtual void DoAbort()
This method to override in derived classes is called when the task is about to stop.
virtual void DoRun()
This method to override in derived classes is the main task loop.
The PLT_ThreadTask class is a base class for executing a given task in a worker thread.
Definition: PltThreadTask.h:56
The PLT_HttpClientTask class is a templatized version of PLT_HttpClientSocketTask to support arbitrar...
Definition: PltHttpClientTask.h:97
HTTP utilities.