51
|
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: factory class to create access and updateer class implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include "cimcachefactory.h"
|
|
22 |
|
|
23 |
#include "cimcacheupdater.h"
|
|
24 |
#include "mimcacheupdater.h"
|
|
25 |
#include "cimcacheaccessor.h"
|
|
26 |
#include "mimcacheaccessor.h"
|
|
27 |
#include "cimcacheclient.h"
|
|
28 |
// logs
|
|
29 |
#include "imcachedebugtrace.h"
|
|
30 |
|
|
31 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
32 |
// -----------------------------------------------------------------------------
|
|
33 |
// CIMCacheFactory::Instance
|
|
34 |
//see whether there is an instance in the TLS
|
|
35 |
//if not create the instance and set the same in TLS
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
EXPORT_C CIMCacheFactory* CIMCacheFactory::InstanceL()
|
|
39 |
{
|
|
40 |
TRACE( T_LIT("CIMCacheFactory::InstanceL begin") );
|
|
41 |
CIMCacheFactory *factory = static_cast<CIMCacheFactory*>( Dll::Tls() );
|
|
42 |
|
|
43 |
if ( ! factory )
|
|
44 |
{
|
|
45 |
// no existing instance, create a new one
|
|
46 |
factory = CIMCacheFactory::NewL();
|
|
47 |
CleanupStack::PushL( factory );
|
|
48 |
User::LeaveIfError( Dll::SetTls( static_cast<TAny*>( factory ) ) );
|
|
49 |
CleanupStack::Pop( factory );
|
|
50 |
}
|
|
51 |
TRACE( T_LIT("CIMCacheFactory::InstanceL end") );
|
|
52 |
factory->IncrementReference();
|
|
53 |
return factory;
|
|
54 |
}
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
// CIMCacheFactory::NewL
|
|
57 |
// Two-phased constructor.
|
|
58 |
// -----------------------------------------------------------------------------
|
|
59 |
//
|
|
60 |
CIMCacheFactory* CIMCacheFactory::NewL()
|
|
61 |
{
|
|
62 |
TRACE( T_LIT("CIMCacheFactory::NewL begin") );
|
|
63 |
CIMCacheFactory* self = new ( ELeave ) CIMCacheFactory() ;
|
|
64 |
CleanupStack::PushL( self );
|
|
65 |
self->ConstructL();
|
|
66 |
CleanupStack::Pop( self ); //self
|
|
67 |
TRACE( T_LIT("CIMCacheFactory::NewL end") );
|
|
68 |
return self;
|
|
69 |
}
|
|
70 |
|
|
71 |
// -----------------------------------------------------------------------------
|
|
72 |
// CIMCacheFactory::Release()
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
EXPORT_C void CIMCacheFactory::Release()
|
|
76 |
{
|
|
77 |
TRACE( T_LIT("CIMCacheFactory::Release start") );
|
|
78 |
//if any instance in TLS get the same and delete it
|
|
79 |
CIMCacheFactory *factory = static_cast<CIMCacheFactory*>( Dll::Tls() );
|
|
80 |
if ( factory && !(factory->DecrementReference()))
|
|
81 |
if ( factory )
|
|
82 |
{
|
|
83 |
delete factory;
|
|
84 |
Dll::SetTls( NULL );
|
|
85 |
}
|
|
86 |
TRACE( T_LIT("CIMCacheFactory::Release end") );
|
|
87 |
}
|
|
88 |
// -----------------------------------------------------------------------------
|
|
89 |
// CIMCacheFactory::IncrementReference()
|
|
90 |
// -----------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
void CIMCacheFactory::IncrementReference()
|
|
93 |
{
|
|
94 |
TRACE( T_LIT("CIMCacheFactory::IncrementReference ") );
|
|
95 |
iReferenceCount++;
|
|
96 |
}
|
|
97 |
|
|
98 |
// -----------------------------------------------------------------------------
|
|
99 |
// CPresenceCacheServer::DecrementReference()
|
|
100 |
// -----------------------------------------------------------------------------
|
|
101 |
//
|
|
102 |
TInt CIMCacheFactory::DecrementReference()
|
|
103 |
{
|
|
104 |
TRACE( T_LIT("CIMCacheFactory::DecrementReference ") );
|
|
105 |
iReferenceCount--;
|
|
106 |
return iReferenceCount;
|
|
107 |
}
|
|
108 |
|
|
109 |
// -----------------------------------------------------------------------------
|
|
110 |
// CIMCacheFactory::CIMCacheFactory()
|
|
111 |
// C++ default constructor can NOT contain any code, that
|
|
112 |
// might leave.
|
|
113 |
// -----------------------------------------------------------------------------
|
|
114 |
//
|
|
115 |
CIMCacheFactory::CIMCacheFactory()
|
|
116 |
{
|
|
117 |
}
|
|
118 |
|
|
119 |
// -----------------------------------------------------------------------------
|
|
120 |
// CIMCacheFactory::~CIMCacheFactory()
|
|
121 |
// Symbian OS desstructor
|
|
122 |
// -----------------------------------------------------------------------------
|
|
123 |
//
|
|
124 |
CIMCacheFactory::~CIMCacheFactory()
|
|
125 |
{
|
|
126 |
TRACE( T_LIT("CIMCacheFactory::~CIMCacheFactory start") );
|
|
127 |
iUpdaterArray.ResetAndDestroy();
|
|
128 |
iAccessorArray.ResetAndDestroy();
|
|
129 |
delete iServerKeepAlive;
|
|
130 |
TRACE( T_LIT("CIMCacheFactory::~CIMCacheFactory end") );
|
|
131 |
}
|
|
132 |
// -----------------------------------------------------------------------------
|
|
133 |
// CIMCacheFactory::ConstructL()
|
|
134 |
// Symbian OS default constructor can leave.
|
|
135 |
// -----------------------------------------------------------------------------
|
|
136 |
//
|
|
137 |
void CIMCacheFactory::ConstructL( )
|
|
138 |
{
|
|
139 |
TRACE( T_LIT("CIMCacheFactory::ConstructL start") );
|
|
140 |
iServerKeepAlive = new(ELeave) CIMCacheClient(); // CSI: 74 # this needs to be like this
|
|
141 |
TRACE( T_LIT("CIMCacheFactory::ConstructL end") );
|
|
142 |
}
|
|
143 |
|
|
144 |
// -----------------------------------------------------------------------------
|
|
145 |
// CIMCacheFactory::CreateUpdaterL()
|
|
146 |
// -----------------------------------------------------------------------------
|
|
147 |
//
|
|
148 |
EXPORT_C MIMCacheUpdater* CIMCacheFactory::CreateUpdaterL(TInt aServiceId,
|
|
149 |
const TDesC& aUserId ,
|
|
150 |
TBool aRegistrationNeeded )
|
|
151 |
{
|
|
152 |
TRACE( T_LIT("CIMCacheFactory::CreateAccessL begin") );
|
|
153 |
|
|
154 |
CIMCacheUpdater* updater = NULL;
|
|
155 |
|
|
156 |
TInt count = iUpdaterArray.Count();
|
|
157 |
for( TInt i = 0; i < count; ++i )
|
|
158 |
{
|
|
159 |
if( iUpdaterArray[i]->ServiceId() == aServiceId )
|
|
160 |
{
|
|
161 |
updater = iUpdaterArray[i];
|
|
162 |
break;
|
|
163 |
}
|
|
164 |
}
|
|
165 |
if( !updater )
|
|
166 |
{
|
|
167 |
updater = CIMCacheUpdater::NewL( aServiceId, aUserId, aRegistrationNeeded );
|
|
168 |
iUpdaterArray.Append(updater);
|
|
169 |
}
|
|
170 |
|
|
171 |
TRACE( T_LIT("CIMCacheFactory::CreateAccessL end") );
|
|
172 |
return updater;
|
|
173 |
}
|
|
174 |
|
|
175 |
// -----------------------------------------------------------------------------
|
|
176 |
// CIMCacheFactory::CreateAccessorL()
|
|
177 |
// -----------------------------------------------------------------------------
|
|
178 |
//
|
|
179 |
EXPORT_C MIMCacheAccessor* CIMCacheFactory::CreateAccessorL(TInt aServiceId,
|
|
180 |
const TDesC& aUserId )
|
|
181 |
{
|
|
182 |
TRACE( T_LIT("CIMCacheFactory::CreateAccessL begin") );
|
|
183 |
|
|
184 |
CIMCacheAccessor* accessor = NULL;
|
|
185 |
|
|
186 |
TInt count = iAccessorArray.Count();
|
|
187 |
for( TInt i = 0; i < count; ++i )
|
|
188 |
{
|
|
189 |
if( iAccessorArray[i]->ServiceId() == aServiceId )
|
|
190 |
{
|
|
191 |
accessor = iAccessorArray[i];
|
|
192 |
break;
|
|
193 |
}
|
|
194 |
}
|
|
195 |
if( !accessor )
|
|
196 |
{
|
|
197 |
accessor = CIMCacheAccessor::NewL( aServiceId, aUserId );
|
|
198 |
iAccessorArray.Append(accessor);
|
|
199 |
}
|
|
200 |
|
|
201 |
TRACE( T_LIT("CIMCacheFactory::CreateAccessL end") );
|
|
202 |
return accessor;
|
|
203 |
}
|
|
204 |
// End of File
|
|
205 |
|