Debian Codegraph @

CodeLite/clCommandProcessor.h

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // Copyright : (C) 2015 Eran Ifrah
5 // File name : clCommandProcessor.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
26 #ifndef CLCOMMANDPROCESSOR_H
27 #define CLCOMMANDPROCESSOR_H
28
29 #include <wx/event.h>
30 #include "asyncprocess.h"
31 #include <wx/string.h>
32 #include "codelite_exports.h"
33 #include "cl_command_event.h"
34
35 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_COMMAND_PROCESSOR_ENDED, clCommandEvent);
36
37 // A process printed output to stdout/err (the process output is accessible via event.GetString())
38 // The caller may handle this event, incase the process is waiting for input the caller
39 // may send its input via event.SetString()
40 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_COMMAND_PROCESSOR_OUTPUT, clCommandEvent);
41
42 class clCommandProcessor;
43 typedef bool (wxEvtHandler::*clCommandProcessorFunc)(const clCommandProcessor* processor);
44 class WXDLLIMPEXP_CL clCommandProcessor : public wxEvtHandler
45 {
46 clCommandProcessor* m_next;
47 clCommandProcessor* m_prev;
48 IProcess* m_process;
49 wxString m_command;
50 wxString m_workingDirectory;
51 size_t m_processFlags;
52 wxString m_output;
53
54 clCommandProcessorFunc m_postExecCallback;
55 wxEvtHandler* m_obj;
56
57 protected:
58 void DeleteChain();
59 clCommandProcessor* GetFirst();
60 clCommandProcessor* GetActiveProcess();
61
62 public:
63 clCommandProcessor(const wxString& command, const wxString& wd, size_t processFlags = IProcessCreateDefault);
64 virtual ~clCommandProcessor();
65
66 void ExecuteCommand();
67
68 const wxString& GetCommand() const { return m_command; }
69 void SetCommand(const wxString& command) { this->m_command = command; }
70
71 const wxString& GetOutput() const { return m_output; }
72 const wxString& GetWorkingDirectory() const { return m_workingDirectory; }
73
74 void SetWorkingDirectory(const wxString& workingDirectory) { this->m_workingDirectory = workingDirectory; }
75 void SetPrev(clCommandProcessor* prev) { this->m_prev = prev; }
76 clCommandProcessor* GetPrev() { return m_prev; }
77 clCommandProcessor* GetNext() { return m_next; }
78 void SetNext(clCommandProcessor* next) { this->m_next = next; }
79
80 IProcess* GetProcess() { return m_process; }
81 /**
82 * @brief set a callback to be called by the processor when the current command execution
83 * is completed. The callback signature is:
84 * bool Class::CallbackName(const clCommandProcessor* processor)
85 * if the callback returns false, the execution of the rest of the chain is stopped
86 */
87 void SetPostExecCallback(wxEvtHandler* handler, clCommandProcessorFunc func)
88 {
89 m_obj = handler;
90 m_postExecCallback = func;
91 }
92
93 /**
94 * @brief link two command so they will be executed one after the other
95 * @return a pointer to the next command ("next")
96 */
97 clCommandProcessor* Link(clCommandProcessor* next);
98
99 /**
100 * @brief terminate the process. If we are part of the chain, search the active process
101 * within the chain and terminate it (this will cause the next process to start)
102 */
103 void Terminate();
104
105 void OnProcessOutput(clProcessEvent& event);
106 void OnProcessTerminated(clProcessEvent& event);
107 };
108
109 #endif // CLCOMMANDPROCESSOR_H