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