src/network/socket/qlocalsocket.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtNetwork module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    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 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QLOCALSOCKET_H
       
    43 #define QLOCALSOCKET_H
       
    44 
       
    45 #include <QtCore/qiodevice.h>
       
    46 #include <QtNetwork/qabstractsocket.h>
       
    47 
       
    48 QT_BEGIN_HEADER
       
    49 
       
    50 QT_BEGIN_NAMESPACE
       
    51 
       
    52 QT_MODULE(Network)
       
    53 
       
    54 #ifndef QT_NO_LOCALSOCKET
       
    55 
       
    56 class QLocalSocketPrivate;
       
    57 
       
    58 class Q_NETWORK_EXPORT QLocalSocket : public QIODevice
       
    59 {
       
    60     Q_OBJECT
       
    61     Q_DECLARE_PRIVATE(QLocalSocket)
       
    62 
       
    63 public:
       
    64     enum LocalSocketError
       
    65     {
       
    66         ConnectionRefusedError = QAbstractSocket::ConnectionRefusedError,
       
    67         PeerClosedError = QAbstractSocket::RemoteHostClosedError,
       
    68         ServerNotFoundError = QAbstractSocket::HostNotFoundError,
       
    69         SocketAccessError = QAbstractSocket::SocketAccessError,
       
    70         SocketResourceError = QAbstractSocket::SocketResourceError,
       
    71         SocketTimeoutError = QAbstractSocket::SocketTimeoutError,
       
    72         DatagramTooLargeError = QAbstractSocket::DatagramTooLargeError,
       
    73         ConnectionError = QAbstractSocket::NetworkError,
       
    74         UnsupportedSocketOperationError = QAbstractSocket::UnsupportedSocketOperationError,
       
    75         UnknownSocketError = QAbstractSocket::UnknownSocketError
       
    76     };
       
    77 
       
    78     enum LocalSocketState
       
    79     {
       
    80         UnconnectedState = QAbstractSocket::UnconnectedState,
       
    81         ConnectingState = QAbstractSocket::ConnectingState,
       
    82         ConnectedState = QAbstractSocket::ConnectedState,
       
    83         ClosingState = QAbstractSocket::ClosingState
       
    84     };
       
    85 
       
    86     QLocalSocket(QObject *parent = 0);
       
    87     ~QLocalSocket();
       
    88 
       
    89     void connectToServer(const QString &name, OpenMode openMode = ReadWrite);
       
    90     void disconnectFromServer();
       
    91 
       
    92     QString serverName() const;
       
    93     QString fullServerName() const;
       
    94 
       
    95     void abort();
       
    96     virtual bool isSequential() const;
       
    97     virtual qint64 bytesAvailable() const;
       
    98     virtual qint64 bytesToWrite() const;
       
    99     virtual bool canReadLine() const;
       
   100     virtual void close();
       
   101     LocalSocketError error() const;
       
   102     bool flush();
       
   103     bool isValid() const;
       
   104     qint64 readBufferSize() const;
       
   105     void setReadBufferSize(qint64 size);
       
   106 
       
   107     bool setSocketDescriptor(quintptr socketDescriptor,
       
   108                              LocalSocketState socketState = ConnectedState,
       
   109                              OpenMode openMode = ReadWrite);
       
   110     quintptr socketDescriptor() const;
       
   111 
       
   112     LocalSocketState state() const;
       
   113     bool waitForBytesWritten(int msecs = 30000);
       
   114     bool waitForConnected(int msecs = 30000);
       
   115     bool waitForDisconnected(int msecs = 30000);
       
   116     bool waitForReadyRead(int msecs = 30000);
       
   117 
       
   118 Q_SIGNALS:
       
   119     void connected();
       
   120     void disconnected();
       
   121     void error(QLocalSocket::LocalSocketError socketError);
       
   122     void stateChanged(QLocalSocket::LocalSocketState socketState);
       
   123 
       
   124 protected:
       
   125     virtual qint64 readData(char*, qint64);
       
   126     virtual qint64 writeData(const char*, qint64);
       
   127 
       
   128 private:
       
   129     Q_DISABLE_COPY(QLocalSocket)
       
   130 #if defined(QT_LOCALSOCKET_TCP)
       
   131     Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState))
       
   132     Q_PRIVATE_SLOT(d_func(), void _q_error(QAbstractSocket::SocketError))
       
   133 #elif defined(Q_OS_WIN)
       
   134     Q_PRIVATE_SLOT(d_func(), void _q_notified())
       
   135     Q_PRIVATE_SLOT(d_func(), void _q_canWrite())
       
   136     Q_PRIVATE_SLOT(d_func(), void _q_pipeClosed())
       
   137     Q_PRIVATE_SLOT(d_func(), void _q_emitReadyRead())
       
   138 #else
       
   139     Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QAbstractSocket::SocketState))
       
   140     Q_PRIVATE_SLOT(d_func(), void _q_error(QAbstractSocket::SocketError))
       
   141     Q_PRIVATE_SLOT(d_func(), void _q_connectToSocket())
       
   142     Q_PRIVATE_SLOT(d_func(), void _q_abortConnectionAttempt())
       
   143 #endif
       
   144 };
       
   145 
       
   146 #ifndef QT_NO_DEBUG_STREAM
       
   147 #include <QtCore/qdebug.h>
       
   148 Q_NETWORK_EXPORT QDebug operator<<(QDebug, QLocalSocket::LocalSocketError);
       
   149 Q_NETWORK_EXPORT QDebug operator<<(QDebug, QLocalSocket::LocalSocketState);
       
   150 #endif
       
   151 
       
   152 #endif // QT_NO_LOCALSOCKET
       
   153 
       
   154 QT_END_NAMESPACE
       
   155 
       
   156 QT_END_HEADER
       
   157 
       
   158 #endif // QLOCALSOCKET_H