|
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: Implementation of storage manager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cvimpststorageserviceview.h" |
|
22 |
|
23 #include <e32std.h> |
|
24 |
|
25 #include "cvimpststoragemanager.h" |
|
26 #include "tvimpststoragepanics.h" |
|
27 #include "vimpstdebugtrace.h" |
|
28 |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CVIMPSTStorageManager::InitialiseLibraryL |
|
34 // Factory method that create the singleton instance of the storage manager |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 void CVIMPSTStorageManager::InitialiseLibraryL() |
|
38 { |
|
39 TRACE( T_LIT("CVIMPSTStorageManager::InitialiseLibraryL() begin") ); |
|
40 //see whether there is an instance in the TLS |
|
41 //if not create the instance and set the same in TLS |
|
42 CVIMPSTStorageManager *sm = static_cast<CVIMPSTStorageManager*>( Dll::Tls() ); |
|
43 if ( ! sm ) |
|
44 { |
|
45 // no existing instance, create a new one |
|
46 CVIMPSTStorageManager *manager = CVIMPSTStorageManager::NewL(); |
|
47 sm = manager; |
|
48 CleanupStack::PushL( manager ); |
|
49 User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( sm ) ) ); |
|
50 CleanupStack::Pop( manager ); |
|
51 } |
|
52 TRACE( T_LIT("CVIMPSTStorageManager::InitialiseLibraryL() end") ); |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CVIMPSTStorageManager::Release |
|
57 // Factory method to release the singleton instance of the storage manager |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 TInt CVIMPSTStorageManager::Release() |
|
61 { |
|
62 TRACE( T_LIT("CVIMPSTStorageManager::Release() begin") ); |
|
63 //if any instance in TLS get the same and delete it |
|
64 CVIMPSTStorageManager *storage = static_cast<CVIMPSTStorageManager*>( Dll::Tls() ); |
|
65 if ( storage ) |
|
66 { |
|
67 delete storage; |
|
68 Dll::SetTls( NULL ); |
|
69 } |
|
70 TRACE( T_LIT("CVIMPSTStorageManager::Release() end") ); |
|
71 return KErrNone; |
|
72 } |
|
73 |
|
74 |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CVIMPSTStorageManager::Instance() |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CVIMPSTStorageManager& CVIMPSTStorageManager::Instance() |
|
81 { |
|
82 //get the instance frm TLS and return the same |
|
83 TRACE( T_LIT("CVIMPSTStorageManager::Instance() begin") ); |
|
84 CVIMPSTStorageManager *storage = static_cast<CVIMPSTStorageManager*>( Dll::Tls() ); |
|
85 |
|
86 __ASSERT_ALWAYS( storage, |
|
87 User::Panic( KPanicCategory, KLIBNOTINITIALIZED ) ); |
|
88 TRACE( T_LIT("CVIMPSTStorageManager::Instance() end") ); |
|
89 return *storage; |
|
90 } |
|
91 |
|
92 |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CVIMPSTStorageManager::NewL |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CVIMPSTStorageManager* CVIMPSTStorageManager::NewL() |
|
99 { |
|
100 TRACE( T_LIT("CVIMPSTStorageManager::NewL() begin") ); |
|
101 //creates the instance |
|
102 CVIMPSTStorageManager* self = new( ELeave ) CVIMPSTStorageManager; |
|
103 CleanupStack::PushL( self ); |
|
104 self->ConstructL(); |
|
105 CleanupStack::Pop( self ); |
|
106 TRACE( T_LIT("CVIMPSTStorageManager::NewL() end") ); |
|
107 return self; |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CVIMPSTStorageManager::ConstructL |
|
112 // Two-phased constructor. |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 void CVIMPSTStorageManager::ConstructL() |
|
116 { |
|
117 TRACE( T_LIT("CVIMPSTStorageManager::ConstructL() begin") ); |
|
118 TRACE( T_LIT("CVIMPSTStorageManager::ConstructL() end") ); |
|
119 } |
|
120 |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CVIMPSTStorageManager::~CVIMPSTStorageManager |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 CVIMPSTStorageManager::~CVIMPSTStorageManager() |
|
127 { |
|
128 TRACE( T_LIT("CVIMPSTStorageManager::~CVIMPSTStorageManager() begin") ); |
|
129 //release all the existing views |
|
130 iServiceViewList.ResetAndDestroy(); |
|
131 TRACE( T_LIT("CVIMPSTStorageManager::~CVIMPSTStorageManager() end") ); |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CVIMPSTStorageManager::CreateServiceViewL |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 CVIMPSTStorageServiceView* CVIMPSTStorageManager::CreateServiceViewL( TUint32 aServiceId, |
|
139 const TDesC& aStoreName, |
|
140 const TDesC& aServiceName ) |
|
141 { |
|
142 TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() begin") ); |
|
143 //creates a new view based on the service id. |
|
144 TInt index = KErrNotFound; |
|
145 CVIMPSTStorageServiceView* serviceView = NULL; |
|
146 |
|
147 //check if the view already exists in the viewlist |
|
148 index = FindServiceView(aServiceId); |
|
149 if( KErrNotFound == index ) |
|
150 { |
|
151 TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() service does not exit") ); |
|
152 // service view is not found |
|
153 // check if store name is valid create a service view for aServiceId |
|
154 if( aStoreName.Length() ) |
|
155 { |
|
156 TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() store name is valid") ); |
|
157 serviceView = CVIMPSTStorageServiceView::NewL(aServiceId, |
|
158 aStoreName, aServiceName); |
|
159 iServiceViewList.Append(serviceView); |
|
160 TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() new view created for serviceId = %d"),aServiceId ); |
|
161 } |
|
162 // if store name is not valid ,return NULL |
|
163 } |
|
164 else |
|
165 { |
|
166 TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() service already exist = %d"),aServiceId ); |
|
167 serviceView = iServiceViewList[ FindServiceView(aServiceId)]; |
|
168 } |
|
169 //return the extisting view from the viewlist |
|
170 TRACE( T_LIT("CVIMPSTStorageManager::CreateServiceViewL() end") ); |
|
171 return serviceView; |
|
172 } |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CVIMPSTStorageManager::FindServiceView |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TInt CVIMPSTStorageManager::FindServiceView( TUint32 aServiceId) |
|
178 { |
|
179 TRACE( T_LIT("CVIMPSTStorageManager::FindServiceView() begin") ); |
|
180 //search whether the view exists in the view list. |
|
181 TInt index = KErrNotFound; |
|
182 TInt count = iServiceViewList.Count(); |
|
183 for(TInt i = 0; i < count; i++ ) |
|
184 { |
|
185 if( aServiceId == iServiceViewList[ i ]->GetServiceId() ) |
|
186 { |
|
187 TRACE( T_LIT("CVIMPSTStorageManager::FindServiceView() aServiceId found = %d") ,aServiceId ); |
|
188 index = i; |
|
189 break; |
|
190 } |
|
191 } |
|
192 TRACE( T_LIT("CVIMPSTStorageManager::FindServiceView() end") ); |
|
193 return index; |
|
194 } |
|
195 |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CVIMPSTStorageManager::RemoveServiceView |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CVIMPSTStorageManager::RemoveServiceView( TUint32 aServiceId) |
|
202 { |
|
203 TRACE( T_LIT("CVIMPSTStorageManager::RemoveServiceView() begin") ); |
|
204 //searches and removes the view from the view list. |
|
205 TInt index = FindServiceView(aServiceId); |
|
206 if( index >= 0 ) |
|
207 { |
|
208 TRACE( T_LIT("CVIMPSTStorageManager::RemoveServiceView() aServiceId found = %d") ,aServiceId ); |
|
209 //view exists, so delete and remove the same |
|
210 CVIMPSTStorageServiceView* serviceView = iServiceViewList[ index ]; |
|
211 iServiceViewList.Remove( index ); |
|
212 delete serviceView; |
|
213 iServiceViewList.Compress(); |
|
214 } |
|
215 TRACE( T_LIT("CVIMPSTStorageManager::RemoveServiceView() end") ); |
|
216 } |
|
217 |
|
218 // End of File |