|
1 /* |
|
2 * Copyright (c) 2010 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: Helper class for Video Center for drive operations/monitoring.* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef CIPTVDRIVEMONITOR_H |
|
22 #define CIPTVDRIVEMONITOR_H |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include <f32file.h> |
|
27 #include "TIptvDriveInfo.h" |
|
28 #include "TIptvDriveMonitorEvent.h" |
|
29 #include "MIptvDriveMonitorObserver.h" |
|
30 #include "IptvDebug.h" |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // MACROS |
|
35 |
|
36 // DATA TYPES |
|
37 |
|
38 // FUNCTION PROTOTYPES |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 |
|
42 // CLASS DECLARATION |
|
43 |
|
44 /** |
|
45 * Helper class for Video Center for drive operations/monitoring. |
|
46 * User can get available drives (through iAvailableDrives public member) |
|
47 * and be notified when drives change (through MIptvDriveMonitorObserver interface). |
|
48 */ |
|
49 NONSHARABLE_CLASS ( CIptvDriveMonitor ) : public CActive |
|
50 { |
|
51 public: // Constructors and destructor |
|
52 |
|
53 /** |
|
54 * Two-phased constructor. |
|
55 */ |
|
56 static CIptvDriveMonitor* NewL(); |
|
57 |
|
58 /** |
|
59 * Two-phased constructor. Use this is owner object already has a file session open. |
|
60 * |
|
61 * @param aFileSession file session. |
|
62 */ |
|
63 static CIptvDriveMonitor* NewL( const RFs& aFileSession ); |
|
64 |
|
65 /** |
|
66 * Destructor. |
|
67 */ |
|
68 virtual ~CIptvDriveMonitor(); |
|
69 |
|
70 public: |
|
71 |
|
72 /** |
|
73 * Registers observer for drive events. |
|
74 * iAvailableDrives is updated automatically if there are any |
|
75 * observers registered, ie there is no need to call RefreshAvailableDrivesL |
|
76 * when observing. |
|
77 * Don't keep observers around if they do not need events. Observing should be used |
|
78 * when user needs to know immedetially about memory card insertion/removed events, |
|
79 * or drive locked/unlocked events. |
|
80 * |
|
81 * @param aObserver observer, ownership does not move. |
|
82 */ |
|
83 void RegisterObserverL( MIptvDriveMonitorObserver* aObserver ); |
|
84 |
|
85 /** |
|
86 * Removes observer, ownership does not move. |
|
87 * @param aObserver observer to be removed from observers list. |
|
88 */ |
|
89 void RemoveObserverL( MIptvDriveMonitorObserver* aObserver ); |
|
90 |
|
91 /** |
|
92 * Updates iAvailableDrives member variable from File server. |
|
93 * This is called in ConstructL() also. |
|
94 */ |
|
95 void RefreshAvailableDrivesL(); |
|
96 |
|
97 /** |
|
98 * Returns the position index of aDrive in iAvailableDrives. |
|
99 * |
|
100 * @param aDrive drive to search. |
|
101 * @return Position index of aDrive in iAvailableDrives. If not found, |
|
102 * KErrNotFound is returned. |
|
103 */ |
|
104 TInt ArrayPos( TInt aDrive ); |
|
105 |
|
106 /** |
|
107 * Returns the position index of aDrive in iAvailableDrives. If not |
|
108 * found, leaves with KErrNotFound code. |
|
109 * |
|
110 * @param aDrive drive to search. |
|
111 * @return Position index of aDrive in iAvailableDrives. |
|
112 */ |
|
113 TInt ArrayPosL( TInt aDrive ); |
|
114 |
|
115 /** |
|
116 * Returns the default removable drive (= memory card drive) from iAvailableDrives |
|
117 * array. Leaves with KErrNotFound if not found. |
|
118 */ |
|
119 TInt MemoryCardDriveL(); |
|
120 |
|
121 /** |
|
122 * Returns the default removable drive (= memory card drive) from iAvailableDrives |
|
123 * array. Returns KErrNotFound if not found. |
|
124 * |
|
125 * @return drive number, or KErrNotFound if not found. |
|
126 */ |
|
127 TInt MemoryCardDrive(); |
|
128 |
|
129 /** |
|
130 * Returns the default mass memory drive if found from iAvailableDrives. |
|
131 * Mass storege drive means the drive which is preferred for storing large |
|
132 * files in the device, the drive itself can be anything, usually not c though. |
|
133 * Leaves with KErrNotFound if not found. |
|
134 * |
|
135 * @return Drive number. |
|
136 */ |
|
137 TInt MassStorageDriveL(); |
|
138 |
|
139 /** |
|
140 * Returns the default mass memory drive if found from iAvailableDrives. |
|
141 * Mass storege drive means the drive which is preferred for storing large |
|
142 * files in the device, the drive itself can be anything except c-drive. |
|
143 * Returns KErrNotFound if not found. |
|
144 * |
|
145 * @return Drive number, or KErrNotFound if not found. |
|
146 */ |
|
147 TInt MassStorageDrive(); |
|
148 |
|
149 /** |
|
150 * Returns the phone memory drive from iAvailableDrives array. |
|
151 * Leaves with KErrNotFound if not found. |
|
152 * |
|
153 * @return Drive number. |
|
154 */ |
|
155 TInt PhoneMemoryDriveL(); |
|
156 |
|
157 /** |
|
158 * Returns the PhoneMemory drive from iAvailableDrives array. |
|
159 * Returns KErrNotFound if not found. |
|
160 * |
|
161 * @return Drive number, or KErrNotFound if not found. |
|
162 */ |
|
163 TInt PhoneMemoryDrive(); |
|
164 |
|
165 /** |
|
166 * Returns the first fixed (= non removable) drive from iAvailableDrives array. |
|
167 * Leaves with KErrNotFound if not found. |
|
168 * |
|
169 * @param aExcludeCDrive If ETrue, then C-drive is excluded. |
|
170 * @return Drive number. |
|
171 */ |
|
172 TInt FixedDriveL( TBool aExcludeCDrive ); |
|
173 |
|
174 /** |
|
175 * Returns the first fixed (= non removable) drive from iAvailableDrives array. |
|
176 * Returns KErrNotFound if not found. |
|
177 * |
|
178 * @param aExcludeCDrive If ETrue, then C-drive is excluded. |
|
179 * @return Drive number, or KErrNotFound if not found. |
|
180 */ |
|
181 TInt FixedDrive( TBool aExcludeCDrive ); |
|
182 |
|
183 /** |
|
184 * @return ETrue if aDrive is the preferred mass storage drive for the large files. |
|
185 */ |
|
186 TBool IsMassStorageDriveL( TInt aDrive ); |
|
187 |
|
188 /** |
|
189 * @return ETrue if aDrive is memory card type. |
|
190 */ |
|
191 TBool IsMemoryCardDriveL( TInt aDrive ); |
|
192 |
|
193 /** |
|
194 * @return ETrue media is present in the drive. (Memory card is inserted and drive is not locked). |
|
195 */ |
|
196 TBool IsPresentL( TInt aDrive ); |
|
197 |
|
198 /** |
|
199 * @return The system drive. Might not be in iAvailableDrives. |
|
200 */ |
|
201 TInt SystemDrive(); |
|
202 |
|
203 /** |
|
204 * Finds out if memory card is inserted and not locked. |
|
205 * |
|
206 * @return Returns ETrue is memory card is inserted and usable (not locked), EFalse otherwise. |
|
207 */ |
|
208 TBool IsMmcInserted(); |
|
209 |
|
210 /** |
|
211 * Gets the used memory from cenrep. If cenrep contains invalid drive or value is not found, |
|
212 * chooses the preferred drive in the following order: 1. mass storage 2. memory card |
|
213 * 3. EDriveC. If cenrep value was not usable, the chosen drive is written to cenrep. |
|
214 * Leaves with system-wide error code if wasn't able to get the used memory. |
|
215 * |
|
216 * @param aUsedMemory The used memory drive is written here. |
|
217 */ |
|
218 void GetUsedMemoryL( TInt& aUsedMemory ); |
|
219 |
|
220 |
|
221 protected: // Functions from base classes |
|
222 |
|
223 /** |
|
224 * From CActive, RunL. |
|
225 * Called when operation completes. |
|
226 */ |
|
227 void RunL(); |
|
228 |
|
229 /** |
|
230 * From CActive, cancels request. |
|
231 */ |
|
232 void DoCancel(); |
|
233 |
|
234 /** |
|
235 * From CActive, handles leaves from RunL. |
|
236 */ |
|
237 TInt RunError( TInt aError ); |
|
238 |
|
239 private: |
|
240 |
|
241 /** |
|
242 * C++ default constructor. |
|
243 */ |
|
244 CIptvDriveMonitor(); |
|
245 |
|
246 /** |
|
247 * By default Symbian 2nd phase constructor is private. |
|
248 */ |
|
249 void ConstructL(); |
|
250 |
|
251 /** |
|
252 * By default Symbian 2nd phase constructor is private. |
|
253 * |
|
254 * @param aFileSession |
|
255 */ |
|
256 void ConstructL( const RFs& aFileSession ); |
|
257 |
|
258 /** |
|
259 * Sends event to observers. |
|
260 * |
|
261 * @param aEvent event to send. |
|
262 * @param aDrive drive which caused the event. |
|
263 */ |
|
264 void SendEvent( TIptvDriveMonitorEvent::TEvent aEvent, TInt aDrive ); |
|
265 |
|
266 /** |
|
267 * Compares iPreviousAvailableDrives and iAvailableDrives arrays and |
|
268 * sends appropriate events if they differ. |
|
269 */ |
|
270 void CompareOldAndNewAvailableDrives(); |
|
271 |
|
272 /** |
|
273 * Returns drive type as a descriptor. For debugging only. |
|
274 * @param aType Drive type, see valid values from e32const.h TMediaType enum. |
|
275 */ |
|
276 const TDesC& DriveTypeDes( TInt aType ); |
|
277 |
|
278 /** |
|
279 * Prints available drives. For debugging only. |
|
280 */ |
|
281 void PrintAvailableDrives(); |
|
282 |
|
283 public: |
|
284 |
|
285 /** |
|
286 * Array of currently available drives. These are updated |
|
287 * with RefreshAvailableDrivesL -method or from file |
|
288 * server event. RefreshAvailableDrivesL is also called upon creation |
|
289 * of this object. |
|
290 * iAvailableDrives array contains drives which are available for mass |
|
291 * storaging videos. If there is hard disk and memory card |
|
292 * available(both e and f-drives), then c-drive is excluded from the array. |
|
293 */ |
|
294 RArray<TIptvDriveInfo> iAvailableDrives; |
|
295 |
|
296 |
|
297 private: |
|
298 |
|
299 /** |
|
300 * Used to detect if refresh had any effect. |
|
301 */ |
|
302 RArray<TIptvDriveInfo> iPreviousAvailableDrives; |
|
303 |
|
304 /** |
|
305 * Array of observers. Pointers not owned. |
|
306 */ |
|
307 RArray<MIptvDriveMonitorObserver*> iObservers; |
|
308 |
|
309 /** |
|
310 * Session to file server. |
|
311 */ |
|
312 RFs iFs; |
|
313 |
|
314 /** |
|
315 * ETrue if iFs is provided by the user of this class. |
|
316 */ |
|
317 TBool iIfsIsProvidedByUser; |
|
318 |
|
319 /** |
|
320 * Default memory for storing large files. |
|
321 */ |
|
322 TInt iDefaultMassStorageDrive; |
|
323 |
|
324 /** |
|
325 * Default memory card. |
|
326 */ |
|
327 TInt iDefaultMemoryCardDrive; |
|
328 |
|
329 /** |
|
330 * System drive. |
|
331 */ |
|
332 TInt iSystemDrive; |
|
333 |
|
334 }; |
|
335 |
|
336 #endif // CIPTVDRIVEMONITOR_H |
|
337 |
|
338 // End of File |