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.

230 lines
6.9 KiB

  1. //--------------------------------------------------------------------
  2. // Microsoft OLE DB iparser object
  3. // (C) Copyright 1997 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // @doc
  6. //
  7. // @module iparser.CPP | IParser object implementation
  8. //
  9. //
  10. #pragma hdrstop
  11. #include "msidxtr.h"
  12. // CImpIParser::CImpIParser ---------------------------------------------------
  13. //
  14. // @mfunc Constructor
  15. //
  16. CImpIParser::CImpIParser()
  17. {
  18. m_cRef = 1;
  19. m_pGlobalPropertyList = 0;
  20. m_pGlobalViewList = 0;
  21. }
  22. // CImpIParser::~CImpIParser --------------------------------------------------
  23. //
  24. // @mfunc Destructor
  25. //
  26. CImpIParser::~CImpIParser()
  27. {
  28. delete m_pGlobalPropertyList;
  29. delete m_pGlobalViewList;
  30. }
  31. //-----------------------------------------------------------------------------
  32. // @func CImpIParser::CreateSession
  33. //
  34. // Creates a unique session within the parser. This session is required to keep
  35. // the views and properties in their correct lifetimes.
  36. //
  37. // @rdesc HRESULT
  38. // S_OK - IParserSession created
  39. // DB_E_DIALECTNOTSUPPOERTED - Specified dialect was not supported
  40. // E_OUTOFMEMORY - low on resources
  41. // E_FAIL - unexpected error
  42. // E_INVALIDARG - pGuidDialect, pIParserVerify, pIColMapCreator,
  43. // or ppIParserSession was a NULL pointer
  44. // (DEBUG ONLY).
  45. //-----------------------------------------------------------------------------
  46. STDMETHODIMP CImpIParser::CreateSession(
  47. const GUID * pGuidDialect, // in | dialect for this session
  48. LPCWSTR pwszMachine, // in | provider's current machine
  49. IParserVerify * pIParserVerify, // in | ptr to ParserVerify
  50. IColumnMapperCreator * pIColMapCreator,
  51. IParserSession ** ppIParserSession ) // out | a unique parser session
  52. {
  53. SCODE sc = S_OK;
  54. #ifdef DEBUG
  55. if ( 0 == ppIParserSession || 0 == pIParserVerify ||
  56. 0 == pIColMapCreator || 0 == pGuidDialect)
  57. sc = E_INVALIDARG;
  58. else
  59. #endif
  60. {
  61. TRANSLATE_EXCEPTIONS;
  62. TRY
  63. {
  64. if ( 0 != ppIParserSession )
  65. *ppIParserSession = 0;
  66. // Check Dialect
  67. if ( DBGUID_MSSQLTEXT == *pGuidDialect || DBGUID_MSSQLJAWS == *pGuidDialect )
  68. {
  69. XPtr<CViewList> xpGlobalViewList;
  70. if ( 0 == m_pGlobalViewList )
  71. xpGlobalViewList.Set( new CViewList() );
  72. XInterface<CImpIParserSession>
  73. xpIParserSession( new CImpIParserSession( pGuidDialect,
  74. pIParserVerify,
  75. pIColMapCreator,
  76. xpGlobalViewList.GetPointer() ) );
  77. XPtr<CPropertyList> xpGlobalPropertyList;
  78. sc = xpIParserSession->FInit( pwszMachine,
  79. &m_pGlobalPropertyList );
  80. if ( FAILED(sc) )
  81. xpIParserSession.Free();
  82. else
  83. {
  84. if ( 0 == m_pGlobalPropertyList )
  85. xpGlobalPropertyList.Set( new CPropertyList(NULL) );
  86. }
  87. delete m_pGlobalViewList;
  88. m_pGlobalViewList = xpGlobalViewList.Acquire();
  89. delete m_pGlobalPropertyList;
  90. m_pGlobalPropertyList = xpGlobalPropertyList.Acquire();
  91. *ppIParserSession = xpIParserSession.Acquire();
  92. }
  93. else
  94. sc = DB_E_DIALECTNOTSUPPORTED;
  95. }
  96. CATCH( CException, e )
  97. {
  98. sc = e.GetErrorCode();
  99. }
  100. END_CATCH
  101. UNTRANSLATE_EXCEPTIONS;
  102. }
  103. return sc;
  104. }
  105. //-----------------------------------------------------------------------------
  106. // @func CImpIParser::QueryInterface
  107. //
  108. // @mfunc Returns a pointer to a specified interface. Callers use
  109. // QueryInterface to determine which interfaces the called object
  110. // supports.
  111. //
  112. // @rdesc HResult indicating the status of the method
  113. // @flag S_OK | Interface is supported and ppvObject is set.
  114. // @flag E_NOINTERFACE | Interface is not supported by the object
  115. // @flag E_INVALIDARG | One or more arguments are invalid.
  116. //-----------------------------------------------------------------------------
  117. STDMETHODIMP CImpIParser::QueryInterface(
  118. REFIID riid, //@parm IN | Interface ID of the interface being queried for.
  119. LPVOID* ppv ) //@parm OUT | Pointer to interface that was instantiated
  120. {
  121. if ( 0 == ppv )
  122. return ResultFromScode(E_INVALIDARG);
  123. // This is the non-delegating IUnknown implementation
  124. if ( (riid == IID_IParser) ||
  125. (riid == IID_IUnknown) )
  126. *ppv = (LPVOID)this;
  127. else
  128. *ppv = 0;
  129. // If we're going to return an interface, AddRef it first
  130. if ( 0 != *ppv )
  131. {
  132. ((LPUNKNOWN)*ppv)->AddRef();
  133. return S_OK;
  134. }
  135. return ResultFromScode(E_NOINTERFACE);
  136. }
  137. //-----------------------------------------------------------------------------
  138. // CImpIParser::AddRef
  139. //
  140. // @mfunc Increments a persistence count for the object.
  141. //
  142. // @rdesc Reference count after operation.
  143. //-----------------------------------------------------------------------------
  144. STDMETHODIMP_(ULONG) CImpIParser::AddRef()
  145. {
  146. return InterlockedIncrement((long *) &m_cRef);
  147. }
  148. //-----------------------------------------------------------------------------
  149. // CImpIParser::Release
  150. //
  151. // @mfunc Decrements a persistence count for the object and if
  152. // persistence count is 0, the object destroys itself.
  153. //
  154. // @rdesc Current reference count
  155. //-----------------------------------------------------------------------------
  156. STDMETHODIMP_(ULONG) CImpIParser::Release()
  157. {
  158. Assert(m_cRef > 0);
  159. ULONG cRef= InterlockedDecrement( (long *) &m_cRef );
  160. if ( 0 == cRef )
  161. {
  162. TRACE("IParser refcount=0, now deleting.\n");
  163. delete this;
  164. return 0;
  165. }
  166. TRACE("IParser refcount=%d after Release().\n", cRef);
  167. return cRef;
  168. }
  169. //-----------------------------------------------------------------------------
  170. // @func MakeIParser
  171. //
  172. // Creates an IParser
  173. //
  174. // @rdesc HRESULT
  175. // S_OK if successful; Error code otherwise
  176. //-----------------------------------------------------------------------------
  177. HRESULT __stdcall MakeIParser(
  178. IParser** ppIParser )
  179. {
  180. SCODE sc = S_OK;
  181. if ( 0 == ppIParser )
  182. sc = E_INVALIDARG;
  183. else
  184. {
  185. TRANSLATE_EXCEPTIONS;
  186. TRY
  187. {
  188. XInterface<CImpIParser> xpIParser( new CImpIParser() );
  189. *ppIParser = xpIParser.Acquire();
  190. }
  191. CATCH( CException, e )
  192. {
  193. sc = e.GetErrorCode();
  194. }
  195. END_CATCH
  196. UNTRANSLATE_EXCEPTIONS;
  197. }
  198. return sc;
  199. }