FConnection Class Reference

This class is a singleton, used to manage the network connection. More...

#include <FConnection.h>

Collaboration diagram for FConnection:
[legend]

List of all members.

Public Member Functions

virtual ~FConnection ()
 Destructor. Closes the connection and the session.
const int startConnection ()
 Starts a new GPRS connection using the default IAP, which name is stored in the member 'iIAPDefaultName'.
const int startConnection (const StringBuffer &aIAPName)
 Starts a new GPRS connection, given the IAP name.
void closeConnection ()
 Closes the active connection.
const int stopConnection ()
 Stops the entire connection by disconnecting the underlying network interface immediately, regardless of whether other clients are using it or not.
const bool isConnected ()
 Checks if the connection is active or down.
void restartSession ()
 Closes and restarts the RSocketServ session.
const StringBuffer & getLocalIpAddress ()
 Returns the local IP address of the device.
void setIAPName (const StringBuffer &aIAPName)
 Sets the IAP name, that will be used in startConnection().
StringBuffer & getIAPName ()
 Returns the current IAP name.
RArray< HBufC * > GetAllIAPNames ()
 Returns an array of (new allocated) descriptors, with all the current IAP names.
RConnection * getConnection ()
 Returns a pointer to the (internally owned) RConnection.
RSocketServ * getSession ()
 Returns a pointer to the (internally owned) SocketServ.
TInt getLastError ()
 Returns the last error code.

Static Public Member Functions

static FConnectiongetInstance ()
 Method to get the sole instance of FConnection.
static void dispose ()
 Method to destroy the instance of FConnection.

Protected Member Functions

 FConnection ()
 Default constructor.

Private Member Functions

void ConstructL ()
 Calls startSession().
void startSession ()
 Starts the session (RSocketServ) and opens a new connection (RConnection).
const int openConnection ()
 Opens the connection.
TInt GetIAPIDFromName (const StringBuffer &aIAPName)
 Returns the IAP ID from its name.
StringBuffer GetIAPNameFromID (const TUint aIAPID)
 Returns the IAP name from its ID.

Static Private Member Functions

static FConnectionNewL ()
static FConnectionNewLC ()

Private Attributes

RSocketServ iSession
 The Socket Server necessary to estabilish internet connection.
RConnection iConnection
 The Network connection interface.
StringBuffer iLocalIpAddress
 Current local IP adress of the device.
TUint32 iIAP
 Current IAP ID of the active connection It's set once the connection is up and running.
StringBuffer iIAPName
 Current IAP name of the active connection.
TInt iLastError
 The last error code.
TInt iRetryConnection
 Counter to know how many times we retry to connect to network.
bool isConnectionOpened
 We don't want to open a RConnection that is already opened, otherwise there can be errors using the connection.

Static Private Attributes

static FConnectioniInstance
 pointer to FConnection sole instance


Detailed Description

This class is a singleton, used to manage the network connection.

Get the only instance of FConnection calling FConnection::getInstance(). Owns the RSocketServ and RConnection of the current connection, that can be used exterally calling getConnection() and getSession().


Member Function Documentation

void FConnection::closeConnection (  ) 

Closes the active connection.

The connection will not be dropped immediately: it will be dropped when there is no more data traffic on the connection.

Note:
If a client needs to shutdown the connection in a hard way, then use stopConnection() instead of this method.

RArray<HBufC*> FConnection::GetAllIAPNames (  ) 

Returns an array of (new allocated) descriptors, with all the current IAP names.

The caller has the ownership of the array, so he should take care of deleting it (calling Close()).

TInt FConnection::GetIAPIDFromName ( const StringBuffer &  aIAPName  )  [private]

Returns the IAP ID from its name.

Scans all the user defined accespoints inside the CommDb database.

Parameters:
aIAPName the IAP name to seach
Returns:
the IAP ID (value >= 0), -1 if not found

StringBuffer FConnection::GetIAPNameFromID ( const TUint  aIAPID  )  [private]

Returns the IAP name from its ID.

Scans all the user defined accespoints inside the CommDb database.

Parameters:
aIAPID the IAP ID to seach
Returns:
the IAP name, empty string if not found

const StringBuffer& FConnection::getLocalIpAddress (  ) 

Returns the local IP address of the device.

TODO

const bool FConnection::isConnected (  ) 

Checks if the connection is active or down.

Between active connection, we search for the one started with startConnection().

Returns:
true if connection is active

const int FConnection::openConnection (  )  [private]

Opens the connection.

It's used internally because we MUST have the connection opened before calling iConnection.Start() or iConnection.EnumerateConnections().

Returns:
0 if connection opened without errors 1 if connection already opened (so nothing done) a system error code <0 in case of errors

void FConnection::restartSession (  ) 

Closes and restarts the RSocketServ session.

It is used in case the session is stuck and always returns an error (KErrNotReady = -18). Calling this method will cause the current connection to be dropped.

void FConnection::setIAPName ( const StringBuffer &  aIAPName  )  [inline]

Sets the IAP name, that will be used in startConnection().

This method should be called at the beginning, so that subsequent calls to startConnection() will use this IAP.

Parameters:
aIAPName the name of the IAP

References iIAPName.

const int FConnection::startConnection ( const StringBuffer &  aIAPName  ) 

Starts a new GPRS connection, given the IAP name.

Parameters:
aIAPName "Ask" or "" : if we want to prompt the user to select the IAP "Default" : will use the default IAP of the system, no prompts "<name>" : will use the <name> IAP, no prompts. If not found, will prompt the user to select the IAP
Returns:
0 if no error

const int FConnection::startConnection (  ) 

Starts a new GPRS connection using the default IAP, which name is stored in the member 'iIAPDefaultName'.

The method setIAPDefaultName() should be called before this method, to set the IAP to be used - otherwise, the user will be prompted to select the IAP.

Returns:
0 if no error

const int FConnection::stopConnection (  ) 

Stops the entire connection by disconnecting the underlying network interface immediately, regardless of whether other clients are using it or not.

Applications using the connection will be sent the socket error code KErrCancel.

Note:
If a client needs to graciously shutdown the connection, closeConnection() should be used instead of this method.
Returns:
0 if no error


Member Data Documentation

StringBuffer FConnection::iIAPName [private]

Current IAP name of the active connection.

It can be set calling setIAPName() method. It's set also when the connection is up and running.

Referenced by getIAPName(), and setIAPName().

We don't want to open a RConnection that is already opened, otherwise there can be errors using the connection.

This bool is used to know if we called iConnection.Open().


The documentation for this class was generated from the following file:

Generated on Tue Apr 6 13:00:42 2010 for Funambol Outlook Plug-in Library by  doxygen 1.5.7.1