psln/pslnengine/src/PslnEcomListener.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     1 /*
       
     2 * Copyright (c) 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:  Listens to ECOM for screensaver plugin changes.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mpslnscreensaverecomobserver.h"
       
    20 
       
    21 #include "PslnEcomListener.h"
       
    22 #include "PslnModel.h"
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // C++ constructor can NOT contain any code, that might leave.
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CPslnEcomListener::CPslnEcomListener( CPslnModel& aModel, 
       
    31     MPslnScreenSaverECOMObserver& aObserver ) : 
       
    32     CActive( CActive::EPriorityStandard ), iModel( &aModel ), 
       
    33     iObserver( &aObserver )
       
    34     {
       
    35     CActiveScheduler::Add( this );
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // Symbian 2nd phase constructor can leave.
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 void CPslnEcomListener::ConstructL()
       
    43     {
       
    44     iSession = REComSession::OpenL();
       
    45     // Start ECOM monitoring
       
    46     StartECOMMonitoringL();
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // Two-phased constructor.
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 EXPORT_C CPslnEcomListener* CPslnEcomListener::NewL( 
       
    54     CPslnModel& aModel, MPslnScreenSaverECOMObserver& aObserver )
       
    55     {
       
    56     CPslnEcomListener* self = 
       
    57         new ( ELeave ) CPslnEcomListener( aModel, aObserver );
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // Destructor.
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CPslnEcomListener::~CPslnEcomListener()
       
    69     {
       
    70     Cancel();
       
    71     iSession.Close();
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // Called when active object is ready.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CPslnEcomListener::RunL()
       
    79     {
       
    80     iModel->LoadScreensaverArrayL();
       
    81     iObserver->HandlePluginListChangeL();
       
    82     StartECOMMonitoringL();
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // Called when active object is cancelled.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CPslnEcomListener::DoCancel()
       
    90     {
       
    91     iSession.CancelNotifyOnChange( iStatus );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // Called when active object is cancelled.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CPslnEcomListener::StartECOMMonitoringL()
       
    99     {
       
   100     if ( !IsActive() )
       
   101         {
       
   102         iSession.NotifyOnChange( iStatus );
       
   103         SetActive();
       
   104         }
       
   105     else
       
   106         {
       
   107         User::Leave( KErrAlreadyExists );
       
   108         }
       
   109     }
       
   110 
       
   111 // End of file