api_metadata.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef NULLSOFT_AGAVE_METADATA_API_METADATA_H
  2. #define NULLSOFT_AGAVE_METADATA_API_METADATA_H
  3. /**
  4. ** Author: Ben Allison
  5. ** original date: April 10, 2006
  6. */
  7. #include <bfc/dispatch.h>
  8. #include "svc_metatag.h"
  9. class api_metadata : public Dispatchable
  10. {
  11. protected:
  12. api_metadata() {}
  13. ~api_metadata() {}
  14. public:
  15. // replacement for IPC_GET_EXTENDED_FILE_INFO, it's slow, so only use for converting old code, or one-off metadata grabbing
  16. int GetExtendedFileInfo(const wchar_t *filename, const wchar_t *tag, wchar_t *data, size_t dataLength);
  17. // replacement for IPC_SET_EXTENDED_FILE_INFO
  18. int SetExtendedFileInfo(const wchar_t *filename, const wchar_t *tag, const wchar_t *data);
  19. int WriteExtendedFileInfo(const wchar_t *filename);
  20. /** faster methods below. these return you an object that you can keep re-using (for a single file)
  21. ** it's still your job to call svc_metaTag::metaTag_open() - see note [2]
  22. ** call svc_metaTag::close() when you're done - see note [3]
  23. */
  24. svc_metaTag *GetMetaTagObject(const wchar_t *filename, int flags=METATAG_ALL, GUID *exclude=0, int numExcludes=0); // see note [1]
  25. svc_metaTag *GetMetaTagObject(const GUID metaTagGuid); // gets a specific svc_metaTag object by GUID
  26. /**
  27. ** Retrieves a unique key for a given field name
  28. ** if one already exists, that index is returned
  29. ** returns -1 on failure/not implemented
  30. **/
  31. uint32_t GenerateKey(const wchar_t *field);
  32. DISPATCH_CODES
  33. {
  34. API_METADATA_GETEXTENDEDFILEINFO = 10,
  35. API_METADATA_SETEXTENDEDFILEINFO = 11,
  36. API_METADATA_WRITEEXTENDEDFILEINFO = 12,
  37. API_METADATA_GETMETATAGOBJECT = 20,
  38. API_METADATA_GETMETATAGOBJECTBYGUID = 30,
  39. API_METADATA_GENERATEKEY = 40,
  40. };
  41. };
  42. /**
  43. ** [1] flags can be set to only use certain metadata providers, file info, database, online lookup (CDDB, etc), guessing
  44. ** exclude list can be use to exclude certain metatag GUIDs. This is useful for metadata services that need to look up metadata themselves
  45. ** e.g. CDDB might need to get a Disc ID, media library wants to ask for info to fill itself in. Neither services wants to have themselves
  46. ** be asked, and might not want a "guessing" metatag provider to be used, either.
  47. ** [2] these methods could technically open the file also, but we've left that out to allow for some flexibility
  48. ** e.g. someone might just be looking for the metaTag service name or GUID.
  49. ** [3] you need to close it even if you never opened it. This allows the object to "self-destruct".
  50. ** If we didn't do this, we would also have to pass back the service factory
  51. **
  52. */
  53. inline int api_metadata::GetExtendedFileInfo(const wchar_t *filename, const wchar_t *tag, wchar_t *data, size_t dataLength)
  54. {
  55. return _call(API_METADATA_GETEXTENDEDFILEINFO, (int)0, filename, tag, data, dataLength);
  56. }
  57. inline int api_metadata::SetExtendedFileInfo(const wchar_t *filename, const wchar_t *tag, const wchar_t *data)
  58. {
  59. return _call(API_METADATA_SETEXTENDEDFILEINFO, (int)0, filename, tag, data);
  60. }
  61. inline int api_metadata::WriteExtendedFileInfo(const wchar_t *filename)
  62. {
  63. return _call(API_METADATA_WRITEEXTENDEDFILEINFO, (int)0, filename);
  64. }
  65. inline svc_metaTag *api_metadata::GetMetaTagObject(const wchar_t *filename, int flags, GUID *exclude, int numExcludes)
  66. {
  67. return _call(API_METADATA_GETMETATAGOBJECT, (svc_metaTag *)NULL, filename, flags, exclude, numExcludes);
  68. }
  69. inline svc_metaTag *api_metadata::GetMetaTagObject(const GUID metaTagGuid)
  70. {
  71. return _call(API_METADATA_GETMETATAGOBJECTBYGUID, (svc_metaTag *)NULL, metaTagGuid);
  72. }
  73. #pragma warning(push)
  74. #pragma warning(disable : 4267)
  75. inline uint32_t api_metadata::GenerateKey(const wchar_t *field)
  76. {
  77. return _call(API_METADATA_GENERATEKEY, (uint32_t)-1);
  78. }
  79. #pragma warning(pop)
  80. // {DFA89F63-995A-407b-8BC8-827900440727}
  81. static const GUID api_metadataGUID =
  82. { 0xdfa89f63, 0x995a, 0x407b, { 0x8b, 0xc8, 0x82, 0x79, 0x0, 0x44, 0x7, 0x27 } };
  83. #endif