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.

345 lines
8.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: cicontrl.cxx
  7. //
  8. // Contents: Contains the implementation of ICiControl interface.
  9. //
  10. // History: 1-17-97 srikants Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include "cicontrl.hxx"
  16. #include "cimanger.hxx"
  17. const GUID clsidCiControl = CLSID_CiControl;
  18. extern long gulcInstances;
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: CCiControlObject::QueryInterface
  22. //
  23. // Synopsis: Returns interfaces to IID_IUknown, IID_ICiControl
  24. //
  25. // History: 01-17-97 srikants Created
  26. //
  27. //----------------------------------------------------------------------------
  28. STDMETHODIMP CCiControlObject::QueryInterface(
  29. REFIID riid,
  30. void **ppvObject)
  31. {
  32. Win4Assert( 0 != ppvObject );
  33. if ( IID_ICiControl == riid )
  34. *ppvObject = (void *)((ICiControl *)this);
  35. else if ( IID_IUnknown == riid )
  36. *ppvObject = (void *)((IUnknown *) (ICiControl *) this);
  37. else
  38. {
  39. *ppvObject = 0;
  40. return E_NOINTERFACE;
  41. }
  42. AddRef();
  43. return S_OK;
  44. } //QueryInterface
  45. //+---------------------------------------------------------------------------
  46. //
  47. // Member: CCiControlObject::AddRef
  48. //
  49. // History: 01-17-97 srikants Created
  50. //
  51. //----------------------------------------------------------------------------
  52. STDMETHODIMP_(ULONG) CCiControlObject::AddRef()
  53. {
  54. return InterlockedIncrement(&_refCount);
  55. } //AddRef
  56. //+---------------------------------------------------------------------------
  57. //
  58. // Member: CCiControlObject::Release
  59. //
  60. // History: 01-17-97 srikants Created
  61. //
  62. //----------------------------------------------------------------------------
  63. STDMETHODIMP_(ULONG) CCiControlObject::Release()
  64. {
  65. Win4Assert( _refCount > 0 );
  66. LONG refCount = InterlockedDecrement(&_refCount);
  67. if ( refCount <= 0 )
  68. delete this;
  69. return (ULONG) refCount;
  70. } //Release
  71. //+---------------------------------------------------------------------------
  72. //
  73. // Member: CCiControlObject::CreateContentIndex
  74. //
  75. // Synopsis: Creates a new Content Index and associates it with the
  76. // ICiCDocStore provided.
  77. //
  78. // Arguments: [pICiCDocStore] - DocStore to associate with
  79. // [ppICiManager] - On output, if successful will have the
  80. // ICiManager interface.
  81. //
  82. // History: 1-17-97 srikants Created
  83. //
  84. //----------------------------------------------------------------------------
  85. STDMETHODIMP CCiControlObject::CreateContentIndex(
  86. ICiCDocStore * pICiCDocStore,
  87. ICiManager ** ppICiManager )
  88. {
  89. *ppICiManager = 0;
  90. SCODE sc = S_OK;
  91. if ( 0 == pICiCDocStore )
  92. return E_INVALIDARG;
  93. TRY
  94. {
  95. CCiManager * pCiManager = new CCiManager( pICiCDocStore );
  96. *ppICiManager = pCiManager;
  97. }
  98. CATCH( CException, e )
  99. {
  100. ciDebugOut(( DEB_ERROR, "Failed to create CCiManager. Error (0x%X)\n",
  101. e.GetErrorCode() ));
  102. sc = e.GetErrorCode();
  103. }
  104. END_CATCH
  105. return sc;
  106. }
  107. //+---------------------------------------------------------------------------
  108. //
  109. // Construction and destruction
  110. //
  111. //----------------------------------------------------------------------------
  112. //+-------------------------------------------------------------------------
  113. //
  114. // Method: CCiControlObjectCF::CCiControlObjectCF
  115. //
  116. // Synopsis: Storage Filter Object class factory constructor
  117. //
  118. // History: 17-Jan-1997 Srikants Created
  119. //
  120. //+-------------------------------------------------------------------------
  121. CCiControlObjectCF::CCiControlObjectCF()
  122. : _RefCount( 1 )
  123. {
  124. InterlockedIncrement( &gulcInstances );
  125. }
  126. //+-------------------------------------------------------------------------
  127. //
  128. // Method: CCiControlObjectCF::~CCiControlObjectCF
  129. //
  130. // Synopsis: Storage Filter Object class factory destructor
  131. //
  132. // History: 6-Jan-1997 Srikants Created
  133. //
  134. //--------------------------------------------------------------------------
  135. CCiControlObjectCF::~CCiControlObjectCF()
  136. {
  137. Win4Assert( _RefCount == 0);
  138. Win4Assert( gulcInstances != 0 );
  139. InterlockedDecrement( &gulcInstances );
  140. }
  141. //+---------------------------------------------------------------------------
  142. //
  143. // IUnknown method implementations
  144. //
  145. //----------------------------------------------------------------------------
  146. //+-------------------------------------------------------------------------
  147. //
  148. // Method: CCiControlObjectCF::AddRef
  149. //
  150. // Synopsis: Increments refcount
  151. //
  152. // History: 17-Jan-1997 Srikants Created
  153. //
  154. //--------------------------------------------------------------------------
  155. ULONG STDMETHODCALLTYPE CCiControlObjectCF::AddRef()
  156. {
  157. return InterlockedIncrement( &_RefCount );
  158. }
  159. //+-------------------------------------------------------------------------
  160. //
  161. // Method: CCiControlObjectCF::Release
  162. //
  163. // Synopsis: Decrement refcount. Delete if necessary.
  164. //
  165. // History: 6-Jan-1997 Srikants Created
  166. //
  167. //--------------------------------------------------------------------------
  168. ULONG STDMETHODCALLTYPE CCiControlObjectCF::Release()
  169. {
  170. Win4Assert( _RefCount != 0 );
  171. LONG RefCount = InterlockedDecrement( &_RefCount );
  172. if ( RefCount <= 0 )
  173. delete this;
  174. return (ULONG) RefCount;
  175. } // Release
  176. //+-------------------------------------------------------------------------
  177. //
  178. // Method: CCiControlObjectCF::QueryInterface
  179. //
  180. // Synopsis: Rebind to other interface
  181. //
  182. // Arguments: [riid] -- IID of new interface
  183. // [ppvObject] -- New interface * returned here
  184. //
  185. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  186. //
  187. // History: 17-Jan-1997 Srikants Created
  188. //
  189. //--------------------------------------------------------------------------
  190. STDMETHODIMP CCiControlObjectCF::QueryInterface(
  191. REFIID riid,
  192. PVOID* ppvObject )
  193. {
  194. Win4Assert( 0 != ppvObject );
  195. if ( IID_IUnknown == riid ) {
  196. AddRef( );
  197. *ppvObject = (PVOID) ((IUnknown *) this );
  198. return S_OK;
  199. } else if ( IID_IClassFactory == riid) {
  200. AddRef( );
  201. *ppvObject = (PVOID) ((IClassFactory *) this );
  202. return S_OK;
  203. } else {
  204. *ppvObject = 0;
  205. return E_NOINTERFACE;
  206. }
  207. }
  208. //+-------------------------------------------------------------------------
  209. //
  210. // Method: CCiControlObjectCF::CreateInstance
  211. //
  212. // Synopsis: Create new CStorageFilterObject instance
  213. //
  214. // Arguments: [pUnkOuter] -- 'Outer' IUnknown; IGNORED
  215. // [riid] -- Interface to bind
  216. // [ppvObject] -- Interface returned here
  217. //
  218. // History: 17-Jan-1997 Srikants Created
  219. //
  220. //--------------------------------------------------------------------------
  221. STDMETHODIMP CCiControlObjectCF::CreateInstance(
  222. IUnknown * pUnkOuter,
  223. REFIID riid,
  224. PVOID * ppvObject )
  225. {
  226. if ( 0 != pUnkOuter )
  227. return ResultFromScode( CLASS_E_NOAGGREGATION );
  228. CCiControlObject * pObject = 0;
  229. SCODE sc = S_OK;
  230. TRANSLATE_EXCEPTIONS;
  231. TRY
  232. {
  233. //
  234. // Create the new object
  235. //
  236. pObject = new CCiControlObject;
  237. //
  238. // Obtain the new interface
  239. //
  240. sc = pObject->QueryInterface( riid , ppvObject );
  241. //
  242. // Regardless of whether the QueryInterface succeeded, we
  243. // release the object.
  244. //
  245. pObject->Release();
  246. }
  247. CATCH(CException, e)
  248. {
  249. Win4Assert( 0 == pObject );
  250. switch( e.GetErrorCode() )
  251. {
  252. case E_OUTOFMEMORY:
  253. sc = (E_OUTOFMEMORY);
  254. break;
  255. default:
  256. sc = (E_UNEXPECTED);
  257. }
  258. }
  259. END_CATCH;
  260. UNTRANSLATE_EXCEPTIONS;
  261. return (sc);
  262. }
  263. //+-------------------------------------------------------------------------
  264. //
  265. // Method: CCiControlObjectCF::LockServer
  266. //
  267. // Synopsis: Force class factory to remain loaded
  268. //
  269. // Arguments: [fLock] -- TRUE if locking, FALSE if unlocking
  270. //
  271. // Returns: S_OK
  272. //
  273. // History: 17-Jan-1997 Srikants Created
  274. //
  275. //--------------------------------------------------------------------------
  276. STDMETHODIMP CCiControlObjectCF::LockServer( BOOL fLock )
  277. {
  278. if (fLock)
  279. InterlockedIncrement( &gulcInstances );
  280. else
  281. InterlockedDecrement( &gulcInstances );
  282. return(S_OK);
  283. }