queuenode.h

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 #include <vector>
00010 
00011 using namespace os;
00012 
00013 // Prototype for the Server class.
00014 class Server;
00015 
00016 /* Node status enum */
00017 enum {
00018         NODE_QUEUED = 1,
00019         NODE_RUNNING,
00020         NODE_PAUSED
00021 };
00022 
00023 enum {
00024         NODE_DOWNLOAD,
00025         NODE_UPLOAD,
00026         NODE_DIRLIST,
00027         NODE_COMMAND
00028 };
00029 
00034 class QueueNode
00035 {
00036 protected:
00037         QueueNode( Server* pcServer, const String& zLocalPath, const String& zRemotePath, int nType, int nID );
00038 
00039 public:
00040         virtual ~QueueNode();   /* I want this to be private but can't be bothered debugging the compiler errors for now */
00041         
00045         int GetStatus()
00046         {
00047                 return( m_nStatus );
00048         }
00049         
00053         int GetType()
00054         {
00055                 return( m_nType );
00056         }
00057         
00062         float GetProgress()
00063         {
00064                 return( 0 );
00065         }
00066         
00067         String GetRemotePath()
00068         {
00069                 return( m_zRemotePath );
00070         }
00071         
00072         String GetLocalPath()
00073         {
00074                 return( m_zLocalPath );
00075         }
00076 
00078         ssize_t GetDownloadedTotal()
00079         {
00080                 return m_nTotalDownloaded;
00081         }
00082         
00084         ssize_t GetUploadedTotal()
00085         {
00086                 return m_nTotalUploaded;
00087         }
00088 
00090         ssize_t GetTotalSize()
00091         {
00092                 return m_nTotalSize;
00093         }
00094         
00095 private:
00096 
00105         virtual size_t Read( void* pBuf, size_t nSize )
00106         {
00107                 printf( "Warning: QueueNode::Read() called!\n" ); 
00108                 return( 0 );
00109         }
00110         
00118         virtual size_t Write( void* pBuf, size_t nSize )
00119         {
00120                 printf( "Warning: QueueNode::Write() called!\n" );
00121                 return( 0 );
00122         }
00123 
00130         virtual int Seek( curl_off_t nOffset, int nOrigin )
00131         {
00132                 printf( "Warning: QueueNode::Seek() called!\n" );
00133                 return( -1 );
00134         }
00135         
00146         virtual int ProgressBar( double fDownTotal, double fDownNow, double fUpTotal, double fUpNow )
00147         {
00148                 printf( "Warning: QueueNode::ProgressBar() called!\n" );
00149                 return( 0 );
00150         }
00151 
00152         static size_t ReadCallback( void* pBuf, size_t nSize, size_t nMult, void* pCookie );
00153         static size_t WriteCallback( void* pBuf, size_t nSize, size_t nMult, void* pCookie );
00154         static int SeekCallback( void* pCookie, curl_off_t nOffset, int nOrigin );
00155         static int ProgressBarCallback( void* pCookie, double fDownTotal, double fDownNow, double fUpTotal, double fUpNow );
00156 
00157 protected:
00161         void SetDownloadedTotal(ssize_t nSize)
00162         {
00163                 m_nTotalDownloaded = nSize;
00164         }
00165 
00169         void SetUploadedTotal(ssize_t nSize)
00170         {
00171                 m_nTotalUploaded = nSize;
00172         }
00173         
00177         void SetTotalSize(ssize_t nSize)
00178         {
00179                 m_nTotalSize = nSize;
00180         }
00181 
00182 protected:
00183         virtual CURLcode AttachToHandle( CURL* pHandle );
00184         virtual CURLcode RemoveFromHandle( CURL* pHandle );
00185 
00187         Server* m_pcServer;
00188 
00190         String m_zLocalPath;
00191         
00193         String m_zRemotePath;
00194         
00202         int m_nType;
00203         
00211         int m_nStatus;
00212         
00214         int m_nID;
00215         
00216         /* Upload/download totals. */
00217         ssize_t m_nTotalSize;
00218         ssize_t m_nTotalDownloaded;
00219         ssize_t m_nTotalUploaded;
00220         
00221         friend class TransferThread;
00222 };
00223 
00228 class DownloadNode : public QueueNode
00229 {
00230 public:
00231         DownloadNode( Server* pcServer, const String& zLocalPath, const String& zRemotePath, int nID );
00232         ~DownloadNode();
00233 
00234         
00235 private:
00236         CURLcode AttachToHandle( CURL* pHandle );
00237         CURLcode RemoveFromHandle( CURL* pHandle );
00238 
00239         size_t Write( void* pBuf, size_t nSize );
00240         int Seek( curl_off_t nOffset, int nOrigin );
00241         int ProgressBar( double fDownTotal, double fDownNow, double fUpTotal, double fUpNow );
00242 
00243         File* m_pcFile; 
00245         friend class TransferThread;
00246 };
00247 
00252 class UploadNode : public QueueNode
00253 {
00254 public:
00255 
00256         UploadNode( Server* pcServer, const String& zLocalPath, const String& zRemotePath, int nID );
00257         ~UploadNode();
00258 
00259 private:
00260         CURLcode AttachToHandle( CURL* pHandle );
00261         CURLcode RemoveFromHandle( CURL* pHandle );
00262         
00263         size_t Read( void* pBuf, size_t nSize );
00264         int Seek( curl_off_t nOffset, int nOrigin );
00265         int ProgressBar( double fDownTotal, double fDownNow, double fUpTotal, double fUpNow );
00266 
00267         File* m_pcFile; 
00269         friend class TransferThread;
00270 };
00271 
00276 class DirListNode : public QueueNode
00277 {
00278 private:
00279         DirListNode( Server* pcServer, const String& zRemotePath, Handler* pcTarget, int nID );
00280         ~DirListNode();
00281         CURLcode AttachToHandle( CURL* pHandle );
00282         
00283         size_t Write( void* pBuf, size_t nSize );
00284         int ProgressBar( double fDownTotal, double fDownNow, double fUpTotal, double fUpNow );
00285         
00287         Handler* m_pcTarget;
00288         
00290         bool m_bInitial;
00291         
00295         String m_zLastLineFragment;
00296 
00297         friend class TransferThread;
00298 };
00299 
00302 class CommandNode : public QueueNode
00303 {
00304 private:
00305         CommandNode( Server* pcServer, const std::vector<String>& azCommands, int nID );
00306         ~CommandNode();
00307         
00308         CURLcode AttachToHandle( CURL* pHandle );
00309         CURLcode RemoveFromHandle( CURL* pHandle );
00310         
00311         std::vector<String> m_azCommands;
00312         
00313         struct curl_slist* m_psCommands;
00314         
00315         friend class TransferThread;
00316 };
00317 
00322 class InitializationNode : public QueueNode
00323 {
00324 private:
00325         InitializationNode( Server* pcServer, int nID );
00326         ~InitializationNode();
00327         
00328         CURLcode AttachToHandle( CURL* pHandle );
00329         CURLcode RemoveFromHandle( CURL* pHandle );
00330         
00331         friend class TransferThread;
00332 };
00333 
00334 #endif  /* __QUEUENODE_H__ */
00335 

Generated on Fri Jan 2 17:22:47 2009 for Transferrer by  doxygen 1.5.1