Server Class Reference

Server class. This is the base server class that provides a common interface for accessing various types of servers. This should be sub-classed for the different types of servers. More...

#include <server.h>

Inheritance diagram for Server:

FTPServer List of all members.

Public Member Functions

 Server (const String &zURL, os::Window *pcTarget, AppSettings *pcSettings)
 Default constructor for the Server. This initializes all the details about the server.
virtual ~Server ()
 Server Deconstructor. This removes the server lock and quits. The m_pcThread is cleaned up on its own when it receives the M_TT_CLOSE message.
int Close ()
 Close all connections. Stop all transfers, close the server connection, free curl handles, stop transfer thread, delete self.
int Lock ()
 Lock the Server. This acts as a mutex lock for the Server so that the internal data structures aren't corrupted due to concurrency issues.
int Unlock ()
 Unlock the Server. This unlocks the Server so that other items can operate on the server.
AppSettingsGetSettings ()
String GetServerAddress ()
 Returns the server address. Returns the address part of the url, eg ftp://my.ftp.com.
const char * GetEntryPath ()
 Get the entry path of the server. Returns the entry path for the user's ftp session. This is the current directory immediately after logging on to the server (eg, user's home dir). The pointer is provided by libcurl. If libcurl hasn't provided the entry path yet, this returns NULL.
int GetDirListing (const String &zPath, Handler *pcTarger)
 Get Directory Listing. Creates and sends a message to the m_pcThread that will cause it to download a directory listing for the given path and generate the corresponding RemoteNodes for each listing. The resulting nodes should be sent to pcTarget.
int GetRemote (const String &zRemoteSource, const String &zLocalDest)
 Get Remote file. Queue a download from the remote file to the local file.
int SendLocal (const String &zLocalSource, const String &zRemoteDest)
 Send a local file. Queue an upload of the given local file to the given remote file.
int DeleteRemote (const String &zPath)
 Delete a remote file. Tells the transfer thread to queue the given file for deletion.
int RemoveRemoteDir (const String &zPath)
 Delete a remote directory. Tells the transfer thread to queue the given dir for deletion.
int CreateRemoteDir (const String &zPath)
 Create a remote directory. Tells the transfer thread to queue a request to create the given dir.
int MoveRemote (const String &zOldPath, const String &zNewPath)
 Move/rename a remote file or dir. Tells the transfer thread to queue a request to rename the given file or dir.
int PauseTransfer (int nNodeID)
 Pause Transfer of a given transfer thread. This pauses the transfer with the given node id.
int ResumeTransfer (int nNodeID)
 Resume Transfer of a given transfer thread. This resumes the transfer of the item with the given node id.
int CancelTransfer (int nNodeID)
 Cancel Transfer of a given transfer thread. This cancels the transfer of the item with the given node id.
Message * CreateUpdateMessage ()
 Create update message to send to the progress window.
void Updated (int nID)
 Updated server. This is used to send a message to the main window signifying that some of the downloads/uploads have been updated.

Private Member Functions

virtual CURLcode _SetupCurlHandle (CURL *pHandle)
 Setup Curl Handle. This initializes the curl handler for the FTP connection.

Private Attributes

String m_zURL
os::Window * m_pcTarget
TransferThreadm_pcThread
AppSettingsm_pcSettings
std::map< int, QueueNode * > m_apcQueue
 List of all queued and running transfers stored as a map from id numbers to QueueNode objects. The reason for using a std::map and giving each node an id number is so that the gui can refer to queue nodes by their id rather than using a pointer. Since we can't be sure that the transfer thread hasn't deleted a node while the gui is still using the pointer.
int m_nNextID
Locker * m_pcLock
const char * m_pzEntryPath

Friends

class TransferThread
class InitializationNode

Detailed Description

Server class. This is the base server class that provides a common interface for accessing various types of servers. This should be sub-classed for the different types of servers.

Todo:
ParseDirListing function should be removed if it is unnecessary.


