cbs/CbsServer/ServerSrc/Ccbsrecnetworklistener.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2003-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:  This module contains the implementation of CCbsRecNetworkListener class 
       
    15 *                member functions.   
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 //  INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <e32svr.h>
       
    24 #include <etelmm.h>
       
    25 #include "CCbsRecNetworkListener.h"
       
    26 #include "CbsLogger.h"
       
    27  
       
    28 // CONSTANTS
       
    29 
       
    30 /// Network listener's priority in active scheduler.
       
    31 const TInt KCbsRecNetworkListenerPriority = CActive::EPriorityStandard + 5;
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CCbsRecNetworkListener::CCbsRecNetworkListener
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CCbsRecNetworkListener::CCbsRecNetworkListener( 
       
    42     RMobilePhone& aPhone )
       
    43     : CActive( KCbsRecNetworkListenerPriority ), 
       
    44       iNetworkInfoRetrieved( EFalse ), 
       
    45       iPhone( aPhone ),
       
    46       iNetworkInfoPckg( iNetworkInfo ),
       
    47       iGetCurrentNetworkActive( EFalse ),
       
    48       iNotifyNwRegChange( EFalse ) 
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CCbsRecNetworkListener::ConstructL
       
    54 // Symbian 2nd phase constructor can leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CCbsRecNetworkListener::ConstructL()
       
    58     {
       
    59     CActiveScheduler::Add( this );
       
    60     IssueGetCurrentNwRequest();
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CCbsRecNetworkListener::NewL
       
    65 // Two-phased constructor.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CCbsRecNetworkListener* CCbsRecNetworkListener::NewL( 
       
    69     RMobilePhone& aPhone )
       
    70     {
       
    71     CCbsRecNetworkListener* self = 
       
    72         new (ELeave) CCbsRecNetworkListener( aPhone );
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop( self );
       
    76     return self;
       
    77     }
       
    78 
       
    79 
       
    80 // Destructor
       
    81 CCbsRecNetworkListener::~CCbsRecNetworkListener()
       
    82     {
       
    83     CBSLOGSTRING("CBSSERVER: >>> CCbsRecNetworkListener::~CCbsRecNetworkListener()");
       
    84     Cancel();
       
    85     CBSLOGSTRING("CBSSERVER: <<< CCbsRecNetworkListener::~CCbsRecNetworkListener()");
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CCbsRecMessage::GetCurrentNetworkInfo
       
    90 // Fetches the current networking info.
       
    91 // (other items were commented in a header).
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 TInt CCbsRecNetworkListener::GetCurrentNetworkInfo(
       
    95     RMobilePhone::TMobilePhoneNetworkInfoV1& aNetworkInfo, 
       
    96     RMobilePhone::TMobilePhoneLocationAreaV1& aArea )
       
    97     {
       
    98     TInt errorCode;
       
    99     if ( !iNetworkInfoRetrieved )
       
   100         {
       
   101         // No network state change notification arrived yet
       
   102         errorCode = KErrNotFound;
       
   103         }
       
   104     else
       
   105         {
       
   106         // Get both infos from member variables        
       
   107         aNetworkInfo = iNetworkInfo;
       
   108         aArea = iArea;
       
   109         errorCode = KErrNone;
       
   110         }
       
   111     return errorCode;
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CCbsRecMessage::RunL
       
   116 // Called after NotifyCurrentNetworkChange is completed by EPOC Telephony Server.
       
   117 // (other items were commented in a header).
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CCbsRecNetworkListener::RunL()
       
   121     {
       
   122     CBSLOGSTRING("CBSSERVER: >>> CCbsRecNetworkListener::RunL()");
       
   123     if ( iGetCurrentNetworkActive )
       
   124         {   
       
   125         // Current request is getting current active network
       
   126         HandleGetCurrentNetworkResult();
       
   127         }
       
   128     else
       
   129         {
       
   130         if ( iNotifyNwRegChange )
       
   131             {
       
   132             // Current request is notifying network registeration change
       
   133             HandleNotifyNetworkRegistrationStatusChangeResult();
       
   134             }
       
   135         else
       
   136             {
       
   137             // Current request is notifying current network state change
       
   138             HandleNotifyCurrentNetworkChangeResult();
       
   139             }
       
   140         }
       
   141     CBSLOGSTRING("CBSSERVER: <<< CCbsRecNetworkListener::RunL()");
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CCbsRecMessage::DoCancel
       
   146 // Called whenever the listener has been requested to cancel.
       
   147 // (other items were commented in a header).
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CCbsRecNetworkListener::DoCancel()
       
   151     {
       
   152     // Cancel current request. Ongoing request can be:
       
   153     // GetCurrentNetwork, NotifyNetworkRegistrationStatusChange and 
       
   154     // NotifyCurrentNetworkChange.
       
   155     
       
   156     // Check if the initialization phase was going on
       
   157     if ( iGetCurrentNetworkActive )
       
   158         {   
       
   159         iPhone.CancelAsyncRequest( EMobilePhoneGetCurrentNetwork );
       
   160         iGetCurrentNetworkActive = EFalse;
       
   161         }
       
   162     else
       
   163         {
       
   164         // Check if the notification of network registration state change
       
   165         if ( iNotifyNwRegChange )
       
   166             {
       
   167             iPhone.CancelAsyncRequest( EMobilePhoneNotifyNetworkRegistrationStatusChange );
       
   168             iNotifyNwRegChange = EFalse;
       
   169             }
       
   170         else
       
   171             {
       
   172             // Current request is notification of current network change
       
   173             iPhone.CancelAsyncRequest( EMobilePhoneNotifyCurrentNetworkChange );
       
   174             }    
       
   175         }
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CCbsRecNetworkListener::IssueGetCurrentNwRequest
       
   180 // Requests getting current network information from EPOC Telephony Server.
       
   181 // (other items were commented in a header).
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CCbsRecNetworkListener::IssueGetCurrentNwRequest()
       
   185     {
       
   186     CBSLOGSTRING("CBSSERVER: >>> CCbsRecNetworkListener::\
       
   187                   IssueGetCurrentNwRequest()");
       
   188     if ( !IsActive() )
       
   189         {
       
   190         iPhone.GetCurrentNetwork( iStatus, iNetworkInfoPckg, iArea );
       
   191         SetActive();
       
   192         iGetCurrentNetworkActive = ETrue;
       
   193         }
       
   194     else
       
   195         {
       
   196         CBSLOGSTRING("CBSSERVER: CCbsRecNetworkListener::\
       
   197                      IssueGetCurrentNwRequest(), Aready active");
       
   198         }
       
   199     CBSLOGSTRING("CBSSERVER: <<< CCbsRecNetworkListener::\
       
   200                   IssueGetCurrentNwRequest()");
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CCbsRecNetworkListener::IssueNotifyNwRegChangeRequest
       
   205 // Requests notification of network registration state change 
       
   206 // from EPOC Telephony Server.
       
   207 // (other items were commented in a header).
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CCbsRecNetworkListener::IssueNotifyNwRegChangeRequest()
       
   211     {
       
   212     CBSLOGSTRING("CBSSERVER: >>> CCbsRecNetworkListener::\
       
   213                   IssueNotifyNwRegChangeRequest()");
       
   214     if ( !IsActive() )
       
   215         {
       
   216         iPhone.NotifyNetworkRegistrationStatusChange( iStatus, iRegistration );
       
   217         SetActive();
       
   218         iNotifyNwRegChange = ETrue;
       
   219         }
       
   220     else
       
   221         {
       
   222         CBSLOGSTRING("CBSSERVER: CCbsRecNetworkListener::\
       
   223                      IssueNotifyNwRegChangeRequest(), Aready active");
       
   224         }
       
   225     CBSLOGSTRING("CBSSERVER: <<< CCbsRecNetworkListener::\
       
   226                   IssueNotifyNwChangeRequest()");
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CCbsRecNetworkListener::IssueNotifyNwChangeRequest
       
   231 // Requests notification of network state change from EPOC Telephony Server.
       
   232 // (other items were commented in a header).
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CCbsRecNetworkListener::IssueNotifyNwChangeRequest()
       
   236     {
       
   237     CBSLOGSTRING("CBSSERVER: >>> CCbsRecNetworkListener::\
       
   238                   IssueNotifyNwChangeRequest");
       
   239     if ( !IsActive() )
       
   240         {
       
   241         iPhone.NotifyCurrentNetworkChange( iStatus, iNetworkInfoPckg, iArea );
       
   242         SetActive();
       
   243         }
       
   244     else
       
   245         {
       
   246         CBSLOGSTRING("CBSSERVER: CCbsRecNetworkListener::\
       
   247                      IssueNotifyNwChangeRequest(), Aready active");
       
   248         }
       
   249     CBSLOGSTRING("CBSSERVER: <<< CCbsRecNetworkListener::\
       
   250                   IssueNotifyNwChangeRequest()");
       
   251     }
       
   252 
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // When the current request is GetCurrentNetwork, handle the return result
       
   256 // (other items were commented in a header).
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CCbsRecNetworkListener::HandleGetCurrentNetworkResult()
       
   260     {
       
   261     CBSLOGSTRING("CBSSERVER: >>> CCbsRecNetworkListener::\
       
   262                   HandleGetCurrentNetworkResult");
       
   263     iGetCurrentNetworkActive = EFalse;
       
   264 
       
   265     if ( KErrNone == iStatus.Int() )
       
   266         {
       
   267         // Get the network information successfully
       
   268         // Submit the notify current network change request.
       
   269         iNetworkInfoRetrieved = ETrue;
       
   270         IssueNotifyNwChangeRequest();
       
   271         }
       
   272     else
       
   273         {
       
   274         // Run into some problems to get network information,
       
   275         // submit the request of notification of network registration
       
   276         // state change
       
   277         CBSLOGSTRING2("CBSSERVER: CCbsRecNetworkListener::\
       
   278         HandleGetCurrentNetworkResult, iStatus is %d", iStatus.Int());
       
   279         IssueNotifyNwRegChangeRequest();
       
   280         } 
       
   281     CBSLOGSTRING("CBSSERVER: <<< CCbsRecNetworkListener::\
       
   282                   HandleGetCurrentNetworkResult");
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // When the current request is NotifyNetworkRegistrationStatusChange, 
       
   287 // handle the return result
       
   288 // (other items were commented in a header).
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void CCbsRecNetworkListener::HandleNotifyNetworkRegistrationStatusChangeResult()
       
   292     {
       
   293     CBSLOGSTRING("CBSSERVER: >>> CCbsRecNetworkListener::\
       
   294                   HandleNotifyNetworkRegistrationStatusChangeResult()");
       
   295 
       
   296     if ( KErrNone == iStatus.Int() )
       
   297         {
       
   298         CBSLOGSTRING2("CBSSERVER: CCbsRecNetworkListener::\
       
   299                        HandleNotifyNetworkRegistrationStatusChangeResult(), \
       
   300                        registration status is %d", iRegistration);
       
   301   
       
   302         if ( ( RMobilePhone::ERegisteredOnHomeNetwork == 
       
   303                iRegistration ) ||
       
   304              ( RMobilePhone::ERegisteredRoaming == iRegistration ) )
       
   305             {
       
   306             // ME successfully registered on network, submit GetCurrentNetwork 
       
   307             // request to get current network information
       
   308             iNotifyNwRegChange = EFalse;
       
   309             IssueGetCurrentNwRequest();
       
   310             }
       
   311         else
       
   312             {
       
   313             // ME didn't successfully registered on network.
       
   314             // Resubmit this request.
       
   315             IssueNotifyNwRegChangeRequest();
       
   316             }
       
   317         }
       
   318     else
       
   319         {
       
   320         CBSLOGSTRING2("CBSSERVER: CCbsRecNetworkListener::\
       
   321                        HandleNotifyNetworkRegistrationStatusChangeResult, \
       
   322                        iStatus is %d", iStatus.Int() );
       
   323         IssueNotifyNwRegChangeRequest();
       
   324         }
       
   325 
       
   326     CBSLOGSTRING("CBSSERVER: <<< CCbsRecNetworkListener::\
       
   327                   HandleNotifyNetworkRegistrationStatusChangeResult()");
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // When the current request is NotifyCurrentNetworkChange, 
       
   332 // handle the return result
       
   333 // (other items were commented in a header).
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CCbsRecNetworkListener::HandleNotifyCurrentNetworkChangeResult()
       
   337     {
       
   338     CBSLOGSTRING("CBSSERVER: >>> CCbsRecNetworkListener::\
       
   339                   HandleNotifyCurrentNetworkChangeResult()");
       
   340 
       
   341     CBSLOGSTRING2("CBSSERVER: CCbsRecNetworkListener::\
       
   342                    HandleNotifyCurrentNetworkChangeResult, \
       
   343                    iStatus is %d", iStatus.Int());
       
   344     iNetworkInfoRetrieved = ( KErrNone == iStatus.Int() ) ? ETrue : EFalse;
       
   345     IssueNotifyNwChangeRequest();
       
   346 
       
   347     CBSLOGSTRING("CBSSERVER: <<< CCbsRecNetworkListener::\
       
   348                   HandleNotifyCurrentNetworkChangeResult()");
       
   349     }
       
   350 
       
   351 //  End of File