TransferThread Class Reference

Class for transfering items in a threaded manner. This is the thread in which all the transfers are done via calls to curl_multi_perform(). More...

#include <transferthread.h>

List of all members.

Public Member Functions

 TransferThread (Server *pcServer)
 TransferThread Constructor. Initializes the TransferThread creating its pipes, locks and curl objects.
 ~TransferThread ()
 TransferThread Deconstructor. This deletes the lock for this thread and cleans up curl data.
int32 Run ()
 The main loop of the thread.
int Lock ()
 Lock the Thread. This is used to lock the thread from further access until any operations being performed are complete.
int Unlock ()
 Unlock the Thread. This unlocks the thread for further operations.
int SendMessage (int nCode)
 Wrapper for sending messages with numerical codes. This creates a Message object using nCode as a parameter.
int SendMessage (Message *pcMsg)
 Send a message to the thread. The message will be deleted by the thread once it is processed, so it should be created via new Message( code ).

Private Member Functions

void _Notify ()
 Notify() writes a piece of data to the pipe to wake the transfer thread from its select() sleep. This is called from gui threads.
void _ProcessMessages ()
 Checks for messages from other threads and carries out the appropriate action.
void _Schedule ()
 Assign queued transfers to idle curl handles. This schedules a transfer for one of the curl handles.
void _Initialize ()
 Initializes the server connection. Creates an InitializationNode and attaches it to a curl handle. Currently this is just to get the entry path.
void _AddNode (int nType, const String &zLocalPath, const String &zRemotePath, Handler *pcTarget)
 Create a new queue node. Creates a new node with the given parameters, and adds it to the Server object's list.
void _PauseNode (int nID)
 Pauses the given transfer. Sets the given node's status to paused, and detaches it from a curl handle, if it was previously attached.
void _ResumeNode (int nID)
void _CancelNode (int nID)
 Cancels the given queue node and deletes it.
void _CleanupNode (int nNode)
 _CleanupNode() cleans up and deletes a finished QueueNode.
void _DeleteFile (const String &zPath)
void _RemoveDir (const String &zPath)
void _MakeDir (const String &zPath)
void _Rename (const String &zOldPath, const String &zNewPath)
void _Close ()
 Clean up and stop transfer thread. Cleans up all transfers, frees curl handles, deletes the Server object and terminates the transfer thread.

Private Attributes

Serverm_pcServer
 Our server object.
int m_nReadPipe
int m_nWritePipe
std::queue< Message * > m_apcMessages
Locker * m_pcLock
 A mutex lock for the thread.
CURLM * m_pCurlMultiHandle
std::vector< CurlHandle_s * > m_asHandles

Friends

class Server


Detailed Description

Class for transfering items in a threaded manner. This is the thread in which all the transfers are done via calls to curl_multi_perform().

Todo:
The class needs to be cleaned up properly.


Constructor & Destructor Documentation

TransferThread::TransferThread ( Server pcServer  ) 

TransferThread Constructor. Initializes the TransferThread creating its pipes, locks and curl objects.

Parameters:
pcServer The server that this thread is working for.

TransferThread::~TransferThread (  ) 

TransferThread Deconstructor. This deletes the lock for this thread and cleans up curl data.

Todo:
Other curl cleanup - remove all easy handles from the multi handle


Member Function Documentation

int TransferThread::SendMessage ( int  nCode  ) 

Wrapper for sending messages with numerical codes. This creates a Message object using nCode as a parameter.

Parameters:
nCode The code to send for the message.

int TransferThread::SendMessage ( Message *  pcMsg  ) 

Send a message to the thread. The message will be deleted by the thread once it is processed, so it should be created via new Message( code ).

Warning:
The messages added to m_apcMessages by this function should be deleted after processing.

void TransferThread::_ProcessMessages (  )  [private]

Checks for messages from other threads and carries out the appropriate action.

Todo:
Move the code for each case into separate functions.
Warning:
Only called from the transfer thread.

void TransferThread::_CleanupNode ( int  nNode  )  [private]

_CleanupNode() cleans up and deletes a finished QueueNode.

Parameters:
nNode The QueueNode ID to remove.


Member Data Documentation

int TransferThread::m_nReadPipe [private]

Read pipe for communication. See pipe function in unistd.h.

int TransferThread::m_nWritePipe [private]

Write pipe for communication. See pipe function in unistd.h.

std::queue< Message* > TransferThread::m_apcMessages [private]

Stores the queue of messages for this thread.

Todo:
Could use std::pair< Transfer*, int > instead?

CURLM* TransferThread::m_pCurlMultiHandle [private]

Our CURLM handle. Contains a pointer to our curl_multi_init() handle.

Todo:
This needs better documentation.

std::vector< CurlHandle_s* > TransferThread::m_asHandles [private]

List of all the curl handles we own, and the corresponding queue nodes.


The documentation for this class was generated from the following files:
Generated on Fri Jan 2 17:23:49 2009 for Transferrer by  doxygen 1.5.1