qlocalsocket.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtNetwork module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QLOCALSOCKET_H
00043 #define QLOCALSOCKET_H
00044 
00045 #include <QtCore/qiodevice.h>
00046 #include <QtNetwork/qabstractsocket.h>
00047 
00048 QT_BEGIN_HEADER
00049 
00050 QT_BEGIN_NAMESPACE
00051 
00052 QT_MODULE(Network)
00053 
00054 #ifndef QT_NO_LOCALSOCKET
00055 
00056 class QLocalSocketPrivate;
00057 
00058 class Q_NETWORK_EXPORT QLocalSocket : public QIODevice
00059 {
00060     Q_OBJECT
00061     Q_DECLARE_PRIVATE(QLocalSocket)
00062 
00063 public:
00064     enum LocalSocketError
00065     {
00066         ConnectionRefusedError = QAbstractSocket::ConnectionRefusedError,
00067         PeerClosedError = QAbstractSocket::RemoteHostClosedError,
00068         ServerNotFoundError = QAbstractSocket::HostNotFoundError,
00069         SocketAccessError = QAbstractSocket::SocketAccessError,
00070         SocketResourceError = QAbstractSocket::SocketResourceError,
00071         SocketTimeoutError = QAbstractSocket::SocketTimeoutError,
00072         DatagramTooLargeError = QAbstractSocket::DatagramTooLargeError,
00073         ConnectionError = QAbstractSocket::NetworkError,
00074         UnsupportedSocketOperationError = QAbstractSocket::UnsupportedSocketOperationError,
00075         UnknownSocketError = QAbstractSocket::UnknownSocketError
00076     };
00077 
00078     enum LocalSocketState
00079     {
00080         UnconnectedState = QAbstractSocket::UnconnectedState,
00081         ConnectingState = QAbstractSocket::ConnectingState,
00082         ConnectedState = QAbstractSocket::ConnectedState,
00083         ClosingState = QAbstractSocket::ClosingState
00084     };
00085 
00086     QLocalSocket(QObject *parent = 0);
00087     ~QLocalSocket();
00088 
00089     void connectToServer(const QString &name, OpenMode openMode = ReadWrite);
00090     void disconnectFromServer();
00091 
00092     QString serverName() const;
00093     QString fullServerName() const;
00094 
00095     void abort();
00096     virtual bool isSequential() const;
00097     virtual qint64 bytesAvailable() const;
00098     virtual qint64 bytesToWrite() const;
00099     virtual bool canReadLine() const;
00100     virtual void close();
00101     LocalSocketError error() const;
00102     bool flush();
00103     bool isValid() const;
00104     qint64 readBufferSize() const;
00105     void setReadBufferSize(qint64 size);
00106 
00107     bool setSocketDescriptor(quintptr socketDescriptor,
00108                              LocalSocketState socketState = ConnectedState,
00109                              OpenMode openMode = ReadWrite);
00110     quintptr socketDescriptor() const;
00111 
00112     LocalSocketState state() const;
00113     bool waitForBytesWritten(int msecs = 30000);
00114     bool waitForConnected(int msecs = 30000);
00115     bool waitForDisconnected(int msecs = 30000);
00116     bool waitForReadyRead(int msecs = 30000);
00117 
00118 Q_SIGNALS:
00119     void connected();
00120     void disconnected();
00121     void error(QLocalSocket::LocalSocketError socketError);
00122     void stateChanged(QLocalSocket::LocalSocketState socketState);
00123 
00124 protected:
00125     virtual qint64 readData(char*, qint64);
00126     virtual qint64 writeData(const char*, qint64);
00127 
00128 private:
00129     Q_DISABLE_COPY(QLocalSocket)
00130 #if defined(QT_LOCALSOCKET_TCP)
00131     Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState))
00132     Q_PRIVATE_SLOT(d_func(), void _q_error(QAbstractSocket::SocketError))
00133 #elif defined(Q_OS_WIN)
00134     Q_PRIVATE_SLOT(d_func(), void _q_notified())
00135     Q_PRIVATE_SLOT(d_func(), void _q_canWrite())
00136     Q_PRIVATE_SLOT(d_func(), void _q_pipeClosed())
00137     Q_PRIVATE_SLOT(d_func(), void _q_emitReadyRead())
00138 #else
00139     Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState))
00140     Q_PRIVATE_SLOT(d_func(), void _q_error(QAbstractSocket::SocketError))
00141     Q_PRIVATE_SLOT(d_func(), void _q_connectToSocket())
00142     Q_PRIVATE_SLOT(d_func(), void _q_abortConnectionAttempt())
00143 #endif
00144 };
00145 
00146 #ifndef QT_NO_DEBUG_STREAM
00147 #include <QtCore/qdebug.h>
00148 Q_NETWORK_EXPORT QDebug operator<<(QDebug, QLocalSocket::LocalSocketError);
00149 Q_NETWORK_EXPORT QDebug operator<<(QDebug, QLocalSocket::LocalSocketState);
00150 #endif
00151 
00152 #endif // QT_NO_LOCALSOCKET
00153 
00154 QT_END_NAMESPACE
00155 
00156 QT_END_HEADER
00157 
00158 #endif // QLOCALSOCKET_H