msgconnmanager/inc/msgconnmanager.h
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Connection manager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __MSGCONNMANAGER__
       
    22 #define __MSGCONNMANAGER__
       
    23 
       
    24 // INCLUDES
       
    25 #include <commdb.h>
       
    26 #include <es_sock.h>
       
    27 #include <commdbconnpref.h>
       
    28 #include <msgconnmanagerapi.h>
       
    29 #include "msgconntimercallback.h"
       
    30 
       
    31 
       
    32 //CONSTANTS
       
    33 _LIT( KConnManLogDir,                           "MsgConnMan" );
       
    34 _LIT( KConnManLogFile,                          "MsgConnManager.txt" );
       
    35 const TInt KConnManLogBufferMaxSize		        = 2000;
       
    36 
       
    37 //FORWARD DECLARATIONS
       
    38 class CMsgConnTimer;
       
    39 class MMsgBearerObsCallback;
       
    40 
       
    41 // CLASS DECLARATION
       
    42 class CMsgConnManager : public CActive,
       
    43                         public MMsgConnManager,
       
    44                         public MMsgConnTimerCallback
       
    45     {
       
    46     public:  // Constructors and destructor
       
    47 
       
    48         /**
       
    49         * Symbian OS default constructor.
       
    50         * @param TInt Default Access Point ID
       
    51         * @return CMsgConnManager*
       
    52         */     
       
    53         static CMsgConnManager* NewL( const TInt aAccessPoint );
       
    54 
       
    55         /**
       
    56         * Destructor.
       
    57         */      
       
    58         virtual ~CMsgConnManager();
       
    59 
       
    60     public:   //New functions   
       
    61         
       
    62         /**
       
    63         * Symbian OS default constructor.
       
    64         * @param TRequestStatus& Request status of the caller
       
    65         * @return void
       
    66         */  
       
    67         virtual void StartConnection( TRequestStatus& aStatus );
       
    68     
       
    69         /**
       
    70         * Stop a connection, synchronous version
       
    71         * @return void
       
    72         */  
       
    73         virtual void StopConnection();
       
    74         
       
    75         /**
       
    76         * Stop a connection, asynchronous version
       
    77         * @return void
       
    78         */  
       
    79         virtual void StopConnection( TRequestStatus& aStatus );
       
    80         
       
    81         /**
       
    82         * Cancel StartConnection(). The method may leave with
       
    83         *   - KErrAbort if the TRequestStatus object the client
       
    84         *     supplied is not active, hence, there is no pending
       
    85         *     request that would require cancelling.
       
    86         * In normal cases - when RConnection::Start() or its 
       
    87         * progress notifications are pending - ConnMan completes
       
    88         * the client's request with the "error" KErrCancel.
       
    89         */
       
    90         virtual void CancelStartL();
       
    91 
       
    92         /**
       
    93         * Set the ID of the Access Point to connect to.
       
    94         * @param aAccessPointID
       
    95         * @return void
       
    96         */
       
    97         virtual void SetAccessPointIDL( const TInt aAccessPointID );
       
    98 
       
    99         /**
       
   100         * Returns the number of connections presently active
       
   101         * @return TInt
       
   102         */
       
   103         virtual TInt NumberOfActiveConns();
       
   104         
       
   105         /**
       
   106         * Read from the Comms Database
       
   107         * @param const TMsgSupportedCommDbRecords& aParameter
       
   108         * @return HBufC8*
       
   109         */
       
   110         virtual HBufC* ReadFromCommsDbLC( const TSupportedCommDbRecords aParameter );
       
   111         
       
   112         /**
       
   113         * Returns a reference to the active socket server.
       
   114         * @return RConnection&
       
   115         */
       
   116         virtual RConnection& Connection();
       
   117 
       
   118         /**
       
   119         * Returns a reference to the active socket server.
       
   120         * @return RSocketServ&
       
   121         */
       
   122         virtual RSocketServ& SocketSession();
       
   123 
       
   124         /**
       
   125         * Add an object to the queue of listeners. The object to be added
       
   126         * must inplement the interface MMsgBearerObsCallback in order
       
   127         * to receive events from the system agent. It is important to note
       
   128         * that the call to the notification handler (HandleBearerEventL())
       
   129         * takes place inside the RunL() method of this Connection Manager,
       
   130         * so the listening object MUST return the control to the Manager
       
   131         * AS SOON AS POSSIBLE in order not to clog the scheduler.
       
   132         * @param MMsgBearerObsCallback* aClient
       
   133         * @return void
       
   134         */
       
   135         virtual void AddEventSubscriberL( MMsgBearerObsCallback* aClient );
       
   136         
       
   137         /**
       
   138         * Remove an object from the queue of listeners. It is no necessary
       
   139         * to call this method at deletion time, as the destructor destroys
       
   140         * the subscriber queue altogether. If, however, a listener object is
       
   141         * destroyed before an instance of Connection Manager, it is mandatory
       
   142         * to remove the listener from the queue prior to deleting the listener.
       
   143         * @param MMsgBearerObsCallback* aClient
       
   144         * @return void
       
   145         */
       
   146         virtual void RemoveEventSubscriber( MMsgBearerObsCallback* aClient );
       
   147 
       
   148         /**
       
   149         * Returns the status of the ConnMan: ETrue if sending is OK, EFalse otherwise
       
   150         * @return TBool
       
   151         */
       
   152         virtual TBool Status() const;
       
   153         
       
   154         /**
       
   155         * Destructor.
       
   156         * @return void
       
   157         */
       
   158         virtual void Destroy();
       
   159         
       
   160     public:
       
   161 
       
   162     #ifdef _DEBUG
       
   163 
       
   164         /**
       
   165         * A Global logging function
       
   166         * @param TRefByValue<const TDesC8> aFmt,...
       
   167         * @return void
       
   168         */ 
       
   169         static void WriteToLog( TRefByValue<const TDesC8> aFmt,... );
       
   170 
       
   171     #endif
       
   172 
       
   173     private:
       
   174         
       
   175         /**
       
   176         * Start to keep an eye on the opened connection
       
   177         * @return void
       
   178         */ 
       
   179         void StartNetworkObserver();
       
   180         
       
   181         /**
       
   182         * Determine the state of the connection opening
       
   183         * @return void
       
   184         */ 
       
   185         void WatchConnectionOpening();
       
   186         
       
   187         /**
       
   188         * Determine the state of the (opened) connection
       
   189         * @return void
       
   190         */ 
       
   191         void DetermineConnectionStatusL();
       
   192         
       
   193         /**
       
   194         * Broadcast the bearer event to registered listeners
       
   195         * @param TMsgBearerEvent aBearerEvent
       
   196         * @return void
       
   197         */ 
       
   198         void BroadcastBearerEventL( const TMsgBearerEvent aBearerEvent );
       
   199 
       
   200         /**
       
   201         * Determine which value is to be fetched from the CommsDb
       
   202         * @param TPtrC& aDbView
       
   203         * @param TPtrC& TPtrC& aDbColumn
       
   204         * @param TMsgSupportedCommDbRecords aParameter
       
   205         * @return TBool
       
   206         */ 
       
   207         TInt DetermineRecordTypeLC( TPtrC& aDbColumn,
       
   208                                     CCommsDbTableView*& aView,
       
   209                                     const TSupportedCommDbRecords aParameter );
       
   210 
       
   211         /**
       
   212         * Broadcast the bearer event to registered listeners
       
   213         * @param TMsgBearerEvent aBearerEvent
       
   214         * @return void
       
   215         */ 
       
   216         TInt InitCommDbViewLC( TPtrC& aDbRecord,
       
   217                                CCommsDbTableView*& aView,
       
   218                                const TSupportedCommDbRecords aParameter );
       
   219         
       
   220         /**
       
   221         * Broadcast the bearer event to registered listeners
       
   222         * @param TMsgBearerEvent aBearerEvent
       
   223         * @return void
       
   224         */ 
       
   225         TBool CheckProxyUsageLC( CCommsDbTableView*& aView );
       
   226 
       
   227         /**
       
   228         * Issue a new asynchronous request
       
   229         * @return void
       
   230         */
       
   231         void IssueRequest();
       
   232         
       
   233         /**
       
   234         * Check the availability of GPRS Network
       
   235         * @return TBool Available or not
       
   236         */
       
   237         TBool IsValidApL( TUint32 aUid );
       
   238         
       
   239         /**
       
   240         * Handle the opening of a new connection
       
   241         * @return void
       
   242         */
       
   243         void HandleNewConnection();
       
   244 
       
   245         /**
       
   246         * Handle an existing connection
       
   247         * @return void
       
   248         */
       
   249         void HandleExistingConnection();
       
   250 
       
   251         /**
       
   252         * Symbian OS second-phase constructor
       
   253         * @param TInt aAccessPoint
       
   254         * @return void
       
   255         */ 
       
   256         void ConstructL( const TInt aAccessPoint );
       
   257         
       
   258         /**
       
   259         * Delete the log files
       
   260         * @return void
       
   261         */ 
       
   262         void DeleteLogFileL();
       
   263 
       
   264         /**
       
   265         * C++ default constructor is private
       
   266         * @return void
       
   267         */      
       
   268         CMsgConnManager();
       
   269 
       
   270         /**
       
   271         * From CActive
       
   272         * @return void
       
   273         */
       
   274         void RunL();
       
   275 
       
   276         /**
       
   277         * From CActive
       
   278         * @return void
       
   279         */
       
   280         void DoCancel();
       
   281     
       
   282     private:  //From MMsgConnectionTimerCallback
       
   283         
       
   284         /**
       
   285         * Catch a timer event
       
   286         * @param TInt aStatus
       
   287         * @return void
       
   288         */
       
   289         virtual void HandleTimerEvent( TInt aStatus );
       
   290         
       
   291     private: //Data
       
   292         
       
   293         enum TMsgConnManState
       
   294             {
       
   295             EMsgConnManIdle = 0,
       
   296             EMsgConnManWaitingForStartComplete,
       
   297             EMsgConnManWaitingForNotifications,
       
   298             EMsgConnManDisconnectingPrevious,
       
   299             EMsgConnManObservingAccessPoint,
       
   300             EMsgConnManBearerSuspended,
       
   301             EMsgConnManBearerLost
       
   302             };
       
   303         
       
   304         TInt                                            iAccessPointID;
       
   305         TInt                                            iLastConnectionStage;
       
   306         TBool                                           iProgressStarted;
       
   307         TBool                                           iConnectionClosed;
       
   308         TNifProgressBuf                                 iProgressBuffer;
       
   309         TMsgConnManState                                iConnManStatus;
       
   310         TRequestStatus*                                 iClientStatus;
       
   311         TRequestStatus*                                 iPingRequestStatus;
       
   312         TRequestStatus*                                 iTimedCompleteStatus;
       
   313         CCommsDatabase*                                 iCommsDatabase;
       
   314         CMsgConnTimer*                                  iConnectionTimer;
       
   315         RConnection                                     iConnection;
       
   316         TCommDbConnPref                                 iAccessPointSettings;     
       
   317         RSocketServ                                     iSocketSession;
       
   318         RPointerArray<MMsgBearerObsCallback>	        iEventSubscribers;
       
   319     };
       
   320 
       
   321 // ---------------------------------------------------------
       
   322 // CMsgConnManager::StartBearerObserver
       
   323 // If the status is any other than EMsgConnManObservingAccessPoint
       
   324 // there is something fishy going on => do not send/receive anything
       
   325 // ---------------------------------------------------------
       
   326 //
       
   327 inline TBool CMsgConnManager::Status() const
       
   328     {
       
   329     return iConnManStatus == EMsgConnManObservingAccessPoint;
       
   330     }
       
   331 
       
   332 // ---------------------------------------------------------
       
   333 // CMsgConnManager::SocketSession
       
   334 // 
       
   335 // ---------------------------------------------------------
       
   336 //
       
   337 inline RSocketServ& CMsgConnManager::SocketSession()
       
   338     {
       
   339     return iSocketSession;
       
   340     }
       
   341 
       
   342 // ---------------------------------------------------------
       
   343 // CMsgConnManager::Connection
       
   344 // 
       
   345 // ---------------------------------------------------------
       
   346 //
       
   347 inline RConnection& CMsgConnManager::Connection()
       
   348     {
       
   349     return iConnection;
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------
       
   353 // CMsgConnManager::Destroy
       
   354 // 
       
   355 // ---------------------------------------------------------
       
   356 //
       
   357 inline void CMsgConnManager::Destroy()
       
   358     {
       
   359     delete this;
       
   360     }
       
   361 
       
   362 #endif
       
   363 
       
   364 
       
   365 // End of File