sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* TestUtil - filewatcher implementation
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
@file
|
sl@0
|
22 |
@test
|
sl@0
|
23 |
@internalComponent
|
sl@0
|
24 |
*/
|
sl@0
|
25 |
|
sl@0
|
26 |
#include "testutilfilewatcher.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
// CFileWatcher
|
sl@0
|
29 |
|
sl@0
|
30 |
/*static*/ CFileWatcher* CFileWatcher::NewL(RFs& aFs, const RMessagePtr2& aMessage)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
CFileWatcher* self=NewLC(aFs, aMessage);
|
sl@0
|
33 |
CleanupStack::Pop(self);
|
sl@0
|
34 |
return self;
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
/*static*/ CFileWatcher* CFileWatcher::NewLC(RFs& aFs, const RMessagePtr2& aMessage)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
CFileWatcher* self=new(ELeave) CFileWatcher(aFs, aMessage);
|
sl@0
|
40 |
CleanupStack::PushL(self);
|
sl@0
|
41 |
self->ConstructL();
|
sl@0
|
42 |
return self;
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
CFileWatcher::~CFileWatcher()
|
sl@0
|
46 |
{
|
sl@0
|
47 |
Cancel();
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
CFileWatcher::CFileWatcher(RFs& aFs, const RMessagePtr2& aMessage)
|
sl@0
|
51 |
: CActive(EPriorityHigh), iFs(aFs), iMessage(aMessage)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
CActiveScheduler::Add(this);
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
void CFileWatcher::ConstructL()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
TInt srcLen = iMessage.GetDesLength(0);
|
sl@0
|
59 |
HBufC* fileName=HBufC::NewLC(srcLen);
|
sl@0
|
60 |
TPtr ptr(fileName->Des());
|
sl@0
|
61 |
TRAPD(err, iMessage.ReadL(0, ptr));
|
sl@0
|
62 |
if (err!=KErrNone)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
iMessage.Complete(KErrBadDescriptor);
|
sl@0
|
65 |
}
|
sl@0
|
66 |
else
|
sl@0
|
67 |
{
|
sl@0
|
68 |
iFs.NotifyChange(ENotifyFile, iStatus, *fileName);
|
sl@0
|
69 |
SetActive();
|
sl@0
|
70 |
}
|
sl@0
|
71 |
CleanupStack::PopAndDestroy(fileName);
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
void CFileWatcher::DoCancel()
|
sl@0
|
75 |
{
|
sl@0
|
76 |
iFs.NotifyChangeCancel(iStatus);
|
sl@0
|
77 |
iMessage.Complete(KErrCancel);
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
void CFileWatcher::RunL()
|
sl@0
|
81 |
{
|
sl@0
|
82 |
iMessage.Complete(iStatus.Int());
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|