bearermanagement/mpm/src/mpmcsidwatcher.cpp
changeset 20 9c97ad6591ae
parent 0 5a93021fdf25
child 71 9f263f780e41
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
    27 // ---------------------------------------------------------------------------
    27 // ---------------------------------------------------------------------------
    28 //
    28 //
    29 CMpmCsIdWatcher::CMpmCsIdWatcher()
    29 CMpmCsIdWatcher::CMpmCsIdWatcher()
    30     : CActive( EPriorityStandard )
    30     : CActive( EPriorityStandard )
    31     {
    31     {
       
    32     MPMLOGSTRING( "CMpmCsIdWatcher::CMpmCsIdWatcher" )
       
    33             
    32     CActiveScheduler::Add( this );    
    34     CActiveScheduler::Add( this );    
    33     }
    35     }
    34 
    36 
    35 
    37 
    36 // ---------------------------------------------------------------------------
    38 // ---------------------------------------------------------------------------
    37 // Creates central repositor object
    39 // Creates central repository object
    38 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    39 //
    41 //
    40 void CMpmCsIdWatcher::ConstructL()
    42 void CMpmCsIdWatcher::ConstructL()
    41     {
    43     {
       
    44     MPMLOGSTRING( "CMpmCsIdWatcher::ConstructL" )
       
    45 
    42     iRepository = CRepository::NewL( KMpmOccCenRepUid );
    46     iRepository = CRepository::NewL( KMpmOccCenRepUid );
    43 
    47 
    44     // Check whether user connection is supported
    48     // Check whether user connection is supported
    45     FeatureManager::InitializeLibL();
    49     FeatureManager::InitializeLibL();
    46     iUserConnectionSupported = FeatureManager::FeatureSupported( 
    50     iUserConnectionSupported = FeatureManager::FeatureSupported( 
    54 // Creates new object
    58 // Creates new object
    55 // ---------------------------------------------------------------------------
    59 // ---------------------------------------------------------------------------
    56 //
    60 //
    57 CMpmCsIdWatcher* CMpmCsIdWatcher::NewL()
    61 CMpmCsIdWatcher* CMpmCsIdWatcher::NewL()
    58     {
    62     {
       
    63     MPMLOGSTRING( "CMpmCsIdWatcher::NewL" )
       
    64 
    59     CMpmCsIdWatcher* self = new( ELeave ) CMpmCsIdWatcher();
    65     CMpmCsIdWatcher* self = new( ELeave ) CMpmCsIdWatcher();
    60     CleanupStack::PushL( self );
    66     CleanupStack::PushL( self );
    61     self->ConstructL();
    67     self->ConstructL();
    62     CleanupStack::Pop( self );
    68     CleanupStack::Pop( self );
    63     return self;
    69     return self;
    66 // ---------------------------------------------------------------------------
    72 // ---------------------------------------------------------------------------
    67 // Destructor
    73 // Destructor
    68 // ---------------------------------------------------------------------------
    74 // ---------------------------------------------------------------------------
    69 //
    75 //
    70 CMpmCsIdWatcher::~CMpmCsIdWatcher()
    76 CMpmCsIdWatcher::~CMpmCsIdWatcher()
    71     {    
    77     {
       
    78     MPMLOGSTRING( "CMpmCsIdWatcher::~CMpmCsIdWatcher" )
       
    79 
    72     Cancel();
    80     Cancel();
    73     delete iRepository;
    81     delete iRepository;
    74     }
    82     }
    75 
    83 
    76 // ---------------------------------------------------------------------------
    84 // ---------------------------------------------------------------------------
    77 // Order notification from changes
    85 // Order notification from changes
    78 // ---------------------------------------------------------------------------
    86 // ---------------------------------------------------------------------------
    79 //
    87 //
    80 void CMpmCsIdWatcher::StartL()
    88 void CMpmCsIdWatcher::StartL()
    81     {
    89     {
    82     // Request notification
    90     MPMLOGSTRING( "CMpmCsIdWatcher::StartL" )
    83     User::LeaveIfError( iRepository->NotifyRequest( KMpmConnectScreenId,
    91             
    84                         iStatus ));
    92     // Get the initial Connect screen ID from repository.
    85     SetActive();
    93     User::LeaveIfError( GetConnectScreenId() );
    86 
    94 
    87     // Get value from central repository
    95     // Request for notifications.
    88     User::LeaveIfError(iRepository->Get(KMpmConnectScreenId, iConnectScreenId));
    96     User::LeaveIfError( RequestNotifications() );
    89     }
    97     }
    90 
    98 
    91 // ---------------------------------------------------------------------------
    99 // ---------------------------------------------------------------------------
    92 // Return connect screen id
   100 // Return connect screen id
    93 // ---------------------------------------------------------------------------
   101 // ---------------------------------------------------------------------------
    94 //
   102 //
    95 TUint32 CMpmCsIdWatcher::ConnectScreenId() const
   103 TUint32 CMpmCsIdWatcher::ConnectScreenId() const
    96     {
   104     {
       
   105     MPMLOGSTRING( "CMpmCsIdWatcher::ConnectScreenId" )
       
   106 
    97     if ( iUserConnectionSupported )
   107     if ( iUserConnectionSupported )
    98         {
   108         {
    99         // Return real value if user connection is supported
   109         // Return real value if user connection is supported
   100         return iConnectScreenId;
   110         return iConnectScreenId;
   101         }
   111         }
   111 // When there is a change in central repository key, event is received in here
   121 // When there is a change in central repository key, event is received in here
   112 // ---------------------------------------------------------------------------
   122 // ---------------------------------------------------------------------------
   113 //
   123 //
   114 void CMpmCsIdWatcher::RunL()
   124 void CMpmCsIdWatcher::RunL()
   115     {
   125     {
   116     // Leave if error
   126     MPMLOGSTRING( "CMpmCsIdWatcher::RunL" )
   117     User::LeaveIfError( iStatus.Int() );
       
   118 
   127 
   119     // Request new notification
   128     if ( iStatus.Int() < KErrNone )
   120     User::LeaveIfError( iRepository->NotifyRequest( KMpmConnectScreenId,
   129         {
   121         iStatus ));
   130         MPMLOGSTRING2("Status: 0x%08X", iStatus.Int())
   122     SetActive();
   131         iErrorCounter++;
   123     
   132         if ( iErrorCounter > KMpmCsIdWatcherCenRepErrorThreshold )
   124     // Get value from central repository
   133             {
   125     iRepository->Get( KMpmConnectScreenId, iConnectScreenId );
   134             MPMLOGSTRING2("Over %d consecutive errors, stopping notifications permanently.",
   126     }
   135                     KMpmCsIdWatcherCenRepErrorThreshold)
       
   136             return;
       
   137             }
       
   138         // Else: Error occured but counter not expired. Proceed.
       
   139         }
       
   140     else
       
   141         {
       
   142         // Notification is received ok => Reset the counter.
       
   143         iErrorCounter = 0;
   127 
   144 
   128 // ---------------------------------------------------------------------------
   145         // Get value from central repository
   129 // From class CActive.
   146         GetConnectScreenId();
   130 // Nothing to do over here
   147         }
   131 // ---------------------------------------------------------------------------
   148 
   132 //
   149     RequestNotifications();
   133 TInt CMpmCsIdWatcher::RunError( TInt /*aError*/ )
       
   134     {
       
   135     return KErrNone;
       
   136     }
   150     }
   137 
   151 
   138 // ---------------------------------------------------------------------------
   152 // ---------------------------------------------------------------------------
   139 // From class CActive.
   153 // From class CActive.
   140 // Cancel outstanding request
   154 // Cancel outstanding request
   141 // ---------------------------------------------------------------------------
   155 // ---------------------------------------------------------------------------
   142 //
   156 //
   143 void CMpmCsIdWatcher::DoCancel()
   157 void CMpmCsIdWatcher::DoCancel()
   144     {
   158     {
       
   159     MPMLOGSTRING( "CMpmCsIdWatcher::DoCancel" )
   145     iRepository->NotifyCancel( KMpmConnectScreenId );
   160     iRepository->NotifyCancel( KMpmConnectScreenId );
   146     }
   161     }
   147 
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // Request notifications.
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 TInt CMpmCsIdWatcher::RequestNotifications()
       
   168     {
       
   169     MPMLOGSTRING( "CMpmCsIdWatcher::RequestNotifications" )
       
   170 
       
   171     TInt err = iRepository->NotifyRequest( KMpmConnectScreenId, iStatus );
       
   172         
       
   173     if ( err == KErrNone )
       
   174         {
       
   175         SetActive();
       
   176         }
       
   177     else
       
   178         {
       
   179         MPMLOGSTRING2( "CMpmCsIdWatcher::RequestNotifications, ERROR: %d", err )
       
   180         }
       
   181     return err;
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // Get current repository key value.
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 TInt CMpmCsIdWatcher::GetConnectScreenId()
       
   189     {
       
   190     MPMLOGSTRING( "CMpmCsIdWatcher::GetConnectScreenId" )
       
   191 
       
   192     TInt err = iRepository->Get( KMpmConnectScreenId, iConnectScreenId );
       
   193         
       
   194     if ( err != KErrNone )
       
   195         {
       
   196         MPMLOGSTRING2( "CMpmCsIdWatcher::GetConnectScreenId, ERROR: %d", err )
       
   197         }
       
   198     return err;
       
   199     }