|
1 /* |
|
2 * Copyright (c) 2008 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 "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 * |
|
16 */ |
|
17 |
|
18 #include <sysutil.h> |
|
19 |
|
20 #include "mcsfreespaceobserver.h" |
|
21 |
|
22 // --------------------------------------------------------------------------- |
|
23 // CMcsFreeSpaceObserver::CMcsFreeSpaceObserver |
|
24 // --------------------------------------------------------------------------- |
|
25 // |
|
26 CMcsFreeSpaceObserver::CMcsFreeSpaceObserver(MMcsFreeSpaceObserver& aCallback, |
|
27 TInt64 aFreeDiskSpace, TInt aDrive) : |
|
28 CActive(EPriorityStandard), // Standard priority |
|
29 iDrive(aDrive), |
|
30 iFreeDiskSpace(aFreeDiskSpace), |
|
31 iCallback(aCallback) |
|
32 { |
|
33 CActiveScheduler::Add(this); // Add to scheduler |
|
34 } |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CMcsFreeSpaceObserver::NewLC |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CMcsFreeSpaceObserver* CMcsFreeSpaceObserver::NewLC(MMcsFreeSpaceObserver& aCallback, |
|
41 TInt64 aFreeDiskSpace, |
|
42 TInt aDrive) |
|
43 { |
|
44 CMcsFreeSpaceObserver* self = new (ELeave) CMcsFreeSpaceObserver(aCallback, |
|
45 aFreeDiskSpace, aDrive); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CMcsFreeSpaceObserver::NewL |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CMcsFreeSpaceObserver* CMcsFreeSpaceObserver::NewL(MMcsFreeSpaceObserver& aCallback, |
|
56 TInt64 aFreeDiskSpace, |
|
57 TInt aDrive) |
|
58 { |
|
59 CMcsFreeSpaceObserver* self = CMcsFreeSpaceObserver::NewLC(aCallback, |
|
60 aFreeDiskSpace, aDrive); |
|
61 CleanupStack::Pop(); // self; |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CMcsFreeSpaceObserver::ConstructL |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 void CMcsFreeSpaceObserver::ConstructL() |
|
70 { |
|
71 User::LeaveIfError( iFs.Connect( ) ); |
|
72 iFs.NotifyDiskSpace( iFreeDiskSpace, iDrive, iStatus ); |
|
73 SetActive(); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CMcsFreeSpaceObserver::~CMcsFreeSpaceObserver |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CMcsFreeSpaceObserver::~CMcsFreeSpaceObserver() |
|
81 { |
|
82 Cancel(); // Cancel any request, if outstanding |
|
83 iFs.Close(); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // CMcsFreeSpaceObserver::DoCancel |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 void CMcsFreeSpaceObserver::DoCancel() |
|
91 { |
|
92 iFs.NotifyDiskSpaceCancel(); |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CMcsFreeSpaceObserver::RunL |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CMcsFreeSpaceObserver::RunL() |
|
100 { |
|
101 TVolumeInfo vol; |
|
102 if ( ( iStatus == KErrNone ) && |
|
103 ( iFs.Volume(vol, iDrive )==KErrNone ) && |
|
104 ( vol.iFree>iFreeDiskSpace ) ) |
|
105 { |
|
106 if( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, |
|
107 MMcsFreeSpaceObserver::EFreeDiskSpace, |
|
108 EDriveC ) ) |
|
109 { |
|
110 iFreeDiskSpace = vol.iFree + MMcsFreeSpaceObserver::EFreeDiskSpace; |
|
111 } |
|
112 else |
|
113 { |
|
114 iCallback.HandleFreeSpaceEventL(); |
|
115 } |
|
116 } |
|
117 iFs.NotifyDiskSpace( iFreeDiskSpace, iDrive, iStatus ); |
|
118 SetActive(); |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CMcsFreeSpaceObserver::RunError |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 TInt CMcsFreeSpaceObserver::RunError(TInt /*aError*/) |
|
126 { |
|
127 iFs.NotifyDiskSpace( iFreeDiskSpace, iDrive, iStatus ); |
|
128 SetActive(); |
|
129 return KErrNone; |
|
130 } |