JSAPI2_HistoryAPI.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "api__ml_history.h"
  2. #include "JSAPI2_HistoryAPI.h"
  3. #include "../Winamp/JSAPI.h"
  4. #include "JSAPI2_HistoryRecordList.h"
  5. #include "HistoryAPI.h"
  6. extern HistoryAPI historyAPI;
  7. JSAPI2::HistoryAPI::HistoryAPI(const wchar_t *_key, JSAPI::ifc_info *_info)
  8. {
  9. info = _info;
  10. key = _key;
  11. refCount = 1;
  12. }
  13. #define DISP_TABLE \
  14. CHECK_ID(Query)\
  15. #define CHECK_ID(str) JSAPI_DISP_ENUMIFY(str),
  16. enum {
  17. DISP_TABLE
  18. };
  19. #undef CHECK_ID
  20. #define CHECK_ID(str) if (wcscmp(rgszNames[i], L## #str) == 0) { rgdispid[i] = JSAPI_DISP_ENUMIFY(str); continue; }
  21. HRESULT JSAPI2::HistoryAPI::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  22. {
  23. bool unknowns = false;
  24. for (unsigned int i = 0;i != cNames;i++)
  25. {
  26. DISP_TABLE
  27. rgdispid[i] = DISPID_UNKNOWN;
  28. unknowns = true;
  29. }
  30. if (unknowns)
  31. return DISP_E_UNKNOWNNAME;
  32. else
  33. return S_OK;
  34. }
  35. HRESULT JSAPI2::HistoryAPI::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  36. {
  37. return E_NOTIMPL;
  38. }
  39. HRESULT JSAPI2::HistoryAPI::GetTypeInfoCount(unsigned int FAR * pctinfo)
  40. {
  41. return E_NOTIMPL;
  42. }
  43. HRESULT JSAPI2::HistoryAPI::Query(WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, unsigned int FAR *puArgErr)
  44. {
  45. JSAPI_VERIFY_METHOD(wFlags);
  46. JSAPI_VERIFY_PARAMCOUNT(pdispparams, 1);
  47. JSAPI_VERIFY_PARAMTYPE(pdispparams, 1, VT_BSTR, puArgErr);
  48. JSAPI_INIT_RESULT(pvarResult, VT_DISPATCH);
  49. if (AGAVE_API_JSAPI2_SECURITY->GetActionAuthorization(L"history", L"query", key, info, JSAPI2::api_security::ACTION_PROMPT) == JSAPI2::api_security::ACTION_ALLOWED)
  50. {
  51. if (pvarResult) // no sense in running the query if they don't care about the return value!
  52. {
  53. historyRecordList *query_results = historyAPI.Query(JSAPI_PARAM(pdispparams, 1).bstrVal);
  54. if (query_results)
  55. V_DISPATCH(pvarResult) = new JSAPI2::HistoryRecordList(query_results);
  56. else
  57. V_DISPATCH(pvarResult) = 0;
  58. }
  59. return S_OK;
  60. }
  61. else
  62. {
  63. V_DISPATCH(pvarResult) = 0;
  64. return S_OK;
  65. }
  66. return E_FAIL;
  67. }
  68. #undef CHECK_ID
  69. #define CHECK_ID(str) case JSAPI_DISP_ENUMIFY(str): return str(wFlags, pdispparams, pvarResult, puArgErr);
  70. HRESULT JSAPI2::HistoryAPI::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  71. {
  72. switch (dispid)
  73. {
  74. DISP_TABLE
  75. }
  76. return DISP_E_MEMBERNOTFOUND;
  77. }
  78. STDMETHODIMP JSAPI2::HistoryAPI::QueryInterface(REFIID riid, PVOID *ppvObject)
  79. {
  80. if (!ppvObject)
  81. return E_POINTER;
  82. else if (IsEqualIID(riid, IID_IDispatch))
  83. *ppvObject = (IDispatch *)this;
  84. else if (IsEqualIID(riid, IID_IUnknown))
  85. *ppvObject = this;
  86. else
  87. {
  88. *ppvObject = NULL;
  89. return E_NOINTERFACE;
  90. }
  91. AddRef();
  92. return S_OK;
  93. }
  94. ULONG JSAPI2::HistoryAPI::AddRef(void)
  95. {
  96. return InterlockedIncrement(&refCount);
  97. }
  98. ULONG JSAPI2::HistoryAPI::Release(void)
  99. {
  100. LONG lRef = InterlockedDecrement(&refCount);
  101. if (lRef == 0) delete this;
  102. return lRef;
  103. }