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 "uiservicetabtracer.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 TRACER_AUTO; |
|
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 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CVIMPSTStorageManager::Release |
|
56 // Factory method to release the singleton instance of the storage manager |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 TInt CVIMPSTStorageManager::Release() |
|
60 { |
|
61 TRACER_AUTO; |
|
62 //if any instance in TLS get the same and delete it |
|
63 CVIMPSTStorageManager *storage = static_cast<CVIMPSTStorageManager*>( Dll::Tls() ); |
|
64 if ( storage ) |
|
65 { |
|
66 delete storage; |
|
67 Dll::SetTls( NULL ); |
|
68 } |
|
69 return KErrNone; |
|
70 } |
|
71 |
|
72 |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CVIMPSTStorageManager::Instance() |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CVIMPSTStorageManager& CVIMPSTStorageManager::Instance() |
|
79 { |
|
80 TRACER_AUTO; |
|
81 //get the instance frm TLS and return the same |
|
82 CVIMPSTStorageManager *storage = static_cast<CVIMPSTStorageManager*>( Dll::Tls() ); |
|
83 |
|
84 __ASSERT_ALWAYS( storage, |
|
85 User::Panic( KPanicCategory, KLIBNOTINITIALIZED ) ); |
|
86 return *storage; |
|
87 } |
|
88 |
|
89 |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CVIMPSTStorageManager::NewL |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CVIMPSTStorageManager* CVIMPSTStorageManager::NewL() |
|
96 { |
|
97 TRACER_AUTO; |
|
98 //creates the instance |
|
99 CVIMPSTStorageManager* self = new( ELeave ) CVIMPSTStorageManager; |
|
100 CleanupStack::PushL( self ); |
|
101 self->ConstructL(); |
|
102 CleanupStack::Pop( self ); |
|
103 return self; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CVIMPSTStorageManager::ConstructL |
|
108 // Two-phased constructor. |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void CVIMPSTStorageManager::ConstructL() |
|
112 { |
|
113 TRACER_AUTO; |
|
114 } |
|
115 |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CVIMPSTStorageManager::~CVIMPSTStorageManager |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 CVIMPSTStorageManager::~CVIMPSTStorageManager() |
|
122 { |
|
123 TRACER_AUTO; |
|
124 //release all the existing views |
|
125 iServiceViewList.ResetAndDestroy(); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CVIMPSTStorageManager::CreateServiceViewL |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 CVIMPSTStorageServiceView* CVIMPSTStorageManager::CreateServiceViewL( TUint32 aServiceId, |
|
133 const TDesC& aStoreName, |
|
134 const TDesC& aServiceName ) |
|
135 { |
|
136 TRACER_AUTO; |
|
137 //creates a new view based on the service id. |
|
138 TInt index = KErrNotFound; |
|
139 CVIMPSTStorageServiceView* serviceView = NULL; |
|
140 |
|
141 //check if the view already exists in the viewlist |
|
142 index = FindServiceView(aServiceId); |
|
143 if( KErrNotFound == index ) |
|
144 { |
|
145 TRACE( "service does not exit" ); |
|
146 // service view is not found |
|
147 // check if store name is valid create a service view for aServiceId |
|
148 if( aStoreName.Length() ) |
|
149 { |
|
150 TRACE(" store name is valid" ); |
|
151 serviceView = CVIMPSTStorageServiceView::NewL(aServiceId, |
|
152 aStoreName, aServiceName); |
|
153 iServiceViewList.Append(serviceView); |
|
154 TRACE( "new view created for serviceId = %d",aServiceId ); |
|
155 } |
|
156 // if store name is not valid ,return NULL |
|
157 } |
|
158 else |
|
159 { |
|
160 TRACE( " service already exist = %d",aServiceId ); |
|
161 serviceView = iServiceViewList[ FindServiceView(aServiceId)]; |
|
162 } |
|
163 //return the extisting view from the viewlist |
|
164 return serviceView; |
|
165 } |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CVIMPSTStorageManager::FindServiceView |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 TInt CVIMPSTStorageManager::FindServiceView( TUint32 aServiceId) |
|
171 { |
|
172 TRACER_AUTO; |
|
173 //search whether the view exists in the view list. |
|
174 TInt index = KErrNotFound; |
|
175 TInt count = iServiceViewList.Count(); |
|
176 for(TInt i = 0; i < count; i++ ) |
|
177 { |
|
178 if( aServiceId == iServiceViewList[ i ]->GetServiceId() ) |
|
179 { |
|
180 TRACE( "aServiceId found = %d" ,aServiceId ); |
|
181 index = i; |
|
182 break; |
|
183 } |
|
184 } |
|
185 return index; |
|
186 } |
|
187 |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CVIMPSTStorageManager::RemoveServiceView |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CVIMPSTStorageManager::RemoveServiceView( TUint32 aServiceId) |
|
194 { |
|
195 TRACER_AUTO; |
|
196 //searches and removes the view from the view list. |
|
197 TInt index = FindServiceView(aServiceId); |
|
198 if( index >= 0 ) |
|
199 { |
|
200 TRACE( "aServiceId found = %d" ,aServiceId ); |
|
201 //view exists, so delete and remove the same |
|
202 CVIMPSTStorageServiceView* serviceView = iServiceViewList[ index ]; |
|
203 iServiceViewList.Remove( index ); |
|
204 delete serviceView; |
|
205 iServiceViewList.Compress(); |
|
206 } |
|
207 } |
|
208 |
|
209 // End of File |
|