svc_metadata.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef _SVC_METADATA_H
  2. #define _SVC_METADATA_H
  3. // see helper class in common/metadatasvc.h to implement this
  4. #include <api/service/services.h>
  5. #include <bfc/dispatch.h>
  6. #include <bfc/string/string.h>
  7. #include <api/db/metatags.h>
  8. class NOVTABLE svc_metaData : public Dispatchable {
  9. public:
  10. static FOURCC getServiceType() { return WaSvc::METADATA; }
  11. int enumMetaData(int n, char *mdName, int mdNameMaxLength, int *mdType, BOOL *mdIndexed, BOOL *mdMaintainUniques);
  12. int hasMetaData(const char *name, int type);
  13. int allowOperation(GUID whom, const char *playstring, int op, char *field, void *data, int data_len);
  14. GUID getGUID();
  15. const char *getMetaTableName();
  16. enum {
  17. HASMETADATA=10,
  18. ENUMMETADATA=20,
  19. ALLOWOPERATION=30,
  20. GETGUID=40,
  21. GETMETANAME=50,
  22. };
  23. };
  24. inline int svc_metaData::hasMetaData(const char *name, int type) {
  25. return _call(HASMETADATA, 0, name, type);
  26. }
  27. inline int svc_metaData::enumMetaData(int n, char *mdName, int mdNameMaxLength, int *mdType, BOOL *mdIndexed, BOOL *mdMaintainUniques) {
  28. return _call(ENUMMETADATA, 0, n, mdName, mdNameMaxLength, mdType, mdIndexed, mdMaintainUniques);
  29. }
  30. inline int svc_metaData::allowOperation(GUID whom, const char *playstring, int op, char *field, void *data, int data_len) {
  31. return _call(ALLOWOPERATION, 0, whom, playstring, op, field, data, data_len);
  32. }
  33. inline GUID svc_metaData::getGUID() {
  34. return _call(GETGUID, INVALID_GUID);
  35. }
  36. inline const char *svc_metaData::getMetaTableName() {
  37. return _call(GETMETANAME, (const char *)NULL);
  38. }
  39. // see helper class in common/metadatasvc.h to implement this
  40. class NOVTABLE svc_metaDataI : public svc_metaData {
  41. public:
  42. virtual int enumMetaData(int n, char *mdName, int mdNameMaxLength, int *mdType, BOOL *mdIndexed, BOOL *mdMaintainUniques)=0;
  43. virtual int hasMetaData(const char *name, int type)=0;
  44. virtual int allowOperation(GUID whom, const char *playstring, int op, char *field, void *data, int data_len)=0;
  45. virtual GUID getGUID()=0;
  46. virtual const char *getMetaTableName()=0;
  47. protected:
  48. RECVS_DISPATCH;
  49. };
  50. #include <api/service/servicei.h>
  51. // if you want to use class MetaDataSvc (instead of deriving from
  52. // svc_metaDataI yourself) use class MetaDataSvcFactory in common/metadatasvc.h
  53. template <class T>
  54. class MetaDataSvcCreator : public waServiceFactoryTSingle<svc_metaData, T> {};
  55. #include <api/service/svc_enum.h>
  56. class MetaDataSvcEnum : public SvcEnumT<svc_metaData> {
  57. public:
  58. MetaDataSvcEnum(const char *metadata=NULL, int mdtype=MDT_NONE) : md(metadata), type(mdtype) {}
  59. protected:
  60. virtual int testService(svc_metaData *svc) {
  61. if (md.isempty() || type == MDT_NONE) return TRUE;
  62. return svc->hasMetaData(md, type);
  63. }
  64. private:
  65. String md;
  66. int type;
  67. };
  68. class MetaDataSvcEnumGuid : public SvcEnumT<svc_metaData> {
  69. public:
  70. MetaDataSvcEnumGuid(GUID g) : guid(g) {}
  71. protected:
  72. virtual int testService(svc_metaData *svc) {
  73. return (svc->getGUID() == guid);
  74. }
  75. private:
  76. GUID guid;
  77. };
  78. #endif