Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
4.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dpenumsessionsobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dpSessdataObj.h"
  14. #include "DPEnumSessionsObj.h"
  15. extern BSTR GUIDtoBSTR(LPGUID pGuid);
  16. extern HRESULT BSTRtoPPGUID(LPGUID *,BSTR);
  17. extern BSTR DPLGUIDtoBSTR(LPGUID pGuid);
  18. extern HRESULT DPLBSTRtoPPGUID(LPGUID *,BSTR);
  19. extern HRESULT FillRealSessionDesc(DPSESSIONDESC2 *dpSessionDesc,DPSessionDesc2 *sessionDesc);
  20. extern void FillCoverSessionDesc(DPSessionDesc2 *sessionDesc,DPSESSIONDESC2 *dpSessionDesc);
  21. /////////////////////////////////////////////////////////////////////////////
  22. extern "C" BOOL PASCAL objEnumSessionsCallback2(const DPSESSIONDESC2 *gameDesc,
  23. DWORD *timeout, DWORD dwFlags, void *lpArg)
  24. {
  25. DPF(1,"Entered objEnumSessionsCallback2\r\n");
  26. //with no elements in a list will still call this callback once
  27. if (!gameDesc) return FALSE;
  28. C_dxj_DPEnumSessionsObject *pObj=(C_dxj_DPEnumSessionsObject*)lpArg;
  29. if (pObj==NULL) return TRUE;
  30. if (pObj->m_nCount >= pObj->m_nMax)
  31. {
  32. pObj->m_nMax += 10;
  33. if (pObj->m_pList)
  34. pObj->m_pList=(DPSessionDesc2*)realloc(pObj->m_pList,sizeof(DPSessionDesc2)* pObj->m_nMax);
  35. else
  36. pObj->m_pList=(DPSessionDesc2*)malloc(sizeof(DPSessionDesc2)* pObj->m_nMax);
  37. if (pObj->m_pList==NULL)
  38. {
  39. pObj->m_bProblem=TRUE;
  40. return FALSE;
  41. }
  42. }
  43. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DPSessionDesc2));
  44. FillCoverSessionDesc(&(pObj->m_pList[pObj->m_nCount]),(DPSESSIONDESC2*)gameDesc);
  45. pObj->m_nCount++;
  46. return TRUE;
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. C_dxj_DPEnumSessionsObject::C_dxj_DPEnumSessionsObject()
  50. {
  51. m_nMax=0;
  52. m_pList=NULL;
  53. m_nCount=0;
  54. m_bProblem=FALSE;
  55. }
  56. C_dxj_DPEnumSessionsObject::~C_dxj_DPEnumSessionsObject()
  57. {
  58. //empty list
  59. if (m_pList){
  60. for (int i=0;i<m_nCount;i++)
  61. {
  62. DPSessionDesc2 *sessionDesc=&(m_pList[i]);
  63. if (sessionDesc->strGuidInstance) SysFreeString(sessionDesc->strGuidInstance);
  64. if (sessionDesc->strGuidApplication) SysFreeString(sessionDesc->strGuidApplication);
  65. if (sessionDesc->strSessionName) SysFreeString(sessionDesc->strSessionName);
  66. if (sessionDesc->strPassword) SysFreeString(sessionDesc->strPassword);
  67. }
  68. free(m_pList);
  69. }
  70. }
  71. HRESULT C_dxj_DPEnumSessionsObject::create(
  72. IDirectPlay4 * pdp,
  73. I_dxj_DirectPlaySessionData *sess,
  74. long timeout, long flags, I_dxj_DPEnumSessions2 **ppRet)
  75. {
  76. HRESULT hr;
  77. C_dxj_DPEnumSessionsObject *pNew=NULL;
  78. if (!sess) return E_INVALIDARG;
  79. *ppRet=NULL;
  80. pNew= new CComObject<C_dxj_DPEnumSessionsObject>;
  81. if (!pNew) return E_OUTOFMEMORY;
  82. pNew->m_bProblem=FALSE;
  83. if (sess){
  84. DPSESSIONDESC2 dpSessionDesc;
  85. //hr=FillRealSessionDesc(&dpSessionDesc,sess);
  86. //if FAILED(hr) return hr;
  87. sess->AddRef();
  88. sess->getData((void*)&dpSessionDesc);
  89. hr = pdp->EnumSessions(&dpSessionDesc, (DWORD)timeout, objEnumSessionsCallback2, pNew,(DWORD) flags);
  90. //if (dpSessionDesc.lpszSessionName) SysFreeString(dpSessionDesc.lpszSessionName);
  91. //if (dpSessionDesc.lpszPassword) SysFreeString(dpSessionDesc.lpszPassword);
  92. sess->Release();
  93. }
  94. else {
  95. hr = pdp->EnumSessions(NULL,(DWORD)timeout, objEnumSessionsCallback2, pNew,(DWORD) flags);
  96. }
  97. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  98. if FAILED(hr)
  99. {
  100. free(pNew->m_pList);
  101. pNew->m_pList=NULL;
  102. delete pNew;
  103. return hr;
  104. }
  105. hr=pNew->QueryInterface(IID_I_dxj_DPEnumSessions2,(void**)ppRet);
  106. return hr;
  107. }
  108. HRESULT C_dxj_DPEnumSessionsObject::getItem( long index, I_dxj_DirectPlaySessionData **info)
  109. {
  110. if (m_pList==NULL) return E_FAIL;
  111. if (index < 1) return E_INVALIDARG;
  112. if (index > m_nCount) return E_INVALIDARG;
  113. HRESULT hr=C_dxj_DirectPlaySessionDataObject::create(&(m_pList[index-1]),info);
  114. /*
  115. memcpy(info,&(m_pList[index]),sizeof(DPSessionDesc2));
  116. if (info->strGuidInstance) SysFreeString(info->strGuidInstance);
  117. if (info->strGuidApplication) SysFreeString(info->strGuidApplication);
  118. if (info->strSessionName) SysFreeString(info->strSessionName);
  119. if (info->strPassword) SysFreeString(info->strPassword);
  120. info->strGuidInstance= SysAllocString(m_pList[index].strGuidInstance);
  121. info->strGuidApplication= SysAllocString(m_pList[index].strGuidApplication);
  122. info->strSessionName = SysAllocString(m_pList[index].strSessionName);
  123. info->strPassword = SysAllocString(m_pList[index].strPassword);
  124. */
  125. return hr;
  126. }
  127. HRESULT C_dxj_DPEnumSessionsObject::getCount(long *retVal)
  128. {
  129. *retVal=m_nCount;
  130. return S_OK;
  131. }