|
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: CMSMemoryCardMonitor implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <driveinfo.h> |
|
19 |
|
20 #include "msmemorycardmonitor.h" |
|
21 #include "msdebug.h" |
|
22 |
|
23 // --------------------------------------------------------------------------- |
|
24 // CMSMemoryCardMonitor::NewL |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 CMSMemoryCardMonitor* CMSMemoryCardMonitor::NewL( |
|
28 MMSMemoryCardObserver* aObserver, RFs& aRfs ) |
|
29 { |
|
30 LOG(_L("[MediaServant]\t CMSMemoryCardMonitor::NewL")); |
|
31 |
|
32 CMSMemoryCardMonitor* self = CMSMemoryCardMonitor::NewLC( aObserver, |
|
33 aRfs ); |
|
34 CleanupStack::Pop( self ); |
|
35 |
|
36 return self; |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CMSMemoryCardMonitor::NewLC |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CMSMemoryCardMonitor* CMSMemoryCardMonitor::NewLC( |
|
44 MMSMemoryCardObserver* aObserver, RFs& aRfs ) |
|
45 { |
|
46 LOG(_L("[MediaServant]\t CMSMemoryCardMonitor::NewLC")); |
|
47 |
|
48 CMSMemoryCardMonitor* self = |
|
49 new(ELeave) CMSMemoryCardMonitor( aObserver, aRfs ); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL(); |
|
52 |
|
53 return self; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CMSMemoryCardMonitor::ConstructL |
|
58 // (other items were commented in a header). |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 void CMSMemoryCardMonitor::ConstructL() |
|
62 { |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CMSMemoryCardMonitor::CMSMemoryCardMonitor |
|
67 // (other items were commented in a header). |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CMSMemoryCardMonitor::CMSMemoryCardMonitor( MMSMemoryCardObserver* aObserver, |
|
71 RFs& aRfs ) |
|
72 : CActive( EPriorityIdle ), |
|
73 iObserver( aObserver ), |
|
74 iFsSession( aRfs ), |
|
75 iMemoryCardExist( EFalse ) |
|
76 { |
|
77 LOG(_L("[MediaServant]\t CMSMemoryCardMonitor::CMSMemoryCardMonitor")); |
|
78 CActiveScheduler::Add( this ); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CMSMemoryCardMonitor::~CMSMemoryCardMonitor |
|
83 // Destructor |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 CMSMemoryCardMonitor::~CMSMemoryCardMonitor() |
|
87 { |
|
88 LOG(_L("[MediaServant]\t CMSMemoryCardMonitor::~CMSMemoryCardMonitor")); |
|
89 |
|
90 Cancel(); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CMSMemoryCardMonitor::DoCancel |
|
95 // cancel monitor |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CMSMemoryCardMonitor::DoCancel() |
|
99 { |
|
100 LOG(_L("[MediaServant]\t CMSMemoryCardMonitor::DoCancel() start")); |
|
101 iFsSession.NotifyChangeCancel(); |
|
102 LOG(_L("[MediaServant]\t CMSMemoryCardMonitor::DoCancel() end")); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // CMSMemoryCardMonitor::RunL |
|
107 // RunL |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 void CMSMemoryCardMonitor::RunL() |
|
111 { |
|
112 LOG(_L("[MediaServant]\t CMSMemoryCardMonitor::RunL() start")); |
|
113 TMemoryCardEvent mmcevent( EMemoryCardOthers ); |
|
114 TBool mmc = MemoryCardExist(); |
|
115 |
|
116 TRACE(Print(_L("[MediaServant]\t CMSMemoryCardMonitor::Runl %d-->%d\n"), |
|
117 iMemoryCardExist, mmc )); |
|
118 |
|
119 if( iMemoryCardExist && !mmc ) |
|
120 { |
|
121 mmcevent = EMemoryCardRemove; |
|
122 } |
|
123 else if( !iMemoryCardExist && mmc ) |
|
124 { |
|
125 mmcevent = EMemoryCardInsert; |
|
126 } |
|
127 |
|
128 if( mmcevent != EMemoryCardOthers && iObserver ) |
|
129 { |
|
130 iObserver->MemoryCardChangedL( mmcevent ); |
|
131 } |
|
132 |
|
133 StartMonitor(); |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // CMSMemoryCardMonitor::RunError |
|
138 // RunError |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 TInt CMSMemoryCardMonitor::RunError( TInt /*aError*/ ) |
|
142 { |
|
143 return KErrNone; |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CMSMemoryCardMonitor::StartMonitor |
|
148 // start |
|
149 // --------------------------------------------------------------------------- |
|
150 // |
|
151 void CMSMemoryCardMonitor::StartMonitor() |
|
152 { |
|
153 LOG(_L("[MediaServant]\t CMSMemoryCardMonitor::StartMonitor")); |
|
154 if ( IsActive() ) |
|
155 { |
|
156 Cancel(); |
|
157 } |
|
158 iMemoryCardExist = MemoryCardExist(); |
|
159 iFsSession.NotifyChange( ENotifyDisk, iStatus ); |
|
160 SetActive(); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CMSMemoryCardMonitor::MemoryCardExist |
|
165 // Get the mmc status |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 TBool CMSMemoryCardMonitor::MemoryCardExist() const |
|
169 { |
|
170 LOG(_L("[MediaServant]\t CMSMemoryCardMonitor::MemoryCardExist")); |
|
171 |
|
172 TBool mmcstatus( EFalse ); |
|
173 TDriveList list; |
|
174 iFsSession.DriveList( list ); |
|
175 |
|
176 for( TInt driveNumber = 0 ; driveNumber <= EDriveZ ; driveNumber++ ) |
|
177 { |
|
178 if( list[driveNumber] ) // Is memorycard available |
|
179 { |
|
180 TDriveInfo driveInfo; |
|
181 iFsSession.Drive( driveInfo, driveNumber ); |
|
182 TUint drvStatus( 0 ); |
|
183 User::LeaveIfError( DriveInfo::GetDriveStatus( iFsSession, |
|
184 driveNumber, |
|
185 drvStatus ) ); |
|
186 TInt removableStatus = drvStatus & DriveInfo::EDriveRemovable; |
|
187 |
|
188 // Check if drive is memory card |
|
189 if( removableStatus && ( driveInfo.iType != EMediaNotPresent ) ) |
|
190 { |
|
191 mmcstatus = ETrue; |
|
192 driveNumber = EDriveZ + 1; |
|
193 } |
|
194 } |
|
195 } |
|
196 return mmcstatus; |
|
197 } |
|
198 |
|
199 // End of File |