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.

888 lines
25 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2001-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: spcallbackobj.cpp
  6. *
  7. * Content: Interprocess communication object object class.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 04/25/01 VanceO Created.
  13. *
  14. ***************************************************************************/
  15. #include "dp8simi.h"
  16. //=============================================================================
  17. // Defines
  18. //=============================================================================
  19. #define REGKEY_DP8SIM L"Software\\Microsoft\\DirectPlay\\DP8Sim"
  20. #define REGKEY_VALUE_DEFAULTSENDPARAMETERS L"DefaultSendParameters"
  21. #define REGKEY_VALUE_DEFAULTRECEIVEPARAMETERS L"DefaultReceiveParameters"
  22. #undef DPF_MODNAME
  23. #define DPF_MODNAME "CDP8SimIPC::CDP8SimIPC"
  24. //=============================================================================
  25. // CDP8SimIPC constructor
  26. //-----------------------------------------------------------------------------
  27. //
  28. // Description: Initializes the new CDP8SimIPC object.
  29. //
  30. // Arguments: None.
  31. //
  32. // Returns: None (the object).
  33. //=============================================================================
  34. CDP8SimIPC::CDP8SimIPC(void)
  35. {
  36. this->m_Sig[0] = 'S';
  37. this->m_Sig[1] = 'I';
  38. this->m_Sig[2] = 'M';
  39. this->m_Sig[3] = 'I';
  40. this->m_hMutex = NULL;
  41. this->m_hFileMapping = NULL;
  42. this->m_pdp8ssm = NULL;
  43. } // CDP8SimIPC::CDP8SimIPC
  44. #undef DPF_MODNAME
  45. #define DPF_MODNAME "CDP8SimIPC::~CDP8SimIPC"
  46. //=============================================================================
  47. // CDP8SimIPC destructor
  48. //-----------------------------------------------------------------------------
  49. //
  50. // Description: Frees the CDP8SimIPC object.
  51. //
  52. // Arguments: None.
  53. //
  54. // Returns: None.
  55. //=============================================================================
  56. CDP8SimIPC::~CDP8SimIPC(void)
  57. {
  58. DNASSERT(this->m_hMutex == NULL);
  59. DNASSERT(this->m_hFileMapping == NULL);
  60. DNASSERT(this->m_pdp8ssm == NULL);
  61. //
  62. // For grins, change the signature before deleting the object.
  63. //
  64. this->m_Sig[3] = 'c';
  65. } // CDP8SimIPC::~CDP8SimIPC
  66. #undef DPF_MODNAME
  67. #define DPF_MODNAME "CDP8SimIPC::Initialize"
  68. //=============================================================================
  69. // CDP8SimIPC::Initialize
  70. //-----------------------------------------------------------------------------
  71. //
  72. // Description: Establishes the IPC connection.
  73. //
  74. // Arguments: None.
  75. //
  76. // Returns: HRESULT
  77. //=============================================================================
  78. HRESULT CDP8SimIPC::Initialize(void)
  79. {
  80. HRESULT hr = DP8SIM_OK;
  81. DP8SIM_PARAMETERS dp8spSend;
  82. DP8SIM_PARAMETERS dp8spReceive;
  83. BOOL fLockedSharedMemory = FALSE;
  84. DPFX(DPFPREP, 5, "(0x%p) Enter", this);
  85. //
  86. // Validate (actually assert) the object.
  87. //
  88. DNASSERT(this->IsValidObject());
  89. DNASSERT(this->m_hMutex == NULL);
  90. DNASSERT(this->m_hFileMapping == NULL);
  91. //
  92. // This defaults to having every option turned off and setting the packet
  93. // header size to IP + UDP.
  94. //
  95. ZeroMemory(&dp8spSend, sizeof(dp8spSend));
  96. dp8spSend.dwSize = sizeof(dp8spSend);
  97. //dp8spSend.dwFlags = 0;
  98. dp8spSend.dwPacketHeaderSize = DP8SIMPACKETHEADERSIZE_IP_UDP;
  99. //dp8spSend.dwBandwidthBPS = 0;
  100. //dp8spSend.fPacketLossPercent = 0.0;
  101. //dp8spSend.dwMinLatencyMS = 0;
  102. //dp8spSend.dwMaxLatencyMS = 0;
  103. ZeroMemory(&dp8spReceive, sizeof(dp8spReceive));
  104. dp8spReceive.dwSize = sizeof(dp8spReceive);
  105. //dp8spReceive.dwFlags = 0;
  106. dp8spReceive.dwPacketHeaderSize = DP8SIMPACKETHEADERSIZE_IP_UDP;
  107. //dp8spReceive.dwBandwidthBPS = 0;
  108. //dp8spReceive.fPacketLossPercent = 0.0;
  109. //dp8spReceive.dwMinLatencyMS = 0;
  110. //dp8spReceive.dwMaxLatencyMS = 0;
  111. //
  112. // Try overriding with registry settings.
  113. //
  114. this->LoadDefaultParameters(&dp8spSend, &dp8spReceive);
  115. //
  116. // Create/open the IPC mutex.
  117. //
  118. if (DNGetOSType() == VER_PLATFORM_WIN32_NT)
  119. {
  120. this->m_hMutex = CreateMutex(DNGetNullDacl(), FALSE, _T("Global\\") DP8SIM_IPC_MUTEXNAME);
  121. }
  122. else
  123. {
  124. this->m_hMutex = CreateMutex(DNGetNullDacl(), FALSE, DP8SIM_IPC_MUTEXNAME);
  125. }
  126. if (this->m_hMutex == NULL)
  127. {
  128. hr = GetLastError();
  129. DPFX(DPFPREP, 0, "Couldn't create shared memory mutex!");
  130. goto Failure;
  131. }
  132. //
  133. // Create/open the IPC memory mapped file.
  134. //
  135. if (DNGetOSType() == VER_PLATFORM_WIN32_NT)
  136. {
  137. this->m_hFileMapping = CreateFileMapping(INVALID_HANDLE_VALUE,
  138. DNGetNullDacl(),
  139. PAGE_READWRITE,
  140. 0,
  141. sizeof(DP8SIM_SHAREDMEMORY),
  142. _T("Global\\") DP8SIM_IPC_FILEMAPPINGNAME);
  143. }
  144. else
  145. {
  146. this->m_hFileMapping = CreateFileMapping(INVALID_HANDLE_VALUE,
  147. DNGetNullDacl(),
  148. PAGE_READWRITE,
  149. 0,
  150. sizeof(DP8SIM_SHAREDMEMORY),
  151. DP8SIM_IPC_FILEMAPPINGNAME);
  152. }
  153. if (this->m_hFileMapping == NULL)
  154. {
  155. hr = GetLastError();
  156. DPFX(DPFPREP, 0, "Couldn't create shared memory mapped file!");
  157. goto Failure;
  158. }
  159. //
  160. // Create a view of the memory mapped file.
  161. //
  162. this->m_pdp8ssm = (DP8SIM_SHAREDMEMORY*) MapViewOfFile(this->m_hFileMapping,
  163. (FILE_MAP_READ | FILE_MAP_WRITE),
  164. 0,
  165. 0,
  166. 0);
  167. if (this->m_pdp8ssm == NULL)
  168. {
  169. hr = GetLastError();
  170. DPFX(DPFPREP, 0, "Couldn't map view of shared memory!");
  171. goto Failure;
  172. }
  173. this->LockSharedMemory();
  174. fLockedSharedMemory = TRUE;
  175. //
  176. // Determine whether we need to initialize the shared memory or not.
  177. //
  178. if (this->m_pdp8ssm->dwVersion == 0)
  179. {
  180. this->m_pdp8ssm->dwVersion = DP8SIM_IPC_VERSION;
  181. CopyMemory(&(this->m_pdp8ssm->dp8spSend), &dp8spSend, sizeof(dp8spSend));
  182. CopyMemory(&(this->m_pdp8ssm->dp8spReceive), &dp8spReceive, sizeof(dp8spReceive));
  183. //ZeroMemory(&(this->m_pdp8ssm->dp8ssSend), sizeof(this->m_pdp8ssm->dp8ssSend));
  184. this->m_pdp8ssm->dp8ssSend.dwSize = sizeof(this->m_pdp8ssm->dp8ssSend);
  185. //ZeroMemory(&(this->m_pdp8ssm->dp8ssReceive), sizeof(this->m_pdp8ssm->dp8ssReceive));
  186. this->m_pdp8ssm->dp8ssReceive.dwSize = sizeof(this->m_pdp8ssm->dp8ssReceive);
  187. }
  188. else
  189. {
  190. //
  191. // It's already initialized. Make sure we know how to play with the
  192. // format given.
  193. //
  194. if (this->m_pdp8ssm->dwVersion != DP8SIM_IPC_VERSION)
  195. {
  196. DPFX(DPFPREP, 0, "Shared memory was initialized by a different version!");
  197. hr = DP8SIMERR_MISMATCHEDVERSION;
  198. goto Failure;
  199. }
  200. DNASSERT(this->m_pdp8ssm->dp8spSend.dwSize = sizeof(DP8SIM_PARAMETERS));
  201. DNASSERT(this->m_pdp8ssm->dp8spReceive.dwSize = sizeof(DP8SIM_PARAMETERS));
  202. DNASSERT(this->m_pdp8ssm->dp8ssSend.dwSize = sizeof(DP8SIM_STATISTICS));
  203. DNASSERT(this->m_pdp8ssm->dp8ssReceive.dwSize = sizeof(DP8SIM_STATISTICS));
  204. }
  205. this->UnlockSharedMemory();
  206. fLockedSharedMemory = FALSE;
  207. Exit:
  208. DPFX(DPFPREP, 5, "(0x%p) Returning: [0x%lx]", this, hr);
  209. return hr;
  210. Failure:
  211. if (fLockedSharedMemory)
  212. {
  213. this->UnlockSharedMemory();
  214. fLockedSharedMemory = FALSE;
  215. }
  216. if (this->m_pdp8ssm != NULL)
  217. {
  218. UnmapViewOfFile(this->m_pdp8ssm);
  219. this->m_pdp8ssm = NULL;
  220. }
  221. if (this->m_hFileMapping != NULL)
  222. {
  223. CloseHandle(this->m_hFileMapping);
  224. this->m_hFileMapping = NULL;
  225. }
  226. if (this->m_hMutex != NULL)
  227. {
  228. CloseHandle(this->m_hMutex);
  229. this->m_hMutex = NULL;
  230. }
  231. goto Exit;
  232. } // CDP8SimIPC::Initialize
  233. #undef DPF_MODNAME
  234. #define DPF_MODNAME "CDP8SimIPC::Close"
  235. //=============================================================================
  236. // CDP8SimIPC::Close
  237. //-----------------------------------------------------------------------------
  238. //
  239. // Description: Closes the IPC connection.
  240. //
  241. // Arguments: None.
  242. //
  243. // Returns: None.
  244. //=============================================================================
  245. void CDP8SimIPC::Close(void)
  246. {
  247. DPFX(DPFPREP, 5, "(0x%p) Enter", this);
  248. if (this->m_pdp8ssm != NULL)
  249. {
  250. //
  251. // Try overriding with registry settings.
  252. //
  253. this->SaveDefaultParameters(&(this->m_pdp8ssm->dp8spSend),
  254. &(this->m_pdp8ssm->dp8spReceive));
  255. UnmapViewOfFile(this->m_pdp8ssm);
  256. this->m_pdp8ssm = NULL;
  257. }
  258. if (this->m_hFileMapping != NULL)
  259. {
  260. CloseHandle(this->m_hFileMapping);
  261. this->m_hFileMapping = NULL;
  262. }
  263. if (this->m_hMutex != NULL)
  264. {
  265. CloseHandle(this->m_hMutex);
  266. this->m_hMutex = NULL;
  267. }
  268. DPFX(DPFPREP, 5, "(0x%p) Leave", this);
  269. } // CDP8SimIPC::Close
  270. #undef DPF_MODNAME
  271. #define DPF_MODNAME "CDP8SimIPC::GetAllParameters"
  272. //=============================================================================
  273. // CDP8SimIPC::GetAllParameters
  274. //-----------------------------------------------------------------------------
  275. //
  276. // Description: Retrieves the current send and receive settings.
  277. //
  278. // Arguments:
  279. // DP8SIM_PARAMETERS * pdp8spSend - Place to store send parameters
  280. // retrieved.
  281. // DP8SIM_PARAMETERS * pdp8spReceive - Place to store receive parameters
  282. // retrieved.
  283. //
  284. // Returns: None.
  285. //=============================================================================
  286. void CDP8SimIPC::GetAllParameters(DP8SIM_PARAMETERS * const pdp8spSend,
  287. DP8SIM_PARAMETERS * const pdp8spReceive)
  288. {
  289. DNASSERT(pdp8spSend != NULL);
  290. DNASSERT(pdp8spSend->dwSize == sizeof(DP8SIM_PARAMETERS));
  291. DNASSERT(pdp8spReceive != NULL);
  292. DNASSERT(pdp8spReceive->dwSize == sizeof(DP8SIM_PARAMETERS));
  293. DNASSERT(this->m_pdp8ssm != NULL);
  294. this->LockSharedMemory();
  295. DNASSERT(this->m_pdp8ssm->dp8spSend.dwSize == sizeof(DP8SIM_PARAMETERS));
  296. CopyMemory(pdp8spSend, &(this->m_pdp8ssm->dp8spSend), sizeof(DP8SIM_PARAMETERS));
  297. DNASSERT(this->m_pdp8ssm->dp8spReceive.dwSize == sizeof(DP8SIM_PARAMETERS));
  298. CopyMemory(pdp8spReceive, &(this->m_pdp8ssm->dp8spReceive), sizeof(DP8SIM_PARAMETERS));
  299. this->UnlockSharedMemory();
  300. } // CDP8SimIPC::GetAllParameters
  301. #undef DPF_MODNAME
  302. #define DPF_MODNAME "CDP8SimIPC::GetAllSendParameters"
  303. //=============================================================================
  304. // CDP8SimIPC::GetAllSendParameters
  305. //-----------------------------------------------------------------------------
  306. //
  307. // Description: Retrieves the current send settings.
  308. //
  309. // Arguments:
  310. // DP8SIM_PARAMETERS * pdp8sp - Place to store parameters retrieved.
  311. //
  312. // Returns: None.
  313. //=============================================================================
  314. void CDP8SimIPC::GetAllSendParameters(DP8SIM_PARAMETERS * const pdp8sp)
  315. {
  316. DNASSERT(pdp8sp != NULL);
  317. DNASSERT(pdp8sp->dwSize == sizeof(DP8SIM_PARAMETERS));
  318. DNASSERT(this->m_pdp8ssm != NULL);
  319. this->LockSharedMemory();
  320. DNASSERT(this->m_pdp8ssm->dp8spSend.dwSize == sizeof(DP8SIM_PARAMETERS));
  321. CopyMemory(pdp8sp, &(this->m_pdp8ssm->dp8spSend), sizeof(DP8SIM_PARAMETERS));
  322. this->UnlockSharedMemory();
  323. } // CDP8SimIPC::GetAllSendParameters
  324. #undef DPF_MODNAME
  325. #define DPF_MODNAME "CDP8SimIPC::GetAllReceiveParameters"
  326. //=============================================================================
  327. // CDP8SimIPC::GetAllReceiveParameters
  328. //-----------------------------------------------------------------------------
  329. //
  330. // Description: Retrieves the current receive settings.
  331. //
  332. // Arguments:
  333. // DP8SIM_PARAMETERS * pdp8sp - Place to store parameters retrieved.
  334. //
  335. // Returns: None.
  336. //=============================================================================
  337. void CDP8SimIPC::GetAllReceiveParameters(DP8SIM_PARAMETERS * const pdp8sp)
  338. {
  339. DNASSERT(pdp8sp != NULL);
  340. DNASSERT(pdp8sp->dwSize == sizeof(DP8SIM_PARAMETERS));
  341. DNASSERT(this->m_pdp8ssm != NULL);
  342. this->LockSharedMemory();
  343. DNASSERT(this->m_pdp8ssm->dp8spReceive.dwSize == sizeof(DP8SIM_PARAMETERS));
  344. CopyMemory(pdp8sp, &(this->m_pdp8ssm->dp8spReceive), sizeof(DP8SIM_PARAMETERS));
  345. this->UnlockSharedMemory();
  346. } // CDP8SimIPC::GetAllReceiveParameters
  347. #undef DPF_MODNAME
  348. #define DPF_MODNAME "CDP8SimIPC::SetAllParameters"
  349. //=============================================================================
  350. // CDP8SimIPC::SetAllParameters
  351. //-----------------------------------------------------------------------------
  352. //
  353. // Description: Stores the send and receive settings.
  354. //
  355. // Arguments:
  356. // DP8SIM_PARAMETERS * pdp8spSend - New send parameters.
  357. // DP8SIM_PARAMETERS * pdp8spReceive - New receive parameters.
  358. //
  359. // Returns: None.
  360. //=============================================================================
  361. void CDP8SimIPC::SetAllParameters(const DP8SIM_PARAMETERS * const pdp8spSend,
  362. const DP8SIM_PARAMETERS * const pdp8spReceive)
  363. {
  364. DNASSERT(pdp8spSend != NULL);
  365. DNASSERT(pdp8spSend->dwSize == sizeof(DP8SIM_PARAMETERS));
  366. DNASSERT(pdp8spReceive != NULL);
  367. DNASSERT(pdp8spReceive->dwSize == sizeof(DP8SIM_PARAMETERS));
  368. DNASSERT(this->m_pdp8ssm != NULL);
  369. this->LockSharedMemory();
  370. DNASSERT(this->m_pdp8ssm->dp8spSend.dwSize == sizeof(DP8SIM_PARAMETERS));
  371. CopyMemory(&(this->m_pdp8ssm->dp8spSend), pdp8spSend, sizeof(DP8SIM_PARAMETERS));
  372. DNASSERT(this->m_pdp8ssm->dp8spReceive.dwSize == sizeof(DP8SIM_PARAMETERS));
  373. CopyMemory(&(this->m_pdp8ssm->dp8spReceive), pdp8spReceive, sizeof(DP8SIM_PARAMETERS));
  374. this->UnlockSharedMemory();
  375. } // CDP8SimIPC::SetAllParameters
  376. #undef DPF_MODNAME
  377. #define DPF_MODNAME "CDP8SimIPC::GetAllStatistics"
  378. //=============================================================================
  379. // CDP8SimIPC::GetAllStatistics
  380. //-----------------------------------------------------------------------------
  381. //
  382. // Description: Retrieves the current send and receive statistics.
  383. //
  384. // Arguments:
  385. // DP8SIM_STATISTICS * pdp8ssSend - Place to store send statistics
  386. // retrieved.
  387. // DP8SIM_STATISTICS * pdp8ssReceive - Place to store receive statistics
  388. // retrieved.
  389. //
  390. // Returns: None.
  391. //=============================================================================
  392. void CDP8SimIPC::GetAllStatistics(DP8SIM_STATISTICS * const pdp8ssSend,
  393. DP8SIM_STATISTICS * const pdp8ssReceive)
  394. {
  395. DNASSERT(pdp8ssSend != NULL);
  396. DNASSERT(pdp8ssSend->dwSize == sizeof(DP8SIM_STATISTICS));
  397. DNASSERT(pdp8ssReceive != NULL);
  398. DNASSERT(pdp8ssReceive->dwSize == sizeof(DP8SIM_STATISTICS));
  399. DNASSERT(this->m_pdp8ssm != NULL);
  400. this->LockSharedMemory();
  401. DNASSERT(this->m_pdp8ssm->dp8ssSend.dwSize == sizeof(DP8SIM_STATISTICS));
  402. CopyMemory(pdp8ssSend, &(this->m_pdp8ssm->dp8ssSend), sizeof(DP8SIM_STATISTICS));
  403. DNASSERT(this->m_pdp8ssm->dp8ssReceive.dwSize == sizeof(DP8SIM_STATISTICS));
  404. CopyMemory(pdp8ssReceive, &(this->m_pdp8ssm->dp8ssReceive), sizeof(DP8SIM_STATISTICS));
  405. this->UnlockSharedMemory();
  406. } // CDP8SimIPC::GetAllStatistics
  407. #undef DPF_MODNAME
  408. #define DPF_MODNAME "CDP8SimIPC::ClearAllStatistics"
  409. //=============================================================================
  410. // CDP8SimIPC::ClearAllStatistics
  411. //-----------------------------------------------------------------------------
  412. //
  413. // Description: Clears the current send and receive statistics.
  414. //
  415. // Arguments: None.
  416. //
  417. // Returns: None.
  418. //=============================================================================
  419. void CDP8SimIPC::ClearAllStatistics(void)
  420. {
  421. DNASSERT(this->m_pdp8ssm != NULL);
  422. this->LockSharedMemory();
  423. DNASSERT(this->m_pdp8ssm->dp8ssSend.dwSize == sizeof(DP8SIM_STATISTICS));
  424. ZeroMemory(&(this->m_pdp8ssm->dp8ssSend), sizeof(DP8SIM_STATISTICS));
  425. this->m_pdp8ssm->dp8ssSend.dwSize = sizeof(DP8SIM_STATISTICS);
  426. DNASSERT(this->m_pdp8ssm->dp8ssReceive.dwSize == sizeof(DP8SIM_STATISTICS));
  427. ZeroMemory(&(this->m_pdp8ssm->dp8ssReceive), sizeof(DP8SIM_STATISTICS));
  428. this->m_pdp8ssm->dp8ssReceive.dwSize = sizeof(DP8SIM_STATISTICS);
  429. this->UnlockSharedMemory();
  430. } // CDP8SimIPC::GetAllStatistics
  431. #undef DPF_MODNAME
  432. #define DPF_MODNAME "CDP8SimIPC::IncrementStatsSendTransmitted"
  433. //=============================================================================
  434. // CDP8SimIPC::IncrementStatsSendTransmitted
  435. //-----------------------------------------------------------------------------
  436. //
  437. // Description: Increments the sends transmitted counters.
  438. //
  439. // Arguments:
  440. // DWORD dwBytes - Size of send, in bytes.
  441. // DWORD dwDelay - Amount the send was delayed, in milliseconds.
  442. //
  443. // Returns: None.
  444. //=============================================================================
  445. void CDP8SimIPC::IncrementStatsSendTransmitted(DWORD dwBytes, DWORD dwDelay)
  446. {
  447. DNASSERT(this->m_pdp8ssm != NULL);
  448. this->LockSharedMemory();
  449. DNASSERT(this->m_pdp8ssm->dp8ssSend.dwSize == sizeof(DP8SIM_STATISTICS));
  450. this->m_pdp8ssm->dp8ssSend.dwTransmittedPackets++;
  451. this->m_pdp8ssm->dp8ssSend.dwTransmittedBytes += dwBytes;
  452. this->m_pdp8ssm->dp8ssSend.dwTotalDelayMS += dwDelay;
  453. this->UnlockSharedMemory();
  454. } // CDP8SimIPC::IncrementStatsSendTransmitted
  455. #undef DPF_MODNAME
  456. #define DPF_MODNAME "CDP8SimIPC::IncrementStatsSendDropped"
  457. //=============================================================================
  458. // CDP8SimIPC::IncrementStatsSendDropped
  459. //-----------------------------------------------------------------------------
  460. //
  461. // Description: Increments the sends dropped counters.
  462. //
  463. // Arguments:
  464. // DWORD dwBytes - Size of send, in bytes.
  465. //
  466. // Returns: None.
  467. //=============================================================================
  468. void CDP8SimIPC::IncrementStatsSendDropped(DWORD dwBytes)
  469. {
  470. DNASSERT(this->m_pdp8ssm != NULL);
  471. this->LockSharedMemory();
  472. DNASSERT(this->m_pdp8ssm->dp8ssSend.dwSize == sizeof(DP8SIM_STATISTICS));
  473. this->m_pdp8ssm->dp8ssSend.dwDroppedPackets++;
  474. this->m_pdp8ssm->dp8ssSend.dwDroppedBytes += dwBytes;
  475. this->UnlockSharedMemory();
  476. } // CDP8SimIPC::IncrementStatsSendDropped
  477. #undef DPF_MODNAME
  478. #define DPF_MODNAME "CDP8SimIPC::IncrementStatsReceiveTransmitted"
  479. //=============================================================================
  480. // CDP8SimIPC::IncrementStatsReceiveTransmitted
  481. //-----------------------------------------------------------------------------
  482. //
  483. // Description: Increments the receives indicated counters.
  484. //
  485. // Arguments:
  486. // DWORD dwBytes - Size of receive, in bytes.
  487. // DWORD dwDelay - Amount the receive was delayed, in milliseconds.
  488. //
  489. // Returns: None.
  490. //=============================================================================
  491. void CDP8SimIPC::IncrementStatsReceiveTransmitted(DWORD dwBytes, DWORD dwDelay)
  492. {
  493. DNASSERT(this->m_pdp8ssm != NULL);
  494. this->LockSharedMemory();
  495. DNASSERT(this->m_pdp8ssm->dp8ssReceive.dwSize == sizeof(DP8SIM_STATISTICS));
  496. this->m_pdp8ssm->dp8ssReceive.dwTransmittedPackets++;
  497. this->m_pdp8ssm->dp8ssReceive.dwTransmittedBytes += dwBytes;
  498. this->m_pdp8ssm->dp8ssReceive.dwTotalDelayMS += dwDelay;
  499. this->UnlockSharedMemory();
  500. } // CDP8SimIPC::IncrementStatsReceiveTransmitted
  501. #undef DPF_MODNAME
  502. #define DPF_MODNAME "CDP8SimIPC::IncrementStatsReceiveDropped"
  503. //=============================================================================
  504. // CDP8SimIPC::IncrementStatsReceiveDropped
  505. //-----------------------------------------------------------------------------
  506. //
  507. // Description: Increments the receives dropped counters.
  508. //
  509. // Arguments:
  510. // DWORD dwBytes - Size of receive, in bytes.
  511. //
  512. // Returns: None.
  513. //=============================================================================
  514. void CDP8SimIPC::IncrementStatsReceiveDropped(DWORD dwBytes)
  515. {
  516. DNASSERT(this->m_pdp8ssm != NULL);
  517. this->LockSharedMemory();
  518. DNASSERT(this->m_pdp8ssm->dp8ssReceive.dwSize == sizeof(DP8SIM_STATISTICS));
  519. this->m_pdp8ssm->dp8ssReceive.dwDroppedPackets++;
  520. this->m_pdp8ssm->dp8ssReceive.dwDroppedBytes += dwBytes;
  521. this->UnlockSharedMemory();
  522. } // CDP8SimIPC::IncrementStatsReceiveDropped
  523. #undef DPF_MODNAME
  524. #define DPF_MODNAME "CDP8SimIPC::LoadDefaultParameters"
  525. //=============================================================================
  526. // CDP8SimIPC::LoadDefaultParameters
  527. //-----------------------------------------------------------------------------
  528. //
  529. // Description: Loads the default send and receive parameters from the registry
  530. // if possible.
  531. //
  532. // Arguments:
  533. // DP8SIM_PARAMETERS * pdp8spSend - Place to store default send
  534. // parameters.
  535. // DP8SIM_PARAMETERS * pdp8spReceive - Place to store default receive
  536. // parameters.
  537. //
  538. // Returns: None.
  539. //=============================================================================
  540. void CDP8SimIPC::LoadDefaultParameters(DP8SIM_PARAMETERS * const pdp8spSend,
  541. DP8SIM_PARAMETERS * const pdp8spReceive)
  542. {
  543. CRegistry RegObject;
  544. DP8SIM_PARAMETERS dp8spTemp;
  545. DWORD dwSize;
  546. DPFX(DPFPREP, 5, "(0x%p) Parameters: (0x%p, 0x%p)",
  547. this, pdp8spSend, pdp8spReceive);
  548. DNASSERT(pdp8spSend != NULL);
  549. DNASSERT(pdp8spSend->dwSize == sizeof(DP8SIM_PARAMETERS));
  550. DNASSERT(pdp8spReceive != NULL);
  551. DNASSERT(pdp8spReceive->dwSize == sizeof(DP8SIM_PARAMETERS));
  552. if (RegObject.Open(HKEY_CURRENT_USER, REGKEY_DP8SIM, TRUE, FALSE))
  553. {
  554. //
  555. // Try to read the default send parameters
  556. //
  557. dwSize = sizeof(dp8spTemp);
  558. if (RegObject.ReadBlob(REGKEY_VALUE_DEFAULTSENDPARAMETERS, (BYTE*) (&dp8spTemp), &dwSize))
  559. {
  560. //
  561. // Successfully read the parameters. Make sure they match the
  562. // expected values.
  563. //
  564. if ((dwSize == sizeof(dp8spTemp)) &&
  565. (dp8spTemp.dwSize == sizeof(dp8spTemp)))
  566. {
  567. DPFX(DPFPREP, 2, "Successfully read default send parameters from registry.");
  568. memcpy(pdp8spSend, &dp8spTemp, sizeof(dp8spTemp));
  569. }
  570. else
  571. {
  572. //
  573. // Default send parameters are unusable, leave the values set
  574. // as they are.
  575. //
  576. DPFX(DPFPREP, 0, "Default send parameters stored in registry are invalid! Ignoring.");
  577. }
  578. }
  579. else
  580. {
  581. //
  582. // Couldn't read the default send parameters, leave the values set
  583. // as they are.
  584. //
  585. DPFX(DPFPREP, 2, "Couldn't read default send parameters from registry, ignoring.");
  586. }
  587. //
  588. // Try to read the default receive parameters
  589. //
  590. dwSize = sizeof(dp8spTemp);
  591. if (RegObject.ReadBlob(REGKEY_VALUE_DEFAULTRECEIVEPARAMETERS, (BYTE*) (&dp8spTemp), &dwSize))
  592. {
  593. //
  594. // Successfully read the parameters. Make sure they match the
  595. // expected values.
  596. //
  597. if ((dwSize == sizeof(dp8spTemp)) &&
  598. (dp8spTemp.dwSize == sizeof(dp8spTemp)))
  599. {
  600. DPFX(DPFPREP, 2, "Successfully read default receive parameters from registry.");
  601. memcpy(pdp8spReceive, &dp8spTemp, sizeof(dp8spTemp));
  602. }
  603. else
  604. {
  605. //
  606. // Default receive parameters are unusable, leave the values set
  607. // as they are.
  608. //
  609. DPFX(DPFPREP, 0, "Default receive parameters stored in registry are invalid! Ignoring.");
  610. }
  611. }
  612. else
  613. {
  614. //
  615. // Couldn't read the default send parameters, leave the values set
  616. // as they are.
  617. //
  618. DPFX(DPFPREP, 2, "Couldn't read default send parameters from registry, ignoring.");
  619. }
  620. }
  621. else
  622. {
  623. //
  624. // Couldn't open the registry key, leave the values set as they are.
  625. //
  626. DPFX(DPFPREP, 2, "Couldn't open DP8Sim registry key, ignoring.");
  627. }
  628. DPFX(DPFPREP, 5, "(0x%p) Leave", this);
  629. } // CDP8SimIPC::LoadDefaultParameters
  630. #undef DPF_MODNAME
  631. #define DPF_MODNAME "CDP8SimIPC::SaveDefaultParameters"
  632. //=============================================================================
  633. // CDP8SimIPC::SaveDefaultParameters
  634. //-----------------------------------------------------------------------------
  635. //
  636. // Description: Writes the given send and receive parameters as the default
  637. // values in the registry.
  638. //
  639. // Arguments:
  640. // DP8SIM_PARAMETERS * pdp8spSend - New default send parameters.
  641. // DP8SIM_PARAMETERS * pdp8spReceive - New default receive parameters.
  642. //
  643. // Returns: None.
  644. //=============================================================================
  645. void CDP8SimIPC::SaveDefaultParameters(const DP8SIM_PARAMETERS * const pdp8spSend,
  646. const DP8SIM_PARAMETERS * const pdp8spReceive)
  647. {
  648. CRegistry RegObject;
  649. DPFX(DPFPREP, 5, "(0x%p) Parameters: (0x%p, 0x%p)",
  650. this, pdp8spSend, pdp8spReceive);
  651. DNASSERT(pdp8spSend != NULL);
  652. DNASSERT(pdp8spSend->dwSize == sizeof(DP8SIM_PARAMETERS));
  653. DNASSERT(pdp8spReceive != NULL);
  654. DNASSERT(pdp8spReceive->dwSize == sizeof(DP8SIM_PARAMETERS));
  655. if (RegObject.Open(HKEY_CURRENT_USER, REGKEY_DP8SIM, FALSE, TRUE))
  656. {
  657. //
  658. // Write the default send and receive parameters, ignoring failure.
  659. //
  660. RegObject.WriteBlob(REGKEY_VALUE_DEFAULTSENDPARAMETERS,
  661. (BYTE*) pdp8spSend,
  662. sizeof(*pdp8spSend));
  663. RegObject.WriteBlob(REGKEY_VALUE_DEFAULTRECEIVEPARAMETERS,
  664. (BYTE*) pdp8spReceive,
  665. sizeof(*pdp8spReceive));
  666. }
  667. else
  668. {
  669. DPFX(DPFPREP, 0, "Couldn't open DP8Sim registry key for writing!");
  670. }
  671. DPFX(DPFPREP, 5, "(0x%p) Leave", this);
  672. } // CDP8SimIPC::SaveDefaultParameters