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.

186 lines
5.8 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: actstrm.hxx
  4. //
  5. // Contents: code for providing a stream with an IBuffer interface
  6. // as well as providing marshalled interface data for
  7. // RPC.
  8. //
  9. // Classes: ActivationStream
  10. //
  11. // Functions: None.
  12. //
  13. // History: 04-Feb-98 Vinaykr ActivationStream
  14. //
  15. //--------------------------------------------------------------------
  16. #ifndef __ACTSTRM_HXX__
  17. #define __ACTSTRM_HXX__
  18. #include <iface.h> // InterfaceData
  19. #include <buffer.h>
  20. #define ActMemAlloc(cb) MIDL_user_allocate(cb)
  21. #define ActMemFree(pv) MIDL_user_free(pv)
  22. //+-------------------------------------------------------------------
  23. //
  24. // Class: ActivationStream
  25. //
  26. // Purpose: Stream wrapper for an InterfaceData structure,
  27. // the construct that is transmitted by Rpc in place of an
  28. // interface pointer.
  29. //
  30. // History: 30-Jan-93 Ricksa Created
  31. //
  32. // Notes:
  33. //
  34. //--------------------------------------------------------------------
  35. class ActivationStream : public IStream, public IBuffer
  36. {
  37. public:
  38. ActivationStream(void);
  39. ActivationStream(ULONG ulMaxSize);
  40. ActivationStream(InterfaceData *pOIR);
  41. ~ActivationStream(void);
  42. STDMETHOD(QueryInterface)(
  43. REFIID iidInterface,
  44. void FAR* FAR* ppvObj);
  45. STDMETHOD_(ULONG,AddRef)(void);
  46. STDMETHOD_(ULONG,Release)(void);
  47. STDMETHOD(Read)(
  48. VOID HUGEP* pv,
  49. ULONG cb,
  50. ULONG FAR* pcbRead);
  51. STDMETHOD(Write)(
  52. VOID const HUGEP* pv,
  53. ULONG cb,
  54. ULONG FAR* pcbWritten);
  55. STDMETHOD(Seek)(
  56. LARGE_INTEGER dlibMove,
  57. DWORD dwOrigin,
  58. ULARGE_INTEGER FAR* plibNewPosition);
  59. STDMETHOD(SetSize) (ULARGE_INTEGER cb);
  60. STDMETHOD(CopyTo)(
  61. IStream FAR* pstm,
  62. ULARGE_INTEGER cb,
  63. ULARGE_INTEGER FAR* pcbRead,
  64. ULARGE_INTEGER FAR* pcbWritten);
  65. STDMETHOD(Commit)(DWORD grfCommitFlags);
  66. STDMETHOD(Revert)(void);
  67. STDMETHOD(LockRegion)(
  68. ULARGE_INTEGER libOffset,
  69. ULARGE_INTEGER cb,
  70. DWORD dwLockType);
  71. STDMETHOD(UnlockRegion)(
  72. ULARGE_INTEGER libOffset,
  73. ULARGE_INTEGER cb,
  74. DWORD dwLockType);
  75. STDMETHOD(Stat)(
  76. STATSTG FAR* pstatstg,
  77. DWORD statflag);
  78. STDMETHOD(Clone)(IStream FAR * FAR *ppstm);
  79. ActivationStream *Clone();
  80. // Methods for IBuffer
  81. STDMETHOD(GetOrCreateBuffer)(DWORD dwReq, DWORD *pdwLen, BYTE **ppBuff);
  82. STDMETHOD(GetBuffer)(DWORD *pdwLength, BYTE **ppBuff);
  83. STDMETHOD(GetLength)(DWORD *pdwLength);
  84. STDMETHOD(GetCopy)(BYTE *ppBuff);
  85. STDMETHOD(SetPosition)(DWORD dwLenFromEnd, DWORD dwPosFromStart);
  86. STDMETHOD(SetBuffer)(DWORD dwLength, BYTE *pBuff);
  87. STDMETHOD(SetCopyAlignment)(DWORD alignment);
  88. void AssignSerializedInterface(InterfaceData **ppIFD);
  89. private:
  90. LONG _clRefs; // reference count
  91. LONG _lOffset; // current ptr
  92. LONG _cSize; // number of bytes written
  93. ULONG _cbData; // size of data
  94. InterfaceData *_pifData; // ptr to data
  95. BOOL _fFree; // TRUE - destructor frees data
  96. DWORD _copyAlignment;
  97. };
  98. inline ActivationStream::ActivationStream(void)
  99. : _clRefs(1), _lOffset(0), _cSize(0), _pifData(NULL), _cbData(0),
  100. _fFree(TRUE), _copyAlignment(1)
  101. {
  102. _pifData = (InterfaceData *) ActMemAlloc(sizeof(DWORD) + 512);
  103. _cbData = _pifData == NULL ? 0 : 512;
  104. }
  105. inline ActivationStream::ActivationStream(ULONG ulMaxSize)
  106. : _clRefs(1), _lOffset(0), _cSize(0), _pifData(NULL), _cbData(0),
  107. _fFree(TRUE), _copyAlignment(1)
  108. {
  109. _pifData = (InterfaceData *) ActMemAlloc(sizeof(DWORD) + ulMaxSize);
  110. _cbData = _pifData == NULL ? 0 : ulMaxSize;
  111. }
  112. inline ActivationStream::ActivationStream(InterfaceData *pIFD)
  113. : _clRefs(1), _lOffset(0), _cSize(0), _pifData(pIFD),
  114. _fFree(FALSE), _copyAlignment(1)
  115. {
  116. _cbData = _pifData == NULL ? 0 : pIFD->ulCntData;
  117. }
  118. inline ActivationStream::~ActivationStream(void)
  119. {
  120. if (_fFree)
  121. {
  122. ActMemFree(_pifData);
  123. }
  124. }
  125. inline void ActivationStream::AssignSerializedInterface(InterfaceData **ppIFD)
  126. {
  127. // Offset of next byte to be written is assumed
  128. // to be size of the buffer since all writing s/b
  129. // sequential.
  130. *ppIFD = _pifData;
  131. if (_cSize)
  132. (*ppIFD)->ulCntData = _cSize;
  133. else
  134. (*ppIFD)->ulCntData = _cbData;
  135. // Tell destructor not to free this buffer as some one
  136. // else owns the destruction now.
  137. _fFree = FALSE;
  138. }
  139. extern HRESULT GetActivationStreamCF(REFIID riid, void** ppv);
  140. #endif // __ACTSTRM_HXX__