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.

226 lines
5.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. queryobj.h
  7. Implementation for the background thread and query objects
  8. FILE HISTORY:
  9. */
  10. #ifndef _QUERYOBJ_H
  11. #define _QUERYOBJ_H
  12. #ifndef _TFSINT_H
  13. #include <tfsint.h>
  14. #endif
  15. #define IMPL
  16. // NOTE: Do not define any data types of this value. This range is reservered
  17. // for internal values for ITFSNode pointers.
  18. #define QDATA_PNODE 0xabcdef29
  19. #define QDATA_TIMER 0xabcdef2a
  20. typedef struct QueueData_tag
  21. {
  22. LPARAM Data;
  23. LPARAM Type;
  24. }
  25. QUEUEDATA, * LPQUEUEDATA;
  26. class CBackgroundThread;
  27. class CQueryObject;
  28. //////////////////////////////////////////////////////////////////////
  29. //
  30. // CBackgroundThread
  31. //
  32. //////////////////////////////////////////////////////////////////////
  33. class CBackgroundThread : public CWinThread
  34. {
  35. public:
  36. CBackgroundThread();
  37. virtual ~CBackgroundThread();
  38. void SetQueryObj(ITFSQueryObject* pQuery);
  39. BOOL Start();
  40. virtual BOOL InitInstance() { return TRUE; } // MFC override
  41. virtual int Run(); // MFC override
  42. void Lock() { ::EnterCriticalSection(&m_cs); }
  43. void Unlock() { ::LeaveCriticalSection(&m_cs); }
  44. private:
  45. CRITICAL_SECTION m_cs; // critical section to sync access to data
  46. SPITFSQueryObject m_spQuery;
  47. };
  48. /*---------------------------------------------------------------------------
  49. Class: CQueryObj
  50. This is the generic query object. If you want to do something real
  51. with this, derive a class from this and do it yourself.
  52. ---------------------------------------------------------------------------*/
  53. class CQueryObject :
  54. public ITFSQueryObject
  55. {
  56. public:
  57. CQueryObject();
  58. virtual ~CQueryObject();
  59. DeclareIUnknownMembers(IMPL)
  60. DeclareITFSQueryObjectMembers(IMPL)
  61. protected:
  62. // Query objects will now have to perform the locking
  63. // functions themselves
  64. void Lock() { ::EnterCriticalSection(&m_cs); }
  65. void Unlock() { ::LeaveCriticalSection(&m_cs); }
  66. CRITICAL_SECTION m_cs;
  67. HANDLE m_hEventAbort;
  68. LONG m_cRef;
  69. SPITFSThreadHandler m_spHandler;
  70. SPITFSQueryObject m_spQuery;
  71. HWND m_hHiddenWnd;
  72. UINT m_uMsgBase;
  73. };
  74. //////////////////////////////////////////////////////////////////////
  75. //
  76. // CNodeList
  77. // collection of nodes
  78. //
  79. //////////////////////////////////////////////////////////////////////
  80. typedef CList<LPQUEUEDATA, LPQUEUEDATA> CQueueDataListBase;
  81. typedef CList<ITFSNode *, ITFSNode *> CNodeListBase;
  82. class CNodeList : public CNodeListBase
  83. {
  84. public:
  85. BOOL RemoveNode(ITFSNode* p)
  86. {
  87. POSITION pos = Find(p);
  88. if (pos == NULL)
  89. return FALSE;
  90. RemoveAt(pos);
  91. return TRUE;
  92. }
  93. void DeleteAllNodes()
  94. {
  95. while (!IsEmpty())
  96. RemoveTail()->Release();
  97. }
  98. BOOL HasNode(ITFSNode* p)
  99. {
  100. return NULL != Find(p);
  101. }
  102. };
  103. /*---------------------------------------------------------------------------
  104. Class: CNodeQueryObject
  105. ---------------------------------------------------------------------------*/
  106. class CNodeQueryObject : public CQueryObject
  107. {
  108. public:
  109. CNodeQueryObject() { m_nQueueCountMax = 1; } // default to notification on
  110. // every item enumed from thread
  111. virtual ~CNodeQueryObject();
  112. BOOL AddToQueue(ITFSNode* pNode);
  113. BOOL AddToQueue(LPARAM Data, LPARAM Type);
  114. LPQUEUEDATA RemoveFromQueue();
  115. BOOL IsQueueEmpty();
  116. BOOL IsQueueFull();
  117. STDMETHOD(OnThreadExit)();
  118. STDMETHOD(OnEventAbort());
  119. STDMETHOD(DoCleanup());
  120. BOOL PostHaveData(LPARAM lParam);
  121. BOOL PostError(DWORD dwErr);
  122. virtual void OnEventAbort(LPARAM Data, LPARAM Type) { };
  123. private:
  124. // communication with ComponentData object
  125. BOOL PostMessageToComponentData(UINT uMsg, LPARAM lParam);
  126. protected:
  127. int m_nQueueCountMax;
  128. CQueueDataListBase m_dataQueue;
  129. };
  130. /*---------------------------------------------------------------------------
  131. Class: CNodeQueryObject
  132. ---------------------------------------------------------------------------*/
  133. class CNodeTimerQueryObject : public CNodeQueryObject
  134. {
  135. public:
  136. virtual ~CNodeTimerQueryObject() { };
  137. STDMETHOD (Execute)(void);
  138. void SetTimerInterval(DWORD dwTimerInterval) { m_dwTimerInterval = dwTimerInterval; }
  139. DWORD GetTimerInterval() { return m_dwTimerInterval; }
  140. private:
  141. protected:
  142. DWORD m_dwTimerInterval;
  143. };
  144. /*---------------------------------------------------------------------------
  145. Inlined functions
  146. ---------------------------------------------------------------------------*/
  147. inline BOOL CNodeQueryObject::PostHaveData(LPARAM lParam)
  148. {
  149. return PostMessageToComponentData(WM_HIDDENWND_INDEX_HAVEDATA, lParam);
  150. }
  151. inline BOOL CNodeQueryObject::PostError(DWORD dwErr)
  152. {
  153. return PostMessageToComponentData(WM_HIDDENWND_INDEX_ERROR, dwErr);
  154. }
  155. inline STDMETHODIMP CQueryObject::Execute()
  156. {
  157. return hrFalse;
  158. }
  159. // This function is called when the thread exits, this gives
  160. // the query object a last chance to send a data notification
  161. // to the node
  162. inline STDMETHODIMP CQueryObject::OnThreadExit()
  163. {
  164. return hrOK;
  165. }
  166. inline HANDLE CQueryObject::GetAbortEventHandle()
  167. {
  168. return m_hEventAbort;
  169. }
  170. inline STDMETHODIMP CQueryObject::OnEventAbort()
  171. {
  172. return hrOK;
  173. }
  174. inline STDMETHODIMP CQueryObject::DoCleanup()
  175. {
  176. return hrOK;
  177. }
  178. #endif _QUERYOBJ_H