storageHelper.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "main.h"
  2. #include "./storageHelper.h"
  3. #include "./storageHandler.h"
  4. #include "./storageHandlerEnum.h"
  5. StorageHelper::StorageHelper()
  6. : ref(1)
  7. {
  8. }
  9. StorageHelper::~StorageHelper()
  10. {
  11. }
  12. HRESULT StorageHelper::CreateInstance(StorageHelper **instance)
  13. {
  14. if (NULL == instance) return E_POINTER;
  15. *instance = new StorageHelper();
  16. if (NULL == *instance) return E_OUTOFMEMORY;
  17. return S_OK;
  18. }
  19. size_t StorageHelper::AddRef()
  20. {
  21. return InterlockedIncrement((LONG*)&ref);
  22. }
  23. size_t StorageHelper::Release()
  24. {
  25. if (0 == ref)
  26. return ref;
  27. LONG r = InterlockedDecrement((LONG*)&ref);
  28. if (0 == r)
  29. delete(this);
  30. return r;
  31. }
  32. int StorageHelper::QueryInterface(GUID interface_guid, void **object)
  33. {
  34. if (NULL == object) return E_POINTER;
  35. if (IsEqualIID(interface_guid, IFC_OmStorageHelper))
  36. *object = static_cast<ifc_omstoragehelper*>(this);
  37. else
  38. {
  39. *object = NULL;
  40. return E_NOINTERFACE;
  41. }
  42. if (NULL == *object)
  43. return E_UNEXPECTED;
  44. AddRef();
  45. return S_OK;
  46. }
  47. HRESULT StorageHelper::CreateHandler(const wchar_t *key, HandlerProc proc, ifc_omstoragehandler **handler)
  48. {
  49. return StorageHandler::CreateInstance(key, proc, StorageHandler::flagCopyKey, (StorageHandler**)handler);
  50. }
  51. HRESULT StorageHelper::CreateEnumerator(const TemplateRecord *recordList, size_t recordCount, ifc_omstoragehandlerenum **enumerator)
  52. {
  53. return StorageHandlerEnum::CreateFromTemplate(recordList, recordCount, (StorageHandlerEnum**)enumerator);
  54. }
  55. #define CBCLASS StorageHelper
  56. START_DISPATCH;
  57. CB(ADDREF, AddRef)
  58. CB(RELEASE, Release)
  59. CB(QUERYINTERFACE, QueryInterface)
  60. CB(API_CREATEHANDLER, CreateHandler)
  61. CB(API_CREATEENUMERATOR, CreateEnumerator)
  62. END_DISPATCH;
  63. #undef CBCLASS