OSDN Git Service

Merge branch 'master' of scm.dev.nokia.troll.no:creator/mainline
[qt-creator-jp/qt-creator-jp.git] / src / plugins / coreplugin / ssh / sshchannel_p.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #ifndef SSHCHANNEL_P_H
31 #define SSHCHANNEL_P_H
32
33 #include <QtCore/QByteArray>
34 #include <QtCore/QObject>
35 #include <QtCore/QString>
36
37 QT_FORWARD_DECLARE_CLASS(QTimer);
38
39 namespace Core {
40 namespace Internal {
41
42 struct SshChannelExitSignal;
43 struct SshChannelExitStatus;
44 class SshIncomingPacket;
45 class SshSendFacility;
46
47 class AbstractSshChannel : public QObject
48 {
49     Q_OBJECT
50 public:
51     enum ChannelState {
52         Inactive, SessionRequested, SessionEstablished, CloseRequested, Closed
53     };
54
55     ChannelState channelState() const { return m_state; }
56     void setChannelState(ChannelState state);
57
58     void setError(const QString &error) { m_errorString = error; }
59     QString errorString() const { return m_errorString; }
60
61     quint32 localChannelId() const { return m_localChannel; }
62     quint32 remoteChannel() const { return m_remoteChannel; }
63
64     virtual void handleChannelSuccess()=0;
65     virtual void handleChannelFailure()=0;
66
67     virtual void closeHook()=0;
68
69     void handleOpenSuccess(quint32 remoteChannelId, quint32 remoteWindowSize,
70         quint32 remoteMaxPacketSize);
71     void handleOpenFailure(const QString &reason);
72     void handleWindowAdjust(quint32 bytesToAdd);
73     void handleChannelEof();
74     void handleChannelClose();
75     void handleChannelData(const QByteArray &data);
76     void handleChannelExtendedData(quint32 type, const QByteArray &data);
77     void handleChannelRequest(const SshIncomingPacket &packet);
78
79     void requestSessionStart();
80     void sendData(const QByteArray &data);
81     void closeChannel();
82
83     virtual ~AbstractSshChannel();
84
85     static const int ReplyTimeout = 10000; // milli seconds
86
87 signals:
88     void timeout();
89
90 protected:
91     AbstractSshChannel(quint32 channelId, SshSendFacility &sendFacility);
92
93     quint32 maxDataSize() const;
94     void checkChannelActive();
95
96     SshSendFacility &m_sendFacility;
97     QTimer * const m_timeoutTimer;
98
99 private:
100     virtual void handleOpenSuccessInternal()=0;
101     virtual void handleOpenFailureInternal()=0;
102     virtual void handleChannelDataInternal(const QByteArray &data)=0;
103     virtual void handleChannelExtendedDataInternal(quint32 type,
104         const QByteArray &data)=0;
105     virtual void handleExitStatus(const SshChannelExitStatus &exitStatus)=0;
106     virtual void handleExitSignal(const SshChannelExitSignal &signal)=0;
107
108     void setState(ChannelState newState);
109     void flushSendBuffer();
110     int handleChannelOrExtendedChannelData(const QByteArray &data);
111
112     const quint32 m_localChannel;
113     quint32 m_remoteChannel;
114     quint32 m_localWindowSize;
115     quint32 m_remoteWindowSize;
116     quint32 m_remoteMaxPacketSize;
117     ChannelState m_state;
118     QByteArray m_sendBuffer;
119     QString m_errorString;
120 };
121
122 } // namespace Internal
123 } // namespace Core
124
125 #endif // SSHCHANNEL_P_H