1
0

api_mldb.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #pragma once
  2. #include <bfc/dispatch.h>
  3. #include "..\..\General\gen_ml/ml.h"
  4. class api_mldb : public Dispatchable
  5. {
  6. protected:
  7. api_mldb() {}
  8. ~api_mldb() {}
  9. public:
  10. itemRecordW *GetFile(const wchar_t *filename);
  11. itemRecordW *GetFileIf(const wchar_t *filename, const wchar_t *query); // returns the item record for a filename, but also checks against the passed query
  12. itemRecordListW *GetAlbum(const wchar_t *albumname, const wchar_t *albumartist);
  13. itemRecordListW *Query(const wchar_t *query);
  14. itemRecordListW *QueryLimit(const wchar_t *query, unsigned int limit);
  15. void SetField(const wchar_t *filename, const char *field, const wchar_t *value);
  16. void SetFieldInteger(const wchar_t *filename, const char *field, int value);
  17. void SetFieldInt128(const wchar_t *filename, const char *field, uint8_t value[16]);
  18. void Sync();
  19. void FreeRecord(itemRecordW *record);
  20. void FreeRecordList(itemRecordListW *recordList);
  21. int AddFile(const wchar_t *filename);
  22. int RemoveFile(const wchar_t *filename);
  23. /* wrappers around ndestring */
  24. void RetainString(wchar_t *str);
  25. void ReleaseString(wchar_t *str);
  26. wchar_t *DuplicateString(const wchar_t *str);
  27. int GetMaxInteger(const char *field, int *max);
  28. DISPATCH_CODES
  29. {
  30. API_MLDB_GETFILE = 10,
  31. API_MLDB_GETFILEIF = 11,
  32. API_MLDB_GETALBUM = 20,
  33. API_MLDB_QUERY = 30,
  34. API_MLDB_QUERYLIMIT = 31,
  35. API_MLDB_FREERECORD = 40,
  36. API_MLDB_FREERECORDLIST = 50,
  37. API_MLDB_SETFIELD = 60,
  38. API_MLDB_SETFIELDINT = 61,
  39. API_MLDB_SETFIELDINT128 = 62,
  40. API_MLDB_SYNC = 70,
  41. API_MLDB_ADDFILE = 80,
  42. API_MLDB_REMOVEFILE = 90,
  43. API_MLDB_RETAINSTRING = 100,
  44. API_MLDB_RELEASESTRING = 110,
  45. API_MLDB_DUPLICATESTRING = 120,
  46. API_MLDB_GETMAXINTEGER = 130,
  47. };
  48. typedef struct
  49. {
  50. time_t played;
  51. int count;
  52. } played_info;
  53. enum
  54. {
  55. // System callbacks for api_mldb
  56. SYSCALLBACK = MK4CC('m','l','d','b'), // Unique identifier for mldb_api callbacks
  57. MLDB_FILE_ADDED = 10, // param1 = filename, param2 = (not used), Callback event for when a new file is added to the local mldb
  58. MLDB_FILE_REMOVED_PRE = 20, // param1 = filename, param2 = (not used), Callback event for when a file is removed from the local mldb (before it happens)
  59. MLDB_FILE_REMOVED_POST = 25, // param1 = filename, param2 = (not used), Callback event for when a file is removed from the local mldb (after it happens)
  60. MLDB_FILE_UPDATED = 30, // param1 = filename, param2 = (not used), Callback event for when a file is modified in the local mldb
  61. MLDB_FILE_UPDATED_EXTERNAL = 35, // param1 = filename, param2 = (not used), Callback event for when a file is modified and is not in the local mldb
  62. MLDB_CLEARED = 40, // param1 = filenames, param2 = count, Callback event for when the local mldb is cleared (useful so removed is not triggered for all files)
  63. MLDB_FILE_PLAYED = 50, // param1 = filename, param2 = played_info, Callback event for when a file is tracked as playing in the local mldb
  64. MLDB_FILE_GET_CLOUD_STATUS = 60, // param1 = filename, param2 = HMENU*, Callback event for when ml_local needs to show a cloud status menu (returned by the handler in param2)
  65. MLDB_FILE_PROCESS_CLOUD_STATUS = 65, // param1 = menu_item, param2 = int*, Callback event for when ml_local needs to process the result of a cloud status menu
  66. };
  67. };
  68. inline itemRecordW *api_mldb::GetFile(const wchar_t *filename)
  69. {
  70. return _call(API_MLDB_GETFILE, (itemRecordW *)0, filename);
  71. }
  72. inline itemRecordW *api_mldb::GetFileIf(const wchar_t *filename, const wchar_t *query)
  73. {
  74. return _call(API_MLDB_GETFILEIF, (itemRecordW *)0, filename, query);
  75. }
  76. inline itemRecordListW *api_mldb::GetAlbum(const wchar_t *albumname, const wchar_t *albumartist)
  77. {
  78. return _call(API_MLDB_GETALBUM, (itemRecordListW *)0, albumname, albumartist);
  79. }
  80. inline itemRecordListW *api_mldb::Query(const wchar_t *query)
  81. {
  82. return _call(API_MLDB_QUERY, (itemRecordListW *)0, query);
  83. }
  84. inline itemRecordListW *api_mldb::QueryLimit(const wchar_t *query, unsigned int limit)
  85. {
  86. return _call(API_MLDB_QUERYLIMIT, (itemRecordListW *)0, query, limit);
  87. }
  88. inline void api_mldb::FreeRecord(itemRecordW *record)
  89. {
  90. _voidcall(API_MLDB_FREERECORD, record);
  91. }
  92. inline void api_mldb::FreeRecordList(itemRecordListW *recordList)
  93. {
  94. _voidcall(API_MLDB_FREERECORDLIST, recordList);
  95. }
  96. inline void api_mldb::SetField(const wchar_t *filename, const char *field, const wchar_t *value)
  97. {
  98. _voidcall(API_MLDB_SETFIELD, filename, field, value);
  99. }
  100. inline void api_mldb::SetFieldInteger(const wchar_t *filename, const char *field, int value)
  101. {
  102. _voidcall(API_MLDB_SETFIELDINT, filename, field, value);
  103. }
  104. inline void api_mldb::SetFieldInt128(const wchar_t *filename, const char *field, uint8_t value[16])
  105. {
  106. _voidcall(API_MLDB_SETFIELDINT128, filename, field, value);
  107. }
  108. inline void api_mldb::Sync()
  109. {
  110. _voidcall(API_MLDB_SYNC);
  111. }
  112. inline int api_mldb::AddFile(const wchar_t *filename)
  113. {
  114. return _call(API_MLDB_ADDFILE, (int)0, filename);
  115. }
  116. inline int api_mldb::RemoveFile(const wchar_t *filename)
  117. {
  118. return _call(API_MLDB_REMOVEFILE, (int)0, filename);
  119. }
  120. inline void api_mldb::RetainString(wchar_t *str)
  121. {
  122. _voidcall(API_MLDB_RETAINSTRING, str);
  123. }
  124. inline void api_mldb::ReleaseString(wchar_t *str)
  125. {
  126. _voidcall(API_MLDB_RELEASESTRING, str);
  127. }
  128. inline wchar_t *api_mldb::DuplicateString(const wchar_t *str)
  129. {
  130. return _call(API_MLDB_DUPLICATESTRING, (wchar_t *)0, str);
  131. }
  132. inline int api_mldb::GetMaxInteger(const char *field, int *max)
  133. {
  134. return _call(API_MLDB_GETMAXINTEGER, (int)1, field, max);
  135. }
  136. // {5A94DABC-E19A-4a12-9AA8-852D8BF06532}
  137. static const GUID mldbApiGuid =
  138. { 0x5a94dabc, 0xe19a, 0x4a12, { 0x9a, 0xa8, 0x85, 0x2d, 0x8b, 0xf0, 0x65, 0x32 } };