OSDN Git Service

9dccc6819ca5616d18d93ff9bba2698d850500c1
[qt-creator-jp/qt-creator-jp.git] / src / libs / utils / ssh / sshchannel_p.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
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 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef SSHCHANNEL_P_H
35 #define SSHCHANNEL_P_H
36
37 #include <QtCore/QByteArray>
38 #include <QtCore/QObject>
39 #include <QtCore/QString>
40
41 QT_FORWARD_DECLARE_CLASS(QTimer)
42
43 namespace Utils {
44 namespace Internal {
45
46 struct SshChannelExitSignal;
47 struct SshChannelExitStatus;
48 class SshIncomingPacket;
49 class SshSendFacility;
50
51 class AbstractSshChannel : public QObject
52 {
53     Q_OBJECT
54 public:
55     enum ChannelState {
56         Inactive, SessionRequested, SessionEstablished, CloseRequested, Closed
57     };
58
59     ChannelState channelState() const { return m_state; }
60     void setChannelState(ChannelState state);
61
62     void setError(const QString &error) { m_errorString = error; }
63     QString errorString() const { return m_errorString; }
64
65     quint32 localChannelId() const { return m_localChannel; }
66     quint32 remoteChannel() const { return m_remoteChannel; }
67
68     virtual void handleChannelSuccess()=0;
69     virtual void handleChannelFailure()=0;
70
71     virtual void closeHook()=0;
72
73     void handleOpenSuccess(quint32 remoteChannelId, quint32 remoteWindowSize,
74         quint32 remoteMaxPacketSize);
75     void handleOpenFailure(const QString &reason);
76     void handleWindowAdjust(quint32 bytesToAdd);
77     void handleChannelEof();
78     void handleChannelClose();
79     void handleChannelData(const QByteArray &data);
80     void handleChannelExtendedData(quint32 type, const QByteArray &data);
81     void handleChannelRequest(const SshIncomingPacket &packet);
82
83     void requestSessionStart();
84     void sendData(const QByteArray &data);
85     void closeChannel();
86
87     virtual ~AbstractSshChannel();
88
89     static const int ReplyTimeout = 10000; // milli seconds
90
91 signals:
92     void timeout();
93
94 protected:
95     AbstractSshChannel(quint32 channelId, SshSendFacility &sendFacility);
96
97     quint32 maxDataSize() const;
98     void checkChannelActive();
99
100     SshSendFacility &m_sendFacility;
101     QTimer * const m_timeoutTimer;
102
103 private:
104     virtual void handleOpenSuccessInternal()=0;
105     virtual void handleOpenFailureInternal()=0;
106     virtual void handleChannelDataInternal(const QByteArray &data)=0;
107     virtual void handleChannelExtendedDataInternal(quint32 type,
108         const QByteArray &data)=0;
109     virtual void handleExitStatus(const SshChannelExitStatus &exitStatus)=0;
110     virtual void handleExitSignal(const SshChannelExitSignal &signal)=0;
111
112     void setState(ChannelState newState);
113     void flushSendBuffer();
114     int handleChannelOrExtendedChannelData(const QByteArray &data);
115
116     const quint32 m_localChannel;
117     quint32 m_remoteChannel;
118     quint32 m_localWindowSize;
119     quint32 m_remoteWindowSize;
120     quint32 m_remoteMaxPacketSize;
121     ChannelState m_state;
122     QByteArray m_sendBuffer;
123     QString m_errorString;
124 };
125
126 } // namespace Internal
127 } // namespace Utils
128
129 #endif // SSHCHANNEL_P_H