Constructor & Destructor Documentation

Server::Server ( const String &  zURL,
os::Window *  pcTarget,
AppSettings pcSettings 
)

Default constructor for the Server. This initializes all the details about the server.

Parameters:
zURL This is the string containing the parsed server URL to connect to.
pcTarget Pointer to the handler for server messages (ie. the window containing the server).
nParallelConnections Number of allowable parallel connections (simultaneous transfers).

Server::~Server (  )  [virtual]

Server Deconstructor. This removes the server lock and quits. The m_pcThread is cleaned up on its own when it receives the M_TT_CLOSE message.

Todo:
Is it true that all other cleanup is done in TransferThread.
Todo:
I want this to be private but can't be bothered debugging the error messages yet.


Member Function Documentation

int Server::Lock (  ) 

Lock the Server. This acts as a mutex lock for the Server so that the internal data structures aren't corrupted due to concurrency issues.

Warning:
Must call Lock() before accessing the node queue.

int Server::Unlock (  ) 

Unlock the Server. This unlocks the Server so that other items can operate on the server.

Warning:
This must be called by the function that called Lock() to allow it to be used by other parts of the application.

int Server::GetDirListing ( const String &  zPath,
Handler *  pcTarget 
)

Get Directory Listing. Creates and sends a message to the m_pcThread that will cause it to download a directory listing for the given path and generate the corresponding RemoteNodes for each listing. The resulting nodes should be sent to pcTarget.

Parameters:
zPath The path to get a directory listing of.
pcTarget The handler for the resulting nodes.

int Server::GetRemote ( const String &  zRemoteSource,
const String &  zLocalDest 
)

Get Remote file. Queue a download from the remote file to the local file.

Parameters:
zRemoteSource Remote source relative to the ftp server, eg /remotedir/file
zLocalDest Local destination for the file.

int Server::SendLocal ( const String &  zLocalSource,
const String &  zRemoteDest 
)

Send a local file. Queue an upload of the given local file to the given remote file.

Parameters:
zRemoteDest Remote destination relative to the ftp server, eg /remotedir/file
zLocalSource Local source where the local file is coming from.

int Server::PauseTransfer ( int  nNodeID  ) 

Pause Transfer of a given transfer thread. This pauses the transfer with the given node id.

Parameters:
nNodeID The node ID of the node to pause the transfer.

int Server::ResumeTransfer ( int  nNodeID  ) 

Resume Transfer of a given transfer thread. This resumes the transfer of the item with the given node id.

Parameters:
nNodeID The node ID of the thread to resume transfering.

int Server::CancelTransfer ( int  nNodeID  ) 

Cancel Transfer of a given transfer thread. This cancels the transfer of the item with the given node id.

Parameters:
nNodeID The node ID of the thread to cancel transfering.

void Server::Updated ( int  nID  ) 

Updated server. This is used to send a message to the main window signifying that some of the downloads/uploads have been updated.

Parameters:
nID,: The id of the node that has been updated. Currently the nID parameter is ignored but a future version will do more fine-grained updating.

CURLcode Server::_SetupCurlHandle ( CURL *  pHandle  )  [private, virtual]

Setup Curl Handle. This initializes the curl handler for the FTP connection.

Parameters:
pHandle The pointer to the CURL handle.
Todo:
This should be a virtual function that is called by the particular server type. Currently it directly implements FTP style transfers which defeates the purpose of having separate Server and FTPServer classes.


Member Data Documentation

String Server::m_zURL [private]

Address of the server.

os::Window* Server::m_pcTarget [private]

The window that created us.

TransferThread* Server::m_pcThread [private]

Our transfer thread, that does all the work.

AppSettings* Server::m_pcSettings [private]

Pointer to the app settings object.

int Server::m_nNextID [private]

Next available ID number.

Locker* Server::m_pcLock [private]

Lock used for concurrency.

const char* Server::m_pzEntryPath [private]

'Entry path' of the ftp server - pointer provided by libcurl.


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