2 #include "IParaWebService.h" 6 #include <boost/asio.hpp> 7 #include <boost/thread.hpp> 8 #include <boost/scoped_ptr.hpp> 11 #include <curl/curl.h> 16 #ifdef HAS_JABBER_CLIENT 17 class CNPLJabberClient;
39 typedef DWORD (*URL_REQUEST_TASK_CALLBACK)(
int nResult,
CURLRequestTask* pRequest, LPVOID lpUserData);
51 URL_REQUEST_HTTP_AUTO,
53 URL_REQUEST_HTTP_POST,
54 URL_REQUEST_HTTP_GETFILE,
61 URL_REQUEST_UNSTARTED,
62 URL_REQUEST_INCOMPLETE,
63 URL_REQUEST_COMPLETED,
66 static const DWORD DEFAULT_TIME_OUT = 15000;
68 CURLRequestTask():m_pFormPost(0), m_nTimeOutTime(DEFAULT_TIME_OUT), m_nStartTime(0),m_responseCode(0), m_pFormLast(0), m_pUserData(0), m_returnCode(CURLE_OK), m_type(URL_REQUEST_HTTP_AUTO), m_nPriority(0), m_nStatus(URL_REQUEST_UNSTARTED), m_pfuncCallBack(0), m_nBytesReceived(0), m_nTotalBytes(0), m_nUserDataType(0) {};
73 CURLFORMcode AppendFormParam(
const char* name,
const char*
value);
80 CURLFORMcode AppendFormParam(
const char* name,
const char* type,
const char* file,
const char* data,
int datalen);
83 void SetCurlEasyOpt(CURL*
handle);
89 static size_t CUrl_write_data_callback(
void *buffer,
size_t size,
size_t nmemb,
void *stream);
90 static size_t CUrl_write_header_callback(
void *buffer,
size_t size,
size_t nmemb,
void *stream);
93 void SetTimeOut(
int nMilliSeconds);
101 void SetAssetRequestOpt(
CAssetRequestData* pRequestData, URL_REQUEST_TASK_CALLBACK pFuncCallback=NULL);
106 static DWORD Asset_HTTP_request_callback(
int nResult,
CURLRequestTask* pRequest, LPVOID lpUserData);
109 void SafeDeleteUserData();
114 bool IsTimedOut(DWORD nCurrentTime);
161 int m_nBytesReceived;
164 vector<char> m_header;
165 string m_sResponseData;
166 string m_sResponseHeader;
168 CURLcode m_returnCode;
195 CUrlWorkerState(): m_easy_handle(NULL), m_pCurrentTask(NULL), m_returnCode(CURLE_OK), m_bIsCompleted(
true) {};
198 CURLcode m_returnCode;
204 CRequestTaskPool():m_nRunningTaskCount(0), m_nMaxWorkerThreads(1), m_nMaxQueuedTask(65535), m_multi_handle(NULL){}
218 void SetMaxTaskSlotsCount(
int nCount);
228 int CURL_MultiPerform();
233 std::list <CURLRequestTask*> m_task_pool;
236 int m_nMaxWorkerThreads;
238 std::list <CUrlWorkerState> m_easy_handles;
241 int m_nMaxQueuedTask;
243 CURLM * m_multi_handle;
245 int m_nRunningTaskCount;
261 static void ReleaseInstance();
276 virtual INPLWebService* OpenWebService(
const char* sURL,
const char* sUserName,
const char* sPassword,
const char* sDomain);
282 virtual bool CloseWebService(
const char* sURL);
301 virtual bool CloseJabberClient(
const char* sJID);
308 virtual void AsyncDownload(
const char* url,
const char* destFolder,
const char* callbackScript,
const char* DownloaderName);
315 virtual void CancelDownload(
const char* DownloaderName);
322 virtual int Download(
const char* url,
const char* destFolder,
const char* callbackScript,
const char* DownloaderName);
328 virtual int ProcessResults();
334 virtual int ProcessDownloaderResults();
337 virtual void DeleteThis();
355 virtual bool AppendURLRequest(
CURLRequestTask* pUrlTask,
const char* sPoolName = NULL);
361 virtual bool ChangeRequestPoolSize(
const char* sPoolName,
int nCount);
367 virtual int ProcessUrlRequests();
372 void AddPendingRequest(
const char* sURL);
377 bool HasPendingRequest(
const char* sURL);
380 void RemovePendingRequest(
const char* sURL);
383 void ClearAllPendingRequests();
386 string GetCachePath(
const char* sFileUrl);
396 #ifdef HAS_JABBER_CLIENT 397 std::map <std::string, CNPLJabberClient*> m_jabberClients;
399 std::map <std::string, CRequestTaskPool*> m_request_pools;
401 std::set <std::string> m_pending_requests;
404 boost::asio::io_service m_dispatcher_io_service;
407 boost::scoped_ptr<boost::thread> m_dispatcherThread;
411 boost::scoped_ptr<boost::asio::io_service::work> m_work_lifetime;
bool m_bLazyLoading
default to true.
Definition: NPLNetClient.h:35
Definition: handle.hpp:33
NPL interface of a XML Web service client proxy.
Definition: IParaWebService.h:50
different physics engine has different winding order.
Definition: EventBinding.h:32
a task pool is a collection of requests of which only a specified limited number of worker threads ar...
Definition: NPLNetClient.h:188
DWORD m_nStartTime
The time that this request is started or received any response.
Definition: NPLNetClient.h:155
URLREQUEST_TYPE m_type
The type of the url request task.
Definition: NPLNetClient.h:150
struct curl_httppost * m_pFormPost
CURLOPT_HTTPPOST.
Definition: NPLNetClient.h:125
URL request can be a HTTP get/post request etc.
Definition: NPLNetClient.h:45
URL_REQUEST_TASK_CALLBACK m_pfuncCallBack
the C++ function to call when task is finished.
Definition: NPLNetClient.h:134
Option names.
Definition: NPLNetClient.h:252
int m_nAssetType
it is of AssetEntity::AssetType
Definition: NPLNetClient.h:31
an asset request data to be sent via the CURLRequestTask
Definition: NPLNetClient.h:24
NPL interface of a Jabber-XMPP client proxy.
Definition: IParaWebService.h:108
URLREQUEST_STATUS m_nStatus
the current status of the request.
Definition: NPLNetClient.h:152
Definition: enum_maker.hpp:46
URLREQUEST_TYPE
type of the url request task
Definition: NPLNetClient.h:49
int m_nPriority
task priority
Definition: NPLNetClient.h:129
url worker state.
Definition: NPLNetClient.h:192
string m_sSaveToFileName
the file name to save the response data to
Definition: NPLNetClient.h:136
bool m_bIsCompleted
what this message means
Definition: NPLNetClient.h:200
string m_sNPLCallback
the NPL function to call when task is finished.
Definition: NPLNetClient.h:131
interface of NPL web service client.
Definition: IParaWebService.h:466
int m_nUserDataType
default to 0.
Definition: NPLNetClient.h:141
string m_url
CURLOPT_URL.
Definition: NPLNetClient.h:123
URLREQUEST_STATUS
url request status
Definition: NPLNetClient.h:58
Base class for managed asset entity in ParaEngine.
Definition: AssetEntity.h:25
DWORD m_nTimeOutTime
for how long the request is considered timed out.
Definition: NPLNetClient.h:159
string m_sAssetKey
this is usually used to locate the asset entity once request is finished.
Definition: NPLNetClient.h:33