supportedCommand.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "main.h"
  2. #include "./supportedCommand.h"
  3. #include <strsafe.h>
  4. DeviceSupportedCommand::DeviceSupportedCommand()
  5. : ref(1), name(NULL), flags(DeviceCommandFlag_None)
  6. {
  7. }
  8. DeviceSupportedCommand::~DeviceSupportedCommand()
  9. {
  10. AnsiString_Free(name);
  11. }
  12. HRESULT DeviceSupportedCommand::CreateInstance(const char *name, DeviceSupportedCommand **instance)
  13. {
  14. DeviceSupportedCommand *self;
  15. if (NULL == instance)
  16. return E_POINTER;
  17. *instance = NULL;
  18. self = new DeviceSupportedCommand();
  19. if (NULL == self)
  20. return E_OUTOFMEMORY;
  21. self->name = AnsiString_Duplicate(name);
  22. *instance = self;
  23. return S_OK;
  24. }
  25. size_t DeviceSupportedCommand::AddRef()
  26. {
  27. return InterlockedIncrement((LONG*)&ref);
  28. }
  29. size_t DeviceSupportedCommand::Release()
  30. {
  31. if (0 == ref)
  32. return ref;
  33. LONG r = InterlockedDecrement((LONG*)&ref);
  34. if (0 == r)
  35. delete(this);
  36. return r;
  37. }
  38. int DeviceSupportedCommand::QueryInterface(GUID interface_guid, void **object)
  39. {
  40. if (NULL == object)
  41. return E_POINTER;
  42. if (IsEqualIID(interface_guid, IFC_DeviceSupportedCommand))
  43. *object = static_cast<ifc_devicesupportedcommand*>(this);
  44. else
  45. {
  46. *object = NULL;
  47. return E_NOINTERFACE;
  48. }
  49. if (NULL == *object)
  50. return E_UNEXPECTED;
  51. AddRef();
  52. return S_OK;
  53. }
  54. const char *DeviceSupportedCommand::GetName()
  55. {
  56. return name;
  57. }
  58. HRESULT DeviceSupportedCommand::GetFlags(DeviceCommandFlags *flagsOut)
  59. {
  60. if (NULL == flagsOut)
  61. return E_POINTER;
  62. *flagsOut = flags;
  63. return S_OK;
  64. }
  65. HRESULT DeviceSupportedCommand::SetFlags(DeviceCommandFlags mask, DeviceCommandFlags value)
  66. {
  67. DeviceCommandFlags temp;
  68. temp = (flags & mask) | (mask & value);
  69. if (temp == flags)
  70. return S_FALSE;
  71. flags = temp;
  72. return S_OK;
  73. }
  74. #define CBCLASS DeviceSupportedCommand
  75. START_DISPATCH;
  76. CB(ADDREF, AddRef)
  77. CB(RELEASE, Release)
  78. CB(QUERYINTERFACE, QueryInterface)
  79. CB(API_GETNAME, GetName)
  80. CB(API_GETFLAGS, GetFlags)
  81. END_DISPATCH;
  82. #undef CBCLASS