knode
knprotocolclient.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef KNPROTOCOLCLIENT_H
00018 #define KNPROTOCOLCLIENT_H
00019
00020 #include <QDateTime>
00021 #include <QThread>
00022 #include <q3cstring.h>
00023
00024 #include <Q3StrList>
00025
00026 #include <knserverinfo.h>
00027
00028 class Q3StrList;
00029 class KNJobData;
00030 struct in_addr;
00031
00032
00033 class KNProtocolClient : public QThread {
00034
00035 public:
00036 enum threadSignal { TSworkDone=0, TSjobStarted=1, TSconnect=2, TSloadGrouplist=3,
00037 TSwriteGrouplist=4, TSdownloadGrouplist=5, TSdownloadNew=6,
00038 TSsortNew=7, TSdownloadArticle=8, TSsendArticle=9, TSsendMail=10,
00039 TSprogressUpdate=11, TSdownloadDesc=12, TSdownloadNewGroups=13 };
00040
00041 KNProtocolClient(int NfdPipeIn, int NfdPipeOut);
00042 ~KNProtocolClient();
00043
00044 virtual void run();
00045
00046 void insertJob(KNJobData *newJob);
00047 void removeJob();
00048
00049 void updatePercentage(int percent);
00050
00051 int getProgressValue() const { return progressValue; }
00053 int getByteCount() const { return byteCount; }
00054 bool isInByteCountMode() const { return byteCountMode; }
00055
00056 void terminateClient() { mTerminate = true; }
00057 protected:
00058
00060 void waitForWork();
00062 virtual void processJob();
00063
00065 virtual bool openConnection();
00066 bool isConnected() { return (tcpSocket!=-1); }
00068 virtual void closeConnection();
00069
00071 virtual bool sendCommand(const QByteArray &cmd, int &rep);
00073 bool sendCommandWCheck(const QByteArray &cmd, int rep);
00075 bool sendMsg(const QByteArray &msg);
00076
00078 bool getNextLine();
00080 char* getCurrentLine() { return thisLine; }
00082 bool getMsg(Q3StrList &msg);
00084 bool getNextResponse(int &rep);
00086 bool checkNextResponse(int rep);
00087
00089 virtual void handleErrors();
00090
00091 void sendSignal(threadSignal s);
00092
00093 KNJobData *job;
00094 KNServerInfo account;
00096 QString errorPrefix;
00097 int progressValue, predictedLines, doneLines;
00098 bool byteCountMode;
00099
00100 private:
00102 bool waitForRead();
00104 bool waitForWrite();
00105 void closeSocket();
00107 bool sendStr(const QByteArray &str);
00109 void clearPipe();
00110
00111 char *input;
00112 char *thisLine, *nextLine, *inputEnd;
00113 unsigned int inputSize;
00115 int fdPipeIn,fdPipeOut;
00116 int tcpSocket;
00118 int byteCount;
00119 QTime timer;
00120 bool mTerminate;
00121
00122 };
00123
00124 #endif