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.

413 lines
9.5 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // TaskVerifyIPAddress.cpp
  7. //
  8. // Description:
  9. // Object Manager implementation.
  10. //
  11. // Documentation:
  12. // Yes.
  13. //
  14. // Maintained By:
  15. // Galen Barbee (GalenB) 14-JUL-1999
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. #include "pch.h"
  19. #include "TaskVerifyIPAddress.h"
  20. #include <iphlpapi.h>
  21. DEFINE_THISCLASS("CTaskVerifyIPAddress")
  22. // ************************************************************************
  23. //
  24. // Constructor / Destructor
  25. //
  26. // ************************************************************************
  27. //////////////////////////////////////////////////////////////////////////////
  28. //
  29. // HRESULT
  30. // CTaskVerifyIPAddress::S_HrCreateInstance(
  31. // IUnknown ** ppunkOut
  32. // )
  33. //
  34. //////////////////////////////////////////////////////////////////////////////
  35. HRESULT
  36. CTaskVerifyIPAddress::S_HrCreateInstance(
  37. IUnknown ** ppunkOut
  38. )
  39. {
  40. TraceFunc( "" );
  41. HRESULT hr;
  42. Assert( ppunkOut != NULL );
  43. CTaskVerifyIPAddress * pTaskVerifyIPAddress = new CTaskVerifyIPAddress;
  44. if ( pTaskVerifyIPAddress != NULL )
  45. {
  46. hr = THR( pTaskVerifyIPAddress->Init() );
  47. if ( SUCCEEDED( hr ) )
  48. {
  49. hr = THR( pTaskVerifyIPAddress->TypeSafeQI( IUnknown, ppunkOut ) );
  50. }
  51. pTaskVerifyIPAddress->Release();
  52. }
  53. else
  54. {
  55. hr = E_OUTOFMEMORY;
  56. }
  57. HRETURN( hr );
  58. } // S_HrCreateInstance()
  59. //////////////////////////////////////////////////////////////////////////////
  60. //
  61. // CTaskVerifyIPAddress::CTaskVerifyIPAddress( void )
  62. //
  63. //////////////////////////////////////////////////////////////////////////////
  64. CTaskVerifyIPAddress::CTaskVerifyIPAddress( void )
  65. {
  66. TraceFunc( "" );
  67. InterlockedIncrement( &g_cObjects );
  68. TraceFuncExit();
  69. } // CTaskVerifyIPAddress()
  70. //////////////////////////////////////////////////////////////////////////////
  71. //
  72. // STDMETHODIMP
  73. // CTaskVerifyIPAddress::Init( void )
  74. //
  75. //////////////////////////////////////////////////////////////////////////////
  76. STDMETHODIMP
  77. CTaskVerifyIPAddress::Init( void )
  78. {
  79. TraceFunc( "" );
  80. HRESULT hr = S_OK;
  81. // IUnknown stuff
  82. Assert( m_cRef == 0 );
  83. AddRef(); // Add one count
  84. HRETURN( hr );
  85. } // Init()
  86. //////////////////////////////////////////////////////////////////////////////
  87. //
  88. // CTaskVerifyIPAddress::~CTaskVerifyIPAddress()
  89. //
  90. //////////////////////////////////////////////////////////////////////////////
  91. CTaskVerifyIPAddress::~CTaskVerifyIPAddress()
  92. {
  93. TraceFunc( "" );
  94. InterlockedDecrement( &g_cObjects );
  95. TraceFuncExit();
  96. } // ~CTaskVerifyIPAddress()
  97. // ************************************************************************
  98. //
  99. // IUnknown
  100. //
  101. // ************************************************************************
  102. //////////////////////////////////////////////////////////////////////////////
  103. //
  104. // STDMETHODIMP
  105. // CTaskVerifyIPAddress::QueryInterface(
  106. // REFIID riid,
  107. // LPVOID *ppv
  108. // )
  109. //
  110. //////////////////////////////////////////////////////////////////////////////
  111. STDMETHODIMP
  112. CTaskVerifyIPAddress::QueryInterface(
  113. REFIID riid,
  114. LPVOID *ppv
  115. )
  116. {
  117. TraceQIFunc( riid, ppv );
  118. HRESULT hr = E_NOINTERFACE;
  119. if ( IsEqualIID( riid, IID_IUnknown ) )
  120. {
  121. *ppv = static_cast< ITaskVerifyIPAddress * >( this );
  122. hr = S_OK;
  123. } // if: IUnknown
  124. else if ( IsEqualIID( riid, IID_ITaskVerifyIPAddress ) )
  125. {
  126. *ppv = TraceInterface( __THISCLASS__, ITaskVerifyIPAddress, this, 0 );
  127. hr = S_OK;
  128. } // else if: ITaskVerifyIPAddress
  129. else if ( IsEqualIID( riid, IID_IDoTask ) )
  130. {
  131. *ppv = TraceInterface( __THISCLASS__, IDoTask, this, 0 );
  132. hr = S_OK;
  133. } // else if: IDoTask
  134. if ( SUCCEEDED( hr ) )
  135. {
  136. ((IUnknown*) *ppv)->AddRef();
  137. } // if: success
  138. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  139. } // QueryInterface()
  140. //////////////////////////////////////////////////////////////////////////////
  141. //
  142. // STDMETHODIMP_(ULONG)
  143. // CTaskVerifyIPAddress::AddRef( void )
  144. //
  145. //////////////////////////////////////////////////////////////////////////////
  146. STDMETHODIMP_(ULONG)
  147. CTaskVerifyIPAddress::AddRef( void )
  148. {
  149. TraceFunc( "[IUnknown]" );
  150. InterlockedIncrement( &m_cRef );
  151. RETURN( m_cRef );
  152. } // AddRef()
  153. //////////////////////////////////////////////////////////////////////////////
  154. //
  155. // STDMETHODIMP_(ULONG)
  156. // CTaskVerifyIPAddress::Release( void )
  157. //
  158. //////////////////////////////////////////////////////////////////////////////
  159. STDMETHODIMP_(ULONG)
  160. CTaskVerifyIPAddress::Release( void )
  161. {
  162. TraceFunc( "[IUnknown]" );
  163. InterlockedDecrement( &m_cRef );
  164. if ( m_cRef )
  165. RETURN( m_cRef );
  166. TraceDo( delete this );
  167. RETURN(0);
  168. } // Release()
  169. //****************************************************************************
  170. //
  171. // IDoTask / ITaskVerifyIPAddress
  172. //
  173. //****************************************************************************
  174. //////////////////////////////////////////////////////////////////////////////
  175. //
  176. // STDMETHODIMP
  177. // CTaskVerifyIPAddress::BeginTask( void )
  178. //
  179. //////////////////////////////////////////////////////////////////////////////
  180. STDMETHODIMP
  181. CTaskVerifyIPAddress::BeginTask( void )
  182. {
  183. TraceFunc( "[IDoTask]" );
  184. ULONG ulHopCountDummy;
  185. ULONG ulRTTDummy;
  186. BOOL fRet;
  187. HRESULT hr = S_OK;
  188. IServiceProvider * psp = NULL;
  189. IConnectionPointContainer * pcpc = NULL;
  190. IConnectionPoint * pcp = NULL;
  191. INotifyUI * pnui = NULL;
  192. IObjectManager * pom = NULL;
  193. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  194. NULL,
  195. CLSCTX_INPROC_SERVER,
  196. TypeSafeParams( IServiceProvider, &psp )
  197. ) );
  198. if ( FAILED( hr ) )
  199. goto Cleanup;
  200. hr = THR( psp->TypeSafeQS( CLSID_ObjectManager,
  201. IObjectManager,
  202. &pom
  203. ) );
  204. if ( FAILED( hr ) )
  205. goto Cleanup;
  206. hr = THR( psp->TypeSafeQS( CLSID_NotificationManager,
  207. IConnectionPointContainer,
  208. &pcpc
  209. ) );
  210. if ( FAILED( hr ) )
  211. goto Cleanup;
  212. hr = THR( pcpc->FindConnectionPoint( IID_INotifyUI,
  213. &pcp
  214. ) );
  215. if ( FAILED( hr ) )
  216. goto Cleanup;
  217. pcp = TraceInterface( L"CTaskVerifyIPAddress!IConnectionPoint", IConnectionPoint, pcp, 1 );
  218. hr = THR( pcp->TypeSafeQI( INotifyUI, &pnui ) );
  219. if ( FAILED( hr ) )
  220. goto Cleanup;
  221. pnui = TraceInterface( L"CTaskVerifyIPAddress!INotifyUI", INotifyUI, pnui, 1 );
  222. // release promptly
  223. psp->Release();
  224. psp = NULL;
  225. fRet = GetRTTAndHopCount( m_dwIPAddress, &ulHopCountDummy, 20, &ulRTTDummy );
  226. if ( fRet )
  227. {
  228. hr = S_FALSE;
  229. }
  230. else
  231. {
  232. hr = S_OK;
  233. }
  234. Cleanup:
  235. if ( psp != NULL )
  236. {
  237. psp->Release();
  238. }
  239. if ( pom != NULL )
  240. {
  241. //
  242. // Update the cookie's status indicating the result of our task.
  243. //
  244. IUnknown * punk;
  245. HRESULT hr2;
  246. hr2 = THR( pom->GetObject( DFGUID_StandardInfo,
  247. m_cookie,
  248. &punk
  249. ) );
  250. if ( SUCCEEDED( hr2 ) )
  251. {
  252. IStandardInfo * psi;
  253. hr2 = THR( punk->TypeSafeQI( IStandardInfo, &psi ) );
  254. punk->Release();
  255. if ( SUCCEEDED( hr2 ) )
  256. {
  257. hr2 = THR( psi->SetStatus( hr ) );
  258. psi->Release();
  259. }
  260. }
  261. pom->Release();
  262. }
  263. if ( pcpc != NULL )
  264. {
  265. pcpc->Release();
  266. }
  267. if ( pcp != NULL )
  268. {
  269. pcp->Release();
  270. }
  271. if ( pnui != NULL )
  272. {
  273. //
  274. // Signal the cookie to indicate that we are done.
  275. //
  276. THR( pnui->ObjectChanged( m_cookie ) );
  277. pnui->Release();
  278. }
  279. HRETURN( hr );
  280. } // BeginTask()
  281. //////////////////////////////////////////////////////////////////////////////
  282. //
  283. // STDMETHODIMP
  284. // CTaskVerifyIPAddress::StopTask( void )
  285. //
  286. //////////////////////////////////////////////////////////////////////////////
  287. STDMETHODIMP
  288. CTaskVerifyIPAddress::StopTask( void )
  289. {
  290. TraceFunc( "[IDoTask]" );
  291. HRESULT hr = S_OK;
  292. HRETURN( hr );
  293. } //*** StopTask
  294. //////////////////////////////////////////////////////////////////////////////
  295. //
  296. // STDMETHODIMP
  297. // CTaskVerifyIPAddress::SetIPAddress(
  298. // DWORD dwIPAddressIn
  299. // )
  300. //
  301. //////////////////////////////////////////////////////////////////////////////
  302. STDMETHODIMP
  303. CTaskVerifyIPAddress::SetIPAddress(
  304. DWORD dwIPAddressIn
  305. )
  306. {
  307. TraceFunc( "[ITaskVerifyIPAddress]" );
  308. HRESULT hr = S_OK;
  309. m_dwIPAddress = dwIPAddressIn;
  310. HRETURN( hr );
  311. } // SetIPAddress()
  312. //////////////////////////////////////////////////////////////////////////////
  313. //
  314. // STDMETHODIMP
  315. // CTaskVerifyIPAddress::SetCookie(
  316. // OBJECTCOOKIE cookieIn
  317. // )
  318. //
  319. //////////////////////////////////////////////////////////////////////////////
  320. STDMETHODIMP
  321. CTaskVerifyIPAddress::SetCookie(
  322. OBJECTCOOKIE cookieIn
  323. )
  324. {
  325. TraceFunc( "[ITaskVerifyIPAddress]" );
  326. HRESULT hr = S_OK;
  327. m_cookie = cookieIn;
  328. HRETURN( hr );
  329. } // SetCookie()