deviceActivity.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_ACTIVITY_HEADER
  2. #define _NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_ACTIVITY_HEADER
  3. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  4. #pragma once
  5. #endif
  6. #include <wtypes.h>
  7. typedef enum DeviceActivityFlags
  8. {
  9. DeviceActivityFlag_Cancelable = (1 << 0),
  10. DeviceActivityFlag_SupportProgress = (1 << 0),
  11. } DeviceActivityFlags;
  12. DEFINE_ENUM_FLAG_OPERATORS(DeviceActivityFlags);
  13. typedef void (*DeviceActivityCallback)(DeviceActivity * /*activity*/);
  14. typedef void (*DeviceActivityProgressCallback)(DeviceActivity * /*activity*/, unsigned int /*position*/, unsigned int /*total*/);
  15. class DeviceActivity: public ifc_deviceactivity
  16. {
  17. protected:
  18. DeviceActivity(DeviceActivityFlags flags,
  19. DeviceActivityCallback startCb,
  20. DeviceActivityCallback finishCb,
  21. DeviceActivityProgressCallback progressCb,
  22. void *user);
  23. ~DeviceActivity();
  24. public:
  25. static HRESULT CreateInstance(DeviceActivityFlags flags,
  26. DeviceActivityCallback startCb,
  27. DeviceActivityCallback finishCb,
  28. DeviceActivityProgressCallback progressCb,
  29. void *user,
  30. DeviceActivity **instance);
  31. public:
  32. /* Dispatchable */
  33. size_t AddRef();
  34. size_t Release();
  35. int QueryInterface(GUID interface_guid, void **object);
  36. /* ifc_deviceactivity */
  37. BOOL GetActive();
  38. BOOL GetCancelable();
  39. HRESULT GetProgress(unsigned int *percentCompleted);
  40. HRESULT GetDisplayName(wchar_t *buffer, size_t bufferMax);
  41. HRESULT GetStatus(wchar_t *buffer, size_t bufferMax);
  42. HRESULT Cancel(HWND hostWindow);
  43. public:
  44. void Lock();
  45. void Unlock();
  46. HRESULT Start(unsigned int duration, unsigned int interval);
  47. HRESULT Stop();
  48. HRESULT SetDisplayName(const wchar_t *displayName);
  49. HRESULT SetStatus(const wchar_t *status);
  50. HRESULT SetUser(void *data);
  51. HRESULT GetUser(void **data);
  52. protected:
  53. DWORD ActivityThread(unsigned int duration, unsigned int interval);
  54. friend static DWORD CALLBACK DeviceActivity_ActivityThreadStarter(void *param);
  55. protected:
  56. size_t ref;
  57. DeviceActivityFlags flags;
  58. DeviceActivityCallback callbackStart;
  59. DeviceActivityCallback callbackFinish;
  60. DeviceActivityProgressCallback callbackProgress;
  61. void *user;
  62. wchar_t *displayName;
  63. wchar_t *status;
  64. HANDLE activityThread;
  65. HANDLE cancelEvent;
  66. unsigned int progress;
  67. CRITICAL_SECTION lock;
  68. protected:
  69. RECVS_DISPATCH;
  70. };
  71. #endif //_NULLSOFT_WINAMP_GEN_DEVICE_PROVIDER_DEVICE_ACTIVITY_HEADER