class MAbstractConnection

Defines the PeerHood Connection interface.

Inheritance:


Public Methods

[more]virtual ~MAbstractConnection()
Default destructor.
[more]virtual MAbstractConnection* AcceptL() = 0
Accepts an incoming connection.
[more]virtual bool IsListening() = 0
Tells if the connection is in the listening state.
[more]virtual bool IsConnected() = 0
Tells if a connection is established to a remote device.
[more]virtual bool Listen() = 0
Moves the connection object to the listening state.
[more]virtual bool HasData() = 0
Moves the connection object to the listening state.
[more]virtual bool Listen(int aPort) = 0
Moves the connection object to the listening state.
[more]virtual void Close() = 0
Closes the connection in uncontrolled way.
[more]virtual bool Connect(const std::string& aAddress, int aPort) = 0
Tries to establish a new connection.
[more]virtual bool Disconnect() = 0
Closes the connection in a controlled way.
[more]virtual int Write(const void* aOutBuf, int aLength) = 0
Sends data to the remote device.
[more]virtual int Read(void* aInBuf, int aLength) = 0
Reads data send by a remote device.
[more]virtual int GetFd() = 0
Returns the file descriptor attached to the connection.
[more]virtual const std::string& GetRemoteAddress() = 0
Returns the address of the remote device.


Documentation

Defines the PeerHood Connection interface. The interface is pure & virtual so each networking technology needs its own implementation of the interface. The PeerHood system uses this interface when communicating with other PeerHood devices. The goal of this interface is to completely hide the underlying networking tehchnology from the PeerHood system. This means that the very same logic can be used when working with different networking technologies, so no modifications to the PeerHood core are required if a new networking technology is to be supported.

ovirtual ~MAbstractConnection()
Default destructor. Currently this does nothing but is here because virtual base classes without a destructor are <b><i>evil</i></b>.

Returns:
none

ovirtual MAbstractConnection* AcceptL() = 0
Accepts an incoming connection. If the connection is accepted succesfully then it's possible to send and receive data using the returned connection object.

Returns:
new connection object or NULL in the case of an error

ovirtual bool IsListening() = 0
Tells if the connection is in the listening state. The listening state doesn't necessarily mean the "listen" state of a traditional socket. Instead, it can mean any state such that the actual networking technology is able to accept incoming connection requests.

Returns:
true if the connection is in the listening state

ovirtual bool IsConnected() = 0
Tells if connection to a remote device is established.

Returns:
true if connection to a remote device is established

ovirtual bool Listen() = 0
Moves the connection object to the listening state. After this fuction call the connection object should be able to receive incoming connection requests.

Returns:
true is the connection is moved to the listening state, otherwise false

ovirtual bool HasData() = 0
Moves the connection object to the listening state. After this fuction call the connection object should be able to receive incoming connection requests.

Returns:
true is the connection is moved to the listening state, otherwise false

ovirtual bool Listen(int aPort) = 0
Moves the connection object to the listening state. After this fuction call the connection object should be able to receive incoming connection requests. This version of the <code>Listen</code> call should be used if some defined port (or equivalent) should be used instead of the networking technology's default port. Note that using other than the default port can have hazardous effects to the system!

Parameters:
aPort - The port that should be listened.
Returns:
true if the connection is moved to the listening state, otherwise false

ovirtual void Close() = 0
Closes an open connection without any further notice. No error codes are returned even if this function called for a closed connection. In that case the program execution should continue normally. <b>This function should not be called except in extreme situations</b> - the normal way to close a connection is the <code>Disconnect</code> function!.

Returns:
none

ovirtual bool Connect(const std::string& aAddress, int aPort) = 0
Tries to establish new connection to a remote device. Note that users should not call this function directly. Instead, they are supposed to use the <code>Connect</code> function in the PeerHood interface. Remote device's address etc. are obtained as a part of PeerHood neighborhood information.

Parameters:
aAddress - Remote device's address.
aPort - Remote device's port.
Returns:
true if the connection establishment succeeded

ovirtual bool Disconnect() = 0
Closes the connection in a controlled way. This is the normal way to close the connection. The similar function <code>Close</code> should not be used unless necessary.

Returns:
true if the connection was closed normally

ovirtual int Write(const void* aOutBuf, int aLength) = 0
Sends data to the remote device. A connection must be established before any data can be transmitted. There's no limit for the data lenght so if the underlying networking techonlogy requires segmentation it must be hidden from the user.

Parameters:
aOutBuf - Buffer containing the data to be sent.
aLength - The length of the data to be sent.
Returns:
the number of bytes sent

ovirtual int Read(void* aInBuf, int aLength) = 0
Reads data send by a remote device. The reserved buffer must be large enough to hold the requested amount of data. If the underlying networking technology requires segmentation then it must be implemented transparently to the user.

Parameters:
aInBuf - The destination buffer.
aLength - The number of bytes to be read.
Returns:
the number of bytes read

ovirtual int GetFd() = 0
Return the file descriptor attached to the current active connection.

Returns:
the active file descriptor or -1 if there's no connection

ovirtual const std::string& GetRemoteAddress() = 0
Returns the address of the remote device. If there's no connection then the returned address is empty.

Returns:
the address of the remote device


Direct child classes:
CVirtualConnection
CTCPConnection
CLocalConnection
CGPRSConnection
CBTConnection
See Also:
CBTConnection

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.