os/security/cryptomgmtlibs/securitytestfw/test/testutil/server/testutilfilewatcher.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-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 the License "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 * TestUtil - filewatcher implementation
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file 
    22  @test
    23  @internalComponent
    24 */
    25 
    26 #include "testutilfilewatcher.h"
    27 
    28 // CFileWatcher
    29 
    30 /*static*/ CFileWatcher* CFileWatcher::NewL(RFs& aFs, const RMessagePtr2& aMessage)
    31 	{
    32 	CFileWatcher* self=NewLC(aFs, aMessage);
    33 	CleanupStack::Pop(self);
    34 	return self;
    35 	}
    36 	
    37 /*static*/ CFileWatcher* CFileWatcher::NewLC(RFs& aFs, const RMessagePtr2& aMessage)
    38 	{
    39 	CFileWatcher* self=new(ELeave) CFileWatcher(aFs, aMessage);
    40 	CleanupStack::PushL(self);
    41 	self->ConstructL();
    42 	return self;	
    43 	}
    44 	
    45 CFileWatcher::~CFileWatcher()
    46 	{
    47 	Cancel();
    48 	}
    49 
    50 CFileWatcher::CFileWatcher(RFs& aFs, const RMessagePtr2& aMessage)
    51 	: CActive(EPriorityHigh), iFs(aFs), iMessage(aMessage)
    52 	{
    53 	CActiveScheduler::Add(this);
    54 	}
    55 
    56 void CFileWatcher::ConstructL()
    57 	{
    58 	TInt srcLen = iMessage.GetDesLength(0);
    59 	HBufC* fileName=HBufC::NewLC(srcLen);
    60 	TPtr ptr(fileName->Des());
    61 	TRAPD(err, iMessage.ReadL(0, ptr));
    62 	if (err!=KErrNone)
    63 		{
    64 		iMessage.Complete(KErrBadDescriptor);
    65 		}
    66 	else
    67 		{
    68 		iFs.NotifyChange(ENotifyFile, iStatus, *fileName);
    69 		SetActive();	
    70 		}
    71 	CleanupStack::PopAndDestroy(fileName);
    72 	}
    73 
    74 void CFileWatcher::DoCancel()
    75 	{
    76 	iFs.NotifyChangeCancel(iStatus);
    77 	iMessage.Complete(KErrCancel);
    78 	}
    79 
    80 void CFileWatcher::RunL()
    81 	{
    82 	iMessage.Complete(iStatus.Int());
    83 	}
    84