messagingapp/msgnotifications/msgerrorwatcher/src/msgerrorroamingobserver.cpp
changeset 70 a15d9966050f
equal deleted inserted replaced
61:8ba0afbb4637 70:a15d9966050f
       
     1 /*
       
     2 * Copyright (c) 2010 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:  
       
    15 *       CMsgErrorRoamingObserver implementation file
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include    <e32base.h>
       
    23 #include    <etel.h>
       
    24 #include    <etelmm.h>
       
    25 #include    <mmtsy_names.h>
       
    26 
       
    27 #include    "msgerrorwatcher_p.h"
       
    28 #include    "msgerrorroamingobserver.h"
       
    29 #include    "debugtraces.h"
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // ================= MEMBER FUNCTIONS =======================
       
    34 
       
    35 /*****************************************************
       
    36 *   Series 60 Customer / ETel
       
    37 *   Series 60  ETel API
       
    38 *****************************************************/
       
    39 
       
    40 // ---------------------------------------------------------
       
    41 // CMsgErrorRoamingObserver::CMsgErrorRoamingObserver
       
    42 //
       
    43 // C++ constructor can NOT contain any code, that
       
    44 // might leave.
       
    45 // ---------------------------------------------------------
       
    46 //
       
    47 CMsgErrorRoamingObserver::CMsgErrorRoamingObserver( CMsgErrorWatcherPrivate&  aWatcher )
       
    48     : CActive( CActive::EPriorityStandard ),
       
    49     iWatcher( aWatcher ),
       
    50     iRoaming( EFalse ),
       
    51     iRegStatus( RMobilePhone::ERegistrationUnknown ),
       
    52     iRequestId( 0 )
       
    53     {
       
    54     QDEBUG_WRITE("CMsgErrorRoamingObserver:CMsgErrorRoamingObserver : Enter");
       
    55     CActiveScheduler::Add( this );
       
    56     QDEBUG_WRITE("CMsgErrorRoamingObserver:CMsgErrorRoamingObserver : Exit");
       
    57     }
       
    58 
       
    59 /*****************************************************
       
    60 *   Series 60 Customer / ETel
       
    61 *   Series 60  ETel API
       
    62 *****************************************************/
       
    63 
       
    64 /*****************************************************
       
    65 *   Series 60 Customer / TSY
       
    66 *   Needs customer TSY implementation
       
    67 *****************************************************/
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // CMsgErrorRoamingObserver::ConstructL()
       
    71 //
       
    72 // Symbian OS default constructor can leave.
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 void CMsgErrorRoamingObserver::ConstructL()
       
    76     {
       
    77     QDEBUG_WRITE("CMsgErrorRoamingObserver:ConstructL : Enter");
       
    78     User::LeaveIfError( iETelServer.Connect() );
       
    79     User::LeaveIfError( iETelServer.LoadPhoneModule( KMmTsyModuleName ) );
       
    80     User::LeaveIfError( iMobilePhone.Open( iETelServer, KMmTsyPhoneName ) );
       
    81     iMobilePhone.GetNetworkRegistrationStatus( iStatus, iRegStatus );
       
    82     iRequestId = EMobilePhoneGetNetworkRegistrationStatus;
       
    83     SetActive();
       
    84     QDEBUG_WRITE("CMsgErrorRoamingObserver:ConstructL : Exit");
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------
       
    88 // CMsgErrorRoamingObserver::NewL
       
    89 //
       
    90 // Two-phased constructor.
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 CMsgErrorRoamingObserver* CMsgErrorRoamingObserver::NewL( CMsgErrorWatcherPrivate& aWatcher )
       
    94     {
       
    95     QDEBUG_WRITE("CMsgErrorRoamingObserver:NewL : Enter");
       
    96     CMsgErrorRoamingObserver* self = new ( ELeave )
       
    97         CMsgErrorRoamingObserver( aWatcher );
       
    98     
       
    99     CleanupStack::PushL( self );
       
   100     self->ConstructL();
       
   101     CleanupStack::Pop( self );
       
   102     QDEBUG_WRITE("CMsgErrorRoamingObserver:NewL : Exit");
       
   103 
       
   104     return self;
       
   105     }
       
   106 
       
   107     
       
   108 /*****************************************************
       
   109 *   Series 60 Customer / ETel
       
   110 *   Series 60  ETel API
       
   111 *****************************************************/
       
   112 
       
   113 /*****************************************************
       
   114 *   Series 60 Customer / TSY
       
   115 *   Needs customer TSY implementation
       
   116 *****************************************************/
       
   117 
       
   118 // ---------------------------------------------------------
       
   119 // CMsgErrorRoamingObserver::~CMsgErrorRoamingObserver
       
   120 //
       
   121 // Destructor
       
   122 // ---------------------------------------------------------
       
   123 //
       
   124 CMsgErrorRoamingObserver::~CMsgErrorRoamingObserver()
       
   125     {
       
   126     QDEBUG_WRITE("CMsgErrorRoamingObserver:~CMsgErrorRoamingObserver : Enter");
       
   127     Cancel();
       
   128     iMobilePhone.Close();
       
   129     iETelServer.UnloadPhoneModule( KMmTsyModuleName );
       
   130     iETelServer.Close();    
       
   131     QDEBUG_WRITE("CMsgErrorRoamingObserver:~CMsgErrorRoamingObserver : Exit");
       
   132     }
       
   133 
       
   134 /*****************************************************
       
   135 *   Series 60 Customer / ETel
       
   136 *   Series 60  ETel API
       
   137 *****************************************************/
       
   138 
       
   139 // ---------------------------------------------------------
       
   140 // CMsgErrorRoamingObserver::UpdateRoamingStatusL
       
   141 //
       
   142 // Checks whether roaming status has actually changed
       
   143 // ---------------------------------------------------------
       
   144 //
       
   145 void CMsgErrorRoamingObserver::UpdateRoamingStatusL()
       
   146     {
       
   147     QDEBUG_WRITE("CMsgErrorRoamingObserver:UpdateRoamingStatusL : Enter");
       
   148     QDEBUG_WRITE_FORMAT("iRoaming: ", iRoaming);
       
   149     QDEBUG_WRITE_FORMAT("iRegStatus: ", iRegStatus);
       
   150     
       
   151     TBool changed = EFalse;
       
   152     if ( iRoaming && iRegStatus == RMobilePhone::ERegisteredOnHomeNetwork )
       
   153         {
       
   154         iRoaming = EFalse;
       
   155         changed = ETrue;
       
   156         }
       
   157     else if ( !iRoaming && iRegStatus == RMobilePhone::ERegisteredRoaming )
       
   158         {
       
   159         iRoaming = ETrue;
       
   160         changed = ETrue;
       
   161         }
       
   162     else
       
   163         {
       
   164         //Nothing to do
       
   165         }  
       
   166     QDEBUG_WRITE_FORMAT("changed: ", changed);
       
   167     if ( changed )
       
   168         {
       
   169         //Inform watcher only when roaming status has changed
       
   170         iWatcher.HandleRoamingEventL( iRoaming );
       
   171         }
       
   172     QDEBUG_WRITE("CMsgErrorRoamingObserver:UpdateRoamingStatusL : Exit");
       
   173     }
       
   174 
       
   175 /*****************************************************
       
   176 *   Series 60 Customer / ETel
       
   177 *   Series 60  ETel API
       
   178 *****************************************************/
       
   179 
       
   180 // ---------------------------------------------------------
       
   181 // CMsgErrorRoamingObserver::Start
       
   182 //
       
   183 // Starts the active object
       
   184 // ---------------------------------------------------------
       
   185 //
       
   186 void CMsgErrorRoamingObserver::Start()
       
   187     {
       
   188     QDEBUG_WRITE("CMsgErrorRoamingObserver:Start : Enter");
       
   189     if ( !IsActive() ) 
       
   190         {
       
   191         iMobilePhone.NotifyNetworkRegistrationStatusChange( iStatus, iRegStatus );
       
   192         iRequestId = EMobilePhoneNotifyNetworkRegistrationStatusChange;
       
   193         SetActive();
       
   194         }
       
   195     QDEBUG_WRITE("CMsgErrorRoamingObserver:Start : Exit");
       
   196     }
       
   197 
       
   198 /*****************************************************
       
   199 *   Series 60 Customer / ETel
       
   200 *   Series 60  ETel API
       
   201 *****************************************************/
       
   202 
       
   203 // ---------------------------------------------------------
       
   204 // CMsgErrorRoamingObserver::DoCancel
       
   205 //
       
   206 // From active object framework
       
   207 // ---------------------------------------------------------
       
   208 //
       
   209 void CMsgErrorRoamingObserver::DoCancel()
       
   210     {
       
   211     QDEBUG_WRITE("CMsgErrorRoamingObserver:DoCancel : Enter");
       
   212     if ( iRequestId )
       
   213         {
       
   214         iMobilePhone.CancelAsyncRequest( iRequestId );
       
   215         iRequestId = 0;
       
   216         }
       
   217     QDEBUG_WRITE("CMsgErrorRoamingObserver:DoCancel : Exit");
       
   218     }
       
   219 
       
   220 /*****************************************************
       
   221 *   Series 60 Customer / ETel
       
   222 *   Series 60  ETel API
       
   223 *****************************************************/
       
   224 
       
   225 // ---------------------------------------------------------
       
   226 // CMsgErrorRoamingObserver::RunL
       
   227 //
       
   228 // From active object framework
       
   229 // ---------------------------------------------------------
       
   230 //
       
   231 void CMsgErrorRoamingObserver::RunL()
       
   232     {
       
   233     QDEBUG_WRITE("CMsgErrorRoamingObserver:RunL : Enter");
       
   234     iRequestId = 0;
       
   235     TInt status = iStatus.Int();
       
   236     if ( status < 0 )
       
   237         {
       
   238         iRegStatus = RMobilePhone::ERegistrationUnknown;
       
   239         }
       
   240     TRAP_IGNORE( UpdateRoamingStatusL() );
       
   241     Start();
       
   242     QDEBUG_WRITE("CMsgErrorRoamingObserver:RunL : Exit");
       
   243     }
       
   244 
       
   245 // ================= OTHER EXPORTED FUNCTIONS ==============
       
   246 
       
   247 //  End of File