networkhandling/networkhandlingengine/NetworkHandlingGsmInc/CNWNetworkViagCbEngine.h
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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:  This file contains the header file of the CNWNetworkViagCbEngine class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CNWNETWORKVIAGCBENGINE_H
       
    21 #define CNWNETWORKVIAGCBENGINE_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include "MNWNetworkTimer.h"
       
    25 #include "NWHandlingEngine.h"
       
    26 #include "CNWGsmMessageHandler.h"
       
    27 #include "CNWNetworkHZCbCacheHandler.h"
       
    28 #include "MHZCachesInitialisationObserver.h"
       
    29 #include <MCbsMcnObserver.h> //For McbsMcnObserver
       
    30 #include <rmmcustomapi.h>
       
    31 #include <e32property.h>
       
    32 
       
    33 // CONSTANTS
       
    34 //timer values
       
    35 #ifdef TESTINGVIAG
       
    36 const TInt KViagTimerSixtySeconds = 6000000;
       
    37 #else
       
    38 const TInt KViagTimerSixtySeconds = 60000000;
       
    39 #endif
       
    40     //operation values to HomeZone cache accessing
       
    41 const TInt KAdd = 1;
       
    42 const TInt KRemove = 2;
       
    43 const TInt KCompare = 3;
       
    44 //values for Viag stuff
       
    45 //Defined in Viag HomeZone spec
       
    46 const TInt KDynCacheCount = 5;
       
    47 //The normal length of CB message for Viag HomeZone
       
    48 const TInt KNWViagHzMsgLength = 12;
       
    49 const TInt KNWViagHzCoordinateLength = 6;
       
    50 //The maximun radius for HomeZone
       
    51 const TInt KNWViagHomeZoneMaxRad = 10000;
       
    52 //specified in HomeZone Mobile Terminal Service specification spec
       
    53 const TUint KNWHomeZoneMsgId = 221; 
       
    54 
       
    55 //Cache start and end values
       
    56 const TInt KFirstCacheValue = 1;
       
    57 const TInt KLastCacheValue = 4;
       
    58 // Cache indexes
       
    59 const TInt KFirstRecordIndex = 0;
       
    60 const TInt KLastRecordIndex = 20;
       
    61 
       
    62 
       
    63 // FORWARD DECLARATIONS
       
    64 class CNWGsmSessionImplementation;
       
    65 class CNWNetworkViagTimer;
       
    66 class CMcn;
       
    67 class CNWGsmMessageHandler;
       
    68 
       
    69 // CLASS DECLARATION
       
    70 
       
    71 /**
       
    72 *  Monitors current network change event from MMEtel.
       
    73 *  
       
    74 *
       
    75 *  @lib networkhandling.lib
       
    76 *  @since Series 60_2.8
       
    77 */
       
    78 class CNWNetworkViagCbEngine : public CBase, 
       
    79                              public MCbsMcnObserver,
       
    80                              protected MNWNetworkTimer,
       
    81                              public MHZCachesInitialisationObserver
       
    82     {
       
    83     private:
       
    84         struct TViagZoneInfo
       
    85             {
       
    86             TUint32 iX;
       
    87             TUint32 iY;
       
    88             TUint32 iR2;
       
    89             TUint iZoneId;
       
    90             TBuf<13> iName;
       
    91             RMmCustomAPI::TActiveFlag iActiveFlag;
       
    92             };
       
    93         // Array of TViagZoneInfo struct data.
       
    94         typedef CArrayFixFlat< TViagZoneInfo > CViagZoneArray;
       
    95     public:  // Constructors and destructor
       
    96         
       
    97         /**
       
    98         * Two-phased constructor.
       
    99         */
       
   100         static CNWNetworkViagCbEngine* NewL(
       
   101                         CNWNetworkViagBaseEngine& aBase,
       
   102                         TNWInfo& aNetworkInfo,
       
   103                         RMmCustomAPI& aCustomAPI,
       
   104                         TNWInterInfo& aInterNetworkInfo,
       
   105                         CNWGsmNetworkCellReselectionHandler& 
       
   106                         aCellReselectionHandler);
       
   107         /**
       
   108         * Destructor.
       
   109         */
       
   110         virtual ~CNWNetworkViagCbEngine();
       
   111 
       
   112 
       
   113     public: // Functions from MCbsMcnObserver
       
   114 
       
   115         /**
       
   116         *   This method is called when a message of a subscribed topic 
       
   117         *   is received from the network.
       
   118         *
       
   119         *   @param  aMcnMessage         MCN message received from the network.
       
   120         *   @return                     Result code
       
   121         */
       
   122         TInt CellInfoChanged( const TCbsMcnMessage& aMcnMessage );
       
   123 
       
   124         /**
       
   125         * Is called by CNWNetworkCurrentNetworkMonitor in case of 
       
   126         * cell re-selection.
       
   127         * @param 
       
   128         * @return Error code.
       
   129         */
       
   130         void CellReselection();
       
   131 
       
   132 
       
   133 
       
   134 		 /**
       
   135         * Is called by CNWNetworkViagBaseEngine in case of Sat refresh to
       
   136         * HZ-EF or 
       
   137         * @param None.
       
   138         * @return
       
   139         */
       
   140         void SatRefreshCompleteNotification();
       
   141 
       
   142         /**
       
   143         * Is called by CNWNetworkViagBaseEngine in case of Cb algo needed 
       
   144         * to stop 
       
   145         * @param None.
       
   146         * @return
       
   147         */
       
   148     
       
   149         void StopCbAlgo();
       
   150         
       
   151         /**
       
   152         * Updates Viag HomeZone parameters from SIM.
       
   153         * 
       
   154         * @param 
       
   155         * @return Error code.
       
   156         */
       
   157         TInt UpdateViagHzParams();
       
   158 
       
   159         /**
       
   160         * Initialises caches
       
   161         * 
       
   162         */
       
   163         void InitilizeCaches();
       
   164 
       
   165     protected:  // Functions from MNWNetworkTimer
       
   166         
       
   167         /**
       
   168         * This method is called when network timer expires.
       
   169         *
       
   170         * @param
       
   171         * @return
       
   172         */
       
   173         void HandleTimeOut();
       
   174 
       
   175     public:  // Functions from MHZCachesInitialisationObserver
       
   176         /**
       
   177         * This method is called when HomeZone caches are read
       
   178         *
       
   179         * @param    aError
       
   180         * @return   None
       
   181         */
       
   182         void NotifyCachesInitialised( );
       
   183         
       
   184 
       
   185     private:
       
   186 
       
   187         /**
       
   188         * C++ default constructor.
       
   189         */
       
   190         CNWNetworkViagCbEngine( CNWNetworkViagBaseEngine& aBase,
       
   191                               TNWInfo& aNetworkInfo,
       
   192                               RMmCustomAPI& aCustomAPI,
       
   193                               TNWInterInfo& aInterNetworkInfo,
       
   194                               CNWGsmNetworkCellReselectionHandler& 
       
   195                               aCellReselectionHandler
       
   196                               );
       
   197 
       
   198 
       
   199 
       
   200         /**
       
   201         * By default Symbian 2nd phase constructor is private.
       
   202         */
       
   203         void ConstructL();
       
   204         
       
   205      private:  // New functions
       
   206         
       
   207         /**
       
   208         * Checks if there are active Home/CityZone(s).
       
   209         * 
       
   210         * @param 
       
   211         * @return Error code.
       
   212         */
       
   213         void IsActiveZone();
       
   214 
       
   215 
       
   216         /**
       
   217         * Registers to listen CBS messages.
       
   218         * 
       
   219         * @param aTopic     Topic id of the CBS messages to listen.
       
   220         * @return Error code.
       
   221         */
       
   222        void RegisterToCBSL( TUint16 aTopic );
       
   223 
       
   224         /**
       
   225         * Handles the zone indicators.
       
   226         * 
       
   227         * @param 
       
   228         * @return 
       
   229         */
       
   230         void StartIndicatorHandlingL( TBool  aRefreshOccured );
       
   231 
       
   232         /**
       
   233         * Handles the CBS messages.
       
   234         * 
       
   235         * @param  aMcnMessage         MCN message received from the network.
       
   236         * @return Possible error code
       
   237         */
       
   238         TInt HandleCBSMessages( const TCbsMcnMessage& aMcnMessage );
       
   239         
       
   240         /**
       
   241         * Checks if current zones coordinates are within some active 
       
   242         * Home-/CityZone limits.
       
   243         * @param  aX    Current zones X-coordinate. 
       
   244         * @param  aY    Current zones Y-coordinate. 
       
   245         * @return Possible error code
       
   246         */
       
   247         TInt CheckCellInHomeZoneArray( TUint32 aX, TUint32 aY );
       
   248 
       
   249         /**
       
   250         * Adds aZone to the HomeZone cache.
       
   251         * 
       
   252         * @param aZone target zone cache
       
   253         * @param aCellInfo cell information to be added
       
   254         * @return Possible error code
       
   255         */
       
   256         TInt AddToHomeZoneCache( const THomeZoneCacheId aZone, 
       
   257             const RMmCustomAPI::TViagCacheRecordContent aCellInfo );
       
   258 
       
   259         /**
       
   260         * Searches HomeZone caches. Stops in first match.
       
   261         * 
       
   262         * @param aCellInfo      Cell to searched
       
   263         * @param aActiveZones   List of zones to be searched
       
   264         * @return               Possible error code
       
   265         */
       
   266         TInt SearchHomeZoneCaches( 
       
   267             const RMmCustomAPI::TViagCacheRecordContent aCellInfo,
       
   268             const CViagZoneArray * aActiveZones );
       
   269 
       
   270         /**
       
   271         * Resets Viag's and MCN display's TNWInfo values.
       
   272         *
       
   273         * @param
       
   274         * @return
       
   275         */
       
   276         void ResetIndicatorValues();
       
   277         
       
   278         /**
       
   279         * Writes Viag-values to networkinfo, shared data and system agent.
       
   280         *
       
   281         * @param aIndicatorType 	Indicates which zone it is.
       
   282         * @param aCacheId 	The Id of the cache that text tag must be read from.
       
   283         * @return
       
   284         */
       
   285         void WriteViagValues( TInt aIndicatorType, TInt aCacheId );
       
   286 
       
   287         /**
       
   288         * Clear all HomeZone caches..
       
   289         *
       
   290         * @param None.
       
   291         * @return None.
       
   292         */
       
   293         void ClearHomeZoneCaches();
       
   294 
       
   295         /**
       
   296         * Validate the content of received HomeZone CBS messag
       
   297         *
       
   298         * @param aMsgData contains the date to be validate
       
   299         * @return ETrue if the aMsgData is valid. EFalse otherwise.
       
   300         */
       
   301         TBool ValidateHZCBSMessage( const TDesC & aMsgData );
       
   302 
       
   303         /**
       
   304         * Removes a first match cell caches
       
   305         *
       
   306         * @param aCellInfo      Source cell id
       
   307         * @return ETrue if operation was succesfull
       
   308         */
       
   309         TBool RemoveFromHomeZoneCaches(
       
   310             const RMmCustomAPI::TViagCacheRecordContent aCellInfo );
       
   311 
       
   312         /**
       
   313         * This method is called internally for handling cache insert operation
       
   314         * in CBS message handling
       
   315         *
       
   316         * @param aCache         Target cache
       
   317         * @param aCellInfo      Source cell id
       
   318         * @return ETrue if operation was succesfull
       
   319         */
       
   320         TInt DoHandleAddToCBSHZCache( 
       
   321             const THomeZoneCacheId aCache,
       
   322             const RMmCustomAPI::TViagCacheRecordContent aCellInfo );
       
   323  
       
   324     private:    // Data
       
   325 
       
   326         CViagZoneArray* iActiveZoneArray;
       
   327 
       
   328         /**
       
   329         * The type for array of Viag elements.
       
   330         */
       
   331         typedef CArrayFixFlat< RMmCustomAPI::TViagElement > TViagElements;
       
   332 
       
   333         TViagElements* iElements;
       
   334         // Viag parameters
       
   335         RMmCustomAPI::TViagParams iParams;
       
   336 
       
   337         //Enumeration for currently active zones
       
   338         enum TActiveZones
       
   339             {
       
   340             ENoneActive,
       
   341             EHomeActive,
       
   342             ECityActive,
       
   343             EBothActive
       
   344             };
       
   345         TActiveZones iIsActiveZones;
       
   346 
       
   347         //Indicates if we are listening VIAG messages.
       
   348         enum
       
   349             {
       
   350             EListeningNone,
       
   351             EListeningViag
       
   352             } iCBSState;
       
   353 
       
   354         //Indicates if 60 second timer is on.
       
   355         enum 
       
   356             {
       
   357             EIdle,
       
   358             ECbsSixtySecondsWaiting
       
   359             } iState;
       
   360 
       
   361         //Timer
       
   362         CNWNetworkViagTimer *   iTimer;
       
   363         //current cell info
       
   364         RMmCustomAPI::TViagCacheRecordContent iCellInfo;
       
   365         // Base servers for HomeZone algoritms     
       
   366          CNWNetworkViagBaseEngine& iBase;
       
   367         // Reference to the network info structure.
       
   368         TNWInfo&                iNWNetworkInfo;
       
   369         // Reference to the customAPI connection
       
   370         RMmCustomAPI&           iCustomAPI;
       
   371         // Pointer to MCN object
       
   372         CMcn*                   iMcn;
       
   373         // Reference to the internal network info structure.
       
   374         TNWInterInfo&           iInterNetworkInfo;
       
   375         //// Reference to the CNWGsmNetworkCellReselectionHandler
       
   376         CNWGsmNetworkCellReselectionHandler& iCellReselectionHandler;
       
   377         // Cached HomeZone CBS Message
       
   378         TCbsMcnMessage          iCachedHZCBSMessage;
       
   379         // Interface to CBS HomeZone/CityZone cache services
       
   380         CNWNetworkHZCbCacheHandler * iCacheHandler;
       
   381     };
       
   382 
       
   383 #endif      // CNWNetworkViagCbEngine_H   
       
   384             
       
   385 // End of File