1
0

deviceSupportedCommand.cpp 2.1 KB

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