mmsharing/mmshui/src/musuicallbackservice.cpp
branchRCL_3
changeset 23 bc78a40cd63c
equal deleted inserted replaced
22:73a1feb507fb 23:bc78a40cd63c
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Asynchronous callback service provider.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "musuicallbackservice.h"
       
    21 #include "musuicallbackobserver.h" // callback observer interface
       
    22 #include "muslogger.h"
       
    23 
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // Two-phased constructor.
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 CMusUiCallbackService* CMusUiCallbackService::NewL(
       
    30                         MMusUiCallbackObserver& aCallbackObserver )
       
    31     {
       
    32     CMusUiCallbackService* self =
       
    33                             new ( ELeave ) CMusUiCallbackService(
       
    34                                                     aCallbackObserver );
       
    35     CleanupStack::PushL( self );
       
    36     self->ConstructL();
       
    37     CleanupStack::Pop( self );
       
    38     return self;
       
    39     }
       
    40 
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // Destructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CMusUiCallbackService::~CMusUiCallbackService()
       
    47     {
       
    48     // Cancel active object
       
    49     MUS_LOG( "mus: [MUSUI ]  -> CMusUiCallbackService::~CMusUiCallbackService" );
       
    50     Cancel();
       
    51     MUS_LOG( "mus: [MUSUI ]  <- CMusUiCallbackService::~CMusUiCallbackService" );
       
    52     }
       
    53 
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // C++ default constructor.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CMusUiCallbackService::CMusUiCallbackService(
       
    60                         MMusUiCallbackObserver& aCallbackObserver )
       
    61     : CActive( EPriorityStandard ),
       
    62     iCallbackObserver( aCallbackObserver ),
       
    63     iEventId( EMusUiAsyncUninitialized )
       
    64     {
       
    65     CActiveScheduler::Add( this );
       
    66     }
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CMusUiCallbackService::ConstructL()
       
    74     {
       
    75     }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // Buffer a request to trigger an event.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CMusUiCallbackService::AsyncEventL( TMusUiAsyncEvent aEventId )
       
    83     {
       
    84     MUS_LOG( "mus: [MUSUI ]  -> CMusUiCallbackService::AsyncEventL" );
       
    85     iEventId = aEventId;
       
    86     Activate();
       
    87     MUS_LOG( "mus: [MUSUI ]  <- CMusUiCallbackService::AsyncEventL" );
       
    88     }
       
    89 
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // Cancels the active request.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CMusUiCallbackService::Cancel()
       
    96     {
       
    97     MUS_LOG( "mus: [MUSUI ]  -> CMusUiCallbackService::Cancel" );
       
    98     CActive::Cancel();
       
    99     iStatus = NULL;
       
   100     MUS_LOG( "mus: [MUSUI ]  <- CMusUiCallbackService::Cancel" );
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // Check what event is currently pending.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 TMusUiAsyncEvent CMusUiCallbackService::CurrentEvent() const
       
   108     {
       
   109     if ( IsActive() )
       
   110         {
       
   111         return iEventId;
       
   112         }
       
   113     return EMusUiAsyncUninitialized;
       
   114     }
       
   115     
       
   116 // -----------------------------------------------------------------------------
       
   117 // From CActive.  Called when a request completes.
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CMusUiCallbackService::RunL()
       
   121     {
       
   122     MUS_LOG( "mus: [MUSUI ]  -> CMusUiCallbackService::RunL" );
       
   123     if ( iEventId )
       
   124         {
       
   125         // Copy the id from member to local so the member can be cleared.
       
   126         TMusUiAsyncEvent eventId = iEventId;
       
   127         iEventId = EMusUiAsyncUninitialized;
       
   128         // Issue the call to the observer interface.
       
   129         iCallbackObserver.HandleAsyncEventL( eventId );
       
   130         MUS_LOG( "mus: [MUSUI ]  <- CMusUiCallbackService::RunL returns" );
       
   131         return;
       
   132         }
       
   133     MUS_LOG( "mus: [MUSUI ]  <- CMusUiCallbackService::RunL" );
       
   134     }
       
   135 
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // From CActive.  Called when a leave occurres in RunL.
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 TInt CMusUiCallbackService::RunError( TInt aError )
       
   142     {
       
   143     MUS_LOG1( "mus: [MUSUI ]        CMusUiCallbackService::RunError [%d]",
       
   144                             aError );
       
   145     iCallbackObserver.HandleAsyncError( aError );
       
   146                             
       
   147     return KErrNone;
       
   148     }
       
   149 
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // From CActive.  Called when a request is cancelled.
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CMusUiCallbackService::DoCancel()
       
   156     {
       
   157     MUS_LOG( "mus: [MUSUI ]  -> CMusUiCallbackService::DoCancel" );
       
   158     MUS_LOG( "mus: [MUSUI ]  <- CMusUiCallbackService::DoCancel" );
       
   159     }
       
   160 
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // Activate the object.
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void CMusUiCallbackService::Activate()
       
   167     {
       
   168     MUS_LOG( "mus: [MUSUI ]  -> CMusUiCallbackService::Activate" );
       
   169     // Call SetActive() so RunL() will be called by the active scheduler
       
   170     if ( IsActive() )
       
   171         {
       
   172         Cancel();
       
   173         }
       
   174     SetPriority( EPriorityHigh );
       
   175     SetActive();
       
   176     iStatus = KRequestPending;
       
   177     TRequestStatus* stat = &iStatus;
       
   178     User::RequestComplete( stat, KErrNone );
       
   179     
       
   180     MUS_LOG( "mus: [MUSUI ]  <- CMusUiCallbackService::Activate" );
       
   181     }
       
   182 
       
   183