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: Central Repository about DB state change information observer |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <centralrepository.h> |
|
19 #include <f32file.h> |
|
20 #include "cpserverdef.h" |
|
21 #include "chdbstatehandler.h" |
|
22 #include "chfactorysettingsplugin.h" |
|
23 |
|
24 |
|
25 _LIT( KParsedDir, "parsed\\fs\\" ); |
|
26 _LIT( KDriveC, "C:" ); |
|
27 |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS ============================= |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CCHDbStateHandler::CCHDbStateHandler() |
|
33 // |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CCHDbStateHandler::CCHDbStateHandler( CCHFactorySettings* aCallback ) : |
|
37 CActive( EPriorityStandard ), // Standard priority |
|
38 iCallback( aCallback ) |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CCHDbStateHandler::NewL() |
|
44 // Two-phased constructor |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CCHDbStateHandler* CCHDbStateHandler::NewL( |
|
48 CCHFactorySettings* aCallback ) |
|
49 { |
|
50 CCHDbStateHandler* self = new (ELeave) CCHDbStateHandler( aCallback ); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CCHDbStateHandler::NewL() |
|
59 // Constructor |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CCHDbStateHandler::ConstructL() |
|
63 { |
|
64 User::LeaveIfError( iFs.Connect() ); |
|
65 ConstructFactorySettingsPathL(); |
|
66 iRepository = CRepository::NewL( KServerUid ); |
|
67 HandleDbStateL(); |
|
68 CActiveScheduler::Add(this); // Add to scheduler |
|
69 iRepository->NotifyRequest( KCPStorageUid, iStatus ); |
|
70 iStatus = KRequestPending; |
|
71 SetActive(); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CCHDbStateHandler::NewL() |
|
76 // |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CCHDbStateHandler::~CCHDbStateHandler() |
|
80 { |
|
81 Cancel(); // Cancel any request, if outstanding |
|
82 delete iRepository; |
|
83 iFs.Close(); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CCHDbStateHandler::NewL() |
|
88 // |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CCHDbStateHandler::DoCancel() |
|
92 { |
|
93 iRepository->NotifyCancel( KCPStorageUid ); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CCHDbStateHandler::RunL() |
|
98 // |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 void CCHDbStateHandler::RunL() |
|
102 { |
|
103 // status contais information about event type |
|
104 if (iStatus.Int() >= KErrNone) |
|
105 { |
|
106 HandleDbStateL(); |
|
107 iRepository->NotifyRequest( KCPStorageUid, iStatus ); |
|
108 iStatus = KRequestPending; |
|
109 SetActive(); |
|
110 } |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CCHDbStateHandler::RunError() |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 TInt CCHDbStateHandler::RunError(TInt aError) |
|
119 { |
|
120 return aError; |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CCHDbStateHandler::ConstructFactorySettingsPathL() |
|
125 // |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void CCHDbStateHandler::ConstructFactorySettingsPathL() |
|
129 { |
|
130 TFileName privatePath; |
|
131 User::LeaveIfError( iFs.PrivatePath( privatePath ) ); |
|
132 iFSPath.Append( KDriveC ); |
|
133 iFSPath.Append( privatePath ); |
|
134 iFSPath.Append( KParsedDir ); |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CCHDbStateHandler::RemoveFactorySettingsParsedFilesL() |
|
139 // |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CCHDbStateHandler::RemoveFactorySettingsParsedFilesL() |
|
143 { |
|
144 CFileMan* fileManager = CFileMan::NewL( iFs ); |
|
145 CleanupStack::PushL( fileManager ); |
|
146 fileManager->Delete( iFSPath, CFileMan::ERecurse ); |
|
147 CleanupStack::PopAndDestroy( fileManager ); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CCHDbStateHandler::HandleDbStateL() |
|
152 // |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CCHDbStateHandler::HandleDbStateL() |
|
156 { |
|
157 TInt value( 0 ); |
|
158 if( iRepository->Get( KCPStorageUid, value ) == KErrNone ) |
|
159 { |
|
160 if( value & KSQLDBStateRestored ) |
|
161 { |
|
162 HandleRestoredDbStateL(); |
|
163 value ^= KSQLDBStateRestored; |
|
164 value |= KSQLDBStateNormal; |
|
165 iRepository->Set( KCPStorageUid, value ); |
|
166 } |
|
167 } |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CCHDbStateHandler::HandleRestoredStateL() |
|
172 // |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CCHDbStateHandler::HandleRestoredDbStateL() |
|
176 { |
|
177 RemoveFactorySettingsParsedFilesL(); |
|
178 iCallback->UpdateL(); |
|
179 } |
|
180 |
|
181 |
|
182 //End file |
|