Debian Codegraph @

CodeLite/clSSHChannel.hpp

raw
1 #ifndef CLSSHCHANNEL_H
2 #define CLSSHCHANNEL_H
3
4 #if USE_SFTP
5
6 #include "cl_ssh.h"
7 #include "codelite_exports.h"
8 #include <wx/msgqueue.h>
9
10 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_SSH_CHANNEL_READ_ERROR, clCommandEvent);
11 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_SSH_CHANNEL_WRITE_ERROR, clCommandEvent);
12 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_SSH_CHANNEL_READ_OUTPUT, clCommandEvent);
13 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_SSH_CHANNEL_READ_STDERR, clCommandEvent);
14 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_SSH_CHANNEL_CLOSED, clCommandEvent);
15 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_SSH_CHANNEL_PTY, clCommandEvent);
16
17 class clJoinableThread;
18 class WXDLLIMPEXP_CL clSSHChannel : public wxEvtHandler
19 {
20 public:
21 typedef wxSharedPtr<clSSHChannel> Ptr_t;
22 enum eChannelType {
23 kInterativeMode,
24 kRemoteCommand,
25 };
26
27 public:
28 struct Message {
29 wxString buffer;
30 bool raw = false;
31 };
32
33 protected:
34 clSSH::Ptr_t m_ssh;
35 SSHChannel_t m_channel = nullptr;
36 clJoinableThread* m_thread = nullptr;
37 wxMessageQueue<Message> m_Queue;
38 wxEvtHandler* m_owner = nullptr;
39 eChannelType m_type = kRemoteCommand;
40 bool m_wantStderr = false;
41
42 protected:
43 wxString BuildError(const wxString& prefix) const;
44 void DoWrite(const wxString& buffer, bool raw);
45
46 void OnReadError(clCommandEvent& event);
47 void OnWriteError(clCommandEvent& event);
48 void OnReadOutput(clCommandEvent& event);
49 void OnReadStderr(clCommandEvent& event);
50 void OnChannelClosed(clCommandEvent& event);
51 void OnChannelPty(clCommandEvent& event);
52
53 public:
54 clSSHChannel(clSSH::Ptr_t ssh, clSSHChannel::eChannelType type, wxEvtHandler* owner, bool wantStderrEvents = false);
55 virtual ~clSSHChannel();
56
57 /**
58 * @brief is the channel opened?
59 */
60 bool IsOpen() const { return m_channel != nullptr; }
61
62 /**
63 * @brief Open the channel
64 * @throw clException
65 */
66 void Open();
67
68 /**
69 * @brief close the channel
70 */
71 void Close();
72
73 /**
74 * @brief execute remote command
75 * The reply will be returned to 'sink' object in form of events
76 */
77 void Execute(const wxString& command);
78
79 /**
80 * @brief write message to the channel
81 */
82 void Write(const wxString& message);
83
84 /**
85 * @brief write the buffer as is
86 */
87 void WriteRaw(const wxString& message);
88
89 bool IsInteractive() const { return m_type == kInterativeMode; }
90
91 /**
92 * @brief Send a signal to remote process
93 */
94 void SendSignal(wxSignal sig);
95
96 /**
97 * @brief detach from the remote process (this does not kill it)
98 */
99 void Detach();
100 };
101 #endif
102 #endif // CLSSHCHANNEL_H