00001 #ifndef __TRANSFERTHREAD_H__
00002 #define __TRANSFERTHREAD_H__
00003
00004 #include <util/thread.h>
00005 #include <util/message.h>
00006 #include <util/locker.h>
00007 #include <list>
00008 #include <queue>
00009
00010 #include <curl/curl.h>
00011
00012 using namespace os;
00013
00014 class Server;
00015
00016 class os::Handler;
00017
00020 enum CurlHandleStatus {
00021 HANDLE_IDLE = -1,
00022 HANDLE_INVALID = -2
00023 };
00024
00028 typedef struct {
00029 CURL* m_pHandle;
00030 int m_nStatus;
00031 } CurlHandle_s;
00032
00039 class TransferThread : public Thread
00040 {
00041 public:
00042 TransferThread( Server* pcServer );
00043 ~TransferThread();
00044
00045
00046 int32 Run();
00047
00048
00049 int Lock();
00050 int Unlock();
00051
00052
00053 int SendMessage( int nCode );
00054 int SendMessage( Message* pcMsg );
00055
00056 private:
00057 void _Notify();
00058
00059 void _ProcessMessages();
00060
00061 void _Schedule();
00062
00063 void _Initialize();
00064
00065 void _AddNode( int nType, const String& zLocalPath, const String& zRemotePath, Handler* pcTarget );
00066 void _PauseNode( int nID );
00067 void _ResumeNode( int nID );
00068 void _CancelNode( int nID );
00069 void _CleanupNode( int nNode );
00070
00071
00072 void _DeleteFile( const String& zPath );
00073 void _RemoveDir( const String& zPath );
00074 void _MakeDir( const String& zPath );
00075 void _Rename( const String& zOldPath, const String& zNewPath );
00076
00077 void _Close();
00078
00080 Server* m_pcServer;
00081
00082
00083 int m_nReadPipe;
00084 int m_nWritePipe;
00085 std::queue< Message* > m_apcMessages;
00086 Locker* m_pcLock;
00088
00089 CURLM* m_pCurlMultiHandle;
00090 std::vector< CurlHandle_s* > m_asHandles;
00092 friend class Server;
00093 };
00094
00095
00096
00097 #endif
00098
00099
00100
00101
00102
00103