sl@0: /*
sl@0: * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of the License "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description: 
sl@0: * testutil - server classes
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: /**
sl@0:  @file 
sl@0:  @test
sl@0:  @internalComponent
sl@0: */
sl@0: 
sl@0: #include <e32base.h>
sl@0: #include "testutilfilewatcher.h"
sl@0: 
sl@0: class CTestUtilServer;
sl@0: 
sl@0: class MTimeoutClient
sl@0: 	{
sl@0: public:
sl@0: 	/** Client's implementation gets called on timer expiry */
sl@0: 	virtual void HandleTimeout() = 0;
sl@0: 	};
sl@0: 
sl@0: /** Simple timer class which calls a callback on timer expiry */
sl@0: class CGenericTimer : public CTimer
sl@0: 	{
sl@0: public:
sl@0: 	static CGenericTimer* NewL(MTimeoutClient& aClient);
sl@0: private:
sl@0: 	CGenericTimer(MTimeoutClient& aClient);
sl@0: 	void RunL();
sl@0: private:
sl@0: 	MTimeoutClient& iClient;
sl@0: 	};
sl@0: 
sl@0: class CTestFileDetector : public CActive, public MTimeoutClient
sl@0: 	{
sl@0: public:
sl@0: 	static CTestFileDetector* NewL(const RMessage2& iMessage, RFs& aFs);
sl@0: 	CTestFileDetector(const RMessage2& iMessage, RFs& aFs);
sl@0: 	~CTestFileDetector();
sl@0: 	void DetectFile();
sl@0: private:
sl@0: 	void ConstructL();
sl@0: 	virtual void HandleTimeout();
sl@0: 	void RunL();
sl@0: 	void DoCancel();
sl@0: 	void CheckAndComplete();
sl@0: private:
sl@0: 	RFs& iFs;
sl@0: 	CGenericTimer* iTimer;
sl@0: 	HBufC* iFileName;
sl@0: 	TInt iTimeInterval;
sl@0: 	const RMessage2& iMessage;
sl@0: 	};
sl@0: 
sl@0: class CTestUtilSession : public CSession2
sl@0: 	{
sl@0: public:
sl@0: 	CTestUtilSession();
sl@0: 	void CreateL();
sl@0: private:
sl@0: 	~CTestUtilSession();
sl@0: 	inline CTestUtilServer& Server();
sl@0: 	void ServiceL(const RMessage2& aMessage);
sl@0: 	void ServiceError(const RMessage2& aMessage,TInt aError);
sl@0: private:
sl@0: 	RArray<RFile> iLockedFileHandles;
sl@0: 	CFileWatcher* iFileWatcher;
sl@0: 	CTestFileDetector* iDetector;
sl@0: 	};
sl@0: 
sl@0: 
sl@0: inline CTestUtilServer& CTestUtilSession::Server()
sl@0: 	{return *static_cast<CTestUtilServer*>(const_cast<CServer2*>(CSession2::Server()));}