|
1 /* |
|
2 * Copyright (c) 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: Presence Service Connection globals holder |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include "ximpfeaturepluginholder.h" |
|
21 #include "apidataobjfactoryaccessor.h" |
|
22 |
|
23 const TInt KPluginArrayGranularity = 3; |
|
24 |
|
25 // ============================ HELPER CLASS =============================== |
|
26 |
|
27 |
|
28 /** |
|
29 * Nested structure to hold global accessor objects. |
|
30 */ |
|
31 |
|
32 // FIXME: probably better would be to encapsulate the struct to CBase object |
|
33 NONSHARABLE_STRUCT( SAccessorHolder ) |
|
34 { |
|
35 /** |
|
36 * Presence obj factory accessor |
|
37 * Owned. |
|
38 */ |
|
39 MApiDataObjFactoryAccessor* iPresenceAccessor; |
|
40 |
|
41 |
|
42 // array of accessor plugins |
|
43 CArrayFixFlat<MApiDataObjFactoryAccessor*>* iAccessorPlugins; |
|
44 |
|
45 /** |
|
46 * TODO: Add here more accessors |
|
47 */ |
|
48 |
|
49 /** |
|
50 * Reference counter |
|
51 */ |
|
52 TInt iRefCount; |
|
53 }; |
|
54 |
|
55 // ============================ MEMBER FUNCTIONS =============================== |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C void FeaturePluginHolder::InitializeL( ) |
|
62 { |
|
63 SAccessorHolder* singleton = ( SAccessorHolder* ) Dll::Tls(); |
|
64 |
|
65 if( !singleton ) |
|
66 { |
|
67 singleton = new ( ELeave ) SAccessorHolder; |
|
68 Dll::SetTls( singleton ); |
|
69 |
|
70 // Initialize the variables |
|
71 singleton->iRefCount = 0; |
|
72 singleton->iPresenceAccessor = NULL; |
|
73 |
|
74 TRAP_IGNORE( singleton->iPresenceAccessor = MApiDataObjFactoryAccessor::NewPresenceAccessorL( ) ); |
|
75 |
|
76 //added to hold accessor plugins |
|
77 singleton->iAccessorPlugins = new(ELeave)CArrayFixFlat<MApiDataObjFactoryAccessor*>(KPluginArrayGranularity); |
|
78 |
|
79 FeaturePluginHolder::LoadAccessorPluginsL() ; |
|
80 } |
|
81 else |
|
82 { |
|
83 // increase the reference counter |
|
84 singleton->iRefCount++; |
|
85 } |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C MApiDataObjFactoryAccessor* FeaturePluginHolder::PresenceObjFactoryAccessor() |
|
93 { |
|
94 SAccessorHolder* singleton = ( SAccessorHolder* ) Dll::Tls(); |
|
95 if( !singleton ) |
|
96 { |
|
97 User::Panic( _L("cximpglobals"), KErrNotFound ); |
|
98 } |
|
99 |
|
100 return singleton->iPresenceAccessor; |
|
101 } |
|
102 |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // FeaturePluginHolder::Release() |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C void FeaturePluginHolder::Release( ) |
|
109 { |
|
110 SAccessorHolder* singleton = ( SAccessorHolder* ) Dll::Tls(); |
|
111 if ( !singleton->iRefCount ) |
|
112 { |
|
113 // No more users, clean the TLS up |
|
114 delete singleton->iPresenceAccessor; |
|
115 if ( singleton->iAccessorPlugins ) |
|
116 { |
|
117 TInt idx = KErrNotFound; |
|
118 while( singleton->iAccessorPlugins->Count() ) |
|
119 { |
|
120 idx = singleton->iAccessorPlugins->Count() - 1; |
|
121 // Delete object |
|
122 delete singleton->iAccessorPlugins->At( idx ); |
|
123 // Delete element |
|
124 singleton->iAccessorPlugins->Delete( idx ); |
|
125 } |
|
126 } |
|
127 |
|
128 delete singleton->iAccessorPlugins; |
|
129 REComSession::FinalClose(); |
|
130 |
|
131 delete singleton; |
|
132 Dll::SetTls(NULL); |
|
133 } |
|
134 else |
|
135 { |
|
136 singleton->iRefCount--; |
|
137 } |
|
138 } |
|
139 |
|
140 void FeaturePluginHolder::LoadAccessorPluginsL() |
|
141 { |
|
142 SAccessorHolder* singleton = ( SAccessorHolder* ) Dll::Tls(); |
|
143 if(!singleton) |
|
144 { |
|
145 User::Panic( _L("cximpglobals"), KErrNotFound ); |
|
146 } |
|
147 else |
|
148 { |
|
149 RImplInfoPtrArray pluginArray; |
|
150 MApiDataObjFactoryAccessor::ListAllImplementationsL(pluginArray) ; |
|
151 if ( pluginArray.Count() ) |
|
152 { |
|
153 for( TInt i = 0; i < pluginArray.Count(); i++ ) |
|
154 { |
|
155 MApiDataObjFactoryAccessor* implementation = NULL ; |
|
156 |
|
157 CImplementationInformation* info = pluginArray[ i ]; |
|
158 |
|
159 TUid id = info->ImplementationUid(); |
|
160 TRAPD(err, implementation = MApiDataObjFactoryAccessor::NewL(id) ); |
|
161 CleanupStack::PushL(implementation); |
|
162 if(err == KErrNone) |
|
163 { |
|
164 singleton->iAccessorPlugins->AppendL( implementation ); |
|
165 } |
|
166 CleanupStack::Pop(implementation); |
|
167 } |
|
168 } |
|
169 pluginArray.ResetAndDestroy(); |
|
170 } |
|
171 } |
|
172 |
|
173 EXPORT_C TInt FeaturePluginHolder::AccessorCount() |
|
174 { |
|
175 SAccessorHolder* singleton = ( SAccessorHolder* ) Dll::Tls(); |
|
176 if(!singleton) |
|
177 { |
|
178 User::Panic( _L("cximpglobals"), KErrNotFound ); |
|
179 } |
|
180 |
|
181 return singleton->iAccessorPlugins->Count() ; |
|
182 |
|
183 } |
|
184 |
|
185 EXPORT_C MApiDataObjFactoryAccessor* FeaturePluginHolder::Accessor(TInt index) |
|
186 { |
|
187 SAccessorHolder* singleton = ( SAccessorHolder* ) Dll::Tls(); |
|
188 if(!singleton) |
|
189 { |
|
190 User::Panic( _L("cximpglobals"), KErrNotFound ); |
|
191 } |
|
192 |
|
193 return singleton->iAccessorPlugins->At(index) ; |
|
194 } |
|
195 |
|
196 // End of file |
|
197 |
|
198 |