transferthread.h

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         /* Main thread code is in Run() */
00046         int32 Run();
00047         
00048         /* Lock/unlock the message list so no-one will change it while we are using it */
00049         int Lock();
00050         int Unlock();
00051         
00052         /* Send a message to the transfer thread asking it to add, start, etc a given transfer */
00053         int SendMessage( int nCode );
00054         int SendMessage( Message* pcMsg );
00055         
00056 private:
00057         void _Notify();         /* Send a signal to the thread to notify it that it has new messages */
00058         
00059         void _ProcessMessages();        /* Process the messages in the message list */
00060         
00061         void _Schedule();       /* Assign queued transfers from the queue to idle curl handles */
00062         
00063         void _Initialize();     /* Initialise the server connection - attach an InitializationNode to curl handles. */
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 );         /* Remove & delete a finished queue node */
00070         
00071         /* File management operations: delete, rename etc */
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();  /* Clean up, delete objects and kill the thread */
00078         
00080         Server* m_pcServer;
00081         
00082         /* Inter-thread communication */
00083         int m_nReadPipe;  
00084         int m_nWritePipe; 
00085         std::queue< Message* > m_apcMessages; 
00086         Locker* m_pcLock; 
00088         /* libcurl stuff */
00089         CURLM* m_pCurlMultiHandle; 
00090         std::vector< CurlHandle_s* > m_asHandles;       
00092         friend class Server;
00093 };
00094 
00095 
00096 
00097 #endif  /* __TRANSFERTHREAD_H__ */
00098 
00099 
00100 
00101 
00102 
00103 

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