|
1 /* |
|
2 * Copyright (c) 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 "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: Enumerator objects |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CMEDIAMTPDATAPROVIDERENUMERATOR_H |
|
20 #define CMEDIAMTPDATAPROVIDERENUMERATOR_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <d32dbms.h> |
|
24 |
|
25 #include "mmmtpenumerationcallback.h" |
|
26 #include "cmmmtpdpperflog.h" |
|
27 |
|
28 // keep here to avoid warning on urel |
|
29 _LIT( KDirectoryScan, "DirectoryScan" ); |
|
30 _LIT( KFormatFilter, "FormatFilter" ); |
|
31 _LIT( KObjectManagerObjectUid, "ObjectManagerObjectUid" ); |
|
32 _LIT( KObjectManagerInsert, "ObjectManagerInsert" ); |
|
33 |
|
34 // Forward declarations |
|
35 class MMTPDataProviderFramework; |
|
36 class MMTPObjectMgr; |
|
37 class CMTPObjectMetaData; |
|
38 class CMediaMtpDataProvider; |
|
39 |
|
40 /** |
|
41 * Defines file enumerator. Enumerates all files/directories under a |
|
42 * specified path or storage |
|
43 */ |
|
44 class CMediaMtpDataProviderEnumerator: public CActive |
|
45 { |
|
46 public: |
|
47 /** |
|
48 * Two phase constructor |
|
49 * @param aFramework Reference to MMTPDataProviderFramework |
|
50 * @param aDataProvider Reference to CMediaMtpDataProvider |
|
51 * @return A pointer to a new instance of the object |
|
52 */ |
|
53 static CMediaMtpDataProviderEnumerator* NewL( MMTPDataProviderFramework& aFramework, |
|
54 CMediaMtpDataProvider& aDataProvider ); |
|
55 |
|
56 /** |
|
57 * destructor |
|
58 */ |
|
59 ~CMediaMtpDataProviderEnumerator(); |
|
60 |
|
61 /** |
|
62 * Kick off the enumeration on the specified storage |
|
63 * @param aStorageId storage to be enumerated |
|
64 */ |
|
65 void StartL( TUint32 aStorageId ); |
|
66 |
|
67 // introduce to cleanup db at close session |
|
68 void SessionClosedL(); |
|
69 |
|
70 protected: |
|
71 // from CActive |
|
72 /** |
|
73 * Cancel the enumeration process |
|
74 */ |
|
75 void DoCancel(); |
|
76 |
|
77 void RunL(); |
|
78 |
|
79 /** |
|
80 * Ignore the error, continue with the next one |
|
81 */ |
|
82 TInt RunError( TInt aError ); |
|
83 |
|
84 private: |
|
85 /** |
|
86 * Standard C++ Constructor |
|
87 * @param aFramework Reference to MMTPDataProviderFramework |
|
88 * @param aDataProvider Reference to CMediaMtpDataProvider |
|
89 */ |
|
90 CMediaMtpDataProviderEnumerator( MMTPDataProviderFramework& aFramework, |
|
91 CMediaMtpDataProvider& aDataProvider ); |
|
92 |
|
93 void ConstructL(); |
|
94 |
|
95 /** |
|
96 * Called when the enumeration is completed |
|
97 */ |
|
98 void SignalCompleteL( MMTPEnumerationCallback& aCallback, |
|
99 TInt aError = KErrNone ); |
|
100 |
|
101 void ScanStorageL( TUint32 aStorageId ); |
|
102 |
|
103 /** |
|
104 * Scan next storage |
|
105 */ |
|
106 void ScanNextStorageL(); |
|
107 |
|
108 /** |
|
109 * Scans directory at aPath recursing into subdirectories on a depth |
|
110 * first basis. |
|
111 * |
|
112 * Directory entries are kept in iDirStack - which is a LIFO stack. |
|
113 * The current path, needed since TEntries don't keep track of it, |
|
114 * is kept in iPath. |
|
115 * |
|
116 * The algorithm works as follows: |
|
117 * |
|
118 * 1. Read directory entries. |
|
119 * 2. ProcessEntriesL is called if no error occurs and >= 1 entries are |
|
120 * read. |
|
121 * 3. ProcessEntriesL adds entries to database, if entry is directory |
|
122 * add to iDirStack. |
|
123 * 4. When all entries are processed pop entry off the dirstack, |
|
124 * if entry is empty TEntry remove one directory from iPath. |
|
125 * 5. Append entry name onto iPath - to update path with new depth |
|
126 * (parent/subdir). |
|
127 * 6. Push an empty TEntry onto iDirStack - this tells us we have |
|
128 * recursed one, think of it as pushing the '\' separator onto |
|
129 * iDirStack. |
|
130 * 7. Repeat 1-7 until iDirStack is empty. |
|
131 */ |
|
132 void ScanDirL(); |
|
133 |
|
134 /** |
|
135 * Recurse into the next directory on the stack |
|
136 * and scan it for entries. |
|
137 */ |
|
138 void ScanNextDirL(); |
|
139 |
|
140 /** |
|
141 * Scan next sub dir |
|
142 */ |
|
143 void ScanNextSubdirL(); |
|
144 |
|
145 /** |
|
146 * Iterates iEntries adding entries as needed to object manager and |
|
147 * iDirStack. |
|
148 */ |
|
149 void ProcessEntriesL(); |
|
150 |
|
151 /** |
|
152 * Add a file entry to the object store |
|
153 * @param aFullFileName current scanned file path |
|
154 */ |
|
155 void AddEntryL( const TDesC& aFullFileName ); |
|
156 |
|
157 /** |
|
158 * Returns a TMTPFormatCode for the requested object |
|
159 */ |
|
160 TMTPFormatCode GetObjectFormatCode( const TDesC& aFullFileName ); |
|
161 |
|
162 /** |
|
163 * @param aFullFileName the object file name |
|
164 * @return the file if needed to be enumeratored? |
|
165 */ |
|
166 TBool IsFileAccepted( const TDesC& aFullFileName ); |
|
167 |
|
168 /** |
|
169 * start count system tick |
|
170 */ |
|
171 void StartEnumerationCount(); |
|
172 |
|
173 /** |
|
174 * check if the system tick more than predefined value |
|
175 * @retuan if more than the predefined value, return true |
|
176 * else return false |
|
177 */ |
|
178 TBool IsOverThreshold(); |
|
179 |
|
180 /** |
|
181 * Get modified content and report to Symbian MTP Framework |
|
182 */ |
|
183 void GetModifiedContentL( const TDesC& aStorageRoot ); |
|
184 |
|
185 private: |
|
186 // Owned |
|
187 /** MMTPDataProviderFramework used to access MTP components*/ |
|
188 MMTPDataProviderFramework& iFramework; |
|
189 |
|
190 /** MTP Object Manager */ |
|
191 MMTPObjectMgr& iObjectMgr; |
|
192 |
|
193 /** MTP Data Provider ID */ |
|
194 TUint iDataProviderId; |
|
195 |
|
196 CMediaMtpDataProvider& iDataProvider; |
|
197 TParse iPath; |
|
198 RDir iDir; |
|
199 TEntryArray iEntries; |
|
200 TInt iFirstUnprocessed; |
|
201 RPointerArray<TEntry> iDirStack; |
|
202 RArray<TUint> iStorages; |
|
203 TUint32 iStorageId; |
|
204 TUint32 iParentHandle; |
|
205 TMTPFormatCode iFormatCode; |
|
206 TBool iScanningDir; |
|
207 |
|
208 // record the system tick |
|
209 TUint iTickCountBegin; |
|
210 TInt iTickPeriod; |
|
211 |
|
212 #if defined(_DEBUG) || defined(MMMTPDP_PERFLOG) |
|
213 CMmMtpDpPerfLog* iPerfLog; |
|
214 #endif |
|
215 |
|
216 }; |
|
217 |
|
218 #endif // CMEDIAMTPDATAPROVIDERENUMERATOR_H |