os/ossrv/lowlevellibsandfws/apputils/src/BACNTF.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/src/BACNTF.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,129 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Started by BLB, October 1996
    1.18 +// Active object for tracking changes in TLocale
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include <bacntf.h>
    1.23 +
    1.24 +inline CEnvironmentChangeNotifier::CEnvironmentChangeNotifier(TInt aPriority)
    1.25 +	: CActive(aPriority)
    1.26 +	{__DECLARE_NAME(_S("CEnvironmentChangeNotifier"));}
    1.27 +
    1.28 +
    1.29 +EXPORT_C CEnvironmentChangeNotifier* CEnvironmentChangeNotifier::NewL(TInt aPriority,const TCallBack& aCallBack)
    1.30 +/** Constructs a new environment change notifier object with the specified active 
    1.31 +object priority and callback function.
    1.32 +
    1.33 +The function requires a priority value for this active object and a reference 
    1.34 +to a TCallBack object encapsulating a pointer to the call back function which 
    1.35 +is to run when change events occur.
    1.36 +
    1.37 +As part of its implementation, the function:
    1.38 +
    1.39 +creates a Kernel side change notifier and opens a handle (an RChangeNotifier) 
    1.40 +to it.
    1.41 +
    1.42 +adds this active object to the current active scheduler.
    1.43 +
    1.44 +Note that construction of the environment change notifier does not issue any 
    1.45 +requests for change events.
    1.46 +
    1.47 +@param aPriority The priority of this active object. Priority values determine 
    1.48 +the order in which an active scheduler handles completed active object requests.
    1.49 +@param aCallBack A reference to a callback object which the caller must construct 
    1.50 +to encapsulate the callback function. 
    1.51 +@return A pointer to the new environment change notifier object.
    1.52 +@see CEnvironmentChangeNotifier::Start()
    1.53 +@see CActive::TPriority */
    1.54 +	{
    1.55 +	CEnvironmentChangeNotifier* This=new(ELeave) CEnvironmentChangeNotifier(aPriority);
    1.56 +	This->iChangeNotifier.Create();
    1.57 +	This->Set(aCallBack);
    1.58 +	CActiveScheduler::Add(This);
    1.59 +	return(This);
    1.60 +	}
    1.61 +
    1.62 +EXPORT_C CEnvironmentChangeNotifier::~CEnvironmentChangeNotifier()
    1.63 +/** Destructor. Frees all resources owned by the object, prior to its destruction.
    1.64 +
    1.65 +In particular, it cancels any outstanding request to the Kernel side change 
    1.66 +notifier before closing the handle to it. */
    1.67 +	{
    1.68 +	Cancel();
    1.69 +	iChangeNotifier.Close();
    1.70 +	}
    1.71 +
    1.72 +EXPORT_C void CEnvironmentChangeNotifier::Start()
    1.73 +/** Issues a request for change events.
    1.74 +
    1.75 +The request completes when change events occur, as signalled by the Kernel 
    1.76 +side change notifier service. The request may also complete if it is cancelled 
    1.77 +by calling the Cancel() member function of this active object.
    1.78 +
    1.79 +When change events occur, the callback function is called.
    1.80 +
    1.81 +Note that after the first call to this function, the callback function is 
    1.82 +called immediately; this is because of the way the underlying change notifier 
    1.83 +is implemented. The changes reported are all those defined by the TChanges 
    1.84 +enum.
    1.85 +
    1.86 +@see CActive::Cancel()
    1.87 +@see TChanges */
    1.88 +	{
    1.89 +	SetActive();
    1.90 +	iChangeNotifier.Logon(iStatus);
    1.91 +	}
    1.92 +
    1.93 +EXPORT_C TInt CEnvironmentChangeNotifier::Set(const TCallBack& aCallBack)
    1.94 +/** Sets the callback function.
    1.95 +
    1.96 +A callback is normally set when this active object is constructed through 
    1.97 +the NewL() function. This function replaces any existing callback object with 
    1.98 +the specified callback object.
    1.99 +
   1.100 +@param aCallBack A reference to the call back object encapsulating the call 
   1.101 +back function. 
   1.102 +@return KErrNone if successful, KErrInUse if this active object currently has 
   1.103 +an outstanding request for change events, or another of the system-wide error-codes. */
   1.104 +	{
   1.105 +	if (IsActive())
   1.106 +		return(KErrInUse);
   1.107 +	iCallBack=aCallBack;
   1.108 +	return(KErrNone);
   1.109 +	}
   1.110 +
   1.111 +void CEnvironmentChangeNotifier::RunL()
   1.112 +//
   1.113 +//	Active framework: Call the callback function
   1.114 +//
   1.115 +	{
   1.116 +	iChange=iStatus.Int();
   1.117 +	Start();
   1.118 +	if (iChange!=0)
   1.119 +		{
   1.120 +		iCallBack.CallBack();
   1.121 +		iChange=0;
   1.122 +		}
   1.123 +	}
   1.124 +
   1.125 +void CEnvironmentChangeNotifier::DoCancel()
   1.126 +//
   1.127 +//	Active framework: Cancel the current request
   1.128 +//	
   1.129 +	{
   1.130 +	iChangeNotifier.LogonCancel();
   1.131 +	}
   1.132 +