Source code of Windows XP (NT5)
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.

208 lines
7.2 KiB

  1. /*++ /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. pcm.h
  5. Abstract:
  6. Define common data structure for precompiled-manifest Writer and Reader
  7. and class definition of PrecompiledManifetWriter and
  8. PrecompiledManifestReader
  9. Author:
  10. Xiaoyu Wu (xiaoyuw) June 2000
  11. Revision History:
  12. --*/
  13. #if !defined(_FUSION_SXS_PCM_H_INCLUDED_)
  14. #define _FUSION_SXS_PCM_H_INCLUDED_
  15. #pragma once
  16. #include "stdinc.h"
  17. #include <ole2.h>
  18. #include <xmlparser.h>
  19. #include "nodefactory.h"
  20. #include "pcmWriterStream.h"
  21. // pcm structure shared between PCMWriter and PCMReader
  22. typedef enum _RECORD_TYPE_PRECOMP_MANIFEST{
  23. CREATENODE_PRECOMP_MANIFEST = 1,
  24. BEGINCHILDREN_PRECOMP_MANIFEST = CREATENODE_PRECOMP_MANIFEST + 1,
  25. ENDCHILDREN_PRECOMP_MANIFEST = BEGINCHILDREN_PRECOMP_MANIFEST + 1
  26. } RECORD_TYPE_PRECOMP_MANIFEST;
  27. typedef struct _PCM_Header{
  28. int iVersion;
  29. ULONG ulRecordCount;
  30. USHORT usMaxNodeCount;
  31. }PCMHeader;
  32. typedef struct _PCM_RecordHeader{
  33. int typeID ;
  34. ULONG RecordSize;
  35. ULONG NodeCount;
  36. }PCM_RecordHeader;
  37. typedef struct _PCM_XML_NODE_INFO{
  38. DWORD dwSize;
  39. DWORD dwType;
  40. DWORD dwSubType;
  41. BOOL fTerminal;
  42. ULONG offset;
  43. ULONG ulLen;
  44. ULONG ulNsPrefixLen;
  45. }PCM_XML_NODE_INFO;
  46. class __declspec(uuid("6745d578-5d84-4890-aa6a-bd794ea50421"))
  47. CPrecompiledManifestReader : public IXMLNodeSource, public IStream {
  48. public :
  49. // IUnknown methods:
  50. STDMETHODIMP_(ULONG) AddRef();
  51. STDMETHODIMP_(ULONG) Release();
  52. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
  53. // IXMLNodeSource methods, only GetLineNumber is implemented got PCM purpose
  54. STDMETHODIMP SetFactory(IXMLNodeFactory __RPC_FAR *pNodeFactory);
  55. STDMETHODIMP GetFactory(IXMLNodeFactory** ppNodeFactory);
  56. STDMETHODIMP Abort(BSTR bstrErrorInfo);
  57. STDMETHODIMP_(ULONG) GetLineNumber(void);
  58. STDMETHODIMP_(ULONG) GetLinePosition(void);
  59. STDMETHODIMP_(ULONG) GetAbsolutePosition(void);
  60. STDMETHODIMP GetLineBuffer(const WCHAR **ppwcBuf, ULONG *pulLen, ULONG *pulStartPos);
  61. STDMETHODIMP GetLastError(void);
  62. STDMETHODIMP GetErrorInfo(BSTR *pbstrErrorInfo);
  63. STDMETHODIMP_(ULONG) GetFlags();
  64. STDMETHODIMP GetURL(const WCHAR **ppwcBuf);
  65. // IStream methods:
  66. STDMETHODIMP Read(void *pv, ULONG cb, ULONG *pcbRead);
  67. STDMETHODIMP Write(void const *pv, ULONG cb, ULONG *pcbWritten);
  68. STDMETHODIMP Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition);
  69. STDMETHODIMP SetSize(ULARGE_INTEGER libNewSize);
  70. STDMETHODIMP CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten);
  71. STDMETHODIMP Commit(DWORD grfCommitFlags);
  72. STDMETHODIMP Revert();
  73. STDMETHODIMP LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  74. STDMETHODIMP UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
  75. STDMETHODIMP Stat(STATSTG *pstatstg, DWORD grfStatFlag);
  76. STDMETHODIMP Clone(IStream **ppIStream);
  77. CPrecompiledManifestReader():m_hFile(INVALID_HANDLE_VALUE),
  78. m_hFileMapping(INVALID_HANDLE_VALUE), m_lpMapAddress(NULL),
  79. m_ulLineNumberFromCreateNodeRecord(ULONG(-1)),
  80. m_dwFilePointer(0), m_dwFileSize(0),
  81. m_cRef(0) { }
  82. ~CPrecompiledManifestReader() { CSxsPreserveLastError ple; this->Close(); ple.Restore(); }
  83. HRESULT InvokeNodeFactory(PCWSTR pcmFileName, IXMLNodeFactory *pNodeFactory);
  84. VOID Reset();
  85. protected:
  86. HANDLE m_hFile;
  87. HANDLE m_hFileMapping;
  88. LPVOID m_lpMapAddress;
  89. ULONG m_ulLineNumberFromCreateNodeRecord;
  90. DWORD m_dwFilePointer; // should we limit the size of pcm file? Since manifest file is not very huge...
  91. DWORD m_dwFileSize;
  92. ULONG m_cRef;
  93. HRESULT Close(
  94. );
  95. HRESULT OpenForRead(
  96. IN PCWSTR pszPCMFileName,
  97. IN DWORD dwShareMode = FILE_SHARE_READ, // share mode
  98. IN DWORD dwCreationDisposition = OPEN_EXISTING, // how to create
  99. IN DWORD dwFlagsAndAttributes = FILE_FLAG_SEQUENTIAL_SCAN // file attributes
  100. );
  101. HRESULT ReadPCMHeader(
  102. OUT PCMHeader* pHeader
  103. );
  104. HRESULT ReadPCMRecordHeader(
  105. OUT PCM_RecordHeader * pHeader
  106. );
  107. HRESULT ReadPCMRecord(
  108. OUT XML_NODE_INFO ** ppNodes,
  109. OUT PCM_RecordHeader * pRecordHeader,
  110. OUT PVOID param
  111. );
  112. };
  113. class __declspec(uuid("1b345c93-eb16-4d07-b366-81e8a2b88414"))
  114. CPrecompiledManifestWriter : public IXMLNodeFactory {
  115. public :
  116. // IUnknown methods:
  117. STDMETHODIMP_(ULONG) AddRef();
  118. STDMETHODIMP_(ULONG) Release();
  119. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppvObj);
  120. // IXMLNodeFactory methods:
  121. STDMETHODIMP NotifyEvent(IXMLNodeSource *pSource, XML_NODEFACTORY_EVENT iEvt);
  122. STDMETHODIMP BeginChildren(IXMLNodeSource *pSource, XML_NODE_INFO *pNodeInfo);
  123. STDMETHODIMP EndChildren(IXMLNodeSource *pSource, BOOL fEmpty, XML_NODE_INFO *pNodeInfo);
  124. STDMETHODIMP Error(IXMLNodeSource *pSource, HRESULT hrErrorCode, USHORT cNumRecs, XML_NODE_INFO **apNodeInfo);
  125. STDMETHODIMP CreateNode(IXMLNodeSource *pSource, PVOID pNodeParent, USHORT cNumRecs, XML_NODE_INFO **apNodeInfo);
  126. // constructor and destructor
  127. CPrecompiledManifestWriter() : m_cRef(0), m_ulRecordCount(0), m_usMaxNodeCount(0) { }
  128. ~CPrecompiledManifestWriter() { }
  129. // write APIs
  130. HRESULT Initialize(
  131. PACTCTXGENCTX ActCtxGenCtx,
  132. PASSEMBLY Assembly,
  133. PACTCTXCTB_ASSEMBLY_CONTEXT AssemblyContext);
  134. HRESULT SetWriterStream(CPrecompiledManifestWriterStream * pSinkedStream); // usually, filename of PCM is not available when
  135. // the stream is opened. and stream is inited by caller
  136. HRESULT Initialize(PCWSTR pcmFileName);
  137. HRESULT WritePrecompiledManifestRecord(
  138. IN RECORD_TYPE_PRECOMP_MANIFEST typeID,
  139. IN PVOID pData,
  140. IN USHORT NodeCount,
  141. IN PVOID param = NULL
  142. );
  143. HRESULT SetFactory(IXMLNodeFactory *pNodeFactory);
  144. HRESULT Close();
  145. protected:
  146. CSmartRef<IXMLNodeFactory> m_pNodeFactory;
  147. CSmartRef<CPrecompiledManifestWriterStream> m_pFileStream;
  148. ULONG m_ulRecordCount;
  149. USHORT m_usMaxNodeCount;
  150. ULONG m_cRef;
  151. HRESULT GetPCMRecordSize(
  152. IN XML_NODE_INFO ** ppNodeInfo,
  153. IN USHORT iNodeCount,
  154. IN ULONG * pSize
  155. );
  156. HRESULT WritePCMHeader( // version is forced to be 1, and the recordCount is forced to be 0;
  157. );
  158. HRESULT WritePCMRecordHeader(
  159. IN PCM_RecordHeader * pHeader
  160. );
  161. HRESULT WritePCMXmlNodeInfo(
  162. IN XML_NODE_INFO ** ppNodeInfo,
  163. IN USHORT iNodeCount,
  164. IN RECORD_TYPE_PRECOMP_MANIFEST typeID,
  165. IN PVOID param
  166. );
  167. };
  168. #endif // _FUSION_SXS_PRECOMPILED_MANIFEST_H_INCLUDED_