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.

145 lines
4.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: S E A R C H C . H
  7. //
  8. // Contents: Client side searching
  9. //
  10. // Notes:
  11. //
  12. // Author: mbend 2 Dec 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "ustring.h"
  16. #include "ulist.h"
  17. #include "upthread.h"
  18. #include "upsync.h"
  19. #include "timer.h"
  20. #include "array.h"
  21. #include "winsock2.h"
  22. #include "ssdp.h"
  23. #include "ssdpapi.h"
  24. #include "ssdptypesc.h"
  25. class CSsdpSearchRequest;
  26. class CSsdpSearchThread : public CThreadBase
  27. {
  28. public:
  29. CSsdpSearchThread(CSsdpSearchRequest * pRequest);
  30. ~CSsdpSearchThread();
  31. private:
  32. CSsdpSearchThread(const CSsdpSearchThread &);
  33. CSsdpSearchThread & operator=(const CSsdpSearchThread &);
  34. DWORD DwRun();
  35. CSsdpSearchRequest * m_pRequest;
  36. };
  37. struct SocketInfo
  38. {
  39. SOCKET m_socket;
  40. GUID m_guidInterface;
  41. };
  42. class CSsdpSearchRequest
  43. {
  44. public:
  45. CSsdpSearchRequest();
  46. ~CSsdpSearchRequest();
  47. HRESULT HrInitialize(char * szType);
  48. HRESULT HrBuildSocketList();
  49. HRESULT HrReBuildSocketList();
  50. HRESULT HrProcessLoopbackAddrOnly();
  51. HRESULT HrSocketSend(const char * szData);
  52. HRESULT HrStartAsync(
  53. BOOL bForceSearch,
  54. SERVICE_CALLBACK_FUNC pfnCallback,
  55. VOID * pvContext);
  56. HRESULT HrStartSync(BOOL bForceSearch);
  57. HRESULT HrShutdown();
  58. HRESULT HrCancelCallback();
  59. void WakeupSelect();
  60. HRESULT HrGetCacheResult();
  61. BOOL FIsInListNotify(const CUString & strType);
  62. BOOL FIsInResponseMessageList(const char * szUSN);
  63. HRESULT HrAddRequestToResponseMessageList(SSDP_REQUEST * pRequest);
  64. DWORD DwThreadFunc();
  65. HRESULT HrGetFirstService(SSDP_MESSAGE ** ppSsdpMessage);
  66. HRESULT HrGetNextService(SSDP_MESSAGE ** ppSsdpMessage);
  67. void TimerFired();
  68. BOOL TimerTryToLock();
  69. void TimerUnlock();
  70. private:
  71. CSsdpSearchRequest(const CSsdpSearchRequest &);
  72. CSsdpSearchRequest & operator=(const CSsdpSearchRequest &);
  73. static HRESULT HrInitializeSsdpSearchRequest(SSDP_REQUEST * pRequest,char * szType);
  74. typedef CUList<SSDP_MESSAGE> ResponseMessageList;
  75. typedef CUArray<SocketInfo> SocketList;
  76. SearchState m_searchState;
  77. CUString m_strType;
  78. CUString m_strSearch;
  79. SERVICE_CALLBACK_FUNC m_pfnCallback;
  80. void * m_pvContext;
  81. long m_nNumOfRetry;
  82. BOOL m_bExit;
  83. ResponseMessageList m_responseMessageList;
  84. ResponseMessageList::Iterator m_iterCurrentResponse;
  85. CTimer<CSsdpSearchRequest> m_timer;
  86. SocketList m_socketList;
  87. BOOL m_bHitWire;
  88. CUCriticalSection m_critSec;
  89. HANDLE m_hEventDone;
  90. CSsdpSearchThread m_searchThread;
  91. OVERLAPPED m_ovInterfaceChange;
  92. volatile BOOL m_bShutdown;
  93. BOOL m_bOnlyLoopBack; // Auto IP issue
  94. BOOL m_bDeletedTimer;
  95. HRESULT HrDeleteTimer();
  96. };
  97. class CSsdpSearchRequestManager
  98. {
  99. public:
  100. ~CSsdpSearchRequestManager();
  101. static CSsdpSearchRequestManager & Instance();
  102. HRESULT HrCleanup();
  103. HRESULT HrCreateAsync(
  104. char * szType,
  105. BOOL bForceSearch,
  106. SERVICE_CALLBACK_FUNC pfnCallback,
  107. VOID * pvContext,
  108. CSsdpSearchRequest ** ppSearchRequest);
  109. HRESULT HrCreateSync(
  110. char * szType,
  111. BOOL bForceSearch,
  112. CSsdpSearchRequest ** ppSearchRequest);
  113. HRESULT HrRemove(CSsdpSearchRequest * pSearchRequest);
  114. HRESULT HrGetFirstService(CSsdpSearchRequest * pSearchRequest, SSDP_MESSAGE ** ppSsdpMessage);
  115. HRESULT HrGetNextService(CSsdpSearchRequest * pSearchRequest, SSDP_MESSAGE ** ppSsdpMessage);
  116. private:
  117. CSsdpSearchRequestManager();
  118. CSsdpSearchRequestManager(const CSsdpSearchRequestManager &);
  119. CSsdpSearchRequestManager & operator=(const CSsdpSearchRequestManager &);
  120. static CSsdpSearchRequestManager s_instance;
  121. typedef CUList<CSsdpSearchRequest> SearchRequestList;
  122. CUCriticalSection m_critSec;
  123. SearchRequestList m_searchRequestList;
  124. };