|
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 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __CIPTVEPGFILESWAPPER_H |
|
20 #define __CIPTVEPGFILESWAPPER_H |
|
21 |
|
22 // System includes |
|
23 #include <e32base.h> // For CActive |
|
24 #include <f32file.h> // For RFs |
|
25 //#include <babackup.h> // F |
|
26 |
|
27 // Forward declarations |
|
28 class CBaBackupSessionWrapper; |
|
29 class MIptvEpgFileSwapObserver; |
|
30 |
|
31 /** |
|
32 * Class to replace given old file with given new file. |
|
33 * This class takes care of requesting to close affected files by |
|
34 * using CBaBackupSessionWrapper and monitors the state of those two files. |
|
35 * When both files are not open by any other instance anymore this class |
|
36 * performs the file switching in it's RunL method and after that signalizes |
|
37 * the observers via CBaBackupSessionWrapper that they are allowed to re-open |
|
38 * the files for reading and writing. |
|
39 */ |
|
40 class CIptvEpgFileSwapper : public CActive |
|
41 { |
|
42 public: |
|
43 /** |
|
44 * Symbian two phace constructor. |
|
45 * @param aOldFileName Name of the file to be replaced |
|
46 * @param aNewFileName Name of the file to be used to replace aOldFileName |
|
47 * @return Pointer to newly created instance of CIptvEpgFileSwapper object |
|
48 */ |
|
49 IMPORT_C static CIptvEpgFileSwapper* NewL( const TFileName& aOldFileName, |
|
50 const TFileName& aNewFileName, |
|
51 MIptvEpgFileSwapObserver& aSwapObserver ); |
|
52 |
|
53 /** |
|
54 * Destructor |
|
55 */ |
|
56 virtual ~CIptvEpgFileSwapper(); |
|
57 |
|
58 public: |
|
59 /** |
|
60 * Method to initiate file swapping process. This method signalizes the |
|
61 * backupwrapper to ask all the backup observers for aOldFileName and aNewFilename |
|
62 * to release their handles to the files and sets this object to active state. |
|
63 * @param None |
|
64 * @return None |
|
65 */ |
|
66 IMPORT_C void SwapFilesL(); |
|
67 |
|
68 private: |
|
69 /** |
|
70 * Default constructor |
|
71 * @param aOldFileName Name of the file to be replaced |
|
72 * @param aNewFileName Name of the file to be used to replace aOldFileName |
|
73 * @param aSwapObserver Reference to a class that observes the file swapping |
|
74 * @return None |
|
75 */ |
|
76 CIptvEpgFileSwapper( const TFileName& aOldFileName, |
|
77 const TFileName& aNewFileName, |
|
78 MIptvEpgFileSwapObserver& aSwapObserver ); |
|
79 |
|
80 /** |
|
81 * Symbian second phase constructor containing the code that might leave |
|
82 * during instantiation of this class. |
|
83 * @param None |
|
84 * @return None |
|
85 */ |
|
86 void ConstructL(); |
|
87 |
|
88 /** |
|
89 * Method that calls RestartFile method of CBaBackupSessionWrapper to allow |
|
90 * observers to re-establish the connections to the files. |
|
91 * @param None |
|
92 * @return None |
|
93 */ |
|
94 void ReleaseFileLocks(); |
|
95 |
|
96 private: // From CActive |
|
97 /** |
|
98 * Overwritten error handling method to get called when active scheduler catches |
|
99 * leave in this active object. |
|
100 * @param aError Symbian error code for the occured error |
|
101 * @return KErrNone if error was handled by this method. If return value is |
|
102 * something else but KErrNone, active scheduler will panic. |
|
103 */ |
|
104 TInt RunError( TInt aError ); |
|
105 |
|
106 /** |
|
107 * Method to get called when active object request has been completed. |
|
108 * @param None |
|
109 * @return None |
|
110 */ |
|
111 void RunL(); |
|
112 |
|
113 /** |
|
114 * Method to handle actual actions required after Cancel-method has been called. |
|
115 */ |
|
116 void DoCancel(); |
|
117 |
|
118 private: // instance variables |
|
119 /** |
|
120 * Handle to the file server session |
|
121 */ |
|
122 RFs iFs; |
|
123 /** |
|
124 * Timer to use when monitoring open files |
|
125 */ |
|
126 RTimer iTimeWaster; |
|
127 |
|
128 /** |
|
129 * Name of the old file that is to be replaced |
|
130 */ |
|
131 TFileName iOldFileName; |
|
132 |
|
133 /** |
|
134 * Name of the file to be used to replace iOldFileName |
|
135 */ |
|
136 TFileName iNewFileName; |
|
137 |
|
138 /** |
|
139 * Backup session to signalize all observers to release handle to |
|
140 * iOldFileName and iNewFileName |
|
141 */ |
|
142 CBaBackupSessionWrapper* iBackupWrapper; |
|
143 |
|
144 /** |
|
145 * Reference to the class that observes the file swapping |
|
146 */ |
|
147 MIptvEpgFileSwapObserver& iSwapObserver; |
|
148 |
|
149 TInt iSwapTriesAmount; |
|
150 }; |
|
151 |
|
152 #endif // __CIPTVEPGFILESWAPPER_H |