1
0

wac_downloadManager_api.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #ifndef NULLSOFT_WAC_DOWNLOAD_MANAGER_API_DOWNLOADMANAGER_H
  2. #define NULLSOFT_WAC_DOWNLOAD_MANAGER_API_DOWNLOADMANAGER_H
  3. #include "bfc/dispatch.h"
  4. typedef void *DownloadToken;
  5. class ifc_downloadManagerCallback;
  6. class api_httpreceiver;
  7. class ifc_downloadManagerCallback : public Dispatchable
  8. {
  9. public:
  10. void OnFinish( DownloadToken token );
  11. void OnTick( DownloadToken token );
  12. void OnError( DownloadToken token, int error );
  13. void OnCancel( DownloadToken token );
  14. void OnConnect( DownloadToken token );
  15. void OnInit( DownloadToken token );
  16. void OnData( DownloadToken token, void *data, size_t datalen );
  17. int GetSource( wchar_t *source, size_t source_cch );
  18. int GetTitle( wchar_t *title, size_t title_cch );
  19. int GetLocation( wchar_t *location, size_t location_cch );
  20. DISPATCH_CODES
  21. {
  22. IFC_DOWNLOADMANAGERCALLBACK_ONFINISH = 10,
  23. IFC_DOWNLOADMANAGERCALLBACK_ONTICK = 20,
  24. IFC_DOWNLOADMANAGERCALLBACK_ONERROR = 30,
  25. IFC_DOWNLOADMANAGERCALLBACK_ONCANCEL = 40,
  26. IFC_DOWNLOADMANAGERCALLBACK_ONCONNECT = 50,
  27. IFC_DOWNLOADMANAGERCALLBACK_ONINIT = 60,
  28. IFC_DOWNLOADMANAGERCALLBACK_ONDATA = 70,
  29. IFC_DOWNLOADMANAGERCALLBACK_GETSOURCE = 80,
  30. IFC_DOWNLOADMANAGERCALLBACK_GETTITLE = 90,
  31. IFC_DOWNLOADMANAGERCALLBACK_GETLOCATION = 100,
  32. };
  33. };
  34. inline void ifc_downloadManagerCallback::OnFinish( DownloadToken token )
  35. {
  36. _voidcall( IFC_DOWNLOADMANAGERCALLBACK_ONFINISH, token );
  37. }
  38. inline void ifc_downloadManagerCallback::OnTick( DownloadToken token )
  39. {
  40. _voidcall( IFC_DOWNLOADMANAGERCALLBACK_ONTICK, token );
  41. }
  42. inline void ifc_downloadManagerCallback::OnError( DownloadToken token, int error )
  43. {
  44. _voidcall( IFC_DOWNLOADMANAGERCALLBACK_ONERROR, token, error );
  45. }
  46. inline void ifc_downloadManagerCallback::OnCancel( DownloadToken token )
  47. {
  48. _voidcall( IFC_DOWNLOADMANAGERCALLBACK_ONCANCEL, token );
  49. }
  50. inline void ifc_downloadManagerCallback::OnConnect( DownloadToken token )
  51. {
  52. _voidcall( IFC_DOWNLOADMANAGERCALLBACK_ONCONNECT, token );
  53. }
  54. inline void ifc_downloadManagerCallback::OnInit( DownloadToken token )
  55. {
  56. _voidcall( IFC_DOWNLOADMANAGERCALLBACK_ONINIT, token );
  57. }
  58. inline void ifc_downloadManagerCallback::OnData( DownloadToken token, void *data, size_t datalen )
  59. {
  60. _voidcall( IFC_DOWNLOADMANAGERCALLBACK_ONDATA, token, data, datalen );
  61. }
  62. inline int ifc_downloadManagerCallback::GetSource( wchar_t *source, size_t source_cch )
  63. {
  64. return _call( IFC_DOWNLOADMANAGERCALLBACK_GETSOURCE, (int)1, source, source_cch );
  65. }
  66. inline int ifc_downloadManagerCallback::GetTitle( wchar_t *title, size_t title_cch )
  67. {
  68. return _call( IFC_DOWNLOADMANAGERCALLBACK_GETTITLE, (int)1, title, title_cch );
  69. }
  70. inline int ifc_downloadManagerCallback::GetLocation( wchar_t *location, size_t location_cch )
  71. {
  72. return _call( IFC_DOWNLOADMANAGERCALLBACK_GETLOCATION, (int)1, location, location_cch );
  73. }
  74. class api_downloadManager : public Dispatchable
  75. {
  76. public:
  77. DownloadToken Download( const char *url, ifc_downloadManagerCallback *callback );
  78. DownloadToken DownloadEx( const char *url, ifc_downloadManagerCallback *callback, int flags );
  79. api_httpreceiver *GetReceiver( DownloadToken token );
  80. const wchar_t *GetLocation( DownloadToken token );
  81. void SetLocation( DownloadToken token, const wchar_t *p_location );
  82. const char *GetExtention( DownloadToken token );
  83. const char *GetUrl( DownloadToken token );
  84. int GetBuffer( DownloadToken token, void **buffer, size_t *bufferLength );
  85. uint64_t GetBytesDownloaded( DownloadToken token );
  86. void ResumePendingDownload( DownloadToken token );
  87. void CancelDownload( DownloadToken token );
  88. void RetainDownload( DownloadToken token );
  89. void ReleaseDownload( DownloadToken token );
  90. /* added in 5.58 */
  91. void RegisterStatusCallback( ifc_downloadManagerCallback *callback );
  92. void UnregisterStatusCallback( ifc_downloadManagerCallback *callback );
  93. const wchar_t *GetSource( DownloadToken token );
  94. const wchar_t *GetTitle( DownloadToken token );
  95. bool IsPending( DownloadToken token );
  96. DISPATCH_CODES
  97. {
  98. API_DOWNLOADMANAGER_DOWNLOAD = 10,
  99. API_DOWNLOADMANAGER_DOWNLOADEX = 20,
  100. API_DOWNLOADMANAGER_GETRECEIVER = 100,
  101. API_DOWNLOADMANAGER_GETLOCATION = 110,
  102. API_DOWNLOADMANAGER_SETLOCATION = 112,
  103. API_DOWNLOADMANAGER_GETEXTENTION = 115,
  104. API_DOWNLOADMANAGER_GETURL = 117,
  105. API_DOWNLOADMANAGER_GETBYTESDOWNLOADED = 120,
  106. API_DOWNLOADMANAGER_GETBUFFER = 130,
  107. API_DOWNLOADMANAGER_CANCELDOWNLOAD = 140,
  108. API_DOWNLOADMANAGER_RETAINDOWNLOAD = 150,
  109. API_DOWNLOADMANAGER_RELEASEDOWNLOAD = 160,
  110. API_DOWNLOADMANAGER_REGISTERSTATUSCALLBACK = 170,
  111. API_DOWNLOADMANAGER_UNREGISTERSTATUSCALLBACK = 180,
  112. API_DOWNLOADMANAGER_GETSOURCE = 190,
  113. API_DOWNLOADMANAGER_GETTITLE = 200,
  114. API_DOWNLOADMANAGER_RESUMEPENDINGDOWNLOAD = 210,
  115. API_DOWNLOADMANAGER_ISPENDING = 220,
  116. };
  117. enum
  118. {
  119. DOWNLOADEX_TEMPFILE = 0, // download as a temporary file
  120. DOWNLOADEX_BUFFER = 1, // download to memory
  121. DOWNLOADEX_CALLBACK = 2, // send data to OnData callback
  122. DOWNLOADEX_MASK_DOWNLOADMETHOD = 0x3,
  123. DOWNLOADEX_PENDING = 0xF00,
  124. DOWNLOADEX_UI = 0xF000, // show up in the download manager UI
  125. };
  126. enum
  127. {
  128. TICK_NODATA = -2, // not necessarily an error, just means no data this time around
  129. TICK_FINISHED = -1,
  130. TICK_SUCCESS = 0,
  131. TICK_FAILURE = 1,
  132. TICK_TIMEOUT = 2,
  133. TICK_CANT_CONNECT = 3,
  134. TICK_WRITE_ERROR = 4,
  135. TICK_CONNECTING = 5,
  136. TICK_CONNECTED = 6,
  137. };
  138. };
  139. inline DownloadToken api_downloadManager::Download( const char *url, ifc_downloadManagerCallback *callback )
  140. {
  141. return _call( API_DOWNLOADMANAGER_DOWNLOAD, (DownloadToken *)0, url, callback );
  142. }
  143. inline DownloadToken api_downloadManager::DownloadEx( const char *url, ifc_downloadManagerCallback *callback, int flags )
  144. {
  145. return _call( API_DOWNLOADMANAGER_DOWNLOADEX, (DownloadToken *)0, url, callback, flags );
  146. }
  147. inline api_httpreceiver *api_downloadManager::GetReceiver( DownloadToken token )
  148. {
  149. return _call( API_DOWNLOADMANAGER_GETRECEIVER, (api_httpreceiver *)0, token );
  150. }
  151. inline const wchar_t *api_downloadManager::GetLocation( DownloadToken token )
  152. {
  153. return _call( API_DOWNLOADMANAGER_GETLOCATION, (const wchar_t *)0, token );
  154. }
  155. inline void api_downloadManager::SetLocation( DownloadToken token, const wchar_t *p_location )
  156. {
  157. _voidcall( API_DOWNLOADMANAGER_SETLOCATION, token, p_location );
  158. }
  159. inline const char *api_downloadManager::GetExtention( DownloadToken token )
  160. {
  161. return _call( API_DOWNLOADMANAGER_GETEXTENTION, (const char *)0, token );
  162. }
  163. inline const char *api_downloadManager::GetUrl( DownloadToken token )
  164. {
  165. return _call( API_DOWNLOADMANAGER_GETURL, (const char *)0, token );
  166. }
  167. inline uint64_t api_downloadManager::GetBytesDownloaded( DownloadToken token )
  168. {
  169. return _call( API_DOWNLOADMANAGER_GETBYTESDOWNLOADED, (uint64_t)0, token );
  170. }
  171. inline int api_downloadManager::GetBuffer( DownloadToken token, void **buffer, size_t *bufferLength )
  172. {
  173. return _call( API_DOWNLOADMANAGER_GETBUFFER, (int)1, token, buffer, bufferLength );
  174. }
  175. inline void api_downloadManager::ResumePendingDownload( DownloadToken token )
  176. {
  177. _voidcall( API_DOWNLOADMANAGER_RESUMEPENDINGDOWNLOAD, token );
  178. }
  179. inline void api_downloadManager::CancelDownload( DownloadToken token )
  180. {
  181. _voidcall( API_DOWNLOADMANAGER_CANCELDOWNLOAD, token );
  182. }
  183. inline void api_downloadManager::RetainDownload( DownloadToken token )
  184. {
  185. _voidcall( API_DOWNLOADMANAGER_RETAINDOWNLOAD, token );
  186. }
  187. inline void api_downloadManager::ReleaseDownload( DownloadToken token )
  188. {
  189. _voidcall( API_DOWNLOADMANAGER_RELEASEDOWNLOAD, token );
  190. }
  191. inline void api_downloadManager::RegisterStatusCallback( ifc_downloadManagerCallback *callback )
  192. {
  193. _voidcall( API_DOWNLOADMANAGER_REGISTERSTATUSCALLBACK, callback );
  194. }
  195. inline void api_downloadManager::UnregisterStatusCallback( ifc_downloadManagerCallback *callback )
  196. {
  197. _voidcall( API_DOWNLOADMANAGER_UNREGISTERSTATUSCALLBACK, callback );
  198. }
  199. inline const wchar_t *api_downloadManager::GetSource( DownloadToken token )
  200. {
  201. return _call( API_DOWNLOADMANAGER_GETSOURCE, (const wchar_t *)0, token );
  202. }
  203. inline const wchar_t *api_downloadManager::GetTitle( DownloadToken token )
  204. {
  205. return _call( API_DOWNLOADMANAGER_GETTITLE, (const wchar_t *)0, token );
  206. }
  207. inline bool api_downloadManager::IsPending( DownloadToken token )
  208. {
  209. return _call( API_DOWNLOADMANAGER_ISPENDING, (bool)0, token );
  210. }
  211. // {9E5E732A-C612-489d-AB52-1501E1AF1710}
  212. static const GUID DownloadManagerGUID =
  213. { 0x9e5e732a, 0xc612, 0x489d, { 0xab, 0x52, 0x15, 0x1, 0xe1, 0xaf, 0x17, 0x10 } };
  214. extern api_downloadManager *g_downloadManagerApi;
  215. #ifndef WAC_API_DOWNLOADMANAGER
  216. #define WAC_API_DOWNLOADMANAGER g_downloadManagerApi
  217. #endif // !WAC_API_DOWNLOADMANAGER
  218. #endif // !NULLSOFT_WAC_DOWNLOAD_MANAGER_API_DOWNLOADMANAGER_H