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.

1169 lines
27 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2001-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: controlobj.cpp
  6. *
  7. * Content: DP8SIM control interface wrapper object class.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 04/24/01 VanceO Created.
  13. *
  14. ***************************************************************************/
  15. #include "dp8simi.h"
  16. #undef DPF_MODNAME
  17. #define DPF_MODNAME "CDP8SimControl::CDP8SimControl"
  18. //=============================================================================
  19. // CDP8SimControl constructor
  20. //-----------------------------------------------------------------------------
  21. //
  22. // Description: Initializes the new CDP8SimControl object.
  23. //
  24. // Arguments: None.
  25. //
  26. // Returns: None (the object).
  27. //=============================================================================
  28. CDP8SimControl::CDP8SimControl(void)
  29. {
  30. this->m_blList.Initialize();
  31. this->m_Sig[0] = 'D';
  32. this->m_Sig[1] = 'P';
  33. this->m_Sig[2] = '8';
  34. this->m_Sig[3] = 'S';
  35. this->m_lRefCount = 1; // someone must have a pointer to this object
  36. this->m_dwFlags = 0;
  37. } // CDP8SimControl::CDP8SimControl
  38. #undef DPF_MODNAME
  39. #define DPF_MODNAME "CDP8SimControl::~CDP8SimControl"
  40. //=============================================================================
  41. // CDP8SimControl destructor
  42. //-----------------------------------------------------------------------------
  43. //
  44. // Description: Frees the CDP8SimControl object.
  45. //
  46. // Arguments: None.
  47. //
  48. // Returns: None.
  49. //=============================================================================
  50. CDP8SimControl::~CDP8SimControl(void)
  51. {
  52. DNASSERT(this->m_blList.IsEmpty());
  53. DNASSERT(this->m_lRefCount == 0);
  54. DNASSERT(this->m_dwFlags == 0);
  55. //
  56. // For grins, change the signature before deleting the object.
  57. //
  58. this->m_Sig[3] = 's';
  59. } // CDP8SimControl::~CDP8SimControl
  60. #undef DPF_MODNAME
  61. #define DPF_MODNAME "CDP8SimControl::QueryInterface"
  62. //=============================================================================
  63. // CDP8SimControl::QueryInterface
  64. //-----------------------------------------------------------------------------
  65. //
  66. // Description: Retrieves a new reference for an interfaces supported by this
  67. // CDP8SimControl object.
  68. //
  69. // Arguments:
  70. // REFIID riid - Reference to interface ID GUID.
  71. // LPVOID * ppvObj - Place to store pointer to object.
  72. //
  73. // Returns: HRESULT
  74. // S_OK - Returning a valid interface pointer.
  75. // DPNHERR_INVALIDOBJECT - The interface object is invalid.
  76. // DPNHERR_INVALIDPOINTER - The destination pointer is invalid.
  77. // E_NOINTERFACE - Invalid interface was specified.
  78. //=============================================================================
  79. STDMETHODIMP CDP8SimControl::QueryInterface(REFIID riid, LPVOID * ppvObj)
  80. {
  81. HRESULT hr = DPN_OK;
  82. DPFX(DPFPREP, 3, "(0x%p) Parameters: (REFIID, 0x%p)", this, ppvObj);
  83. //
  84. // Validate the object.
  85. //
  86. if (! this->IsValidObject())
  87. {
  88. DPFX(DPFPREP, 0, "Invalid DP8SimControl object!");
  89. hr = DPNERR_INVALIDOBJECT;
  90. goto Failure;
  91. }
  92. //
  93. // Validate the parameters.
  94. //
  95. if ((! IsEqualIID(riid, IID_IUnknown)) &&
  96. (! IsEqualIID(riid, IID_IDP8SimControl)))
  97. {
  98. DPFX(DPFPREP, 0, "Unsupported interface!");
  99. hr = E_NOINTERFACE;
  100. goto Failure;
  101. }
  102. if ((ppvObj == NULL) ||
  103. (IsBadWritePtr(ppvObj, sizeof(void*))))
  104. {
  105. DPFX(DPFPREP, 0, "Invalid interface pointer specified!");
  106. hr = DPNERR_INVALIDPOINTER;
  107. goto Failure;
  108. }
  109. //
  110. // Add a reference, and return the interface pointer (which is actually
  111. // just the object pointer, they line up because CDP8SimControl inherits
  112. // from the interface declaration).
  113. //
  114. this->AddRef();
  115. (*ppvObj) = this;
  116. Exit:
  117. DPFX(DPFPREP, 3, "(0x%p) Returning: [0x%lx]", this, hr);
  118. return hr;
  119. Failure:
  120. goto Exit;
  121. } // CDP8SimControl::QueryInterface
  122. #undef DPF_MODNAME
  123. #define DPF_MODNAME "CDP8SimControl::AddRef"
  124. //=============================================================================
  125. // CDP8SimControl::AddRef
  126. //-----------------------------------------------------------------------------
  127. //
  128. // Description: Adds a reference to this CDP8SimControl object.
  129. //
  130. // Arguments: None.
  131. //
  132. // Returns: New refcount.
  133. //=============================================================================
  134. STDMETHODIMP_(ULONG) CDP8SimControl::AddRef(void)
  135. {
  136. LONG lRefCount;
  137. DNASSERT(this->IsValidObject());
  138. //
  139. // There must be at least 1 reference to this object, since someone is
  140. // calling AddRef.
  141. //
  142. DNASSERT(this->m_lRefCount > 0);
  143. lRefCount = InterlockedIncrement(&this->m_lRefCount);
  144. DPFX(DPFPREP, 3, "[0x%p] RefCount [0x%lx]", this, lRefCount);
  145. return lRefCount;
  146. } // CDP8SimControl::AddRef
  147. #undef DPF_MODNAME
  148. #define DPF_MODNAME "CDP8SimControl::Release"
  149. //=============================================================================
  150. // CDP8SimControl::Release
  151. //-----------------------------------------------------------------------------
  152. //
  153. // Description: Removes a reference to this CDP8SimControl object. When the
  154. // refcount reaches 0, this object is destroyed.
  155. // You must NULL out your pointer to this object after calling
  156. // this function.
  157. //
  158. // Arguments: None.
  159. //
  160. // Returns: New refcount.
  161. //=============================================================================
  162. STDMETHODIMP_(ULONG) CDP8SimControl::Release(void)
  163. {
  164. LONG lRefCount;
  165. DNASSERT(this->IsValidObject());
  166. //
  167. // There must be at least 1 reference to this object, since someone is
  168. // calling Release.
  169. //
  170. DNASSERT(this->m_lRefCount > 0);
  171. lRefCount = InterlockedDecrement(&this->m_lRefCount);
  172. //
  173. // Was that the last reference? If so, we're going to destroy this object.
  174. //
  175. if (lRefCount == 0)
  176. {
  177. DPFX(DPFPREP, 3, "[0x%p] RefCount hit 0, destroying object.", this);
  178. //
  179. // First pull it off the global list.
  180. //
  181. DNEnterCriticalSection(&g_csGlobalsLock);
  182. this->m_blList.RemoveFromList();
  183. DNASSERT(g_lOutstandingInterfaceCount > 0);
  184. g_lOutstandingInterfaceCount--; // update count so DLL can unload now works correctly
  185. DNLeaveCriticalSection(&g_csGlobalsLock);
  186. //
  187. // Make sure it's closed.
  188. //
  189. if (this->m_dwFlags & DP8SIMCONTROLOBJ_INITIALIZED)
  190. {
  191. //
  192. // Assert so that the user can fix his/her broken code!
  193. //
  194. DNASSERT(! "DP8SimControl object being released without calling Close first!");
  195. //
  196. // Then go ahead and do the right thing. Ignore error, we can't do
  197. // much about it.
  198. //
  199. this->Close(0);
  200. }
  201. //
  202. // Then uninitialize the object.
  203. //
  204. this->UninitializeObject();
  205. //
  206. // Finally delete this (!) object.
  207. //
  208. delete this;
  209. }
  210. else
  211. {
  212. DPFX(DPFPREP, 3, "[0x%p] RefCount [0x%lx]", this, lRefCount);
  213. }
  214. return lRefCount;
  215. } // CDP8SimControl::Release
  216. #undef DPF_MODNAME
  217. #define DPF_MODNAME "CDP8SimControl::Initialize"
  218. //=============================================================================
  219. // CDP8SimControl::Initialize
  220. //-----------------------------------------------------------------------------
  221. //
  222. // Description: Initializes this DP8Sim Control interface.
  223. //
  224. // Arguments:
  225. // DWORD dwFlags - Unused, must be zero.
  226. //
  227. // Returns: HRESULT
  228. // DP8SIM_OK - The DP8Sim control object was
  229. // successfully initialized.
  230. // DP8SIMERR_ALREADYINITIALIZED - The DP8Sim control object has already
  231. // been initialized.
  232. // DP8SIMERR_INVALIDFLAGS - Invalid flags were specified.
  233. // DP8SIMERR_INVALIDOBJECT - The DP8Sim control object is invalid.
  234. // DP8SIMERR_MISMATCHEDVERSION - A different version of DP8Sim is already
  235. // in use on this system.
  236. //=============================================================================
  237. STDMETHODIMP CDP8SimControl::Initialize(const DWORD dwFlags)
  238. {
  239. HRESULT hr = DP8SIM_OK;
  240. BOOL fHaveLock = FALSE;
  241. BOOL fInitializedIPCObject = FALSE;
  242. DPFX(DPFPREP, 2, "(0x%p) Parameters: (0x%x)", this, dwFlags);
  243. #ifndef DPNBUILD_NOPARAMVAL
  244. //
  245. // Validate the object.
  246. //
  247. if (! this->IsValidObject())
  248. {
  249. DPFX(DPFPREP, 0, "Invalid DP8Sim control object!");
  250. hr = DP8SIMERR_INVALIDOBJECT;
  251. goto Failure;
  252. }
  253. //
  254. // Validate the parameters.
  255. //
  256. if (dwFlags != 0)
  257. {
  258. DPFX(DPFPREP, 0, "Invalid flags specified!");
  259. hr = DP8SIMERR_INVALIDFLAGS;
  260. goto Failure;
  261. }
  262. #endif // ! DPNBUILD_NOPARAMVAL
  263. DNEnterCriticalSection(&this->m_csLock);
  264. fHaveLock = TRUE;
  265. //
  266. // Validate the object state.
  267. //
  268. if (this->m_dwFlags & DP8SIMCONTROLOBJ_INITIALIZED)
  269. {
  270. DPFX(DPFPREP, 0, "Control object already initialized!");
  271. hr = DP8SIMERR_ALREADYINITIALIZED;
  272. goto Failure;
  273. }
  274. //
  275. // Connect the shared memory.
  276. //
  277. hr = this->m_DP8SimIPC.Initialize();
  278. if (hr != DPN_OK)
  279. {
  280. DPFX(DPFPREP, 0, "Couldn't initialize IPC object!");
  281. goto Failure;
  282. }
  283. fInitializedIPCObject = TRUE;
  284. //
  285. // We're now initialized.
  286. //
  287. this->m_dwFlags |= DP8SIMCONTROLOBJ_INITIALIZED;
  288. Exit:
  289. if (fHaveLock)
  290. {
  291. DNLeaveCriticalSection(&this->m_csLock);
  292. }
  293. DPFX(DPFPREP, 2, "(0x%p) Returning: [0x%lx]", this, hr);
  294. return hr;
  295. Failure:
  296. if (fInitializedIPCObject)
  297. {
  298. this->m_DP8SimIPC.Close();
  299. fInitializedIPCObject = FALSE;
  300. }
  301. goto Exit;
  302. } // CDP8SimControl::Initialize
  303. #undef DPF_MODNAME
  304. #define DPF_MODNAME "CDP8SimControl::Close"
  305. //=============================================================================
  306. // CDP8SimControl::Close
  307. //-----------------------------------------------------------------------------
  308. //
  309. // Description: Closes this DP8Sim Control interface.
  310. //
  311. // Arguments:
  312. // DWORD dwFlags - Unused, must be zero.
  313. //
  314. // Returns: HRESULT
  315. // DP8SIM_OK - The DP8Sim control object was successfully
  316. // closed.
  317. // DP8SIMERR_INVALIDFLAGS - Invalid flags were specified.
  318. // DP8SIMERR_INVALIDOBJECT - The DP8Sim control object is invalid.
  319. // DP8SIMERR_NOTINITIALIZED - The DP8Sim control object has not been
  320. // initialized.
  321. //=============================================================================
  322. STDMETHODIMP CDP8SimControl::Close(const DWORD dwFlags)
  323. {
  324. HRESULT hr = DP8SIM_OK;
  325. BOOL fHaveLock = FALSE;
  326. DPFX(DPFPREP, 2, "(0x%p) Parameters: (0x%x)", this, dwFlags);
  327. #ifndef DPNBUILD_NOPARAMVAL
  328. //
  329. // Validate the object.
  330. //
  331. if (! this->IsValidObject())
  332. {
  333. DPFX(DPFPREP, 0, "Invalid DP8Sim control object!");
  334. hr = DP8SIMERR_INVALIDOBJECT;
  335. goto Failure;
  336. }
  337. //
  338. // Validate the parameters.
  339. //
  340. if (dwFlags != 0)
  341. {
  342. DPFX(DPFPREP, 0, "Invalid flags specified!");
  343. hr = DP8SIMERR_INVALIDFLAGS;
  344. goto Failure;
  345. }
  346. #endif // ! DPNBUILD_NOPARAMVAL
  347. DNEnterCriticalSection(&this->m_csLock);
  348. fHaveLock = TRUE;
  349. //
  350. // Validate the object state.
  351. //
  352. if (! (this->m_dwFlags & DP8SIMCONTROLOBJ_INITIALIZED))
  353. {
  354. DPFX(DPFPREP, 0, "Control object not initialized!");
  355. hr = DP8SIMERR_NOTINITIALIZED;
  356. goto Failure;
  357. }
  358. //
  359. // Disconnect the shared memory.
  360. //
  361. this->m_DP8SimIPC.Close();
  362. //
  363. // Turn off the initialized flags.
  364. //
  365. this->m_dwFlags &= ~DP8SIMCONTROLOBJ_INITIALIZED;
  366. DNASSERT(this->m_dwFlags == 0);
  367. //
  368. // Drop the lock, nobody should be touching this object now.
  369. //
  370. DNLeaveCriticalSection(&this->m_csLock);
  371. fHaveLock = FALSE;
  372. Exit:
  373. DPFX(DPFPREP, 2, "(0x%p) Returning: [0x%lx]", this, hr);
  374. return hr;
  375. Failure:
  376. if (fHaveLock)
  377. {
  378. DNLeaveCriticalSection(&this->m_csLock);
  379. }
  380. goto Exit;
  381. } // CDP8SimControl::Close
  382. #undef DPF_MODNAME
  383. #define DPF_MODNAME "CDP8SimControl::GetAllParameters"
  384. //=============================================================================
  385. // CDP8SimControl::GetAllParameters
  386. //-----------------------------------------------------------------------------
  387. //
  388. // Description: Retrieves all of the current DP8Sim settings.
  389. //
  390. // Arguments:
  391. // DP8SIM_PARAMETERS * pdp8spSend - Place to store current send
  392. // parameters.
  393. // DP8SIM_PARAMETERS * pdp8spReceive - Place to store current receive
  394. // parameters.
  395. // DWORD dwFlags - Unused, must be zero.
  396. //
  397. // Returns: HRESULT
  398. // DP8SIM_OK - The parameters were successfully retrieved.
  399. // DP8SIMERR_INVALIDFLAGS - Invalid flags were specified.
  400. // DP8SIMERR_INVALIDOBJECT - The DP8Sim control object is invalid.
  401. // DP8SIMERR_INVALIDPARAM - An invalid structure was specified.
  402. // DP8SIMERR_INVALIDPOINTER - An invalid structure pointer was specified.
  403. // DP8SIMERR_NOTINITIALIZED - The DP8Sim control object has not been
  404. // initialized.
  405. //=============================================================================
  406. STDMETHODIMP CDP8SimControl::GetAllParameters(DP8SIM_PARAMETERS * const pdp8spSend,
  407. DP8SIM_PARAMETERS * const pdp8spReceive,
  408. const DWORD dwFlags)
  409. {
  410. HRESULT hr = DP8SIM_OK;
  411. BOOL fHaveLock = FALSE;
  412. DPFX(DPFPREP, 2, "(0x%p) Parameters: (0x%p, 0x%p, 0x%x)",
  413. this, pdp8spSend, pdp8spReceive, dwFlags);
  414. #ifndef DPNBUILD_NOPARAMVAL
  415. //
  416. // Validate the object.
  417. //
  418. if (! this->IsValidObject())
  419. {
  420. DPFX(DPFPREP, 0, "Invalid DP8Sim control object!");
  421. hr = DP8SIMERR_INVALIDOBJECT;
  422. goto Failure;
  423. }
  424. //
  425. // Validate the parameters.
  426. //
  427. if ((pdp8spSend == NULL) ||
  428. (IsBadWritePtr(pdp8spSend, sizeof(DP8SIM_PARAMETERS))))
  429. {
  430. DPFX(DPFPREP, 0, "Invalid send parameters pointer!");
  431. hr = DP8SIMERR_INVALIDPOINTER;
  432. goto Failure;
  433. }
  434. if (pdp8spSend->dwSize != sizeof(DP8SIM_PARAMETERS))
  435. {
  436. DPFX(DPFPREP, 0, "Send parameters structure size is invalid!");
  437. hr = DP8SIMERR_INVALIDPARAM;
  438. goto Failure;
  439. }
  440. if ((pdp8spReceive == NULL) ||
  441. (IsBadWritePtr(pdp8spReceive, sizeof(DP8SIM_PARAMETERS))))
  442. {
  443. DPFX(DPFPREP, 0, "Invalid receive parameters pointer!");
  444. hr = DP8SIMERR_INVALIDPOINTER;
  445. goto Failure;
  446. }
  447. if (pdp8spReceive->dwSize != sizeof(DP8SIM_PARAMETERS))
  448. {
  449. DPFX(DPFPREP, 0, "Receive parameters structure size is invalid!");
  450. hr = DP8SIMERR_INVALIDPARAM;
  451. goto Failure;
  452. }
  453. if (dwFlags != 0)
  454. {
  455. DPFX(DPFPREP, 0, "Invalid flags specified!");
  456. hr = DP8SIMERR_INVALIDFLAGS;
  457. goto Failure;
  458. }
  459. #endif // ! DPNBUILD_NOPARAMVAL
  460. DNEnterCriticalSection(&this->m_csLock);
  461. fHaveLock = TRUE;
  462. //
  463. // Validate the object state.
  464. //
  465. if (! (this->m_dwFlags & DP8SIMCONTROLOBJ_INITIALIZED))
  466. {
  467. DPFX(DPFPREP, 0, "Control object not initialized!");
  468. hr = DP8SIMERR_NOTINITIALIZED;
  469. goto Failure;
  470. }
  471. //
  472. // Retrieve the settings from the IPC object.
  473. //
  474. this->m_DP8SimIPC.GetAllParameters(pdp8spSend, pdp8spReceive);
  475. //
  476. // Drop the lock.
  477. //
  478. DNLeaveCriticalSection(&this->m_csLock);
  479. fHaveLock = FALSE;
  480. Exit:
  481. DPFX(DPFPREP, 2, "(0x%p) Returning: [0x%lx]", this, hr);
  482. return hr;
  483. Failure:
  484. if (fHaveLock)
  485. {
  486. DNLeaveCriticalSection(&this->m_csLock);
  487. }
  488. goto Exit;
  489. } // CDP8SimControl::GetAllParameters
  490. #undef DPF_MODNAME
  491. #define DPF_MODNAME "CDP8SimControl::SetAllParameters"
  492. //=============================================================================
  493. // CDP8SimControl::SetAllParameters
  494. //-----------------------------------------------------------------------------
  495. //
  496. // Description: Modifies the current DP8Sim settings.
  497. //
  498. // Arguments:
  499. // DP8SIM_PARAMETERS * pdp8spSend - Structure containing desired send
  500. // parameters.
  501. // DP8SIM_PARAMETERS * pdp8spReceive - Structure containing desired
  502. // receive parameters.
  503. // DWORD dwFlags - Unused, must be zero.
  504. //
  505. // Returns: HRESULT
  506. // DP8SIM_OK - The parameters were successfully changed.
  507. // DP8SIMERR_INVALIDFLAGS - Invalid flags were specified.
  508. // DP8SIMERR_INVALIDOBJECT - The DP8Sim control object is invalid.
  509. // DP8SIMERR_INVALIDPARAM - An invalid structure was specified.
  510. // DP8SIMERR_INVALIDPOINTER - An invalid structure pointer was specified.
  511. // DP8SIMERR_NOTINITIALIZED - The DP8Sim control object has not been
  512. // initialized.
  513. //=============================================================================
  514. STDMETHODIMP CDP8SimControl::SetAllParameters(const DP8SIM_PARAMETERS * const pdp8spSend,
  515. const DP8SIM_PARAMETERS * const pdp8spReceive,
  516. const DWORD dwFlags)
  517. {
  518. HRESULT hr = DP8SIM_OK;
  519. BOOL fHaveLock = FALSE;
  520. DPFX(DPFPREP, 2, "(0x%p) Parameters: (0x%p, 0x%p, 0x%x)",
  521. this, pdp8spSend, pdp8spReceive, dwFlags);
  522. #ifndef DPNBUILD_NOPARAMVAL
  523. //
  524. // Validate the object.
  525. //
  526. if (! this->IsValidObject())
  527. {
  528. DPFX(DPFPREP, 0, "Invalid DP8Sim control object!");
  529. hr = DP8SIMERR_INVALIDOBJECT;
  530. goto Failure;
  531. }
  532. //
  533. // Validate the parameters.
  534. //
  535. if ((pdp8spSend == NULL) ||
  536. (IsBadReadPtr(pdp8spSend, sizeof(DP8SIM_PARAMETERS))))
  537. {
  538. DPFX(DPFPREP, 0, "Invalid send parameters pointer!");
  539. hr = DP8SIMERR_INVALIDPOINTER;
  540. goto Failure;
  541. }
  542. if (pdp8spSend->dwSize != sizeof(DP8SIM_PARAMETERS))
  543. {
  544. DPFX(DPFPREP, 0, "Send parameters structure size is invalid!");
  545. hr = DP8SIMERR_INVALIDPARAM;
  546. goto Failure;
  547. }
  548. if (pdp8spSend->dwFlags != 0)
  549. {
  550. DPFX(DPFPREP, 0, "Send parameters structure flags must be 0!");
  551. hr = DP8SIMERR_INVALIDPARAM;
  552. goto Failure;
  553. }
  554. if ((pdp8spSend->fPacketLossPercent < 0.0) ||
  555. (pdp8spSend->fPacketLossPercent > 100.0))
  556. {
  557. DPFX(DPFPREP, 0, "Send packet loss must be between 0.0 and 100.0!");
  558. hr = DP8SIMERR_INVALIDPARAM;
  559. goto Failure;
  560. }
  561. if (pdp8spSend->dwMinLatencyMS > pdp8spSend->dwMaxLatencyMS)
  562. {
  563. DPFX(DPFPREP, 0, "Minimum send latency must be less than or equal to the maximum send latency!");
  564. hr = DP8SIMERR_INVALIDPARAM;
  565. goto Failure;
  566. }
  567. if ((pdp8spReceive == NULL) ||
  568. (IsBadReadPtr(pdp8spReceive, sizeof(DP8SIM_PARAMETERS))))
  569. {
  570. DPFX(DPFPREP, 0, "Invalid receive parameters pointer!");
  571. hr = DP8SIMERR_INVALIDPOINTER;
  572. goto Failure;
  573. }
  574. if (pdp8spReceive->dwSize != sizeof(DP8SIM_PARAMETERS))
  575. {
  576. DPFX(DPFPREP, 0, "Receive parameters structure size is invalid!");
  577. hr = DP8SIMERR_INVALIDPARAM;
  578. goto Failure;
  579. }
  580. if (pdp8spReceive->dwFlags != 0)
  581. {
  582. DPFX(DPFPREP, 0, "Receive parameters structure flags must be 0!");
  583. hr = DP8SIMERR_INVALIDPARAM;
  584. goto Failure;
  585. }
  586. if ((pdp8spReceive->fPacketLossPercent < 0.0) ||
  587. (pdp8spReceive->fPacketLossPercent > 100.0))
  588. {
  589. DPFX(DPFPREP, 0, "Receive packet loss must be between 0.0 and 100.0!");
  590. hr = DP8SIMERR_INVALIDPARAM;
  591. goto Failure;
  592. }
  593. if (pdp8spReceive->dwMinLatencyMS > pdp8spReceive->dwMaxLatencyMS)
  594. {
  595. DPFX(DPFPREP, 0, "Minimum receive latency must be less than or equal to the receive send latency!");
  596. hr = DP8SIMERR_INVALIDPARAM;
  597. goto Failure;
  598. }
  599. if (dwFlags != 0)
  600. {
  601. DPFX(DPFPREP, 0, "Invalid flags specified!");
  602. hr = DP8SIMERR_INVALIDFLAGS;
  603. goto Failure;
  604. }
  605. #endif // ! DPNBUILD_NOPARAMVAL
  606. DNEnterCriticalSection(&this->m_csLock);
  607. fHaveLock = TRUE;
  608. //
  609. // Validate the object state.
  610. //
  611. if (! (this->m_dwFlags & DP8SIMCONTROLOBJ_INITIALIZED))
  612. {
  613. DPFX(DPFPREP, 0, "Control object not initialized!");
  614. hr = DP8SIMERR_NOTINITIALIZED;
  615. goto Failure;
  616. }
  617. //
  618. // Store the settings with the IPC object.
  619. //
  620. this->m_DP8SimIPC.SetAllParameters(pdp8spSend, pdp8spReceive);
  621. //
  622. // Drop the lock.
  623. //
  624. DNLeaveCriticalSection(&this->m_csLock);
  625. fHaveLock = FALSE;
  626. Exit:
  627. DPFX(DPFPREP, 2, "(0x%p) Returning: [0x%lx]", this, hr);
  628. return hr;
  629. Failure:
  630. if (fHaveLock)
  631. {
  632. DNLeaveCriticalSection(&this->m_csLock);
  633. }
  634. goto Exit;
  635. } // CDP8SimControl::SetAllParameters
  636. #undef DPF_MODNAME
  637. #define DPF_MODNAME "CDP8SimControl::GetAllStatistics"
  638. //=============================================================================
  639. // CDP8SimControl::GetAllStatistics
  640. //-----------------------------------------------------------------------------
  641. //
  642. // Description: Retrieves all of the current DP8Sim statistics.
  643. //
  644. // Arguments:
  645. // DP8SIM_STATISTICS * pdp8ssSend - Place to store current send
  646. // statistics.
  647. // DP8SIM_STATISTICS * pdp8ssReceive - Place to store current receive
  648. // statistics.
  649. // DWORD dwFlags - Unused, must be zero.
  650. //
  651. // Returns: HRESULT
  652. // DP8SIM_OK - The statistics were successfully retrieved.
  653. // DP8SIMERR_INVALIDFLAGS - Invalid flags were specified.
  654. // DP8SIMERR_INVALIDOBJECT - The DP8Sim control object is invalid.
  655. // DP8SIMERR_INVALIDPARAM - An invalid structure was specified.
  656. // DP8SIMERR_INVALIDPOINTER - An invalid structure pointer was specified.
  657. // DP8SIMERR_NOTINITIALIZED - The DP8Sim control object has not been
  658. // initialized.
  659. //=============================================================================
  660. STDMETHODIMP CDP8SimControl::GetAllStatistics(DP8SIM_STATISTICS * const pdp8ssSend,
  661. DP8SIM_STATISTICS * const pdp8ssReceive,
  662. const DWORD dwFlags)
  663. {
  664. HRESULT hr = DP8SIM_OK;
  665. BOOL fHaveLock = FALSE;
  666. DPFX(DPFPREP, 2, "(0x%p) Parameters: (0x%p, 0x%p, 0x%x)",
  667. this, pdp8ssSend, pdp8ssReceive, dwFlags);
  668. #ifndef DPNBUILD_NOPARAMVAL
  669. //
  670. // Validate the object.
  671. //
  672. if (! this->IsValidObject())
  673. {
  674. DPFX(DPFPREP, 0, "Invalid DP8Sim control object!");
  675. hr = DP8SIMERR_INVALIDOBJECT;
  676. goto Failure;
  677. }
  678. //
  679. // Validate the parameters.
  680. //
  681. if ((pdp8ssSend == NULL) ||
  682. (IsBadWritePtr(pdp8ssSend, sizeof(DP8SIM_STATISTICS))))
  683. {
  684. DPFX(DPFPREP, 0, "Invalid send statistics pointer!");
  685. hr = DP8SIMERR_INVALIDPOINTER;
  686. goto Failure;
  687. }
  688. if (pdp8ssSend->dwSize != sizeof(DP8SIM_STATISTICS))
  689. {
  690. DPFX(DPFPREP, 0, "Send statistics structure size is invalid!");
  691. hr = DP8SIMERR_INVALIDPARAM;
  692. goto Failure;
  693. }
  694. if ((pdp8ssReceive == NULL) ||
  695. (IsBadWritePtr(pdp8ssReceive, sizeof(DP8SIM_STATISTICS))))
  696. {
  697. DPFX(DPFPREP, 0, "Invalid receive statistics pointer!");
  698. hr = DP8SIMERR_INVALIDPOINTER;
  699. goto Failure;
  700. }
  701. if (pdp8ssReceive->dwSize != sizeof(DP8SIM_STATISTICS))
  702. {
  703. DPFX(DPFPREP, 0, "Receive statistics structure size is invalid!");
  704. hr = DP8SIMERR_INVALIDPARAM;
  705. goto Failure;
  706. }
  707. if (dwFlags != 0)
  708. {
  709. DPFX(DPFPREP, 0, "Invalid flags specified!");
  710. hr = DP8SIMERR_INVALIDFLAGS;
  711. goto Failure;
  712. }
  713. #endif // ! DPNBUILD_NOPARAMVAL
  714. DNEnterCriticalSection(&this->m_csLock);
  715. fHaveLock = TRUE;
  716. //
  717. // Validate the object state.
  718. //
  719. if (! (this->m_dwFlags & DP8SIMCONTROLOBJ_INITIALIZED))
  720. {
  721. DPFX(DPFPREP, 0, "Control object not initialized!");
  722. hr = DP8SIMERR_NOTINITIALIZED;
  723. goto Failure;
  724. }
  725. //
  726. // Retrieve the stats from the IPC object.
  727. //
  728. this->m_DP8SimIPC.GetAllStatistics(pdp8ssSend, pdp8ssReceive);
  729. //
  730. // Drop the lock.
  731. //
  732. DNLeaveCriticalSection(&this->m_csLock);
  733. fHaveLock = FALSE;
  734. Exit:
  735. DPFX(DPFPREP, 2, "(0x%p) Returning: [0x%lx]", this, hr);
  736. return hr;
  737. Failure:
  738. if (fHaveLock)
  739. {
  740. DNLeaveCriticalSection(&this->m_csLock);
  741. }
  742. goto Exit;
  743. } // CDP8SimControl::GetAllStatistics
  744. #undef DPF_MODNAME
  745. #define DPF_MODNAME "CDP8SimControl::ClearAllStatistics"
  746. //=============================================================================
  747. // CDP8SimControl::ClearAllStatistics
  748. //-----------------------------------------------------------------------------
  749. //
  750. // Description: Clears all of the current DP8Sim statistics.
  751. //
  752. // Arguments:
  753. // DWORD dwFlags - Unused, must be zero.
  754. //
  755. // Returns: HRESULT
  756. // DP8SIM_OK - The statistics were successfully cleared.
  757. // DP8SIMERR_INVALIDFLAGS - Invalid flags were specified.
  758. // DP8SIMERR_INVALIDOBJECT - The DP8Sim control object is invalid.
  759. // DP8SIMERR_NOTINITIALIZED - The DP8Sim control object has not been
  760. // initialized.
  761. //=============================================================================
  762. STDMETHODIMP CDP8SimControl::ClearAllStatistics(const DWORD dwFlags)
  763. {
  764. HRESULT hr = DP8SIM_OK;
  765. BOOL fHaveLock = FALSE;
  766. DPFX(DPFPREP, 2, "(0x%p) Parameters: (0x%x)", this, dwFlags);
  767. #ifndef DPNBUILD_NOPARAMVAL
  768. //
  769. // Validate the object.
  770. //
  771. if (! this->IsValidObject())
  772. {
  773. DPFX(DPFPREP, 0, "Invalid DP8Sim control object!");
  774. hr = DP8SIMERR_INVALIDOBJECT;
  775. goto Failure;
  776. }
  777. //
  778. // Validate the parameters.
  779. //
  780. if (dwFlags != 0)
  781. {
  782. DPFX(DPFPREP, 0, "Invalid flags specified!");
  783. hr = DP8SIMERR_INVALIDFLAGS;
  784. goto Failure;
  785. }
  786. #endif // ! DPNBUILD_NOPARAMVAL
  787. DNEnterCriticalSection(&this->m_csLock);
  788. fHaveLock = TRUE;
  789. //
  790. // Validate the object state.
  791. //
  792. if (! (this->m_dwFlags & DP8SIMCONTROLOBJ_INITIALIZED))
  793. {
  794. DPFX(DPFPREP, 0, "Control object not initialized!");
  795. hr = DP8SIMERR_NOTINITIALIZED;
  796. goto Failure;
  797. }
  798. //
  799. // Have the IPC object clear the stats.
  800. //
  801. this->m_DP8SimIPC.ClearAllStatistics();
  802. //
  803. // Drop the lock.
  804. //
  805. DNLeaveCriticalSection(&this->m_csLock);
  806. fHaveLock = FALSE;
  807. Exit:
  808. DPFX(DPFPREP, 2, "(0x%p) Returning: [0x%lx]", this, hr);
  809. return hr;
  810. Failure:
  811. if (fHaveLock)
  812. {
  813. DNLeaveCriticalSection(&this->m_csLock);
  814. }
  815. goto Exit;
  816. } // CDP8SimControl::ClearAllStatistics
  817. #undef DPF_MODNAME
  818. #define DPF_MODNAME "CDP8SimControl::InitializeObject"
  819. //=============================================================================
  820. // CDP8SimControl::InitializeObject
  821. //-----------------------------------------------------------------------------
  822. //
  823. // Description: Sets up the object for use like the constructor, but may
  824. // fail with OUTOFMEMORY. Should only be called by class factory
  825. // creation routine.
  826. //
  827. // Arguments: None.
  828. //
  829. // Returns: HRESULT
  830. // S_OK - Initialization was successful.
  831. // E_OUTOFMEMORY - There is not enough memory to initialize.
  832. //=============================================================================
  833. HRESULT CDP8SimControl::InitializeObject(void)
  834. {
  835. HRESULT hr;
  836. DPFX(DPFPREP, 5, "(0x%p) Enter", this);
  837. DNASSERT(this->IsValidObject());
  838. //
  839. // Create the lock.
  840. //
  841. if (! DNInitializeCriticalSection(&this->m_csLock))
  842. {
  843. hr = E_OUTOFMEMORY;
  844. goto Failure;
  845. }
  846. //
  847. // Don't allow critical section reentry.
  848. //
  849. DebugSetCriticalSectionRecursionCount(&this->m_csLock, 0);
  850. hr = S_OK;
  851. Exit:
  852. DPFX(DPFPREP, 5, "(0x%p) Returning: [0x%lx]", this, hr);
  853. return hr;
  854. Failure:
  855. goto Exit;
  856. } // CDP8SimControl::InitializeObject
  857. #undef DPF_MODNAME
  858. #define DPF_MODNAME "CDP8SimControl::UninitializeObject"
  859. //=============================================================================
  860. // CDP8SimControl::UninitializeObject
  861. //-----------------------------------------------------------------------------
  862. //
  863. // Description: Cleans up the object like the destructor, mostly to balance
  864. // InitializeObject.
  865. //
  866. // Arguments: None.
  867. //
  868. // Returns: None.
  869. //=============================================================================
  870. void CDP8SimControl::UninitializeObject(void)
  871. {
  872. DPFX(DPFPREP, 5, "(0x%p) Enter", this);
  873. DNASSERT(this->IsValidObject());
  874. DNDeleteCriticalSection(&this->m_csLock);
  875. DPFX(DPFPREP, 5, "(0x%p) Returning", this);
  876. } // CDP8SimControl::UninitializeObject