| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2008 by Eran Ifrah |
| 5 |
// file name : worker_thread.h |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
#ifndef _ProcessReaderThread_H_ |
| 26 |
#define _ProcessReaderThread_H_ |
| 27 |
|
| 28 |
#include "cl_command_event.h" |
| 29 |
#include "codelite_exports.h" |
| 30 |
#include "wx/event.h" |
| 31 |
#include "wx/thread.h" |
| 32 |
#include <atomic> |
| 33 |
#include <deque> |
| 34 |
|
| 35 |
class IProcess; |
| 36 |
/** |
| 37 |
* Worker Thread class |
| 38 |
* usually user should define the ProcessRequest method |
| 39 |
*/ |
| 40 |
class WXDLLIMPEXP_CL ProcessReaderThread : public wxThread |
| 41 |
{ |
| 42 |
protected: |
| 43 |
wxEvtHandler* m_notifiedWindow = nullptr; |
| 44 |
IProcess* m_process = nullptr; |
| 45 |
std::atomic_bool m_suspend; |
| 46 |
std::atomic_bool m_is_suspended; |
| 47 |
|
| 48 |
protected: |
| 49 |
void NotifyTerminated(); |
| 50 |
|
| 51 |
public: |
| 52 |
/** |
| 53 |
* Default constructor. |
| 54 |
*/ |
| 55 |
ProcessReaderThread(); |
| 56 |
|
| 57 |
/** |
| 58 |
* Destructor. |
| 59 |
*/ |
| 60 |
virtual ~ProcessReaderThread(); |
| 61 |
|
| 62 |
/** |
| 63 |
* Thread execution point. |
| 64 |
*/ |
| 65 |
virtual void* Entry(); |
| 66 |
|
| 67 |
/** |
| 68 |
* Called when the thread exits |
| 69 |
* whether it terminates normally or is stopped with Delete() (but not when it is Kill()'ed!) |
| 70 |
*/ |
| 71 |
virtual void OnExit(){}; |
| 72 |
|
| 73 |
/** |
| 74 |
* Set the window to be notified when a change was done |
| 75 |
* between current source file tree and the actual tree. |
| 76 |
* \param evtHandler |
| 77 |
*/ |
| 78 |
void SetNotifyWindow(wxEvtHandler* evtHandler) { m_notifiedWindow = evtHandler; } |
| 79 |
|
| 80 |
/** |
| 81 |
* Stops the thread |
| 82 |
* This function returns only when the thread is terminated. |
| 83 |
* \note This call must be called from the context of other thread (e.g. main thread) |
| 84 |
*/ |
| 85 |
void Stop(); |
| 86 |
|
| 87 |
/** |
| 88 |
* Start the thread as joinable thread. |
| 89 |
* \note This call must be called from the context of other thread (e.g. main thread) |
| 90 |
*/ |
| 91 |
void Start(int priority = WXTHREAD_DEFAULT_PRIORITY); |
| 92 |
|
| 93 |
void SetProcess(IProcess* proc) { m_process = proc; } |
| 94 |
|
| 95 |
/** |
| 96 |
* @brief suspend the reader thread |
| 97 |
*/ |
| 98 |
void Suspend(); |
| 99 |
|
| 100 |
/** |
| 101 |
* @brief resume the reader thread |
| 102 |
*/ |
| 103 |
void Resume(); |
| 104 |
}; |
| 105 |
|
| 106 |
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_ASYNC_PROCESS_OUTPUT, clProcessEvent); |
| 107 |
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_ASYNC_PROCESS_STDERR, clProcessEvent); |
| 108 |
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_ASYNC_PROCESS_TERMINATED, clProcessEvent); |
| 109 |
|
| 110 |
#endif // _ProcessReaderThread_H_ |