2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
22 * @brief Manage a connection with a remote server.
24 * This class can be used to manage a connection with a chess server. Once connected,
25 * it emits the signal @ref receivedLine whenever a new whole line is received.
26 * Partial lines are kept in an internal buffer.
27 * The Connection class supports the use of a helper such as timeseal.
29 class Connection
: public QObject
{
34 QTextStream
* logStream
;
37 QString m_unsent_text
;
46 * Create a new connection object. No actual connection is made
47 * until @ref establish is called.
52 * Destroy the object and kill the helper, if present.
54 virtual ~Connection();
57 * Create an actual connection to an internet host.
58 * @param host Fully qualified name of the host.
59 * @param port Host port to connect to.
60 * @param helper Full path of a helper. A null or empty string if no helper is needed.
61 * @param args Helper arguments. They can optionally contain variabiles which will be expaded
62 * before they are passed to the helper.
63 * Supported variables: $(HOST_NAME), $(HOST_IP), $(PORT).
65 void establish(const char* host
, quint16 port
,
66 const QString
& helper
, const QString
& args
);
69 * Whether the connection has been initialized.
71 inline bool initialized() const { return m_initialized
; }
74 * Set the inizialized flag of the connection. Use this after you have
75 * sent initial commands.
77 inline void setInitialized() { m_initialized
= true; }
81 * Send some text to the server using the connection. A newline will be sent afterwards.
83 void sendText(const QString
&);
84 void lookedUp(const QHostInfo
&host
);
88 * Read data from the socket and appropriate signals.
98 * Emitted when a partial line is received.
100 * @param text Received text.
101 * @param newDataOffset Offset where new data starts.
102 * @note Whenever a partial line is received, is it recorded in an internal buffer,
103 * and an offset is incremented, to distinguish new data from old data
104 * as the next payload arrives.
106 void receivedText(QString text
, int newDataOffset
);
109 * Emitted when a full line is received.
111 * @param line Received line.
112 * @param newDataOffset Offset where new data starts.
116 void receivedLine(QString line
, int newDataOffset
);
119 #endif // CONNECTION_H