securitydialogs/Autolock/src/AutoLockLockObserver.cpp
branchRCL_3
changeset 50 03674e5abf46
equal deleted inserted replaced
49:09b1ac925e3f 50:03674e5abf46
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *		Obsererver for Set System Locked event	
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 #include		<bldvariant.hrh>
       
    21 #include		<e32property.h>
       
    22 #include	<PSVariables.h>
       
    23 #include		<coreapplicationuisdomainpskeys.h>
       
    24 
       
    25 #include	"AutoLockLockObserverPS.h"
       
    26 #include	"AutolockAppUiPS.h"
       
    27 #include	"AutoLockModelPS.h"
       
    28 
       
    29 
       
    30 // ================= MEMBER	FUNCTIONS	=======================
       
    31 //
       
    32 // ----------------------------------------------------------
       
    33 // CLockObserver::NewL()
       
    34 // Constructs	a	new	entry	with given values.
       
    35 // ----------------------------------------------------------
       
    36 //
       
    37 CLockObserver* CLockObserver::NewL(CAutolockAppUi* aAppUi)
       
    38 		{
       
    39 		CLockObserver* self	=	new	(ELeave) CLockObserver(aAppUi);
       
    40 		CleanupStack::PushL(self);
       
    41 		self->ConstructL();
       
    42 		CleanupStack::Pop();
       
    43 		return self;
       
    44 		}
       
    45 //
       
    46 // ----------------------------------------------------------
       
    47 // CLockObserver::CLockObserver()
       
    48 // Destructor
       
    49 // ----------------------------------------------------------
       
    50 //
       
    51 CLockObserver::~CLockObserver()
       
    52 		{
       
    53 		Cancel();
       
    54 		iProperty.Close();
       
    55 		}
       
    56 //
       
    57 // ----------------------------------------------------------
       
    58 // CNoSimCard::Start()
       
    59 // Starts	listening	KUidAutolockStatus event 
       
    60 // ----------------------------------------------------------
       
    61 //
       
    62 TInt CLockObserver::Start()
       
    63 		{
       
    64 		if (IsActive())
       
    65 				return KErrInUse;
       
    66 		iStatus	=	KRequestPending;
       
    67 		iProperty.Attach(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus);		 
       
    68 		iProperty.Subscribe(iStatus);
       
    69 		SetActive();
       
    70 		return KErrNone;
       
    71 		}
       
    72 //
       
    73 // ----------------------------------------------------------
       
    74 // CLockObserver::CLockObserver()
       
    75 // C++ constructor
       
    76 // ----------------------------------------------------------
       
    77 // 
       
    78 CLockObserver::CLockObserver(CAutolockAppUi* aAppUi) : CActive(0), iAppUi(aAppUi)
       
    79 	{														 
       
    80 		}
       
    81 //
       
    82 // ----------------------------------------------------------
       
    83 // CLockObserver::ConstructL()
       
    84 // Symbian OS	default	constructor
       
    85 // ----------------------------------------------------------
       
    86 // 
       
    87 void CLockObserver::ConstructL()
       
    88 		{
       
    89 	    
       
    90 	#if	defined(_DEBUG)	
       
    91     RDebug::Print(_L("(AUTOLOCK)CLockObserver::ConstructL()"));
       
    92     #endif
       
    93         
       
    94 		// Add this	active object	to the scheduler.
       
    95 	CActiveScheduler::Add(this);
       
    96 	    
       
    97 	TInt ret;
       
    98 	_LIT_SECURITY_POLICY_PASS(KReadPolicy);	
       
    99 	_LIT_SECURITY_POLICY_C1(KWritePolicy,	ECapabilityWriteDeviceData);
       
   100 	
       
   101 	ret	=	RProperty::Define(KPSUidCoreApplicationUIs,	KCoreAppUIsAutolockStatus, RProperty::EInt,	KReadPolicy, KWritePolicy);
       
   102 		if(ret !=	KErrAlreadyExists)
       
   103 				User::LeaveIfError(ret);
       
   104 				    
       
   105 	// Begin obsering	PubSub event	
       
   106 	Start();	
       
   107 		}
       
   108 //
       
   109 // ----------------------------------------------------------
       
   110 // CLockObserver::RunL()
       
   111 // Called	when device	(autolock) is	activated	from menu.
       
   112 // ----------------------------------------------------------
       
   113 // 
       
   114 void CLockObserver::RunL()
       
   115 	{
       
   116 	// set ui	locked.
       
   117 		TInt autolockState;
       
   118 		iProperty.Get( autolockState );
       
   119 		if (autolockState	>	EAutolockOff)
       
   120 				{
       
   121 		iAppUi->Model()->LockSystemL(autolockState);
       
   122 		}
       
   123 	// Continue	observing	PubSub event	
       
   124 	Start();	
       
   125 	}
       
   126 //
       
   127 // ----------------------------------------------------------
       
   128 // CLockObserver::DoCancel()
       
   129 // Cancels event listening
       
   130 // ----------------------------------------------------------
       
   131 // 
       
   132 void CLockObserver::DoCancel()
       
   133 		{
       
   134 		iProperty.Cancel();
       
   135 		}
       
   136 // End of	file