1 /* -------------------------------------------------------------
3 dict.h (part of The KDE Dictionary Client)
5 Copyright (C) 2000-2001 Christian Gebauer <gebauer@kde.org>
6 (C) by Matthias Hölzer 1998
8 This file is distributed under the Artistic License.
9 See LICENSE for details.
11 -------------------------------------------------------------
13 JobData used for data transfer between Client and Interface
14 DictAsyncClient all network related stuff happens here in an asynchrous thread
15 DictInterface interface for DictAsyncClient, job management
17 -------------------------------------------------------------*/
24 #include <qsocketnotifier.h>
26 class QSocketNotifier
;
30 //********* JobData ******************************************
38 enum QueryType
{ //type of transaction
49 enum ErrType
{ // error codes
51 ErrCommunication
, // display result!
54 ErrConnect
, // display result!
58 ErrCommandNotImplemented
,
64 ErrServerError
, // display result!
68 JobData(QueryType Ntype
,bool NnewServer
,QString
const& Nserver
,int Nport
,
69 int NidleHold
, int Ntimeout
, int NpipeSize
, QString
const& Nencoding
, bool NAuthEnabled
,
70 QString
const& Nuser
, QString
const& Nsecret
, unsigned int NheadLayout
);
85 int port
, timeout
, pipeSize
, idleHold
;
89 QStringList databases
,strategies
;
91 unsigned int headLayout
;
95 //********* DictAsyncClient ******************************************
103 DictAsyncClient(int NfdPipeIn
, int NfdPipeOut
);
106 static void* startThread(void* pseudoThis
);
108 void insertJob(JobData
*newJob
);
113 void waitForWork(); // main loop
115 bool getDefinitions();
117 void showDatabases();
119 void showStrategies();
123 void openConnection(); // connect, handshake and authorization
125 void doQuit(); // send "quit" without timeout, without checks, close connection
126 bool waitForRead(); // used by getNextIntoBuffer()
127 bool waitForWrite(); // used by sendBuffer() & connect()
128 void clearPipe(); // remove start/stop signal
130 bool sendBuffer(); // send cmdBuffer to the server
131 bool getNextLine(); // set thisLine to next complete line of input
132 bool nextResponseOk(int code
); // reads next line and checks the response code
133 bool getNextResponse(int &code
); // reads next line and returns the response code
136 void resultAppend(const char* str
);
137 void resultAppend(QString str
);
142 const unsigned int inputSize
;
143 char *thisLine
, *nextLine
, *inputEnd
;
144 int fdPipeIn
,fdPipeOut
; //IPC-Pipes to/from async thread
145 int tcpSocket
,timeout
,idleHold
;
150 //********* DictInterface *************************************************
152 class DictInterface
: public QObject
163 void serverChanged(); // inform the client when server settings get changed
164 void stop(); // cancel all pending jobs
166 void define(const QString
&query
);
167 void getDefinitions(QStringList query
);
168 void match(const QString
&query
);
169 void showDbInfo(const QString
&db
); // fetch detailed db info
170 void showDatabases(); // fetch misc. info...
171 void showStrategies();
173 void updateServer(); // get info about databases & strategies the server knows
177 void infoReady(); // updateServer done
178 void resultReady(const QString
&result
, const QString
&query
); // define done
179 void matchReady(const QStringList
&result
); // match done
180 void started(const QString
&message
); // Client is active now, activate indicator
181 void stopped(const QString
&message
); // Client is now halted, deactivate indicator
189 JobData
* generateQuery(JobData::QueryType type
, QString query
);
190 void insertJob(JobData
* job
); // insert in job list, if nesscary cancel/remove previous jobs
191 void startClient(); // send start signal
192 void cleanPipes(); // empty the pipes, so that notifier stops firing
194 QSocketNotifier
*notifier
;
195 int fdPipeIn
[2],fdPipeOut
[2]; //IPC-Pipes to/from async thread
197 DictAsyncClient
*client
;
198 QPtrList
<JobData
> jobList
;
199 bool newServer
,clientDoneInProgress
;
202 extern DictInterface
*interface
;