harvester/server/src/pauseobserverao.cpp
changeset 0 c53acadfccc6
child 17 50de4d668bb6
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:  Harvester server's P&S pause observer active object
       
    15 *
       
    16 */
       
    17 
       
    18 #include "pauseobserverao.h"
       
    19 
       
    20 #include <harvesterpauseps.h>
       
    21 #include "harvesterserver.h"
       
    22 
       
    23 #include "harvesterlog.h"
       
    24 
       
    25 CPauseObserverAO* CPauseObserverAO::NewL( CHarvesterServer& aHarvesterServer )
       
    26 	{
       
    27 	WRITELOG("CPauseObserverAO::NewL()");
       
    28 	CPauseObserverAO* self = new (ELeave) CPauseObserverAO( aHarvesterServer );
       
    29 	CleanupStack::PushL( self );
       
    30 	self->ConstructL();
       
    31 	CleanupStack::Pop( self );
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 CPauseObserverAO::~CPauseObserverAO()
       
    36 	{
       
    37 	Cancel();
       
    38 	iPauseProperty.Close();
       
    39 	}
       
    40 
       
    41 
       
    42 CPauseObserverAO::CPauseObserverAO( CHarvesterServer& aHarvesterServer ) :
       
    43 	CActive( CActive::EPriorityUserInput ), 
       
    44 	iHarvesterServer( aHarvesterServer )
       
    45 	{
       
    46 	CActiveScheduler::Add( this );
       
    47 	}
       
    48 
       
    49 void CPauseObserverAO::ConstructL()
       
    50 	{
       
    51 	WRITELOG("CPauseObserverAO::ConstructL()");
       
    52 
       
    53 	TUid cat = KPsHarvesterPauseCategory;
       
    54 	TInt key = KPsHarvesterPauseKey;
       
    55 	TInt error = iPauseProperty.Define( cat, 
       
    56 			key, RProperty::EInt );
       
    57 
       
    58 	WRITELOG1("CPauseObserverAO::ConstructL() Define error: %d", error);
       
    59 
       
    60 	if( KErrAlreadyExists != error )
       
    61 		{
       
    62 		User::LeaveIfError( error );
       
    63 		}
       
    64 
       
    65 	error = iPauseProperty.Attach( cat, 
       
    66 			key, EOwnerThread );
       
    67 
       
    68 	WRITELOG1("CPauseObserverAO::ConstructL() Attach error: %d", error);	
       
    69 
       
    70 	User::LeaveIfError( error );
       
    71 
       
    72 	iPauseProperty.Subscribe( iStatus );
       
    73     SetActive();
       
    74     WRITELOG("CPauseObserverAO::ConstructL() - ends");
       
    75 	}
       
    76 
       
    77 void CPauseObserverAO::RunL()
       
    78 	{
       
    79 	WRITELOG("CPauseObserverAO::RunL()");
       
    80 
       
    81 	TInt status = iStatus.Int();
       
    82 
       
    83 	if( status != KErrNone )
       
    84         {
       
    85         WRITELOG1("CPauseObserverAO::RunL() - error: %d", status);
       
    86         }
       
    87 
       
    88     // resubscribe before processing new value to prevent missing updates
       
    89 	iPauseProperty.Subscribe( iStatus );
       
    90     SetActive();
       
    91 
       
    92 	TInt pauseState = EPsHarvesterPauseResume;
       
    93 
       
    94 	TUid cat = KPsHarvesterPauseCategory;
       
    95 	TInt key = KPsHarvesterPauseKey;	
       
    96 	iPauseProperty.Get( cat, key, pauseState );
       
    97 
       
    98 	if ( EPsHarvesterPausePause == pauseState )
       
    99 		{
       
   100 		WRITELOG("CPauseObserverAO::RunL() - pause");
       
   101 		iHarvesterServer.Pause();
       
   102 		}
       
   103 	else
       
   104 		{
       
   105 		WRITELOG("CPauseObserverAO::RunL() - resume");
       
   106 		iHarvesterServer.Resume();
       
   107 		}	
       
   108 	}
       
   109 
       
   110 void CPauseObserverAO::DoCancel()
       
   111 	{
       
   112 	iPauseProperty.Cancel();
       
   113 	}
       
   114 
       
   115 TInt CPauseObserverAO::RunError( TInt /*aError*/ )
       
   116 	{
       
   117 	return KErrNone;
       
   118 	}