|
1 /* |
|
2 * Copyright (c) 2006-2007 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: sync collection and harvester db contents |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CMPXDBSYNCHRONIZER_H |
|
20 #define CMPXDBSYNCHRONIZER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 |
|
25 // FORWARD DECLARATIONS |
|
26 class RFs; |
|
27 class MMPXDbSyncObserver; |
|
28 class MMPXCollectionUtility; |
|
29 class CMPXHarvesterDatabaseManager; |
|
30 class CMPXHarvesterDatabaseTable; |
|
31 |
|
32 /** |
|
33 * CMPXDbSynchronizer |
|
34 * |
|
35 * Sync collection and harvester databases |
|
36 * |
|
37 * @lib mpxfilehandler |
|
38 * @since S60 3.0 |
|
39 */ |
|
40 NONSHARABLE_CLASS( CMPXDbSynchronizer ) : public CActive |
|
41 { |
|
42 enum ESyncState |
|
43 { |
|
44 ESyncStopped, |
|
45 ESyncMusic, |
|
46 ESyncPlaylist, |
|
47 ESyncPodcast |
|
48 }; |
|
49 |
|
50 public: |
|
51 /** |
|
52 * Two-phased constructor |
|
53 * @param aObs synchronization observer |
|
54 * @param aDbMng reference to the database manager |
|
55 * @param aMusic reference to the music collection uid |
|
56 * @param aPodcast reference to the podcast collection uid |
|
57 * @param aFs file session |
|
58 */ |
|
59 static CMPXDbSynchronizer* NewL(MMPXDbSyncObserver& aStateObs, |
|
60 CMPXHarvesterDatabaseManager& aDbMng, |
|
61 const TUid& aMusic, |
|
62 const TUid& aPodcast, |
|
63 RFs& aFs, |
|
64 TBool aDisablePodcast ); |
|
65 |
|
66 /** |
|
67 * Virtual destructor |
|
68 */ |
|
69 virtual ~CMPXDbSynchronizer(); |
|
70 |
|
71 /** |
|
72 * Check databases on these drives for sync issues, result within a callback to observer |
|
73 * @param aDrives the drives to be used |
|
74 * @param aColUtil collection utility reference |
|
75 */ |
|
76 void Synchronize(RArray<TInt>& aDbIndexes, MMPXCollectionUtility* aColUtil); |
|
77 |
|
78 protected: // From Base Class |
|
79 /** |
|
80 * From CActive |
|
81 */ |
|
82 void RunL(); |
|
83 |
|
84 /** |
|
85 * From CActive |
|
86 */ |
|
87 void DoCancel(); |
|
88 |
|
89 /** |
|
90 * From CActive |
|
91 */ |
|
92 TInt RunError(TInt aError); |
|
93 |
|
94 private: // New Functions |
|
95 /** |
|
96 * Sync a portion of data to avoid blocking thread for long |
|
97 * @return ETrue if there is more data to process |
|
98 * EFalse if the sync process is complete |
|
99 */ |
|
100 TBool DoSynchronizeStepL(); |
|
101 |
|
102 /** |
|
103 * Handles what to do when synchronization is done |
|
104 * @param aErr error to return to the client |
|
105 */ |
|
106 void DoSynchronizeComplete(TInt aErr); |
|
107 |
|
108 //Helper functions used inside DoSynchronizeStepL |
|
109 void DoMusicTableSyncL(CMPXHarvesterDatabaseTable& aTable); |
|
110 void DoPlaylistTableSyncL(CMPXHarvesterDatabaseTable& aTable); |
|
111 void DoPodcastTableSyncL(CMPXHarvesterDatabaseTable& aTable); |
|
112 //Misc helper functions for internal use |
|
113 inline void CompleteSelf(); |
|
114 inline void GetTableCountL(TInt aDbId, TInt aTable); |
|
115 inline TInt CopyTableRecordsL(CMPXHarvesterDatabaseTable& aTable, |
|
116 TInt aColDbId, TInt aColTable); |
|
117 |
|
118 private: |
|
119 /** |
|
120 * Private constructor |
|
121 * @param aObs synchronization observer |
|
122 * @param aDbMng reference to the database manager |
|
123 * @param aMusic reference to the music collection uid |
|
124 * @param aPodcast reference to the podcast collection uid |
|
125 * @param aFs file session |
|
126 */ |
|
127 CMPXDbSynchronizer(MMPXDbSyncObserver& aObs, |
|
128 CMPXHarvesterDatabaseManager& aDbMng, |
|
129 const TUid& aMusic, |
|
130 const TUid& aPodcast, |
|
131 RFs& aFs, |
|
132 TBool aDisablePodcast ); |
|
133 |
|
134 /** |
|
135 * 2nd Phase constructor |
|
136 */ |
|
137 void ConstructL(); |
|
138 |
|
139 private: // data |
|
140 MMPXDbSyncObserver& iSyncObserver; |
|
141 CMPXHarvesterDatabaseManager& iDBManager; // Not owned |
|
142 MMPXCollectionUtility* iColUtil; //Not owned |
|
143 const TUid& iMusicUid; |
|
144 const TUid& iPodcastUid; |
|
145 RFs& iFs; // Not owned |
|
146 |
|
147 // Databases on these drives to be synchronized |
|
148 RArray<TInt> iDbDrives; |
|
149 |
|
150 ESyncState iSyncState; |
|
151 TInt iCurDrive; |
|
152 TInt iDbRecTotalCount; |
|
153 TInt iCurDbRecCount; |
|
154 TInt iLastID; |
|
155 TBool iDisablePodcasting; |
|
156 }; |
|
157 |
|
158 #endif // CMPXDBSYNCHRONIZER_H |