JSAPI2_AsyncDownloader.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #pragma once
  2. #include <ocidl.h>
  3. #include "JSAPI_Info.h"
  4. #include <vector>
  5. #include "JSAPI_CallbackParameters.h"
  6. namespace JSAPI2
  7. {
  8. class AsyncDownloaderAPI : public IDispatch
  9. {
  10. public:
  11. AsyncDownloaderAPI(const wchar_t *_key, JSAPI::ifc_info *info);
  12. ~AsyncDownloaderAPI();
  13. STDMETHOD(QueryInterface)(REFIID riid, PVOID *ppvObject);
  14. STDMETHOD_(ULONG, AddRef)(void);
  15. STDMETHOD_(ULONG, Release)(void);
  16. // *** IDispatch Methods ***
  17. STDMETHOD (GetIDsOfNames)(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid);
  18. STDMETHOD (GetTypeInfo)(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo);
  19. STDMETHOD (GetTypeInfoCount)(unsigned int FAR * pctinfo);
  20. STDMETHOD (Invoke)(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr);
  21. public:
  22. /** Callbacks
  23. ** JSAPI2::CallbackManager will have been nice enough to marshall onto our thread
  24. ** so we don't have to worry about that
  25. */
  26. void OnInit(const wchar_t *url);
  27. void OnConnect(const wchar_t *url);
  28. void OnData(const wchar_t *url, size_t downloadedlen, size_t totallen);
  29. void OnCancel(const wchar_t *url);
  30. void OnError(const wchar_t *url, int error);
  31. void OnFinish(const wchar_t *url, const wchar_t *destfilename);
  32. void InvokeEvent(const wchar_t *eventName, JSAPI::CallbackParameters::PropertyTemplate *parameters, size_t parametersCount);
  33. //Getter for key
  34. const wchar_t *GetKey();
  35. private:
  36. const wchar_t *key;
  37. volatile LONG refCount;
  38. JSAPI::ifc_info *info;
  39. typedef std::vector<IDispatch*> EventsList;
  40. EventsList events;
  41. STDMETHOD (DownloadMedia)(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr);
  42. STDMETHOD (RegisterForEvents)(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr);
  43. STDMETHOD (UnregisterFromEvents)(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr);
  44. };
  45. }