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.

1659 lines
51 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000-2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: User.cpp
  6. * Content: DNET user call-back routines
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 08/02/99 mjn Created
  12. * 01/06/00 mjn Moved NameTable stuff to NameTable.h
  13. * 01/07/00 mjn Allow reply in DN_UserIndicateConnect
  14. * 01/08/00 mjn DN_UserIndicateConnect provides failed buffer back to DN_UserConnectComplete
  15. * 01/10/00 mjn Added DN_UserUpdateAppDesc
  16. * 01/16/00 mjn Upgraded to new UserMessageHandler definition
  17. * 01/17/00 mjn Added DN_UserHostMigrate
  18. * 01/17/00 mjn Implemented send time
  19. * 01/18/00 rmt Added calls into voice layer for events
  20. * 01/22/00 mjn Added DN_UserHostDestroyPlayer
  21. * 01/27/00 mjn Added support for retention of receive buffers
  22. * 01/28/00 mjn Added DN_UserConnectionTerminated
  23. * 02/01/00 mjn Implement Player/Group context values
  24. * 02/01/00 mjn Implement Player/Group context values
  25. * 03/24/00 mjn Set player context through INDICATE_CONNECT notification
  26. * 04/04/00 mjn Added DN_UserTerminateSession()
  27. * 04/05/00 mjn Updated DN_UserHostDestroyPlayer()
  28. * 04/18/00 mjn Added DN_UserReturnBuffer
  29. * mjn Added ppvReplyContext to DN_UserIndicateConnect
  30. * 04/19/00 mjn Removed hAsyncOp (unused) from DPNMSG_INDICATE_CONNECT
  31. * 06/26/00 mjn Added reasons for DELETE_PLAYER and DESTROY_GROUP
  32. * 07/29/00 mjn Added DNUserIndicatedConnectAborted()
  33. * mjn DNUserConnectionTerminated() supercedes DN_TerminateSession()
  34. * mjn Added HRESULT to DNUserReturnBuffer()
  35. * 07/30/00 mjn Added pAddressDevice to DNUserIndicateConnect()
  36. * mjn Use DNUserTerminateSession() rather than DNUserConnectionTerminated()
  37. * 07/31/00 mjn DN_UserDestroyGroup() -> DNUserDestroyGroup()
  38. * mjn DN_UserDeletePlayer() -> DNUserDestroyPlayer()
  39. * mjn Removed DN_UserHostDestroyPlayer()
  40. * mjn Renamed DPN_MSGID_ASYNC_OPERATION_COMPLETE to DPN_MSGID_ASYNC_OP_COMPLETE
  41. * 08/01/00 mjn DN_UserReceive() -> DNUserReceive()
  42. * 08/02/00 mjn DN_UserAddPlayer() -> DNUserCreatePlayer()
  43. * 08/05/00 RichGr IA64: Use %p format specifier in DPFs for 32/64-bit pointers and handles.
  44. * 08/08/00 mjn DN_UserCreateGroup() -> DNUserCreateGroup()
  45. * 08/20/00 mjn Added DNUserEnumQuery() and DNUserEnumResponse()
  46. * 09/17/00 mjn Changed parameters list of DNUserCreateGroup(),DNUserCreatePlayer(),
  47. * DNUserAddPlayerToGroup(),DNUserRemovePlayerFromGroup()
  48. * 02/05/01 mjn Added CCallbackThread
  49. * 07/24/01 mjn Added DPNBUILD_NOSERVER compile flag
  50. * 10/16/01 vanceo Added some multicast callbacks
  51. *@@END_MSINTERNAL
  52. *
  53. ***************************************************************************/
  54. #include "dncorei.h"
  55. // DNUserConnectComplete
  56. //
  57. // Send a CONNECT_COMPLETE message to the user's message handler
  58. #undef DPF_MODNAME
  59. #define DPF_MODNAME "DNUserConnectComplete"
  60. HRESULT DNUserConnectComplete(DIRECTNETOBJECT *const pdnObject,
  61. const DPNHANDLE hAsyncOp,
  62. PVOID const pvContext,
  63. const HRESULT hr,
  64. CRefCountBuffer *const pRefCountBuffer)
  65. {
  66. #ifndef DPNBUILD_NOPARAMVAL
  67. CCallbackThread CallbackThread;
  68. #endif // ! DPNBUILD_NOPARAMVAL
  69. HRESULT hResultCode;
  70. DPNMSG_CONNECT_COMPLETE Msg;
  71. CNameTableEntry *pLocalPlayer = NULL;
  72. // ensure initialized (need message handler)
  73. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  74. DPFX(DPFPREP, 6,"Parameters: hAsyncOp [0x%lx], pvContext [0x%p], hr [0x%lx], pRefCountBuffer [0x%p]",
  75. hAsyncOp,pvContext,hr,pRefCountBuffer);
  76. Msg.dwSize = sizeof(DPNMSG_CONNECT_COMPLETE);
  77. Msg.pvUserContext = pvContext;
  78. Msg.hAsyncOp = hAsyncOp;
  79. Msg.hResultCode = hr;
  80. if (pRefCountBuffer)
  81. {
  82. Msg.pvApplicationReplyData = pRefCountBuffer->GetBufferAddress();
  83. Msg.dwApplicationReplyDataSize = pRefCountBuffer->GetBufferSize();
  84. }
  85. else
  86. {
  87. Msg.pvApplicationReplyData = NULL;
  88. Msg.dwApplicationReplyDataSize = 0;
  89. }
  90. if (pdnObject->NameTable.GetLocalPlayerRef(&pLocalPlayer) == DPN_OK)
  91. {
  92. Msg.dpnidLocal = pLocalPlayer->GetDPNID();
  93. pLocalPlayer->Release();
  94. pLocalPlayer = NULL;
  95. }
  96. else
  97. {
  98. Msg.dpnidLocal = 0;
  99. }
  100. #ifndef DPNBUILD_NOPARAMVAL
  101. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  102. {
  103. CallbackThread.Initialize();
  104. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  105. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  106. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  107. }
  108. #endif // !DPNBUILD_NOPARAMVAL
  109. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  110. DPN_MSGID_CONNECT_COMPLETE,reinterpret_cast<BYTE*>(&Msg));
  111. #ifndef DPNBUILD_NOPARAMVAL
  112. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  113. {
  114. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  115. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  116. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  117. CallbackThread.Deinitialize();
  118. }
  119. #endif // !DPNBUILD_NOPARAMVAL
  120. hResultCode = DPN_OK;
  121. DNASSERT( pLocalPlayer == NULL );
  122. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  123. return(hResultCode);
  124. }
  125. // DNUserIndicateConnect
  126. //
  127. // Send an INDICATE_CONNECT message to the user's message handler
  128. #undef DPF_MODNAME
  129. #define DPF_MODNAME "DNUserIndicateConnect"
  130. HRESULT DNUserIndicateConnect(DIRECTNETOBJECT *const pdnObject,
  131. PVOID const pvConnectData,
  132. const DWORD dwConnectDataSize,
  133. void **const ppvReplyData,
  134. DWORD *const pdwReplyDataSize,
  135. void **const ppvReplyContext,
  136. IDirectPlay8Address *const pAddressPlayer,
  137. IDirectPlay8Address *const pAddressDevice,
  138. void **const ppvPlayerContext)
  139. {
  140. #ifndef DPNBUILD_NOPARAMVAL
  141. CCallbackThread CallbackThread;
  142. #endif // ! DPNBUILD_NOPARAMVAL
  143. HRESULT hResultCode;
  144. DPNMSG_INDICATE_CONNECT Msg;
  145. DPFX(DPFPREP, 6,"Parameters: pvConnectData [0x%p], dwConnectDataSize [%ld], ppvReplyData [0x%p], pdwReplyDataSize [0x%p]",
  146. pvConnectData,dwConnectDataSize,ppvReplyData,pdwReplyDataSize);
  147. // ensure initialized (need message handler)
  148. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  149. DNASSERT(ppvReplyData != NULL);
  150. DNASSERT(pdwReplyDataSize != NULL);
  151. Msg.dwSize = sizeof(DPNMSG_INDICATE_CONNECT);
  152. Msg.pvUserConnectData = pvConnectData;
  153. Msg.dwUserConnectDataSize = dwConnectDataSize;
  154. Msg.pvReplyData = NULL;
  155. Msg.dwReplyDataSize = 0;
  156. Msg.pvReplyContext = NULL;
  157. Msg.pvPlayerContext = NULL;
  158. Msg.pAddressPlayer = pAddressPlayer;
  159. Msg.pAddressDevice = pAddressDevice;
  160. #ifndef DPNBUILD_NOPARAMVAL
  161. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  162. {
  163. CallbackThread.Initialize();
  164. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  165. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  166. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  167. }
  168. #endif // !DPNBUILD_NOPARAMVAL
  169. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  170. DPN_MSGID_INDICATE_CONNECT,reinterpret_cast<BYTE*>(&Msg));
  171. #ifndef DPNBUILD_NOPARAMVAL
  172. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  173. {
  174. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  175. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  176. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  177. CallbackThread.Deinitialize();
  178. }
  179. #endif // !DPNBUILD_NOPARAMVAL
  180. *ppvReplyData = Msg.pvReplyData;
  181. *pdwReplyDataSize = Msg.dwReplyDataSize;
  182. *ppvReplyContext = Msg.pvReplyContext;
  183. *ppvPlayerContext = Msg.pvPlayerContext;
  184. if (hResultCode != DPN_OK)
  185. {
  186. hResultCode = DPNERR_HOSTREJECTEDCONNECTION;
  187. }
  188. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  189. return(hResultCode);
  190. }
  191. // DNUserIndicatedConnectAborted
  192. //
  193. // Send an INDICATED_CONNECT_ABORTED message to the user's message handler
  194. #undef DPF_MODNAME
  195. #define DPF_MODNAME "DNUserIndicatedConnectAborted"
  196. HRESULT DNUserIndicatedConnectAborted(DIRECTNETOBJECT *const pdnObject,
  197. void *const pvPlayerContext)
  198. {
  199. #ifndef DPNBUILD_NOPARAMVAL
  200. CCallbackThread CallbackThread;
  201. #endif // ! DPNBUILD_NOPARAMVAL
  202. HRESULT hResultCode;
  203. DPNMSG_INDICATED_CONNECT_ABORTED Msg;
  204. DPFX(DPFPREP, 6,"Parameters: pvPlayerContext [0x%p]",pvPlayerContext);
  205. DNASSERT(pdnObject != NULL);
  206. Msg.dwSize = sizeof(DPNMSG_INDICATED_CONNECT_ABORTED);
  207. Msg.pvPlayerContext = pvPlayerContext;
  208. #ifndef DPNBUILD_NOPARAMVAL
  209. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  210. {
  211. CallbackThread.Initialize();
  212. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  213. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  214. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  215. }
  216. #endif // !DPNBUILD_NOPARAMVAL
  217. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  218. DPN_MSGID_INDICATED_CONNECT_ABORTED,reinterpret_cast<BYTE*>(&Msg));
  219. #ifndef DPNBUILD_NOPARAMVAL
  220. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  221. {
  222. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  223. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  224. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  225. CallbackThread.Deinitialize();
  226. }
  227. #endif // !DPNBUILD_NOPARAMVAL
  228. hResultCode = DPN_OK;
  229. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  230. return(hResultCode);
  231. }
  232. // DNUserCreatePlayer
  233. //
  234. // Send a CREATE_PLAYER message to the user's message handler
  235. #undef DPF_MODNAME
  236. #define DPF_MODNAME "DNUserCreatePlayer"
  237. HRESULT DNUserCreatePlayer(DIRECTNETOBJECT *const pdnObject,
  238. CNameTableEntry *const pNTEntry)
  239. {
  240. #ifndef DPNBUILD_NOPARAMVAL
  241. CCallbackThread CallbackThread;
  242. #endif // ! DPNBUILD_NOPARAMVAL
  243. HRESULT hResultCode;
  244. DPNMSG_CREATE_PLAYER Msg;
  245. DPFX(DPFPREP, 6,"Parameters: pNTEntry [0x%p]",pNTEntry);
  246. // ensure initialized (need message handler)
  247. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  248. #ifndef DPNBUILD_NOVOICE
  249. Voice_Notify( pdnObject, DVEVENT_ADDPLAYER, pNTEntry->GetDPNID(), 0 );
  250. #endif // !DPNBUILD_NOVOICE
  251. Msg.dwSize = sizeof(DPNMSG_CREATE_PLAYER);
  252. Msg.dpnidPlayer = pNTEntry->GetDPNID();
  253. Msg.pvPlayerContext = pNTEntry->GetContext();
  254. #ifndef DPNBUILD_NOPARAMVAL
  255. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  256. {
  257. CallbackThread.Initialize();
  258. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  259. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  260. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  261. }
  262. #endif // !DPNBUILD_NOPARAMVAL
  263. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  264. DPN_MSGID_CREATE_PLAYER,reinterpret_cast<BYTE*>(&Msg));
  265. #ifndef DPNBUILD_NOPARAMVAL
  266. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  267. {
  268. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  269. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  270. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  271. CallbackThread.Deinitialize();
  272. }
  273. #endif // !DPNBUILD_NOPARAMVAL
  274. //
  275. // Save context value on NameTableEntry
  276. //
  277. pNTEntry->Lock();
  278. pNTEntry->SetContext( Msg.pvPlayerContext );
  279. pNTEntry->SetCreated();
  280. pNTEntry->Unlock();
  281. pNTEntry->NotifyRelease();
  282. DPFX(DPFPREP, 7,"Set context [0x%p]",pNTEntry->GetContext());
  283. hResultCode = DPN_OK;
  284. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  285. return(hResultCode);
  286. }
  287. // DNUserDestroyPlayer
  288. //
  289. // Send a DESTROY_PLAYER message to the user's message handler
  290. #undef DPF_MODNAME
  291. #define DPF_MODNAME "DNUserDestroyPlayer"
  292. HRESULT DNUserDestroyPlayer(DIRECTNETOBJECT *const pdnObject,
  293. CNameTableEntry *const pNTEntry)
  294. {
  295. #ifndef DPNBUILD_NOPARAMVAL
  296. CCallbackThread CallbackThread;
  297. #endif // ! DPNBUILD_NOPARAMVAL
  298. HRESULT hResultCode;
  299. DPNMSG_DESTROY_PLAYER Msg;
  300. DPFX(DPFPREP, 6,"Parameters: pNTEntry [0x%p]",pNTEntry);
  301. // ensure initialized (need message handler)
  302. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  303. DNASSERT(pNTEntry != NULL);
  304. DNASSERT(pNTEntry->GetDPNID() != 0);
  305. DNASSERT(pNTEntry->GetDestroyReason() != 0);
  306. #ifndef DPNBUILD_NOVOICE
  307. Voice_Notify( pdnObject, DVEVENT_REMOVEPLAYER, pNTEntry->GetDPNID(), 0 );
  308. #endif // !DPNBUILD_NOVOICE
  309. Msg.dwSize = sizeof(DPNMSG_DESTROY_PLAYER);
  310. Msg.dpnidPlayer = pNTEntry->GetDPNID();
  311. Msg.pvPlayerContext = pNTEntry->GetContext();
  312. Msg.dwReason = pNTEntry->GetDestroyReason();
  313. #ifndef DPNBUILD_NOPARAMVAL
  314. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  315. {
  316. CallbackThread.Initialize();
  317. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  318. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  319. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  320. }
  321. #endif // !DPNBUILD_NOPARAMVAL
  322. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  323. DPN_MSGID_DESTROY_PLAYER,reinterpret_cast<BYTE*>(&Msg));
  324. #ifndef DPNBUILD_NOPARAMVAL
  325. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  326. {
  327. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  328. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  329. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  330. CallbackThread.Deinitialize();
  331. }
  332. #endif // !DPNBUILD_NOPARAMVAL
  333. hResultCode = DPN_OK;
  334. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  335. return(hResultCode);
  336. }
  337. // DNUserCreateGroup
  338. //
  339. // Send an CREATE_GROUP message to the user's message handler
  340. #undef DPF_MODNAME
  341. #define DPF_MODNAME "DNUserCreateGroup"
  342. HRESULT DNUserCreateGroup(DIRECTNETOBJECT *const pdnObject,
  343. CNameTableEntry *const pNTEntry)
  344. {
  345. #ifndef DPNBUILD_NOPARAMVAL
  346. CCallbackThread CallbackThread;
  347. #endif // ! DPNBUILD_NOPARAMVAL
  348. HRESULT hResultCode;
  349. DPNMSG_CREATE_GROUP Msg;
  350. DPFX(DPFPREP, 6,"Parameters: pNTEntry [0x%p]",pNTEntry);
  351. // ensure initialized (need message handler)
  352. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  353. #ifndef DPNBUILD_NOVOICE
  354. Voice_Notify( pdnObject, DVEVENT_CREATEGROUP, pNTEntry->GetDPNID(), 0 );
  355. #endif // !DPNBUILD_NOVOICE
  356. Msg.dwSize = sizeof(DPNMSG_CREATE_GROUP);
  357. Msg.dpnidGroup = pNTEntry->GetDPNID();
  358. if (pNTEntry->IsAutoDestructGroup())
  359. {
  360. CNameTableEntry *pOwner = NULL;
  361. Msg.dpnidOwner = pNTEntry->GetOwner();
  362. if (pdnObject->NameTable.FindEntry(pNTEntry->GetOwner(),&pOwner) == DPN_OK)
  363. {
  364. Msg.pvOwnerContext = pOwner->GetContext();
  365. pOwner->Release();
  366. pOwner = NULL;
  367. }
  368. DNASSERT( pOwner == NULL );
  369. }
  370. else
  371. {
  372. Msg.dpnidOwner = 0;
  373. }
  374. Msg.pvGroupContext = pNTEntry->GetContext();
  375. #ifndef DPNBUILD_NOPARAMVAL
  376. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  377. {
  378. CallbackThread.Initialize();
  379. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  380. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  381. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  382. }
  383. #endif // !DPNBUILD_NOPARAMVAL
  384. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  385. DPN_MSGID_CREATE_GROUP,reinterpret_cast<BYTE*>(&Msg));
  386. #ifndef DPNBUILD_NOPARAMVAL
  387. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  388. {
  389. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  390. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  391. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  392. CallbackThread.Deinitialize();
  393. }
  394. #endif // !DPNBUILD_NOPARAMVAL
  395. //
  396. // Save context value on NameTableEntry
  397. //
  398. pNTEntry->Lock();
  399. pNTEntry->SetContext( Msg.pvGroupContext );
  400. pNTEntry->SetCreated();
  401. pNTEntry->Unlock();
  402. pNTEntry->NotifyRelease();
  403. DPFX(DPFPREP, 7,"Set context [0x%p]",pNTEntry->GetContext());
  404. hResultCode = DPN_OK;
  405. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  406. return(hResultCode);
  407. }
  408. // DNUserDestroyGroup
  409. //
  410. // Send a DESTROY_GROUP message to the user's message handler
  411. #undef DPF_MODNAME
  412. #define DPF_MODNAME "DNUserDestroyGroup"
  413. HRESULT DNUserDestroyGroup(DIRECTNETOBJECT *const pdnObject,
  414. CNameTableEntry *const pNTEntry)
  415. {
  416. #ifndef DPNBUILD_NOPARAMVAL
  417. CCallbackThread CallbackThread;
  418. #endif // ! DPNBUILD_NOPARAMVAL
  419. HRESULT hResultCode;
  420. DPNMSG_DESTROY_GROUP Msg;
  421. DPFX(DPFPREP, 6,"Parameters: pNTEntry [0x%p]",pNTEntry);
  422. // ensure initialized (need message handler)
  423. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  424. DNASSERT(pNTEntry != NULL);
  425. DNASSERT(pNTEntry->GetDPNID() != 0);
  426. DNASSERT(pNTEntry->GetDestroyReason() != 0);
  427. #ifndef DPNBUILD_NOVOICE
  428. Voice_Notify( pdnObject, DVEVENT_DELETEGROUP, pNTEntry->GetDPNID(), 0 );
  429. #endif // !DPNBUILD_NOVOICE
  430. Msg.dwSize = sizeof(DPNMSG_DESTROY_GROUP);
  431. Msg.dpnidGroup = pNTEntry->GetDPNID();
  432. Msg.pvGroupContext = pNTEntry->GetContext();
  433. Msg.dwReason = pNTEntry->GetDestroyReason();
  434. #ifndef DPNBUILD_NOPARAMVAL
  435. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  436. {
  437. CallbackThread.Initialize();
  438. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  439. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  440. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  441. }
  442. #endif // !DPNBUILD_NOPARAMVAL
  443. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  444. DPN_MSGID_DESTROY_GROUP,reinterpret_cast<BYTE*>(&Msg));
  445. #ifndef DPNBUILD_NOPARAMVAL
  446. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  447. {
  448. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  449. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  450. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  451. CallbackThread.Deinitialize();
  452. }
  453. #endif // !DPNBUILD_NOPARAMVAL
  454. hResultCode = DPN_OK;
  455. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  456. return(hResultCode);
  457. }
  458. // DNUserAddPlayerToGroup
  459. //
  460. // Send an ADD_PLAYER_TO_GROUP message to the user's message handler
  461. #undef DPF_MODNAME
  462. #define DPF_MODNAME "DNUserAddPlayerToGroup"
  463. HRESULT DNUserAddPlayerToGroup(DIRECTNETOBJECT *const pdnObject,
  464. CNameTableEntry *const pGroup,
  465. CNameTableEntry *const pPlayer)
  466. {
  467. #ifndef DPNBUILD_NOPARAMVAL
  468. CCallbackThread CallbackThread;
  469. #endif // ! DPNBUILD_NOPARAMVAL
  470. HRESULT hResultCode;
  471. DPNMSG_ADD_PLAYER_TO_GROUP Msg;
  472. DPFX(DPFPREP, 6,"Parameters: pGroup [0x%p], pPlayer [0x%p]",pGroup,pPlayer);
  473. // ensure initialized (need message handler)
  474. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  475. DNASSERT(pGroup != NULL);
  476. DNASSERT(pPlayer != NULL);
  477. #ifndef DPNBUILD_NOVOICE
  478. Voice_Notify( pdnObject, DVEVENT_ADDPLAYERTOGROUP, pGroup->GetDPNID(), pPlayer->GetDPNID() );
  479. #endif // !DPNBUILD_NOVOICE
  480. Msg.dwSize = sizeof(DPNMSG_ADD_PLAYER_TO_GROUP);
  481. Msg.dpnidGroup = pGroup->GetDPNID();
  482. Msg.pvGroupContext = pGroup->GetContext();
  483. Msg.dpnidPlayer = pPlayer->GetDPNID();
  484. Msg.pvPlayerContext = pPlayer->GetContext();
  485. #ifndef DPNBUILD_NOPARAMVAL
  486. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  487. {
  488. CallbackThread.Initialize();
  489. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  490. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  491. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  492. }
  493. #endif // !DPNBUILD_NOPARAMVAL
  494. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  495. DPN_MSGID_ADD_PLAYER_TO_GROUP,reinterpret_cast<BYTE*>(&Msg));
  496. #ifndef DPNBUILD_NOPARAMVAL
  497. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  498. {
  499. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  500. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  501. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  502. CallbackThread.Deinitialize();
  503. }
  504. #endif // !DPNBUILD_NOPARAMVAL
  505. hResultCode = DPN_OK;
  506. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  507. return(hResultCode);
  508. }
  509. // DNUserRemovePlayerFromGroup
  510. //
  511. // Send a REMOVE_PLAYER_FROM_GROUP message to the user's message handler
  512. #undef DPF_MODNAME
  513. #define DPF_MODNAME "DNUserRemovePlayerFromGroup"
  514. HRESULT DNUserRemovePlayerFromGroup(DIRECTNETOBJECT *const pdnObject,
  515. CNameTableEntry *const pGroup,
  516. CNameTableEntry *const pPlayer)
  517. {
  518. #ifndef DPNBUILD_NOPARAMVAL
  519. CCallbackThread CallbackThread;
  520. #endif // ! DPNBUILD_NOPARAMVAL
  521. HRESULT hResultCode;
  522. DPNMSG_REMOVE_PLAYER_FROM_GROUP Msg;
  523. DPFX(DPFPREP, 6,"Parameters: pGroup [0x%p], pPlayer [0x%p]",pGroup,pPlayer);
  524. // ensure initialized (need message handler)
  525. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  526. DNASSERT(pGroup != NULL);
  527. DNASSERT(pPlayer != NULL);
  528. #ifndef DPNBUILD_NOVOICE
  529. Voice_Notify( pdnObject, DVEVENT_REMOVEPLAYERFROMGROUP, pGroup->GetDPNID(), pPlayer->GetDPNID());
  530. #endif // !DPNBUILD_NOVOICE
  531. Msg.dwSize = sizeof(DPNMSG_REMOVE_PLAYER_FROM_GROUP);
  532. Msg.dpnidGroup = pGroup->GetDPNID();
  533. Msg.pvGroupContext = pGroup->GetContext();
  534. Msg.dpnidPlayer = pPlayer->GetDPNID();
  535. Msg.pvPlayerContext = pPlayer->GetContext();
  536. #ifndef DPNBUILD_NOPARAMVAL
  537. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  538. {
  539. CallbackThread.Initialize();
  540. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  541. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  542. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  543. }
  544. #endif // !DPNBUILD_NOPARAMVAL
  545. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  546. DPN_MSGID_REMOVE_PLAYER_FROM_GROUP,reinterpret_cast<BYTE*>(&Msg));
  547. #ifndef DPNBUILD_NOPARAMVAL
  548. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  549. {
  550. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  551. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  552. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  553. CallbackThread.Deinitialize();
  554. }
  555. #endif // !DPNBUILD_NOPARAMVAL
  556. hResultCode = DPN_OK;
  557. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  558. return(hResultCode);
  559. }
  560. #undef DPF_MODNAME
  561. #define DPF_MODNAME "DNUserUpdateGroupInfo"
  562. HRESULT DNUserUpdateGroupInfo(DIRECTNETOBJECT *const pdnObject,
  563. const DPNID dpnid,
  564. const PVOID pvContext)
  565. {
  566. #ifndef DPNBUILD_NOPARAMVAL
  567. CCallbackThread CallbackThread;
  568. #endif // ! DPNBUILD_NOPARAMVAL
  569. HRESULT hResultCode;
  570. DPNMSG_GROUP_INFO MsgGroupInfo;
  571. DPFX(DPFPREP, 6,"Parameters: dpnid [0x%lx], pvContext [0x%p]",dpnid,pvContext);
  572. // ensure initialized (need message handler)
  573. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  574. MsgGroupInfo.dwSize = sizeof(DPNMSG_GROUP_INFO);
  575. MsgGroupInfo.dpnidGroup = dpnid;
  576. MsgGroupInfo.pvGroupContext = pvContext;
  577. #ifndef DPNBUILD_NOPARAMVAL
  578. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  579. {
  580. CallbackThread.Initialize();
  581. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  582. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  583. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  584. }
  585. #endif // !DPNBUILD_NOPARAMVAL
  586. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  587. DPN_MSGID_GROUP_INFO,reinterpret_cast<BYTE*>(&MsgGroupInfo));
  588. #ifndef DPNBUILD_NOPARAMVAL
  589. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  590. {
  591. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  592. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  593. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  594. CallbackThread.Deinitialize();
  595. }
  596. #endif // !DPNBUILD_NOPARAMVAL
  597. hResultCode = DPN_OK;
  598. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  599. return(hResultCode);
  600. }
  601. #undef DPF_MODNAME
  602. #define DPF_MODNAME "DNUserUpdatePeerInfo"
  603. HRESULT DNUserUpdatePeerInfo(DIRECTNETOBJECT *const pdnObject,
  604. const DPNID dpnid,
  605. const PVOID pvContext)
  606. {
  607. #ifndef DPNBUILD_NOPARAMVAL
  608. CCallbackThread CallbackThread;
  609. #endif // ! DPNBUILD_NOPARAMVAL
  610. HRESULT hResultCode;
  611. DPNMSG_PEER_INFO MsgPeerInfo;
  612. DPFX(DPFPREP, 6,"Parameters: dpnid [0x%lx], pvContext [0x%p]",dpnid,pvContext);
  613. // ensure initialized (need message handler)
  614. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  615. MsgPeerInfo.dwSize = sizeof(DPNMSG_PEER_INFO);
  616. MsgPeerInfo.dpnidPeer = dpnid;
  617. MsgPeerInfo.pvPlayerContext = pvContext;
  618. #ifndef DPNBUILD_NOPARAMVAL
  619. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  620. {
  621. CallbackThread.Initialize();
  622. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  623. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  624. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  625. }
  626. #endif // !DPNBUILD_NOPARAMVAL
  627. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  628. DPN_MSGID_PEER_INFO,reinterpret_cast<BYTE*>(&MsgPeerInfo));
  629. #ifndef DPNBUILD_NOPARAMVAL
  630. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  631. {
  632. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  633. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  634. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  635. CallbackThread.Deinitialize();
  636. }
  637. #endif // !DPNBUILD_NOPARAMVAL
  638. hResultCode = DPN_OK;
  639. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  640. return(hResultCode);
  641. }
  642. #ifndef DPNBUILD_NOSERVER
  643. #undef DPF_MODNAME
  644. #define DPF_MODNAME "DNUserUpdateClientInfo"
  645. HRESULT DNUserUpdateClientInfo(DIRECTNETOBJECT *const pdnObject,
  646. const DPNID dpnid,
  647. const PVOID pvContext)
  648. {
  649. #ifndef DPNBUILD_NOPARAMVAL
  650. CCallbackThread CallbackThread;
  651. #endif // ! DPNBUILD_NOPARAMVAL
  652. HRESULT hResultCode;
  653. DPNMSG_CLIENT_INFO MsgClientInfo;
  654. DPFX(DPFPREP, 6,"Parameters: dpnid [0x%lx], pvContext [0x%p]",dpnid,pvContext);
  655. // ensure initialized (need message handler)
  656. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  657. MsgClientInfo.dwSize = sizeof(DPNMSG_CLIENT_INFO);
  658. MsgClientInfo.dpnidClient = dpnid;
  659. MsgClientInfo.pvPlayerContext = pvContext;
  660. #ifndef DPNBUILD_NOPARAMVAL
  661. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  662. {
  663. CallbackThread.Initialize();
  664. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  665. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  666. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  667. }
  668. #endif // !DPNBUILD_NOPARAMVAL
  669. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  670. DPN_MSGID_CLIENT_INFO,reinterpret_cast<BYTE*>(&MsgClientInfo));
  671. #ifndef DPNBUILD_NOPARAMVAL
  672. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  673. {
  674. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  675. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  676. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  677. CallbackThread.Deinitialize();
  678. }
  679. #endif // !DPNBUILD_NOPARAMVAL
  680. hResultCode = DPN_OK;
  681. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  682. return(hResultCode);
  683. }
  684. #endif // DPNBUILD_NOSERVER
  685. #undef DPF_MODNAME
  686. #define DPF_MODNAME "DNUserUpdateServerInfo"
  687. HRESULT DNUserUpdateServerInfo(DIRECTNETOBJECT *const pdnObject,
  688. const DPNID dpnid,
  689. const PVOID pvContext)
  690. {
  691. #ifndef DPNBUILD_NOPARAMVAL
  692. CCallbackThread CallbackThread;
  693. #endif // ! DPNBUILD_NOPARAMVAL
  694. HRESULT hResultCode;
  695. DPNMSG_SERVER_INFO MsgServerInfo;
  696. DPFX(DPFPREP, 6,"Parameters: dpnid [0x%lx], pvContext [0x%p]",dpnid,pvContext);
  697. // ensure initialized (need message handler)
  698. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  699. MsgServerInfo.dwSize = sizeof(DPNMSG_SERVER_INFO);
  700. MsgServerInfo.dpnidServer = dpnid;
  701. MsgServerInfo.pvPlayerContext = pvContext;
  702. #ifndef DPNBUILD_NOPARAMVAL
  703. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  704. {
  705. CallbackThread.Initialize();
  706. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  707. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  708. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  709. }
  710. #endif // !DPNBUILD_NOPARAMVAL
  711. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  712. DPN_MSGID_SERVER_INFO,reinterpret_cast<BYTE*>(&MsgServerInfo));
  713. #ifndef DPNBUILD_NOPARAMVAL
  714. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  715. {
  716. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  717. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  718. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  719. CallbackThread.Deinitialize();
  720. }
  721. #endif // !DPNBUILD_NOPARAMVAL
  722. hResultCode = DPN_OK;
  723. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  724. return(hResultCode);
  725. }
  726. // DNUserAsyncComplete
  727. //
  728. // Send a DN_MSGID_ASYNC_OPERATION_COMPLETE message to the user's message handler
  729. #undef DPF_MODNAME
  730. #define DPF_MODNAME "DNUserAsyncComplete"
  731. HRESULT DNUserAsyncComplete(DIRECTNETOBJECT *const pdnObject,
  732. const DPNHANDLE hAsyncOp,
  733. PVOID const pvContext,
  734. const HRESULT hr)
  735. {
  736. #ifndef DPNBUILD_NOPARAMVAL
  737. CCallbackThread CallbackThread;
  738. #endif // ! DPNBUILD_NOPARAMVAL
  739. HRESULT hResultCode;
  740. DPNMSG_ASYNC_OP_COMPLETE Msg;
  741. DPFX(DPFPREP, 6,"Parameters: hAsyncOp [0x%lx], pvContext [0x%p], hr [0x%lx]",hAsyncOp,pvContext,hr);
  742. // ensure initialized (need message handler)
  743. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  744. Msg.dwSize = sizeof(DPNMSG_ASYNC_OP_COMPLETE);
  745. Msg.hAsyncOp = hAsyncOp;
  746. Msg.pvUserContext = pvContext;
  747. Msg.hResultCode = hr;
  748. #ifndef DPNBUILD_NOPARAMVAL
  749. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  750. {
  751. CallbackThread.Initialize();
  752. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  753. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  754. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  755. }
  756. #endif // !DPNBUILD_NOPARAMVAL
  757. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  758. DPN_MSGID_ASYNC_OP_COMPLETE,reinterpret_cast<BYTE*>(&Msg));
  759. #ifndef DPNBUILD_NOPARAMVAL
  760. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  761. {
  762. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  763. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  764. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  765. CallbackThread.Deinitialize();
  766. }
  767. #endif // !DPNBUILD_NOPARAMVAL
  768. hResultCode = DPN_OK;
  769. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  770. return(hResultCode);
  771. }
  772. // DNUserSendComplete
  773. //
  774. // Send a DN_MSGID_SEND_COMPLETE message to the user's message handler
  775. #undef DPF_MODNAME
  776. #define DPF_MODNAME "DNUserSendComplete"
  777. HRESULT DNUserSendComplete(DIRECTNETOBJECT *const pdnObject,
  778. const DPNHANDLE hAsyncOp,
  779. PVOID const pvContext,
  780. const DWORD dwStartTime,
  781. const HRESULT hr,
  782. const DWORD dwFirstFrameRTT,
  783. const DWORD dwFirstFrameRetryCount)
  784. {
  785. #ifndef DPNBUILD_NOPARAMVAL
  786. CCallbackThread CallbackThread;
  787. #endif // ! DPNBUILD_NOPARAMVAL
  788. HRESULT hResultCode;
  789. DPNMSG_SEND_COMPLETE Msg;
  790. DWORD dwEndTime;
  791. DPFX(DPFPREP, 6,"Parameters: hAsyncOp [0x%lx], pvContext [0x%p], hr [0x%lx]",hAsyncOp,pvContext,hr);
  792. // ensure initialized (need message handler)
  793. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  794. Msg.dwSize = sizeof(DPNMSG_SEND_COMPLETE);
  795. Msg.hAsyncOp = hAsyncOp;
  796. Msg.pvUserContext = pvContext;
  797. Msg.hResultCode = hr;
  798. dwEndTime = GETTIMESTAMP();
  799. Msg.dwSendTime = dwEndTime - dwStartTime;
  800. Msg.dwFirstFrameRTT = dwFirstFrameRTT;
  801. Msg.dwFirstFrameRetryCount = dwFirstFrameRetryCount;
  802. #ifndef DPNBUILD_NOPARAMVAL
  803. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  804. {
  805. CallbackThread.Initialize();
  806. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  807. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  808. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  809. }
  810. #endif // !DPNBUILD_NOPARAMVAL
  811. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  812. DPN_MSGID_SEND_COMPLETE,reinterpret_cast<BYTE*>(&Msg));
  813. #ifndef DPNBUILD_NOPARAMVAL
  814. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  815. {
  816. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  817. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  818. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  819. CallbackThread.Deinitialize();
  820. }
  821. #endif // !DPNBUILD_NOPARAMVAL
  822. hResultCode = DPN_OK;
  823. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  824. return(hResultCode);
  825. }
  826. // DNUserUpdateAppDesc
  827. //
  828. // Send a DN_MSGID_APPLICATION_DESC message to the user's message handler
  829. #undef DPF_MODNAME
  830. #define DPF_MODNAME "DNUserUpdateAppDesc"
  831. HRESULT DNUserUpdateAppDesc(DIRECTNETOBJECT *const pdnObject)
  832. {
  833. #ifndef DPNBUILD_NOPARAMVAL
  834. CCallbackThread CallbackThread;
  835. #endif // ! DPNBUILD_NOPARAMVAL
  836. HRESULT hResultCode;
  837. DPFX(DPFPREP, 6,"Parameters: (none)");
  838. // ensure initialized (need message handler)
  839. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  840. #ifndef DPNBUILD_NOPARAMVAL
  841. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  842. {
  843. CallbackThread.Initialize();
  844. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  845. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  846. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  847. }
  848. #endif // !DPNBUILD_NOPARAMVAL
  849. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  850. DPN_MSGID_APPLICATION_DESC,NULL);
  851. #ifndef DPNBUILD_NOPARAMVAL
  852. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  853. {
  854. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  855. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  856. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  857. CallbackThread.Deinitialize();
  858. }
  859. #endif // !DPNBUILD_NOPARAMVAL
  860. hResultCode = DPN_OK;
  861. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  862. return(hResultCode);
  863. }
  864. // DNUserReceive
  865. //
  866. // Send a DN_MSGID_RECEIVE message to the user's message handler
  867. #undef DPF_MODNAME
  868. #define DPF_MODNAME "DNUserReceive"
  869. HRESULT DNUserReceive(DIRECTNETOBJECT *const pdnObject,
  870. CNameTableEntry *const pNTEntry,
  871. BYTE *const pBufferData,
  872. const DWORD dwBufferSize,
  873. const DPNHANDLE hBufferHandle)
  874. {
  875. #ifndef DPNBUILD_NOPARAMVAL
  876. CCallbackThread CallbackThread;
  877. #endif // ! DPNBUILD_NOPARAMVAL
  878. HRESULT hResultCode;
  879. DPNMSG_RECEIVE Msg;
  880. DPFX(DPFPREP, 6,"Parameters: pNTEntry [0x%p], pBufferData [0x%p], dwBufferSize [%ld], hBufferHandle [0x%lx]",
  881. pNTEntry,pBufferData,dwBufferSize,hBufferHandle);
  882. // ensure initialized (need message handler)
  883. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  884. DNASSERT(pNTEntry != NULL);
  885. Msg.dwSize = sizeof(DPNMSG_RECEIVE);
  886. Msg.pReceiveData = pBufferData;
  887. Msg.dwReceiveDataSize = dwBufferSize;
  888. if (pdnObject->dwFlags & DN_OBJECT_FLAG_CLIENT)
  889. {
  890. Msg.dpnidSender = 0;
  891. }
  892. else
  893. {
  894. Msg.dpnidSender = pNTEntry->GetDPNID();
  895. }
  896. Msg.pvPlayerContext = pNTEntry->GetContext();
  897. Msg.hBufferHandle = hBufferHandle;
  898. #ifndef DPNBUILD_NOPARAMVAL
  899. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  900. {
  901. CallbackThread.Initialize();
  902. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  903. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  904. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  905. }
  906. #endif // !DPNBUILD_NOPARAMVAL
  907. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  908. DPN_MSGID_RECEIVE,reinterpret_cast<BYTE*>(&Msg));
  909. #ifndef DPNBUILD_NOPARAMVAL
  910. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  911. {
  912. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  913. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  914. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  915. CallbackThread.Deinitialize();
  916. }
  917. #endif // !DPNBUILD_NOPARAMVAL
  918. if (hResultCode != DPNERR_PENDING)
  919. {
  920. hResultCode = DPN_OK;
  921. }
  922. pNTEntry->NotifyRelease();
  923. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  924. return(hResultCode);
  925. }
  926. // DN_UserHostMigrate
  927. //
  928. // Send a DN_MSGID_HOST_MIGRATE message to the user's message handler
  929. #undef DPF_MODNAME
  930. #define DPF_MODNAME "DN_UserHostMigrate"
  931. HRESULT DN_UserHostMigrate(DIRECTNETOBJECT *const pdnObject,
  932. const DPNID dpnidNewHost,
  933. const PVOID pvPlayerContext)
  934. {
  935. #ifndef DPNBUILD_NOPARAMVAL
  936. CCallbackThread CallbackThread;
  937. #endif // ! DPNBUILD_NOPARAMVAL
  938. HRESULT hResultCode;
  939. DPNMSG_HOST_MIGRATE Msg;
  940. DPFX(DPFPREP, 6,"Parameters: (none)");
  941. // ensure initialized (need message handler)
  942. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  943. #ifndef DPNBUILD_NOVOICE
  944. Voice_Notify( pdnObject, DVEVENT_MIGRATEHOST, dpnidNewHost, 0 );
  945. #endif // !DPNBUILD_NOVOICE
  946. Msg.dwSize = sizeof(DPNMSG_HOST_MIGRATE);
  947. Msg.dpnidNewHost = dpnidNewHost;
  948. Msg.pvPlayerContext = pvPlayerContext;
  949. #ifndef DPNBUILD_NOPARAMVAL
  950. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  951. {
  952. CallbackThread.Initialize();
  953. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  954. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  955. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  956. }
  957. #endif // !DPNBUILD_NOPARAMVAL
  958. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  959. DPN_MSGID_HOST_MIGRATE,reinterpret_cast<BYTE*>(&Msg));
  960. #ifndef DPNBUILD_NOPARAMVAL
  961. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  962. {
  963. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  964. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  965. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  966. CallbackThread.Deinitialize();
  967. }
  968. #endif // !DPNBUILD_NOPARAMVAL
  969. hResultCode = DPN_OK;
  970. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  971. return(hResultCode);
  972. }
  973. // DNUserTerminateSession
  974. //
  975. // Send a DN_MSGID_CONNECTION_TERMINATED message to the user's message handler
  976. #undef DPF_MODNAME
  977. #define DPF_MODNAME "DNUserTerminateSession"
  978. HRESULT DNUserTerminateSession(DIRECTNETOBJECT *const pdnObject,
  979. const HRESULT hr,
  980. void *const pvTerminateData,
  981. const DWORD dwTerminateDataSize)
  982. {
  983. #ifndef DPNBUILD_NOPARAMVAL
  984. CCallbackThread CallbackThread;
  985. #endif // ! DPNBUILD_NOPARAMVAL
  986. HRESULT hResultCode;
  987. DPNMSG_TERMINATE_SESSION Msg;
  988. DPFX(DPFPREP, 6,"Parameters: hr [0x%lx],pvTerminateData [0x%p], dwTerminateDataSize [%ld]",
  989. hr,pvTerminateData,dwTerminateDataSize);
  990. // ensure initialized (need message handler)
  991. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  992. Msg.dwSize = sizeof(DPNMSG_TERMINATE_SESSION);
  993. Msg.hResultCode = hr;
  994. Msg.pvTerminateData = pvTerminateData;
  995. Msg.dwTerminateDataSize = dwTerminateDataSize;
  996. #ifndef DPNBUILD_NOPARAMVAL
  997. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  998. {
  999. CallbackThread.Initialize();
  1000. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1001. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  1002. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1003. }
  1004. #endif // !DPNBUILD_NOPARAMVAL
  1005. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  1006. DPN_MSGID_TERMINATE_SESSION,reinterpret_cast<BYTE*>(&Msg));
  1007. #ifndef DPNBUILD_NOPARAMVAL
  1008. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1009. {
  1010. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1011. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  1012. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1013. CallbackThread.Deinitialize();
  1014. }
  1015. #endif // !DPNBUILD_NOPARAMVAL
  1016. hResultCode = DPN_OK;
  1017. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  1018. return(hResultCode);
  1019. }
  1020. // DNUserReturnBuffer
  1021. //
  1022. // Send a DPN_MSGID_RETURN_BUFFER message to the user's message handler
  1023. #undef DPF_MODNAME
  1024. #define DPF_MODNAME "DNUserReturnBuffer"
  1025. HRESULT DNUserReturnBuffer(DIRECTNETOBJECT *const pdnObject,
  1026. const HRESULT hr,
  1027. void *const pvBuffer,
  1028. void *const pvUserContext)
  1029. {
  1030. #ifndef DPNBUILD_NOPARAMVAL
  1031. CCallbackThread CallbackThread;
  1032. #endif // ! DPNBUILD_NOPARAMVAL
  1033. HRESULT hResultCode;
  1034. DPNMSG_RETURN_BUFFER Msg;
  1035. DPFX(DPFPREP, 6,"Parameters: hr [0x%lx], pvBuffer [0x%p], pvUserContext [0x%p]",hr,pvBuffer,pvUserContext);
  1036. // ensure initialized (need message handler)
  1037. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  1038. Msg.dwSize = sizeof(DPNMSG_RETURN_BUFFER);
  1039. Msg.hResultCode = hr;
  1040. Msg.pvBuffer = pvBuffer;
  1041. Msg.pvUserContext = pvUserContext;
  1042. #ifndef DPNBUILD_NOPARAMVAL
  1043. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1044. {
  1045. CallbackThread.Initialize();
  1046. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1047. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  1048. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1049. }
  1050. #endif // !DPNBUILD_NOPARAMVAL
  1051. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  1052. DPN_MSGID_RETURN_BUFFER,reinterpret_cast<BYTE*>(&Msg));
  1053. #ifndef DPNBUILD_NOPARAMVAL
  1054. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1055. {
  1056. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1057. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  1058. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1059. CallbackThread.Deinitialize();
  1060. }
  1061. #endif // !DPNBUILD_NOPARAMVAL
  1062. hResultCode = DPN_OK;
  1063. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  1064. return(hResultCode);
  1065. }
  1066. // DNUserEnumQuery
  1067. //
  1068. // Send a DPN_MSGID_ENUM_QUERY message to the user's message handler
  1069. #undef DPF_MODNAME
  1070. #define DPF_MODNAME "DNUserEnumQuery"
  1071. HRESULT DNUserEnumQuery(DIRECTNETOBJECT *const pdnObject,
  1072. DPNMSG_ENUM_HOSTS_QUERY *const pMsg)
  1073. {
  1074. #ifndef DPNBUILD_NOPARAMVAL
  1075. CCallbackThread CallbackThread;
  1076. #endif // ! DPNBUILD_NOPARAMVAL
  1077. HRESULT hResultCode;
  1078. DPFX(DPFPREP, 6,"Parameters: pMsg [0x%p]",pMsg);
  1079. DNASSERT(pdnObject != NULL);
  1080. DNASSERT(pMsg != NULL);
  1081. #ifndef DPNBUILD_NOPARAMVAL
  1082. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1083. {
  1084. CallbackThread.Initialize();
  1085. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1086. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  1087. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1088. }
  1089. #endif // !DPNBUILD_NOPARAMVAL
  1090. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  1091. DPN_MSGID_ENUM_HOSTS_QUERY,reinterpret_cast<BYTE*>(pMsg));
  1092. #ifndef DPNBUILD_NOPARAMVAL
  1093. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1094. {
  1095. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1096. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  1097. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1098. CallbackThread.Deinitialize();
  1099. }
  1100. #endif // !DPNBUILD_NOPARAMVAL
  1101. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  1102. return(hResultCode);
  1103. }
  1104. // DNUserEnumResponse
  1105. //
  1106. // Send a DPN_MSGID_ENUM_RESPONSE message to the user's message handler
  1107. #undef DPF_MODNAME
  1108. #define DPF_MODNAME "DNUserEnumResponse"
  1109. HRESULT DNUserEnumResponse(DIRECTNETOBJECT *const pdnObject,
  1110. DPNMSG_ENUM_HOSTS_RESPONSE *const pMsg)
  1111. {
  1112. #ifndef DPNBUILD_NOPARAMVAL
  1113. CCallbackThread CallbackThread;
  1114. #endif // ! DPNBUILD_NOPARAMVAL
  1115. HRESULT hResultCode;
  1116. DPFX(DPFPREP, 6,"Parameters: pMsg [0x%p]",pMsg);
  1117. DNASSERT(pdnObject != NULL);
  1118. DNASSERT(pMsg != NULL);
  1119. #ifndef DPNBUILD_NOPARAMVAL
  1120. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1121. {
  1122. CallbackThread.Initialize();
  1123. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1124. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  1125. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1126. }
  1127. #endif // !DPNBUILD_NOPARAMVAL
  1128. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  1129. DPN_MSGID_ENUM_HOSTS_RESPONSE,reinterpret_cast<BYTE*>(pMsg));
  1130. #ifndef DPNBUILD_NOPARAMVAL
  1131. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1132. {
  1133. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1134. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  1135. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1136. CallbackThread.Deinitialize();
  1137. }
  1138. #endif // !DPNBUILD_NOPARAMVAL
  1139. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  1140. return(hResultCode);
  1141. }
  1142. #ifndef DPNBUILD_NOMULTICAST
  1143. // DNUserJoinComplete
  1144. //
  1145. // Send a JOIN_COMPLETE message to the user's message handler
  1146. #undef DPF_MODNAME
  1147. #define DPF_MODNAME "DNUserJoinComplete"
  1148. HRESULT DNUserJoinComplete(DIRECTNETOBJECT *const pdnObject,
  1149. const DPNHANDLE hAsyncOp,
  1150. PVOID const pvContext,
  1151. const HRESULT hr)
  1152. {
  1153. #ifndef DPNBUILD_NOPARAMVAL
  1154. CCallbackThread CallbackThread;
  1155. #endif // ! DPNBUILD_NOPARAMVAL
  1156. HRESULT hResultCode;
  1157. DPNMSG_JOIN_COMPLETE Msg;
  1158. // ensure initialized (need message handler)
  1159. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  1160. DPFX(DPFPREP, 6,"Parameters: hAsyncOp [0x%lx], pvContext [0x%p], hr [0x%lx]",
  1161. hAsyncOp,pvContext,hr);
  1162. Msg.dwSize = sizeof(DPNMSG_JOIN_COMPLETE);
  1163. Msg.hAsyncOp = hAsyncOp;
  1164. Msg.pvUserContext = pvContext;
  1165. Msg.hResultCode = hr;
  1166. #ifndef DPNBUILD_NOPARAMVAL
  1167. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1168. {
  1169. CallbackThread.Initialize();
  1170. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1171. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  1172. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1173. }
  1174. #endif // !DPNBUILD_NOPARAMVAL
  1175. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  1176. DPN_MSGID_JOIN_COMPLETE,reinterpret_cast<BYTE*>(&Msg));
  1177. #ifndef DPNBUILD_NOPARAMVAL
  1178. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1179. {
  1180. CallbackThread.Deinitialize();
  1181. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1182. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  1183. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1184. }
  1185. #endif // !DPNBUILD_NOPARAMVAL
  1186. hResultCode = DPN_OK;
  1187. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  1188. return(hResultCode);
  1189. }
  1190. // DNUserReceiveMulticast
  1191. //
  1192. // Send a DN_MSGID_RECEIVE_MULTICAST message to the user's message handler
  1193. #undef DPF_MODNAME
  1194. #define DPF_MODNAME "DNUserReceiveMulticast"
  1195. HRESULT DNUserReceiveMulticast(DIRECTNETOBJECT *const pdnObject,
  1196. void * const pvSenderContext,
  1197. IDirectPlay8Address *const pSenderAddress,
  1198. IDirectPlay8Address *const pDeviceAddress,
  1199. BYTE *const pBufferData,
  1200. const DWORD dwBufferSize,
  1201. const DPNHANDLE hBufferHandle)
  1202. {
  1203. #ifndef DPNBUILD_NOPARAMVAL
  1204. CCallbackThread CallbackThread;
  1205. #endif // ! DPNBUILD_NOPARAMVAL
  1206. HRESULT hResultCode;
  1207. DPNMSG_RECEIVE_MULTICAST Msg;
  1208. DPFX(DPFPREP, 6,"Parameters: pvSenderContext [0x%p], pSenderAddress [0x%p], pDeviceAddress [0x%p], pBufferData [0x%p], dwBufferSize [%ld], hBufferHandle [0x%lx]",
  1209. pvSenderContext,pSenderAddress,pDeviceAddress,pBufferData,dwBufferSize,hBufferHandle);
  1210. // ensure initialized (need message handler)
  1211. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  1212. Msg.dwSize = sizeof(DPNMSG_RECEIVE_MULTICAST);
  1213. Msg.pvSenderContext = pvSenderContext;
  1214. Msg.pAddressSender = pSenderAddress;
  1215. Msg.pAddressDevice = pDeviceAddress;
  1216. Msg.pReceiveData = pBufferData;
  1217. Msg.dwReceiveDataSize = dwBufferSize;
  1218. Msg.hBufferHandle = hBufferHandle;
  1219. #ifndef DPNBUILD_NOPARAMVAL
  1220. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1221. {
  1222. CallbackThread.Initialize();
  1223. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1224. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  1225. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1226. }
  1227. #endif // !DPNBUILD_NOPARAMVAL
  1228. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  1229. DPN_MSGID_RECEIVE_MULTICAST,reinterpret_cast<BYTE*>(&Msg));
  1230. #ifndef DPNBUILD_NOPARAMVAL
  1231. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1232. {
  1233. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1234. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  1235. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1236. CallbackThread.Deinitialize();
  1237. }
  1238. #endif // !DPNBUILD_NOPARAMVAL
  1239. if (hResultCode != DPNERR_PENDING)
  1240. {
  1241. hResultCode = DPN_OK;
  1242. }
  1243. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  1244. return(hResultCode);
  1245. }
  1246. // DNUserCreateSenderContext
  1247. //
  1248. // Send a CREATE_SENDER_CONTEXT message to the user's message handler
  1249. #undef DPF_MODNAME
  1250. #define DPF_MODNAME "DNUserCreateSenderContext"
  1251. HRESULT DNUserCreateSenderContext(DIRECTNETOBJECT *const pdnObject,
  1252. void *const pvContext)
  1253. {
  1254. #ifndef DPNBUILD_NOPARAMVAL
  1255. CCallbackThread CallbackThread;
  1256. #endif // ! DPNBUILD_NOPARAMVAL
  1257. HRESULT hResultCode;
  1258. DPNMSG_CREATE_SENDER_CONTEXT Msg;
  1259. DPFX(DPFPREP, 6,"Parameters: pvContext [0x%p]",pvContext);
  1260. // ensure initialized (need message handler)
  1261. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  1262. Msg.dwSize = sizeof(DPNMSG_CREATE_SENDER_CONTEXT);
  1263. Msg.pvSenderContext = pvContext;
  1264. #ifndef DPNBUILD_NOPARAMVAL
  1265. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1266. {
  1267. CallbackThread.Initialize();
  1268. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1269. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  1270. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1271. }
  1272. #endif // !DPNBUILD_NOPARAMVAL
  1273. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  1274. DPN_MSGID_CREATE_SENDER_CONTEXT,reinterpret_cast<BYTE*>(&Msg));
  1275. #ifndef DPNBUILD_NOPARAMVAL
  1276. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1277. {
  1278. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1279. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  1280. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1281. CallbackThread.Deinitialize();
  1282. }
  1283. #endif // !DPNBUILD_NOPARAMVAL
  1284. hResultCode = DPN_OK;
  1285. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  1286. return(hResultCode);
  1287. }
  1288. // DNUserDestroySenderContext
  1289. //
  1290. // Send a DESTROY_SENDER_CONTEXT message to the user's message handler
  1291. #undef DPF_MODNAME
  1292. #define DPF_MODNAME "DNUserDestroySenderContext"
  1293. HRESULT DNUserDestroySenderContext(DIRECTNETOBJECT *const pdnObject,
  1294. void *const pvContext)
  1295. {
  1296. #ifndef DPNBUILD_NOPARAMVAL
  1297. CCallbackThread CallbackThread;
  1298. #endif // ! DPNBUILD_NOPARAMVAL
  1299. HRESULT hResultCode;
  1300. DPNMSG_DESTROY_SENDER_CONTEXT Msg;
  1301. DPFX(DPFPREP, 6,"Parameters: pvContext [0x%p]",pvContext);
  1302. // ensure initialized (need message handler)
  1303. DNASSERT(pdnObject->dwFlags & DN_OBJECT_FLAG_INITIALIZED);
  1304. Msg.dwSize = sizeof(DPNMSG_DESTROY_SENDER_CONTEXT);
  1305. Msg.pvSenderContext = pvContext;
  1306. //Msg.dwReason = pNTEntry->GetDestroyReason();
  1307. #ifndef DPNBUILD_NOPARAMVAL
  1308. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1309. {
  1310. CallbackThread.Initialize();
  1311. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1312. CallbackThread.GetCallbackThreadsBilink()->InsertBefore(&pdnObject->m_bilinkCallbackThreads);
  1313. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1314. }
  1315. #endif // !DPNBUILD_NOPARAMVAL
  1316. hResultCode = (pdnObject->pfnDnUserMessageHandler)(pdnObject->pvUserContext,
  1317. DPN_MSGID_DESTROY_SENDER_CONTEXT,reinterpret_cast<BYTE*>(&Msg));
  1318. #ifndef DPNBUILD_NOPARAMVAL
  1319. if (pdnObject->dwFlags & DN_OBJECT_FLAG_PARAMVALIDATION)
  1320. {
  1321. DNEnterCriticalSection(&pdnObject->csCallbackThreads);
  1322. CallbackThread.GetCallbackThreadsBilink()->RemoveFromList();
  1323. DNLeaveCriticalSection(&pdnObject->csCallbackThreads);
  1324. CallbackThread.Deinitialize();
  1325. }
  1326. #endif // !DPNBUILD_NOPARAMVAL
  1327. hResultCode = DPN_OK;
  1328. DPFX(DPFPREP, 6,"Returning: [0x%lx]",hResultCode);
  1329. return(hResultCode);
  1330. }
  1331. #endif // ! DPNBUILD_NOMULTICAST