waservicefactorybase.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef __WASERVICEFACTORYBASE_IMPL_H
  2. #define __WASERVICEFACTORYBASE_IMPL_H
  3. /*<?<autoheader/>*/
  4. class CfgItem;
  5. /*?>*/
  6. #include "waservicefactoryi.h"
  7. template <class SERVICETYPE, class SERVICE>
  8. class NOVTABLE waServiceFactoryBaseX : public waServiceFactoryI {
  9. public:
  10. waServiceFactoryBaseX(GUID myGuid = INVALID_GUID) : guid(myGuid) {}
  11. virtual FOURCC svc_serviceType()=0;
  12. virtual const char *svc_getServiceName() { return SERVICE::getServiceName(); }
  13. virtual GUID svc_getGuid() { return guid; }
  14. virtual void *svc_getInterfaceAndLock() {// this is only for back compat
  15. return getInterface(TRUE);
  16. }
  17. virtual void *svc_getInterface(int global_lock)=0;
  18. virtual int svc_releaseInterface(void *ptr)=0;
  19. virtual CfgItem *svc_getCfgInterface() { return NULL; }
  20. virtual const wchar_t *svc_getTestString() { return NULL; }
  21. virtual int svc_notify(int msg, int param1 = 0, int param2 = 0) { return 0; }
  22. private:
  23. GUID guid;
  24. };
  25. // if you derive from this, all you have to do is override the newService()
  26. // and delService() methods... if all you need to do is instantiate a class
  27. // and destroy it use the helper below (waServiceFactoryT)
  28. template <class SERVICETYPE, class SERVICE>
  29. class NOVTABLE waServiceFactoryBase : public waServiceFactoryBaseX<SERVICETYPE, SERVICE> {
  30. public:
  31. waServiceFactoryBase(GUID myGuid = INVALID_GUID) : waServiceFactoryBaseX<SERVICETYPE, SERVICE>(myGuid) {}
  32. virtual FOURCC svc_serviceType() { return SERVICETYPE::getServiceType(); }
  33. virtual void *svc_getInterface(int global_lock) { // new style, client optionally does the locking
  34. SERVICETYPE *ret = newService();
  35. if (global_lock) WASABI_API_SVC->service_lock(this, ret);
  36. return ret;
  37. }
  38. virtual int svc_releaseInterface(void *ptr) {
  39. return delService(static_cast<SERVICE*>(static_cast<SERVICETYPE*>(ptr)));
  40. }
  41. protected:
  42. virtual SERVICETYPE *newService()=0;
  43. virtual int delService(SERVICETYPE *service)=0;
  44. };
  45. // and this one just exposes a service pointer, without factory. note that
  46. // SERVICETYPE and SERVICE do not have to be related (unlike waServiceFactoryBase
  47. // who needs a relationship between the classes in releaseInterface)
  48. template <class SERVICETYPE, class SERVICE>
  49. class NOVTABLE waServiceBase : public waServiceFactoryBaseX<SERVICETYPE, SERVICE> {
  50. public:
  51. waServiceBase(GUID myGuid = INVALID_GUID) : waServiceFactoryBaseX<SERVICETYPE, SERVICE>(myGuid) {}
  52. virtual FOURCC svc_serviceType() { return SERVICE::getServiceType(); }
  53. virtual void *svc_getInterface(int global_lock) { // new style, client optionally does the locking
  54. SERVICETYPE *ret = getService();
  55. if (global_lock) WASABI_API_SVC->service_lock(this, ret);
  56. return ret;
  57. }
  58. virtual int svc_releaseInterface(void *ptr) {
  59. return TRUE;
  60. }
  61. protected:
  62. virtual SERVICETYPE *getService()=0;
  63. };
  64. #endif // __WASERVICEFACTORYBASE_IMPL_H