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.

146 lines
3.8 KiB

  1. // queryreq.h Query request header file
  2. #ifndef _QUERYREQ_H_
  3. #define _QUERYREQ_H_
  4. #include "rowitem.h"
  5. #include <cmnquery.h>
  6. #include <shlobj.h>
  7. #include <dsclient.h>
  8. #define QUERY_PAGE_SIZE 64
  9. #define MAX_RESULT_ITEMS 10000
  10. //////////////////////////////////////////////////////////////////////////////////////////////
  11. // Query request class
  12. //
  13. enum QUERY_NOTIFY
  14. {
  15. QRYN_NEWROWITEMS = 1,
  16. QRYN_STOPPED,
  17. QRYN_COMPLETED,
  18. QRYN_FAILED
  19. };
  20. enum QUERYREQ_STATE
  21. {
  22. QRST_INACTIVE = 0,
  23. QRST_QUEUED,
  24. QRST_ACTIVE,
  25. QRST_STOPPED,
  26. QRST_COMPLETE,
  27. QRST_FAILED
  28. };
  29. class CQueryCallback;
  30. class CQueryRequest
  31. {
  32. public:
  33. friend class CQueryThread;
  34. friend LRESULT CALLBACK QueryRequestWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
  35. static HRESULT CreateInstance(CQueryRequest** ppQueryReq)
  36. {
  37. VALIDATE_POINTER( ppQueryReq );
  38. *ppQueryReq = new CQueryRequest();
  39. if (*ppQueryReq != NULL)
  40. {
  41. (*ppQueryReq)->m_cRef = 1;
  42. return S_OK;
  43. }
  44. else
  45. {
  46. return E_OUTOFMEMORY;
  47. }
  48. }
  49. HRESULT SetQueryParameters(LPCWSTR pszScope, LPCWSTR pszFilter, string_vector* pvstrClasses, string_vector* pvstrAttr);
  50. HRESULT SetSearchPreferences(ADS_SEARCHPREF_INFO* paSrchPrefs, int cPrefs);
  51. HRESULT SetCallback(CQueryCallback* pQueryCallback, LPARAM lUserParam);
  52. HRESULT Start();
  53. HRESULT Stop(BOOL bNotify);
  54. void Release();
  55. RowItemVector& GetNewRowItems() { Lock(); return m_vRowsNew; }
  56. void ReleaseNewRowItems() { m_vRowsNew.clear(); Unlock(); }
  57. HRESULT GetStatus() { return m_hrStatus; }
  58. private:
  59. CQueryRequest();
  60. ~CQueryRequest();
  61. void Lock() { DWORD dw = WaitForSingleObject(m_hMutex, INFINITE); ASSERT(dw == WAIT_OBJECT_0); }
  62. void Unlock() { BOOL bStat = ReleaseMutex(m_hMutex); ASSERT(bStat); }
  63. void Execute();
  64. static HWND m_hWndCB; // callback window for query thread messages
  65. static HANDLE m_hMutex; // mutex for query locking
  66. tstring m_strScope; // scope to search
  67. tstring m_strFilter; // query filter string
  68. string_vector m_vstrClasses; // classes return by query
  69. string_vector* m_pvstrAttr; // attributes to collect
  70. ADS_SEARCHPREF_INFO* m_paSrchPrefs; // preferences array
  71. int m_cPrefs; // preference count
  72. CQueryCallback* m_pQueryCallback; // callback interface
  73. LPARAM m_lUserParam; // user data
  74. QUERYREQ_STATE m_eState; // Query request state
  75. RowItemVector m_vRowsNew; // New row items
  76. HRESULT m_hrStatus; // status
  77. int m_cRef; // ref count
  78. };
  79. class CQueryCallback
  80. {
  81. public:
  82. virtual void QueryCallback(QUERY_NOTIFY event, CQueryRequest* pQueryReq, LPARAM lUserParam) = 0;
  83. };
  84. ////////////////////////////////////////////////////////////////////////////////////////////
  85. // Query thread object
  86. class CQueryThread
  87. {
  88. public:
  89. CQueryThread()
  90. {
  91. m_hThread = NULL;
  92. m_hEvent = NULL;
  93. m_uThreadID = 0;
  94. }
  95. ~CQueryThread()
  96. {
  97. Kill();
  98. }
  99. BOOL Start();
  100. void Kill();
  101. BOOL PostRequest(CQueryRequest* pQueryReq);
  102. private:
  103. static unsigned _stdcall ThreadProc(void* pVoid);
  104. static HRESULT ExecuteQuery(CQueryRequest* pQueryReq, HWND hWndReply);
  105. HANDLE m_hThread; // thread handle
  106. HANDLE m_hEvent; // start event
  107. unsigned m_uThreadID; // thread ID
  108. };
  109. #endif // _QUERYREQ_H_