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 -------------------------------------------------------------*/
23 #include <q3ptrlist.h>
24 #include <qsocketnotifier.h>
28 class QSocketNotifier
;
32 //********* JobData ******************************************
40 enum QueryType
{ //type of transaction
51 enum ErrType
{ // error codes
53 ErrCommunication
, // display result!
56 ErrConnect
, // display result!
60 ErrCommandNotImplemented
,
66 ErrServerError
, // display result!
70 JobData(QueryType Ntype
,bool NnewServer
,QString
const& Nserver
,int Nport
,
71 int NidleHold
, int Ntimeout
, int NpipeSize
, QString
const& Nencoding
, bool NAuthEnabled
,
72 QString
const& Nuser
, QString
const& Nsecret
, unsigned int NheadLayout
);
87 int port
, timeout
, pipeSize
, idleHold
;
91 QStringList databases
,strategies
;
93 unsigned int headLayout
;
97 //********* DictAsyncClient ******************************************
100 class DictAsyncClient
105 DictAsyncClient(int NfdPipeIn
, int NfdPipeOut
);
108 static void* startThread(void* pseudoThis
);
110 void insertJob(JobData
*newJob
);
115 void waitForWork(); // main loop
117 bool getDefinitions();
119 void showDatabases();
121 void showStrategies();
125 void openConnection(); // connect, handshake and authorization
127 void doQuit(); // send "quit" without timeout, without checks, close connection
128 bool waitForRead(); // used by getNextIntoBuffer()
129 bool waitForWrite(); // used by sendBuffer() & connect()
130 void clearPipe(); // remove start/stop signal
132 bool sendBuffer(); // send cmdBuffer to the server
133 bool getNextLine(); // set thisLine to next complete line of input
134 bool nextResponseOk(int code
); // reads next line and checks the response code
135 bool getNextResponse(int &code
); // reads next line and returns the response code
138 void resultAppend(const char* str
);
139 void resultAppend(QString str
);
144 const unsigned int inputSize
;
145 char *thisLine
, *nextLine
, *inputEnd
;
146 int fdPipeIn
,fdPipeOut
; //IPC-Pipes to/from async thread
147 int tcpSocket
,timeout
,idleHold
;
152 //********* DictInterface *************************************************
154 class DictInterface
: public QObject
165 void serverChanged(); // inform the client when server settings get changed
166 void stop(); // cancel all pending jobs
168 void define(const QString
&query
);
169 void getDefinitions(QStringList query
);
170 void match(const QString
&query
);
171 void showDbInfo(const QString
&db
); // fetch detailed db info
172 void showDatabases(); // fetch misc. info...
173 void showStrategies();
175 void updateServer(); // get info about databases & strategies the server knows
179 void infoReady(); // updateServer done
180 void resultReady(const QString
&result
, const QString
&query
); // define done
181 void matchReady(const QStringList
&result
); // match done
182 void started(const QString
&message
); // Client is active now, activate indicator
183 void stopped(const QString
&message
); // Client is now halted, deactivate indicator
191 JobData
* generateQuery(JobData::QueryType type
, QString query
);
192 void insertJob(JobData
* job
); // insert in job list, if nesscary cancel/remove previous jobs
193 void startClient(); // send start signal
194 void cleanPipes(); // empty the pipes, so that notifier stops firing
196 QSocketNotifier
*notifier
;
197 int fdPipeIn
[2],fdPipeOut
[2]; //IPC-Pipes to/from async thread
199 DictAsyncClient
*client
;
200 Q3PtrList
<JobData
> jobList
;
201 bool newServer
,clientDoneInProgress
;
204 extern DictInterface
*interface
;