internetradio2.0/irnetworkcontroller/inc/irnetworkcontroller.h
changeset 14 896e9dbc5f19
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Controls the network interface(s) for Internet Radio.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_IRNETWORKCONTROLLER_H
       
    20 #define C_IRNETWORKCONTROLLER_H
       
    21 
       
    22 #include <badesca.h>
       
    23 #include <es_sock.h>
       
    24 #include <rhttpsession.h>
       
    25 //Added for ALR/SNAP
       
    26 #include <comms-infras/cs_mobility_apiext.h>
       
    27 
       
    28 #include "iractivenetworkobserver.h"
       
    29 #include "irnetworkcontrollerobserver.h"
       
    30 #include "irdatatransfertracker.h"
       
    31 
       
    32 class CIRNetworkObserver;
       
    33 class CIRSettings;
       
    34 class MIRActiveNetworkObserver;
       
    35 
       
    36 /**
       
    37  * This class provides the interface to IRNetworkController component
       
    38  *
       
    39  * @code
       
    40  * // CIRNetworkController follows a singleton pattern
       
    41  * // hence the destructor is private and to destroy it we need to use an API
       
    42  * // For creating a network controller which has provision for network monitoring
       
    43  * // we need to pass the reference of the observer which should derive from
       
    44  * // MIRNetworkControllerObserver class the network even observed will be
       
    45  * // indicated to the observer with the call back IRNetworkEvent() function
       
    46  * CIRNetworkController* iNetworkController = CIRNetworkController::NewL(iObserver)
       
    47  *
       
    48  * // For creating a network controller which does not have provision for network monitoring
       
    49  * // we use the overloaded NewL() of CIRNetworkController
       
    50  * CIRNetworkController* iNetworkController = CIRNetworkController::NewL()
       
    51  *
       
    52  * // This API is used to destroy the network controller handle
       
    53  * iNetworkController->DestroyNetworkController();
       
    54  *
       
    55  * // This API returns the instance of RConnection
       
    56  * // The same RConnection object is used across the entire iRAPP components to
       
    57  * // provide central arbiter and monitoring of Network Connection
       
    58  * iNetworkController->GetIRConnection();
       
    59  *
       
    60  * // This API returns the instance of RSocketServ
       
    61  * // The same RSocketServ object is used across the entire iRAPP components to
       
    62  * // provide central arbiter and monitoring of Network Connection
       
    63  * iNetworkController->GetIRSocketServer();
       
    64  *
       
    65  * // This API returns a pointer to the x-wap-profile string.
       
    66  * // The ownership of the object is passed onto the caller
       
    67  * iNetworkController->GetWapProfString();
       
    68  *
       
    69  * // This API returns a pointer to the UAProf string.
       
    70  * // The ownership of the object is passed onto the caller
       
    71  * iNetworkController->GetUAProfString();
       
    72  *
       
    73  * // This API returns ETrue of network connection is up and running EFalse
       
    74  * // otherwise
       
    75  * iNetworkController->GetNetworkStatus();
       
    76  *
       
    77  * // This API returns the IAP id of the connected connection
       
    78  * // this is used by download manager for choosing the access point
       
    79  * iNetworkController->GetIAPId();
       
    80  *
       
    81  * // This API is called to initiate access point selection
       
    82  * iNetworkController->ChooseAccessPointL();
       
    83  *
       
    84  * // This API returns ETrue if the phone is in offline mode, EFalse
       
    85  * // otherwise
       
    86  * iNetworkController->IsOfflineMode();
       
    87  *
       
    88  * // This API returns ETrue if WLan is supported on the device, EFalse
       
    89  * // otherwise
       
    90  * iNetworkController->IsWlanSupported();
       
    91  *
       
    92  * // This API allows the caller to reset the network connection status
       
    93  * iNetworkController->ResetConnectionStatus();
       
    94  *
       
    95  * // This API returns the type of connection open
       
    96  * iNetworkController->IdentifyConnectionType();
       
    97  *
       
    98  * @endcode
       
    99  *
       
   100  */
       
   101 NONSHARABLE_CLASS( CIRNetworkController ): public CActive, 
       
   102                                            public MIRDataTransferObserver,
       
   103                                            public MMobilityProtocolResp
       
   104     {
       
   105 public:
       
   106 
       
   107     /**
       
   108      *  Creates an Instance of CIRNetworkController
       
   109      *  @return CIRNetworkController*
       
   110      */
       
   111     IMPORT_C static CIRNetworkController* OpenL( MIRNetworkController* aObserver = NULL );
       
   112 
       
   113     /**
       
   114      *  Conditionally destroys the IRNetworkController object
       
   115      */
       
   116     IMPORT_C void Close();
       
   117 
       
   118     /**
       
   119      *  Default C++ Destructor
       
   120      */
       
   121     ~CIRNetworkController();
       
   122 
       
   123     /**
       
   124      *  Returns the instance of RConnection
       
   125      *  The same RConnection object is used across the entire iRAPP components to
       
   126      *  provide central arbiter and monitoring of Network Connection
       
   127      *  @return RConnection&
       
   128      */
       
   129     IMPORT_C RConnection& GetIRConnection();
       
   130 
       
   131     /**
       
   132      *  Returns the instance of RSocketServ
       
   133      *  The same RSocketServ object is used across the entire iRAPP components to
       
   134      *  provide central arbiter and monitoring of Network Connection
       
   135      *  @return RSocketServ&
       
   136      */
       
   137     IMPORT_C RSocketServ& GetIRSocketServer();
       
   138 
       
   139     /**
       
   140      *  Returns a HBufC pointer to the x-wap-profile string
       
   141      *  Transfers the ownership of the returned HBufC8 object
       
   142      *  The caller must takecare of deleting the returned object
       
   143      *  @return HBufC8*
       
   144      */
       
   145     IMPORT_C HBufC8* GetWapProfString();
       
   146 
       
   147     /**
       
   148      *  Returns a HBufC pointer to the UAProf string
       
   149      *  Transfers the ownership of the returned HBufC8 object
       
   150      *  The caller must takecare of deleting the returned object
       
   151      *  @return HBufC8*
       
   152      */
       
   153     IMPORT_C HBufC8* GetUAProfString();
       
   154 
       
   155     /**
       
   156      *  Returns the variable which indicates if connection is active or not
       
   157      *  @return TBool iIsConnectedToNetwork
       
   158      */
       
   159     IMPORT_C TBool GetNetworkStatus() const;
       
   160 
       
   161     /**
       
   162      *  Gets the IAP Id of the chosen IAP
       
   163      *  @return TInt Error code.
       
   164      */
       
   165     IMPORT_C TInt GetIAPId(TUint32& aIapId) const;
       
   166 
       
   167   /**
       
   168      *  Configures the Access Point which is used by all the components for network connectivity
       
   169      */
       
   170     IMPORT_C void ChooseAccessPointL(TBool aDefaultConnection = ETrue);
       
   171 
       
   172     /*
       
   173      * cancel configuring access point
       
   174      */
       
   175     IMPORT_C void CancelConnecting();
       
   176     
       
   177     /**
       
   178      *  This api is used to determine if the phone is in offline mode
       
   179      *  @return ETrue if the phone is in offline mode else EFalse
       
   180      */
       
   181     IMPORT_C TBool IsOfflineMode();
       
   182 
       
   183     /**
       
   184      *  This api is used to determine if the phone supports WLan usage
       
   185      *  @return ETrue if the phone supports else EFalse
       
   186      */
       
   187     IMPORT_C TBool IsWlanSupported() const;
       
   188 
       
   189     /**
       
   190      *  Reset the connection status to Disconnected state
       
   191      */
       
   192     IMPORT_C  void ResetConnectionStatus();
       
   193 
       
   194     /**
       
   195      *  Used to determine the type of connection
       
   196      *  @return enum describing the type of connection ( GPRS/3G/WiFi )
       
   197      */
       
   198     IMPORT_C TIRConnectionType IdentifyConnectionType() const;
       
   199 
       
   200     /**
       
   201      *  Binds DataTranseferTracker instance to HTTPSession (Byte Counter Impl)
       
   202      */
       
   203     IMPORT_C  void InitializeHttpSessionL( const RHTTPSession& aHTTPSession, 
       
   204                         MIRDataTransferTracker::TIRTransferCategory aCategory );
       
   205 
       
   206     /**
       
   207      *  Binds LogoDataTranseferTracker instance to Logo HTTPSession (Byte Counter Impl)
       
   208      */
       
   209     IMPORT_C  void RegisterLogoDataTransferTrackerL( RHTTPSession& aHTTPSession );
       
   210 
       
   211     /**
       
   212      *  DataTranseferTracker instance for observers and Raw sockets (Byte Counter Impl)
       
   213      */
       
   214     IMPORT_C  MIRDataTransferTracker& DataTransferTracker();
       
   215 
       
   216     /**
       
   217      *  LogoDataTranseferTracker instance for observers and Raw sockets (Byte Counter Impl)
       
   218      */
       
   219     IMPORT_C  MIRDataTransferTracker& LogoDataTransferTracker();
       
   220 
       
   221     /**
       
   222      *  Method to receive notification when logo is downloaded
       
   223      */
       
   224     void HandleDataTransferEventL( const MIRDataTransferTracker::TIRDataTransferPckg& aData );
       
   225 
       
   226     /*
       
   227      * Registers the observer that will be notified for 
       
   228      * a network connection.
       
   229      * Observer requires notification to reissue pending request
       
   230      */ 
       
   231     IMPORT_C  void RegisterActiveNetworkObserverL( MIRActiveNetworkObserver& aActiveNetworkObserver );
       
   232 
       
   233     /**
       
   234      * DeleteRoamingObserver()
       
   235      * Used to remove an observer for roaming events from the observer array
       
   236      */
       
   237     IMPORT_C void DeleteActiveNetworkObserver( MIRActiveNetworkObserver& aActiveNetworkObserver );
       
   238         
       
   239     /**
       
   240      * Notifies all observers whose network request is active
       
   241      * to reissue the request  
       
   242      * NotifyActiveNetworkObserversL()
       
   243      */    
       
   244     IMPORT_C  void NotifyActiveNetworkObserversL( TIRNetworkEvent aEvent );
       
   245      
       
   246      /**
       
   247      * Notifies all observers whose network request is active
       
   248      * to reset the pending request status  
       
   249      * ResetPendingRequests()
       
   250      */    
       
   251      void ResetPendingRequests( TBool aValue );
       
   252 
       
   253 protected:
       
   254 
       
   255     /**
       
   256      *  Derived from CActive
       
   257      */
       
   258 
       
   259     /**
       
   260      * The function is called by the active scheduler when a request completion event occurs,
       
   261      */
       
   262     virtual void RunL();
       
   263 
       
   264     /**
       
   265      *  Cancels the pending requests on the CIRNetworkController Active object
       
   266      */
       
   267     virtual void DoCancel();
       
   268     
       
   269     
       
   270 public: // From MMobilityProtocolResp        //to be changed to private after demo
       
   271 
       
   272             //Added for ALR/SNAP
       
   273         void PreferredCarrierAvailable( TAccessPointInfo aOldAPInfo,
       
   274                                         TAccessPointInfo aNewAPInfo,
       
   275                                         TBool aIsUpgrade,
       
   276                                         TBool aIsSeamless );
       
   277         void NewCarrierActive( TAccessPointInfo aNewAPInfo, TBool aIsSeamless );
       
   278         void Error( TInt aError );    
       
   279         
       
   280 public:
       
   281         /**
       
   282          * IsHandingOverConnection()
       
   283          * Indicates if the Hand over of Network connection has happened
       
   284          */
       
   285         IMPORT_C TBool IsHandingOverConnection();
       
   286         
       
   287         void ResetHandingOverConnection();
       
   288         
       
   289 private:
       
   290 
       
   291     /**
       
   292      *  Used to determine the current profile
       
   293      *  @return TInt describing the profile value
       
   294      */
       
   295     TInt DetermineCurrentProfile() const;
       
   296 
       
   297     /**
       
   298      *  Pops up the access point list.
       
   299      *  @return TBool ETrue feature is supported EFalse otherwise
       
   300      */
       
   301     TBool CheckFeatureL( TInt aFeatureId ) const;
       
   302 
       
   303     /**
       
   304      *  Default C++ Constructor
       
   305      */
       
   306     CIRNetworkController();
       
   307 
       
   308     /**
       
   309      *  Second Phase construction.
       
   310      */
       
   311     void ConstructL();
       
   312 
       
   313     /**
       
   314      *  Second Phase construction.
       
   315      *    @param aObserver pointer to the observer class if an observer is needed
       
   316      */
       
   317     void ConstructL( MIRNetworkController* aObserver );
       
   318 
       
   319     /**
       
   320      *  Determines the available access points using CommsDat Api
       
   321      */
       
   322     void QueryCommsForIAPL();
       
   323 
       
   324     /**
       
   325      *  Queries the system and extracts the UAProf information
       
   326      *  Used by IRDataProvider and IRStreamSource
       
   327      */
       
   328     void BuildUAProfStringL();
       
   329 
       
   330     /**
       
   331      *  Retrievs the string from Central Repository for the specified key and cen rep uid
       
   332      *  Transfers the ownership of the returned HBufC object
       
   333      *  The caller must takecare of deleting the returned object*
       
   334      *    @param aRepositoryUid specifies the Uid of the repository to be used
       
   335      *    @param aKey specifies the key to be used
       
   336      *    @return HufC* pointer to the retrieved string
       
   337      */
       
   338     HBufC* CentralRepositoryStringValueL( const TUid& aRepositoryUid,
       
   339         TUint32 aKey ) const;
       
   340 
       
   341     /**
       
   342      *  Pops up the access point list.
       
   343      *  @return TBool ETrue is we need to proceed with access point selection EFalse otherwise
       
   344      */
       
   345     TBool DisplayAccessPointListL();
       
   346 
       
   347     /**
       
   348      *  Validates the access point availablity etc.
       
   349      */
       
   350     TBool ValidateAccessPointsL();
       
   351 
       
   352     /**
       
   353      *  Handles the success case of Network connection in RunL
       
   354      */
       
   355     void HandleRunLSuccessL();
       
   356     
       
   357     /**
       
   358      *  Handles the error case of Network connection in RunL
       
   359      */
       
   360     void HandleRunLErrorL( TInt aStatusCode );
       
   361     
       
   362 public:
       
   363     /**
       
   364      * Indicates if ChooseAccessPointL is called
       
   365      */
       
   366     TBool iIsConnectRequestIssued;
       
   367 
       
   368 private:
       
   369     /**
       
   370      * This is the physical connection we are putting up
       
   371      */
       
   372     RConnection* iIRNetworkConnection;
       
   373 
       
   374     /**
       
   375      * Actual RSocketServ instance
       
   376      */
       
   377     RSocketServ iIRSocketServer;
       
   378 
       
   379     /**
       
   380      * Number of objects currently referring to the singleton object CIRNetworkController
       
   381      */
       
   382     TInt iSingletonInstances;
       
   383 
       
   384     /**
       
   385      * Used to access Settings object
       
   386      */
       
   387     CIRSettings* iIRSettings;
       
   388 
       
   389     /**
       
   390      * IR Network component observer
       
   391      */
       
   392     MIRNetworkController* iObserver;
       
   393 
       
   394     /**
       
   395      * Enum declaration which indicate the network status
       
   396      */
       
   397     enum TIRNetworkConnectionStatus
       
   398         {
       
   399         EIRNetworkConnectionActive = 1,
       
   400         EIRNetworkConnectionInActive
       
   401         };
       
   402 
       
   403     /**
       
   404      * Variable to keep track of the RConnection connection status
       
   405      */
       
   406     TIRNetworkConnectionStatus iNetworkConnectionState;
       
   407 
       
   408     /**
       
   409      * Enum declaration which indicate the connection to RSocketServ status
       
   410      */
       
   411     enum TIRSocketServerConnectionStatus
       
   412         {
       
   413         EIRSocketServerActive = 1,
       
   414         EIRSocketServerInActive
       
   415         };
       
   416 
       
   417     /**
       
   418      * Variable to keep track of the RSocketServ connection status
       
   419      */
       
   420     TIRSocketServerConnectionStatus iSocketServerConnectionState;
       
   421 
       
   422     /**
       
   423      * Enum declaration to indicate the NetworkController state
       
   424      */
       
   425     enum TIRNetworkControllerState
       
   426         {
       
   427         EInActive = 1,
       
   428         EConnectingToNetwork
       
   429         };
       
   430 
       
   431     /**
       
   432      * Specifies the Network controller state
       
   433      */
       
   434     TIRNetworkControllerState iNetworkControllerState;
       
   435 
       
   436     /**
       
   437      * Indicates the current network connection status
       
   438      */
       
   439     TBool iIsConnectedToNetwork;
       
   440 
       
   441     /**
       
   442      * Network observer
       
   443      */
       
   444     CIRNetworkObserver* iIRNetworkObserver;
       
   445 
       
   446     /**
       
   447      * Pointer to UAProf string
       
   448      */
       
   449     HBufC8* iIRUAProf;
       
   450 
       
   451     /**
       
   452      * Pointer to x-wap-profile string
       
   453      */
       
   454     HBufC8* iIRWapProf;
       
   455 
       
   456     /**
       
   457      * Access point list for settings view
       
   458      */
       
   459     CDesCArrayFlat* iIapList;
       
   460 
       
   461   /**
       
   462      * Indicates if WiFi is supported or not
       
   463      */
       
   464     TBool iIsWlanSupported;
       
   465 
       
   466     /**
       
   467      * Used to determine if connection is open or not
       
   468      */
       
   469 
       
   470     TBool iConnectionPresent;
       
   471 
       
   472     /**
       
   473      * Tracks data transferred over the network for the connection.
       
   474      * Owned.
       
   475      */
       
   476 
       
   477     CIRDataTransferTracker* iDataTransferTracker;
       
   478 
       
   479     /**
       
   480      * Tracks data transferred over the network for the Logo session.
       
   481      * Owned.
       
   482      */
       
   483 
       
   484     CIRDataTransferTracker* iLogoDataTransferTracker;
       
   485     
       
   486     //Added for ALR/SNAP
       
   487     
       
   488     /**
       
   489     * Observes the preferred network within defined destination
       
   490     */
       
   491     CActiveCommsMobilityApiExt* iMobility;
       
   492 
       
   493     /**
       
   494      * ETrue if the ALR handover is ongoing
       
   495      */
       
   496     TBool iHandingOver;
       
   497     
       
   498     /**
       
   499      * Array of observers for change in roaming events
       
   500      */
       
   501     RPointerArray<MIRActiveNetworkObserver> iActiveNetworkObserverArray;
       
   502     
       
   503     TBool iDefaultConnection;
       
   504     };
       
   505 
       
   506 #endif // C_IRNETWORKCONTROLLER_H