bearermanagement/S60MCPR/src/s60mpmnotifications.cpp
changeset 0 5a93021fdf25
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 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: Handling of Mobility Policy Manager notifications.
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 @file s60mpmnotifications.cpp
       
    20 Handling of Mobility Policy Manager notifications.
       
    21 */
       
    22 #include <rmpm.h>
       
    23 
       
    24 #include "s60mpmnotifications.h"
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CMPMPolicyNotifications::NewL
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CMPMPolicyNotifications* CMPMPolicyNotifications::NewL( MMPMPolicyNotificationUser& aUser, RMPM& aMpm )
       
    33     {
       
    34     CMPMPolicyNotifications* self = new ( ELeave ) CMPMPolicyNotifications( aUser, aMpm );
       
    35     return self;
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CMPMPolicyNotifications::CMPMPolicyNotifications
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CMPMPolicyNotifications::CMPMPolicyNotifications( MMPMPolicyNotificationUser& aUser, RMPM& aMpm )
       
    43     : CActive( EPriorityStandard ),
       
    44       iNotificationUser( aUser ),
       
    45       iMpm( aMpm ),
       
    46       iCommitedToDeleteItself( EFalse )
       
    47     {
       
    48     CActiveScheduler::Add( this );
       
    49     S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyNotifications<%x>::CMPMPolicyNotifications()", this )
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CMPMPolicyNotifications::~CMPMPolicyNotifications
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CMPMPolicyNotifications::~CMPMPolicyNotifications()
       
    57     {
       
    58     S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyNotifications<%x>::~CMPMPolicyNotifications", this )
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CMPMPolicyNotifications::CancelRequestAndDestroyD
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CMPMPolicyNotifications::CancelRequestAndDestroyD( TRequestStatus* aStatus )
       
    66     {
       
    67     S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyNotifications<%x>::CancelRequestAndDestroyD", this )
       
    68     iDeletedStatus = aStatus;
       
    69     if ( iMpm.Connected() && IsActive() )
       
    70         {
       
    71         S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyNotifications<%x>::CancelRequestAndDestroyD Start asynch delete", this )
       
    72         iMpm.SendCancelRequest( EMPMWaitNotification );
       
    73         iCommitedToDeleteItself = ETrue;
       
    74         *iDeletedStatus = KRequestPending;
       
    75         }
       
    76     else
       
    77         {
       
    78         S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyNotifications<%x>::CancelRequestAndDestroyD Delete immediately", this )
       
    79         ASSERT( !IsActive() );
       
    80         ASSERT( !aStatus );
       
    81         delete this;
       
    82         }
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CMPMPolicyNotifications::Activate
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CMPMPolicyNotifications::Activate()
       
    90     {
       
    91     if ( !IsActive() )
       
    92         {
       
    93         S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyNotifications<%x>::Activate Wait notification", this )
       
    94         iMpm.WaitNotification( iMsgBuffer, iStatus );
       
    95         SetActive();
       
    96         }
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CMPMPolicyNotifications::RunL
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CMPMPolicyNotifications::RunL()
       
   104     {
       
   105     ASSERT( iMpm.Connected() );
       
   106 
       
   107     if ( iCommitedToDeleteItself )
       
   108         {
       
   109         S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyNotifications<%x>::RunL Completing iDeletedStatus %d", this, KErrNone )
       
   110         User::RequestComplete( iDeletedStatus, KErrNone );
       
   111         delete this;
       
   112         return;
       
   113         }
       
   114     // In case notification, is errored we shouldn't resubmit any request. 
       
   115     if ( iStatus.Int() != KErrNone )
       
   116         {
       
   117         S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyNotifications<%x>::RunL status %d", this, iStatus.Int() )
       
   118         return;
       
   119         }
       
   120     // Typically deliver the notification and resubmit a request for new one.
       
   121     TUint8* msgBufferPtr = const_cast<TUint8*>( iMsgBuffer.Ptr() );
       
   122     TMpmNotification* notification = 
       
   123                           reinterpret_cast<TMpmNotification*>( msgBufferPtr );
       
   124 
       
   125     iNotificationUser.PolicyNotification( *const_cast<TMpmNotification*>( notification ) );
       
   126 
       
   127     S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyNotifications<%x>::RunL Wait notification", this )
       
   128     iMpm.WaitNotification( iMsgBuffer, iStatus );
       
   129     SetActive();
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CMPMPolicyNotifications::DoCancel
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CMPMPolicyNotifications::DoCancel()
       
   137     {
       
   138     // Not allowed! Cancel() may cause deadlock!
       
   139     _LIT( KPanicMsg, "CMPMPolicyNotifications::DoCancel" );
       
   140     User::Panic( KPanicMsg, KErrNotSupported );
       
   141     }
       
   142 
       
   143 // End of file