#include <transferthread.h>
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 | |
Server * | m_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 |
TransferThread::TransferThread | ( | Server * | pcServer | ) |
TransferThread Constructor. Initializes the TransferThread creating its pipes, locks and curl objects.
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.
int TransferThread::SendMessage | ( | int | nCode | ) |
Wrapper for sending messages with numerical codes. This creates a Message object using nCode as a parameter.
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 ).
void TransferThread::_ProcessMessages | ( | ) | [private] |
Checks for messages from other threads and carries out the appropriate action.
void TransferThread::_CleanupNode | ( | int | nNode | ) | [private] |
_CleanupNode() cleans up and deletes a finished QueueNode.
nNode | The QueueNode ID to remove. |
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.
CURLM* TransferThread::m_pCurlMultiHandle [private] |
Our CURLM handle. Contains a pointer to our curl_multi_init() handle.
std::vector< CurlHandle_s* > TransferThread::m_asHandles [private] |
List of all the curl handles we own, and the corresponding queue nodes.