Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MSN::Connection Class Reference

#include <connection.h>

Inheritance diagram for MSN::Connection:

MSN::FileTransferConnection MSN::NotificationServerConnection MSN::SwitchboardServerConnection List of all members.

Detailed Description

An abstract base class that represents a connection to another computer.

Connection provides an interface and some functionality that is common to notification, switchboard and file transfer connections.

Todo:
Connection should have a read buffer that stores all incoming data that is waiting to be processed. Member functions should use that for necessary data, and not call Connection::readExactly.


Public Member Functions

 Connection ()
virtual ~Connection ()
virtual void dispatchCommand (std::vector< std::string > &args)=0
 Dispatch a command to its appropriate handler routines based on args.
std::vector< std::string > getLine ()
 Read a line from the network and split it into its components.
bool isWholeLineAvailable ()
bool bytesAvailable ()
virtual size_t write (std::string s, bool log=true) throw (std::runtime_error)
 Write a string to the connection.
virtual size_t write (std::ostringstream &s, bool log=true) throw (std::runtime_error)
 Write the contents of a stringstream to the connection.
virtual void connect (const std::string &hostname, unsigned int port)=0
 Connect ourself to hostname on port.
virtual void disconnect ()=0
void showError (int errorCode)
 Notify the calling library that an error with code errorCode has occured.
bool isConnected ()
 Is this Connection connected to a remote endpoint?
virtual NotificationServerConnectionmyNotificationServer ()=0
External Socket Hooks
These members should be called whenever an appropriate socket event occurs.

virtual void dataArrivedOnSocket ()
 New data is available on the connection.
virtual void socketConnectionCompleted ()
 The connection has been established.
virtual void socketIsWritable ()
virtual void errorOnSocket (int errno_)
 An error has occurred on the socket.

Public Attributes

int sock
 The socket which connects this Connection to another computer.
bool connected
 Indicates whether a connection has been established.
void * user_data

Protected Member Functions

void handle_MSG (std::vector< std::string > &args)
 Process a MSG command.
virtual void handleIncomingData ()=0

Protected Attributes

int trID
 The transaction ID of the next command to be sent.
std::string readBuffer


Constructor & Destructor Documentation

MSN::Connection::Connection  ) 
 

MSN::Connection::~Connection  )  [virtual]
 


Member Function Documentation

bool MSN::Connection::bytesAvailable  ) 
 

virtual void MSN::Connection::connect const std::string &  hostname,
unsigned int  port
[pure virtual]
 

Connect ourself to hostname on port.

Implemented in MSN::FileTransferConnection, MSN::NotificationServerConnection, and MSN::SwitchboardServerConnection.

void MSN::Connection::dataArrivedOnSocket  )  [virtual]
 

New data is available on the connection.

Reimplemented in MSN::FileTransferConnection.

void MSN::Connection::disconnect  )  [pure virtual]
 

Implemented in MSN::FileTransferConnection, MSN::NotificationServerConnection, and MSN::SwitchboardServerConnection.

virtual void MSN::Connection::dispatchCommand std::vector< std::string > &  args  )  [pure virtual]
 

Dispatch a command to its appropriate handler routines based on args.

Parameters:
args A vector of strings containing arguments, returned from readLine.

Implemented in MSN::FileTransferConnection, MSN::NotificationServerConnection, and MSN::SwitchboardServerConnection.

void MSN::Connection::errorOnSocket int  errno_  )  [virtual]
 

An error has occurred on the socket.

std::vector< std::string > MSN::Connection::getLine  ) 
 

Read a line from the network and split it into its components.

MSN commands and their arguments are separated by white space.

void MSN::Connection::handle_MSG std::vector< std::string > &  args  )  [protected]
 

Process a MSG command.

This method will read the remaining message data from the network @ and then delegates to private message_* functions based on the Content-Type header found in the message.

virtual void MSN::Connection::handleIncomingData  )  [protected, pure virtual]
 

Implemented in MSN::FileTransferConnection, MSN::NotificationServerConnection, and MSN::SwitchboardServerConnection.

bool MSN::Connection::isConnected  )  [inline]
 

Is this Connection connected to a remote endpoint?

bool MSN::Connection::isWholeLineAvailable  ) 
 

virtual NotificationServerConnection* MSN::Connection::myNotificationServer  )  [pure virtual]
 

Implemented in MSN::FileTransferConnection, MSN::NotificationServerConnection, and MSN::SwitchboardServerConnection.

void MSN::Connection::showError int  errorCode  ) 
 

Notify the calling library that an error with code errorCode has occured.

void MSN::Connection::socketConnectionCompleted  )  [virtual]
 

The connection has been established.

Reimplemented in MSN::FileTransferConnection, MSN::NotificationServerConnection, and MSN::SwitchboardServerConnection.

virtual void MSN::Connection::socketIsWritable  )  [inline, virtual]
 

Reimplemented in MSN::FileTransferConnection.

size_t MSN::Connection::write std::ostringstream &  s,
bool  log = true
throw (std::runtime_error) [virtual]
 

Write the contents of a stringstream to the connection.

Parameters:
s The stringstream to write.
log Should we log this output to the console.
write will buffer the output if a connection has not yet been established. In this case, the data will be written as soon as a connection is established.

size_t MSN::Connection::write std::string  s,
bool  log = true
throw (std::runtime_error) [virtual]
 

Write a string to the connection.


Member Data Documentation

bool MSN::Connection::connected
 

Indicates whether a connection has been established.

Todo:
This is currently public only because FileTransferInvitation::receiveFile accesses it. It should be made protected in the future, and FileTransferInvitation refactored to remove it's dependency on this attribute.

std::string MSN::Connection::readBuffer [protected]
 

int MSN::Connection::sock
 

The socket which connects this Connection to another computer.

Deprecated:
In the future, this member will be made private. Any functions that access this member should be converted to member functions of a subclass.

int MSN::Connection::trID [protected]
 

The transaction ID of the next command to be sent.

void* MSN::Connection::user_data
 


The documentation for this class was generated from the following files:
Generated on Sun Feb 6 19:59:40 2005 for libmsn by  doxygen 1.4.1