00001
00002
00003
00004
00005
00006 #ifndef _POCLIENT_H_
00007 #define _POCLIENT_H_
00008 #include<qobject.h>
00009 #include<string>
00010 #include<vector>
00011 #include<qstring.h>
00012 #include<POAddress.h>
00013
00014
00015
00016 #define MAX_MSG_SIZE (1024*1024*4) // 4MB
00017
00018 using namespace std;
00019
00020 class QSocket;
00021 class POMessage;
00022 class POBoxListMsg;
00023 class POPartialMsg;
00024
00025 class PEXPR_API POClient : public QObject
00026 {
00027 Q_OBJECT
00028 public:
00029 enum CLIENT_STATE { CONNECTED, WAIT_CLIST, DISCONNECTED };
00030 POClient( int fd );
00031 POClient( const string& host, int port );
00032 ~POClient();
00033
00034 string getClientName()const { return m_clientname; }
00035 int getState()const { return m_state; }
00036
00037 vector<string> getAllBoxes()const { return m_clientboxes; }
00038 public slots:
00039 void sendMessage( const POAddress& adr, const POMessage* msg );
00040 void sendMessage( const POMessage* msg );
00041
00042 private slots:
00043 void error( int );
00044 void socketConnected();
00045 void socketClosed();
00046 void read();
00047
00048 signals:
00049 void socketConnected( POClient* client );
00050 void connectionEstablished( POClient* client );
00051 void receivedMessage( const POMessage* msg );
00052 void connectionLost( POClient* );
00053 void newPOBox( const string& clientname, const string& boxname );
00054
00055 private:
00056 void handleSegment( POPartialMsg* msg );
00057 void handleBoxListMsg( const POBoxListMsg* msg );
00058 void removeClientBox( const string& box );
00059
00060 int m_state;
00061 string m_clientname;
00062 vector<string> m_clientboxes;
00063 QSocket* m_socket;
00064 char* m_buffer;
00065 int m_usedsize;
00066 string m_peeradr;
00067 int m_peerport;
00068
00069 POInt m_incommingsize;
00070 vector<POPartialMsg*> m_msgsegments;
00071 };
00072
00073 #endif