|
1 /* |
|
2 * Copyright (c) 2008-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 |
|
22 /** |
|
23 @file |
|
24 @test |
|
25 @internalComponent |
|
26 */ |
|
27 |
|
28 #include "testutilsdpfilewatcher.h" |
|
29 |
|
30 // CFileWatcher |
|
31 |
|
32 /*static*/ CFileWatcher* CFileWatcher::NewL(RFs& aFs, const RMessagePtr2& aMessage) |
|
33 { |
|
34 CFileWatcher* self=NewLC(aFs, aMessage); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 /*static*/ CFileWatcher* CFileWatcher::NewLC(RFs& aFs, const RMessagePtr2& aMessage) |
|
40 { |
|
41 CFileWatcher* self=new(ELeave) CFileWatcher(aFs, aMessage); |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CFileWatcher::~CFileWatcher() |
|
48 { |
|
49 Cancel(); |
|
50 } |
|
51 |
|
52 CFileWatcher::CFileWatcher(RFs& aFs, const RMessagePtr2& aMessage) |
|
53 : CActive(EPriorityHigh), iFs(aFs), iMessage(aMessage) |
|
54 { |
|
55 CActiveScheduler::Add(this); |
|
56 } |
|
57 |
|
58 void CFileWatcher::ConstructL() |
|
59 { |
|
60 TInt srcLen = iMessage.GetDesLength(0); |
|
61 HBufC* fileName=HBufC::NewLC(srcLen); |
|
62 TPtr ptr(fileName->Des()); |
|
63 TRAPD(err, iMessage.ReadL(0, ptr)); |
|
64 if (err!=KErrNone) |
|
65 { |
|
66 iMessage.Complete(KErrBadDescriptor); |
|
67 } |
|
68 else |
|
69 { |
|
70 iFs.NotifyChange(ENotifyFile, iStatus, *fileName); |
|
71 SetActive(); |
|
72 } |
|
73 CleanupStack::PopAndDestroy(fileName); |
|
74 } |
|
75 |
|
76 void CFileWatcher::DoCancel() |
|
77 { |
|
78 iFs.NotifyChangeCancel(iStatus); |
|
79 iMessage.Complete(KErrCancel); |
|
80 } |
|
81 |
|
82 void CFileWatcher::RunL() |
|
83 { |
|
84 iMessage.Complete(iStatus.Int()); |
|
85 } |