Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.0 KiB

  1. #ifndef _CAGGUNK_H
  2. #define _CAGGUNK_H
  3. class CAggregatedUnknown : public IUnknown
  4. {
  5. public:
  6. // *** IUnknown ***
  7. virtual STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  8. virtual STDMETHODIMP_(ULONG) AddRef(void);
  9. virtual STDMETHODIMP_(ULONG) Release(void);
  10. protected:
  11. virtual ~CAggregatedUnknown(); // so that subclasses get deleted right
  12. CAggregatedUnknown(IUnknown *punkAgg);
  13. // This is the IUnknown that subclasses returns from their CreateInstance func
  14. IUnknown* _GetInner() { return &_unkInner; }
  15. // A couple helper functions for subclasses to cache their aggregator's
  16. // (or their own) interfaces.
  17. void _ReleaseOuterInterface(IUnknown** ppunk);
  18. HRESULT _QueryOuterInterface(REFIID riid, void ** ppvOut);
  19. // Do non-cached QIs off this IUnknown
  20. IUnknown* _GetOuter() { return _punkAgg; }
  21. // Allow "delayed aggregation"
  22. void _SetOuter(IUnknown* punk) { _punkAgg = punk; }
  23. // This is the QueryInterface the aggregator implements
  24. virtual HRESULT v_InternalQueryInterface(REFIID riid, void **ppvObj) = 0;
  25. virtual BOOL v_HandleDelete(PLONG pcRef) { return FALSE; };
  26. private:
  27. // Get a non-refcounted pointer to the canonical IUnknown of the
  28. // controlling unknown. Used by _QueryOuterInterface and
  29. // _ReleaseOuterInterface.
  30. IUnknown *_GetCanonicalOuter(void);
  31. // Embed default IUnknown handler
  32. class CUnkInner : public IUnknown
  33. {
  34. public:
  35. virtual STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  36. virtual STDMETHODIMP_(ULONG) AddRef(void) ;
  37. virtual STDMETHODIMP_(ULONG) Release(void);
  38. CUnkInner() { _cRef = 1; }
  39. private:
  40. LONG _cRef;
  41. };
  42. friend class CUnkInner;
  43. CUnkInner _unkInner;
  44. IUnknown* _punkAgg; // points to _unkInner or aggregating IUnknown
  45. };
  46. #define RELEASEOUTERINTERFACE(p) _ReleaseOuterInterface((IUnknown**)((void **)&p))
  47. #endif // _CAGGUNK_H