00001 #ifndef __QUEUENODE_H__
00002 #define __QUEUENODE_H__
00003
00004 #include <storage/file.h>
00005 #include <util/string.h>
00006 #include <util/handler.h>
00007 #include <curl/curl.h>
00008
00009 using namespace os;
00010
00011
00012 class Server;
00013
00014
00015 enum {
00016 NODE_QUEUED = 1,
00017 NODE_RUNNING = 2
00018 };
00019
00020 enum {
00021 NODE_DOWNLOAD,
00022 NODE_UPLOAD,
00023 NODE_DIRLIST
00024 };
00025
00030 class QueueNode
00031 {
00032 protected:
00033 QueueNode( Server* pcServer, const String& zLocalPath, const String& zRemotePath, int nType, int nID );
00034
00035 public:
00036 virtual ~QueueNode();
00037
00041 int GetStatus()
00042 {
00043 return( m_nStatus );
00044 }
00045
00049 int GetType()
00050 {
00051 return( m_nType );
00052 }
00053
00058 float GetProgress()
00059 {
00060 return( 0 );
00061 }
00062
00063 private:
00064
00073 virtual size_t Read( void* pBuf, size_t nSize )
00074 {
00075 printf( "Warning: QueueNode::Read() called!\n" );
00076 return( 0 );
00077 }
00078
00086 virtual size_t Write( void* pBuf, size_t nSize )
00087 {
00088 printf( "Warning: QueueNode::Write() called!\n" );
00089 return( 0 );
00090 }
00091
00098 virtual int Seek( curl_off_t nOffset, int nOrigin )
00099 {
00100 printf( "Warning: QueueNode::Seek() called!\n" );
00101 return( -1 );
00102 }
00103
00114 virtual int ProgressBar( double fDownTotal, double fDownNow, double fUpTotal, double fUpNow )
00115 {
00116 printf( "Warning: QueneNode::ProgressBar() called!\n" );
00117 return( 0 );
00118 }
00119
00120 static size_t ReadCallback( void* pBuf, size_t nSize, size_t nMult, void* pCookie );
00121 static size_t WriteCallback( void* pBuf, size_t nSize, size_t nMult, void* pCookie );
00122 static int SeekCallback( void* pCookie, curl_off_t nOffset, int nOrigin );
00123 static int ProgressBarCallback( void* pCookie, double fDownTotal, double fDownNow, double fUpTotal, double fUpNow );
00124
00125 protected:
00126 virtual CURLcode SetupCurlHandleForTransfer( CURL* pHandle );
00127
00129 Server* m_pcServer;
00130
00132 String m_zLocalPath;
00133
00135 String m_zRemotePath;
00136
00144 int m_nType;
00145
00153 int m_nStatus;
00154
00156 int m_nID;
00157
00158 friend class TransferThread;
00159 };
00160
00165 class DownloadNode : public QueueNode
00166 {
00167 public:
00168
00169 private:
00170 DownloadNode( Server* pcServer, const String& zLocalPath, const String& zRemotePath, int nID );
00171 ~DownloadNode();
00172 CURLcode SetupCurlHandleForTransfer( CURL* pHandle );
00173
00174 size_t Write( void* pBuf, size_t nSize );
00175 int Seek( curl_off_t nOffset, int nOrigin );
00176 int ProgressBar( double fDownTotal, double fDownNow, double fUpTotal, double fUpNow );
00177
00178 File* m_pcFile;
00180 friend class TransferThread;
00181 };
00182
00187 class UploadNode : public QueueNode
00188 {
00189 private:
00190 UploadNode( Server* pcServer, const String& zLocalPath, const String& zRemotePath, int nID );
00191 ~UploadNode();
00192 CURLcode SetupCurlHandleForTransfer( CURL* pHandle );
00193
00194 size_t Read( void* pBuf, size_t nSize );
00195 int Seek( curl_off_t nOffset, int nOrigin );
00196 int ProgressBar( double fDownTotal, double fDownNow, double fUpTotal, double fUpNow );
00197
00198 File* m_pcFile;
00200 friend class TransferThread;
00201 };
00202
00207 class DirListNode : public QueueNode
00208 {
00209 private:
00210 DirListNode( Server* pcServer, const String& zRemotePath, Handler* pcTarget, int nID );
00211 ~DirListNode();
00212 CURLcode SetupCurlHandleForTransfer( CURL* pHandle );
00213
00214 size_t Write( void* pBuf, size_t nSize );
00215 int ProgressBar( double fDownTotal, double fDownNow, double fUpTotal, double fUpNow );
00216
00218 Handler* m_pcTarget;
00219
00221 bool m_bInitial;
00222
00226 String m_zLastLineFragment;
00227
00228 friend class TransferThread;
00229 };
00230
00231 #endif
00232
00233
00234
00235