Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

net::Protocol Class Reference

#include <Protocol.h>

List of all members.


Detailed Description

Protocol is a universal representation of an ascii line -based protocol.

It reads a line from a generalized file (disk file, socket, whatever), sends it as a service request to the actual protocol implementation, and sends the returned reply to a client.


Public Methods

 Protocol ()
 Create a new Protocol with no file.

 Protocol (util::io::GeneralFile *f)
 Create a Protocol that reads and writes f.

 Protocol (util::io::GeneralFile &f)
 Create a Protocol that reads and writes f.

virtual ~Protocol ()
void setFile (util::io::GeneralFile *f)
 Set the file that this protocol works with.

void setFile (util::io::GeneralFile &f)
 Set the file that this protocol works with.

util::io::GeneralFilegetFile (void)
 Get the file this protocol uses for communications.

void start (void)
 Start the protocol.

virtual std::string request (const std::string &r, int n)=0 throw (ConnectionClosedException&)
 A service request.


Protected Attributes

util::io::GeneralFile_pFile
 A pointer to the file that is used for communications.


Constructor & Destructor Documentation

net::Protocol::Protocol util::io::GeneralFile   f [inline]
 

Create a Protocol that reads and writes f.

The memory pointed to by f is automatically released upon the deletion of this protocol.

Parameters:
f  the file to be read from and written to

net::Protocol::Protocol util::io::GeneralFile   f [inline]
 

Create a Protocol that reads and writes f.

The memory referenced by f is not automatically released. Note that a pointer to the file is stored, so that the actual object must be available through the life cycle of this protocol.

Parameters:
f  the file to be read from and written to


Member Function Documentation

virtual std::string net::Protocol::request const std::string &    r,
int    n
throw (ConnectionClosedException&) [pure virtual]
 

A service request.

When started, the protocol will start delivering service request to the subclass that implements this method. After reading a line from the client, the protocol will pass it to the subclass, which should reply with requested data.

When the protocol has done its due and wants to break the request-reply loop, it should throw a ConnectionClosedException&. The message stored in the thrown exception will be shown to the client if it differs from NULL.

Parameters:
r  the service request
n  a sequence number for the request. The first sequence number is 0, to which a protocol may reply with a greeting message.
Returns:
the reply. If the length of the reply is 0, then no message will be sent to the client, but a new line is read instead.
Exceptions:
ConnectionClosedException  if the connection should be closed. The message of the exception will be sent to the client if it differs from NULL.

void net::Protocol::setFile util::io::GeneralFile   f
 

Set the file that this protocol works with.

Data is read and written from the specified file. Memory is not automatically released.

void net::Protocol::setFile util::io::GeneralFile   f
 

Set the file that this protocol works with.

Data is read and written from the specified file. Memory is automatically released.

void net::Protocol::start void   
 

Start the protocol.

This will start a request-reply loop that can be broken by a subclass by throwing a ConnectionClosedException from the request method.


The documentation for this class was generated from the following files:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.