videofeeds/scheduleddlplugin/src/iptvphoneregistrationwatcher.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     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 the License "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 is helper class which observes whether the phone is on*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #include "IptvDebug.h"
       
    21 #include <mmtsy_names.h>
       
    22 
       
    23 #include "iptvphoneregistrationwatcher.h"
       
    24 #include "iptvphoneregistrationobserver.h"
       
    25 
       
    26 
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // CIptvPhoneRegistrationWatcher::CIptvPhoneRegistrationWatcher
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CIptvPhoneRegistrationWatcher::CIptvPhoneRegistrationWatcher() : CActive( EPriorityNormal )
       
    33     {
       
    34     }
       
    35 
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CIptvPhoneRegistrationWatcher::ConstructL
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 void CIptvPhoneRegistrationWatcher::ConstructL()
       
    42     {
       
    43     IPTVLOGSTRING_HIGH_LEVEL(">>> CIptvPhoneRegistrationWatcher::ConstructL");
       
    44 
       
    45     CActiveScheduler::Add(this);
       
    46 
       
    47 	User::LeaveIfError( iTelServer.Connect() );
       
    48     User::LeaveIfError( iMobilePhone.Open( iTelServer, KMmTsyPhoneName ) );
       
    49 
       
    50     StartObserving();
       
    51 
       
    52     IPTVLOGSTRING_HIGH_LEVEL("<<< CIptvPhoneRegistrationWatcher::ConstructL");
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CIptvPhoneRegistrationWatcher::NewL
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 CIptvPhoneRegistrationWatcher* CIptvPhoneRegistrationWatcher::NewL()
       
    61     {
       
    62     CIptvPhoneRegistrationWatcher* self = CIptvPhoneRegistrationWatcher::NewLC();
       
    63     CleanupStack::Pop( self );
       
    64     return self;
       
    65     }
       
    66 
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CIptvPhoneRegistrationWatcher::NewLC
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CIptvPhoneRegistrationWatcher* CIptvPhoneRegistrationWatcher::NewLC()
       
    73     {
       
    74     CIptvPhoneRegistrationWatcher* self = new( ELeave ) CIptvPhoneRegistrationWatcher;
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     return self;
       
    78     }
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CIptvPhoneRegistrationWatcher::~CIptvPhoneRegistrationWatcher
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CIptvPhoneRegistrationWatcher::~CIptvPhoneRegistrationWatcher()
       
    86     {
       
    87     IPTVLOGSTRING_HIGH_LEVEL(">>> CIptvPhoneRegistrationWatcher::~CIptvPhoneRegistrationWatcher");
       
    88 
       
    89     Cancel();
       
    90     iObservers.Reset();
       
    91     iMobilePhone.Close();
       
    92     iTelServer.Close();
       
    93 
       
    94     IPTVLOGSTRING_HIGH_LEVEL("<<< CIptvPhoneRegistrationWatcher::~CIptvPhoneRegistrationWatcher");
       
    95     }
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CIptvPhoneRegistrationWatcher::AddObserverL
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 void CIptvPhoneRegistrationWatcher::AddObserverL( MPhoneRegistrationWatcherObserver* aObserver )
       
   103     {
       
   104     iObservers.AppendL( aObserver );
       
   105     }
       
   106 
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // CIptvPhoneRegistrationWatcher::RemoveObserver
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CIptvPhoneRegistrationWatcher::RemoveObserver( MPhoneRegistrationWatcherObserver* aObserver )
       
   113     {
       
   114     TInt index = iObservers.Find( aObserver );
       
   115     if (index != KErrNotFound)
       
   116         {
       
   117         iObservers.Remove( index );
       
   118         }
       
   119     }
       
   120 
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CIptvPhoneRegistrationWatcher::IsOnHomeNetwork
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TBool CIptvPhoneRegistrationWatcher::IsOnHomeNetwork()
       
   127     {
       
   128     IPTVLOGSTRING_HIGH_LEVEL(">>> CIptvPhoneRegistrationWatcher::IsOnHomeNetwork");
       
   129 
       
   130     TBool retVal = EFalse;
       
   131 
       
   132 	TRequestStatus status;
       
   133 	RMobilePhone::TMobilePhoneRegistrationStatus regStatus;
       
   134 	iMobilePhone.GetNetworkRegistrationStatus( status, regStatus );
       
   135 	User::WaitForRequest( status );
       
   136 
       
   137 	if (status.Int() == KErrNone && regStatus == RMobilePhone::ERegisteredOnHomeNetwork)
       
   138 		{
       
   139 		retVal = ETrue;
       
   140         IPTVLOGSTRING_HIGH_LEVEL("CIptvPhoneRegistrationWatcher::IsOnHomeNetwork, on home network");
       
   141 		}
       
   142 
       
   143     IPTVLOGSTRING_HIGH_LEVEL("<<< CIptvPhoneRegistrationWatcher::IsOnHomeNetwork");
       
   144 
       
   145     return retVal;
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CIptvPhoneRegistrationWatcher::StartObserving
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void CIptvPhoneRegistrationWatcher::StartObserving()
       
   153     {
       
   154     IPTVLOGSTRING_HIGH_LEVEL(">>> CIptvPhoneRegistrationWatcher::StartObserving");
       
   155 
       
   156     if (!IsActive())
       
   157         {
       
   158         iMobilePhone.NotifyNetworkRegistrationStatusChange( iStatus, iRegStatus );
       
   159         SetActive();
       
   160         }
       
   161 
       
   162     IPTVLOGSTRING_HIGH_LEVEL("<<< CIptvPhoneRegistrationWatcher::StartObserving");
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CIptvPhoneRegistrationWatcher::RunL
       
   168 //
       
   169 // From class CActive.
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void CIptvPhoneRegistrationWatcher::RunL()
       
   173     {
       
   174     IPTVLOGSTRING_HIGH_LEVEL(">>> CIptvPhoneRegistrationWatcher::RunL");
       
   175 
       
   176     //  Get the current state and inform observers
       
   177     if (iStatus.Int() != KErrNone)
       
   178         {
       
   179         //  Inform observers about error
       
   180         IPTVLOGSTRING2_HIGH_LEVEL("CIptvPhoneRegistrationWatcher::RunL, error = %d", iStatus.Int());
       
   181         }
       
   182     else
       
   183         {
       
   184         if (iRegStatus != RMobilePhone::ERegisteredOnHomeNetwork)
       
   185             {
       
   186             IPTVLOGSTRING_HIGH_LEVEL("CIptvPhoneRegistrationWatcher::RunL, not on home network");
       
   187             }
       
   188         else
       
   189             {
       
   190             IPTVLOGSTRING_HIGH_LEVEL("CIptvPhoneRegistrationWatcher::RunL, on home network");
       
   191             }
       
   192 
       
   193         //  Inform observers the home network state
       
   194         for (TInt i = 0; i < iObservers.Count(); i++)
       
   195             {
       
   196             iObservers[i]->OnHomeNetwork(
       
   197                 iRegStatus == RMobilePhone::ERegisteredOnHomeNetwork );
       
   198             }
       
   199 
       
   200         }
       
   201 
       
   202     StartObserving();
       
   203 
       
   204     IPTVLOGSTRING_HIGH_LEVEL("<<< CIptvPhoneRegistrationWatcher::RunL");
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // CIptvPhoneRegistrationWatcher::DoCancel
       
   209 // 
       
   210 // From class CActive.
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void CIptvPhoneRegistrationWatcher::DoCancel()
       
   214     {
       
   215     iMobilePhone.CancelAsyncRequest( EMobilePhoneNotifyNetworkRegistrationStatusChange );
       
   216     }
       
   217