SapProcessing.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _SAPPROCESSING_H_
  2. #define _SAPPROCESSING_H_
  3. // SapProcessing.h : header file
  4. //
  5. #include "SapClassBasicDef.h"
  6. #include "SapPerformance.h"
  7. // Forward declarations
  8. class SAPCLASSBASIC_CLASS SapProCallbackInfo;
  9. typedef void (*SapProCallback)(SapProCallbackInfo *);
  10. //
  11. // SapProcessing class declaration
  12. //
  13. class SAPCLASSBASIC_CLASS SapProcessing : public SapManager
  14. {
  15. public:
  16. // Constructor/Destructor
  17. SapProcessing(SapBuffer *pBuffer, SapProCallback pCallback = NULL, void *pContext = NULL);
  18. SapProcessing(const SapProcessing &pro);
  19. virtual ~SapProcessing();
  20. SapProcessing &operator=(const SapProcessing &pro);
  21. // Module create/destroy
  22. virtual BOOL Create();
  23. virtual BOOL Destroy();
  24. // Access to implementation
  25. SapBuffer *GetBuffer() const { return m_pBuffers; }
  26. SapProCallback GetCallback() const { return m_pCallback; }
  27. void *GetContext() const { return m_pContext; }
  28. float GetTime() const { return m_Time; }
  29. int GetIndex() const { return m_Index; }
  30. int GetThreadPriority() const { return m_ThreadPriority; }
  31. virtual BOOL SetBuffer(SapBuffer *pBuffer);
  32. virtual BOOL SetCallbackInfo(SapProCallback pCallback, void *pContext);
  33. // Processing Control
  34. virtual void Init();
  35. virtual void Execute();
  36. virtual void Execute(int index);
  37. virtual void ExecuteNext();
  38. virtual BOOL IsAutoEmpty() const { return m_bAutoEmpty; }
  39. virtual void SetAutoEmpty(BOOL isAutoEmpty) { m_bAutoEmpty = isAutoEmpty; }
  40. #if COR_WIN32
  41. virtual void SetThreadPriority( int priority) { m_ThreadPriority= priority; if( m_hThread != NULL) ::SetThreadPriority( m_hThread, priority);}
  42. #else
  43. virtual void SetThreadPriority( int priority) { m_ThreadPriority= priority; }
  44. #endif
  45. // Obsolete methods, kept for backward compatibility
  46. SapBuffer *GetBuffers() const { return GetBuffer(); }
  47. virtual BOOL SetBuffers(SapBuffer *pBuffers) { return SetBuffer(pBuffers); }
  48. protected:
  49. void Construct(SapBuffer *pBuffer, SapProCallback pCallback, void *pContext, BOOL bAutoEmpty, int threadPriority);
  50. virtual BOOL Run() = 0;
  51. virtual void Next();
  52. virtual void StartTime();
  53. virtual void StopTime();
  54. static UINT WINAPI ProcessThreadProc(LPVOID lpParam);
  55. protected:
  56. // Parameters
  57. SapBuffer *m_pBuffers; // Reference to a buffer object
  58. SapProCallback m_pCallback; // Application callback function
  59. void *m_pContext; // Application context
  60. // Other variables
  61. SapPerformance m_Perf; // Timer object
  62. float m_Time; // Execution time
  63. BOOL m_bAutoEmpty; // TRUE to automatically empty buffers
  64. // Processing thread management
  65. int m_Index; // Index of the last processed buffer
  66. int m_NextIndex; // Index of the next buffer to process
  67. HANDLE m_hThread; // Thread handle
  68. int m_ThreadPriority; // Thread priority
  69. HANDLE m_hStartEvent; // Signaled by the thread after it is started
  70. HANDLE m_hExitEvent; // When signaled, causes the thread to exit
  71. HANDLE m_hProcessEvent; // Signaled when a buffer is ready to be processed
  72. HANDLE m_hIdleEvent; // Signaled by the thread when it has no work to do
  73. LONG m_BuffersLeft; // Number of buffers left to process by the thread
  74. #if !COR_WIN32
  75. pthread_t m_ThreadID; // Processing thread ID
  76. #endif
  77. };
  78. //
  79. // SapProCallbackInfo class declaration
  80. //
  81. class SAPCLASSBASIC_CLASS SapProCallbackInfo
  82. {
  83. public:
  84. SapProCallbackInfo(SapProcessing *pPro, void *context)
  85. { m_pPro = pPro; m_Context = context; }
  86. ~SapProCallbackInfo() {}
  87. // Obsolete constructor
  88. SapProCallbackInfo(void *context)
  89. { m_pPro = NULL; m_Context = context; }
  90. SapProcessing *GetProcessing() const { return m_pPro; }
  91. void *GetContext() const { return m_Context; }
  92. protected:
  93. SapProcessing *m_pPro;
  94. void *m_Context;
  95. };
  96. #endif // _SAPPROCESSING_H_