browserplugins/browsersysteminfoplugin/src/NetworkObserver.cpp
branchRCL_3
changeset 48 8e6fa1719340
parent 0 84ad3b177aa3
equal deleted inserted replaced
47:6385c4c93049 48:8e6fa1719340
       
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <limits.h>
       
    21 #include "NetworkObserver.h"
       
    22 #include "SystemInfoPlugin.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CNetworkObserver::NewL
       
    28 // Two-phased constructor.
       
    29 // -----------------------------------------------------------------------------
       
    30 CNetworkObserver* CNetworkObserver::NewL( CSystemInfoPlugin* aPlugin )
       
    31     {
       
    32     CNetworkObserver* self = new (ELeave) CNetworkObserver( aPlugin );
       
    33     CleanupStack::PushL( self );
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CNetworkObserver::CNetworkObserver
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 CNetworkObserver::CNetworkObserver( CSystemInfoPlugin* aPlugin )
       
    45   : iSystemInfoPlugin( aPlugin ),
       
    46     iSignalPckg( iSignal ),
       
    47     iRegistrationStatusPckg( iRegistrationStatus ),
       
    48     iNetworkInfoPckg( iNetworkInfo )
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CNetworkObserver::ConstructL
       
    54 // Symbian 2nd phase constructor can leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 void CNetworkObserver::ConstructL()
       
    57     {
       
    58     iSignalObserver = CSystemInfoObserver::NewL( this, EIdSignalStrength );
       
    59     iRegistrationStatusObserver = CSystemInfoObserver::NewL( this, EIdRegistrationStatus );
       
    60     iNetworkInfoObserver = CSystemInfoObserver::NewL( this, EIdNetworkInfo );
       
    61 
       
    62     iTelephony = CTelephony::NewL();
       
    63     iTelephony2 = CTelephony::NewL();
       
    64     iTelephony3 = CTelephony::NewL();
       
    65 
       
    66     // bootstrap monitoring
       
    67 
       
    68     // signal
       
    69     iSignal.iSignalStrength = INT_MIN; // default indicates unknown
       
    70     iSignal.iBar = CHAR_MIN; // default indicates unknown
       
    71     iSignalObserver->RequestNotificationL();
       
    72 
       
    73     // registration status
       
    74     iRegistrationStatus.iRegStatus = CTelephony::ERegistrationUnknown; // default
       
    75     iRegistrationStatusObserver->RequestNotificationL();
       
    76 
       
    77     // network info
       
    78     iNetworkInfo.iDisplayTag.Copy(_L("")); // default indicates unknown
       
    79     iNetworkInfoObserver->RequestNotificationL();
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CNetworkObserver::~CNetworkObserver()
       
    84 // Destructor
       
    85 // -----------------------------------------------------------------------------
       
    86 CNetworkObserver::~CNetworkObserver()
       
    87     {
       
    88     delete iSignalObserver;
       
    89     delete iRegistrationStatusObserver;
       
    90     delete iRegistrationStatusChangedFunction;
       
    91     delete iNetworkInfoObserver;
       
    92     delete iTelephony;
       
    93     delete iTelephony2;
       
    94     delete iTelephony3;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CNetworkObserver::SignalBars
       
    99 // -----------------------------------------------------------------------------
       
   100 TInt CNetworkObserver::SignalBars() const
       
   101     {
       
   102     if ( !iSignalStarted )
       
   103         {
       
   104         return INT_MIN; // value indicates unknown
       
   105         }
       
   106     return iSignal.iBar;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CNetworkObserver::RegistrationStatus
       
   111 // -----------------------------------------------------------------------------
       
   112 TInt CNetworkObserver::RegistrationStatus() const
       
   113     {
       
   114     TInt s = iRegistrationStatus.iRegStatus;
       
   115     // explicitly map enum values in case CTelephony API changes.
       
   116     switch ( s )
       
   117         {
       
   118     case CTelephony::ERegistrationUnknown:
       
   119         s = 0;
       
   120         break;
       
   121     case CTelephony::ENotRegisteredNoService:
       
   122         s = 1;
       
   123         break;
       
   124     case CTelephony::ENotRegisteredEmergencyOnly:
       
   125         s = 2;
       
   126         break;
       
   127     case CTelephony::ENotRegisteredSearching:
       
   128         s = 3;
       
   129         break;
       
   130     case CTelephony::ERegisteredBusy:
       
   131         s = 4;
       
   132         break;
       
   133     case CTelephony::ERegisteredOnHomeNetwork:
       
   134         s = 5;
       
   135         break;
       
   136     case CTelephony::ERegistrationDenied:
       
   137         s = 6;
       
   138         break;
       
   139     case CTelephony::ERegisteredRoaming:
       
   140         s = 7;
       
   141         break;
       
   142     default:
       
   143         s = 0;
       
   144         break;
       
   145         };
       
   146 
       
   147     return s;
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CNetworkObserver::NetworkName
       
   152 // -----------------------------------------------------------------------------
       
   153 const TDesC& CNetworkObserver::NetworkName() const
       
   154     {
       
   155     return iNetworkInfo.iDisplayTag;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CNetworkObserver::RequestNotificationL
       
   160 // -----------------------------------------------------------------------------
       
   161 void CNetworkObserver::RequestNotificationL( TIdNetworkItem aId, HBufC8* aFunctionName )
       
   162     {
       
   163     if ( aId == EIdRegistrationStatus )
       
   164         {
       
   165         delete iRegistrationStatusChangedFunction;
       
   166         iRegistrationStatusChangedFunction = aFunctionName;
       
   167         // already monitoring, don't request notification again
       
   168         }
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CNetworkObserver::SubscribeL
       
   173 // -----------------------------------------------------------------------------
       
   174 void CNetworkObserver::SubscribeL( TInt aId, TRequestStatus& aStatus )
       
   175     {
       
   176     if ( aId == EIdSignalStrength )
       
   177         {
       
   178         if ( iSignalStarted )
       
   179             {
       
   180             iTelephony->NotifyChange( aStatus,
       
   181                                       CTelephony::ESignalStrengthChange,
       
   182                                       iSignalPckg );
       
   183             }
       
   184         else
       
   185             {
       
   186             iTelephony->GetSignalStrength( aStatus, iSignalPckg );
       
   187             }
       
   188         }
       
   189     else if ( aId == EIdRegistrationStatus )
       
   190         {
       
   191         if ( iRegistrationStatusStarted )
       
   192             {
       
   193             iTelephony2->NotifyChange( aStatus,
       
   194                                        CTelephony::ENetworkRegistrationStatusChange,
       
   195                                        iRegistrationStatusPckg );
       
   196             }
       
   197         else
       
   198             {
       
   199             iTelephony2->GetNetworkRegistrationStatus( aStatus, iRegistrationStatusPckg );
       
   200             }
       
   201         }
       
   202     else if ( aId == EIdNetworkInfo )
       
   203         {
       
   204         if ( iNetworkInfoStarted )
       
   205             {
       
   206             iTelephony3->NotifyChange( aStatus,
       
   207                                        CTelephony::ECurrentNetworkInfoChange,
       
   208                                        iNetworkInfoPckg );
       
   209             }
       
   210         else
       
   211             {
       
   212             iTelephony3->GetCurrentNetworkInfo( aStatus, iNetworkInfoPckg );
       
   213             }
       
   214         }
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CNetworkObserver::UpdateL
       
   219 // -----------------------------------------------------------------------------
       
   220 void CNetworkObserver::UpdateL( TInt aId )
       
   221     {
       
   222     if ( aId == EIdSignalStrength )
       
   223         {
       
   224         iSignalStarted = 1;
       
   225         }
       
   226     else if ( aId == EIdRegistrationStatus )
       
   227         {
       
   228         iRegistrationStatusStarted = 1;
       
   229         if ( iRegistrationStatusChangedFunction )
       
   230             {
       
   231             iSystemInfoPlugin->InvokeCallback( *iRegistrationStatusChangedFunction, NULL, 0 );
       
   232             }
       
   233         }
       
   234     else if ( aId == EIdNetworkInfo )
       
   235         {
       
   236         iNetworkInfoStarted = 1;
       
   237         // FUTURE add callback to script API
       
   238         }
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CNetworkObserver::Cancel
       
   243 // -----------------------------------------------------------------------------
       
   244 void CNetworkObserver::Cancel( TInt aId )
       
   245     {
       
   246     if ( aId == EIdSignalStrength )
       
   247         {
       
   248         (void) iTelephony->CancelAsync( ( iSignalStarted ?
       
   249                                           CTelephony::ESignalStrengthChangeCancel
       
   250                                           : CTelephony::EGetSignalStrengthCancel ) );
       
   251         }
       
   252     else if ( aId == EIdRegistrationStatus )
       
   253         {
       
   254         (void) iTelephony2->CancelAsync( ( iRegistrationStatusStarted ?
       
   255                                            CTelephony::ENetworkRegistrationStatusChangeCancel
       
   256                                            : CTelephony::EGetNetworkRegistrationStatusCancel ) );
       
   257         }
       
   258     else if ( aId == EIdNetworkInfo )
       
   259         {
       
   260         (void) iTelephony3->CancelAsync( ( iNetworkInfoStarted ?
       
   261                                            CTelephony::ECurrentNetworkInfoChangeCancel
       
   262                                            : CTelephony::EGetCurrentNetworkInfoCancel ) );
       
   263         }
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CNetworkObserver::Close
       
   268 // -----------------------------------------------------------------------------
       
   269 void CNetworkObserver::Close( TInt /*aId*/ )
       
   270     {
       
   271     }
       
   272 
       
   273 //  End of File