|
1 /* |
|
2 * Copyright (c) 2007-2009 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: Static Tls data storage |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "resmrstatic.h" |
|
20 |
|
21 #include "cesmrcontactmenuhandler.h" |
|
22 #include "cesmrcontactmanagerhandler.h" |
|
23 |
|
24 // DEBUG |
|
25 #include "emailtrace.h" |
|
26 |
|
27 /** |
|
28 * Storage stuct for RESMRStatic. |
|
29 */ |
|
30 struct TESMRStaticData |
|
31 { |
|
32 TInt iInstanceCount; |
|
33 TInt iContactManagerHandlerCount; |
|
34 CESMRContactManagerHandler* iContactManagerHandler; |
|
35 TInt iContactMenuHandlerCount; |
|
36 CESMRContactMenuHandler* iContactMenuHandler; |
|
37 |
|
38 TInt iPbkxContactListingServiceCount; |
|
39 TInt iCurrentFieldIndex; |
|
40 }; |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // RESMRStatic::RESMRStatic |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C RESMRStatic::RESMRStatic( ) |
|
49 { |
|
50 FUNC_LOG; |
|
51 //do nothing |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // RESMRStatic::~RESMRStatic |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C RESMRStatic::~RESMRStatic( ) |
|
59 { |
|
60 FUNC_LOG; |
|
61 if ( iStaticData ) |
|
62 { |
|
63 delete iStaticData->iContactMenuHandler; |
|
64 iStaticData->iContactMenuHandler = NULL; |
|
65 |
|
66 delete iStaticData->iContactManagerHandler; |
|
67 iStaticData->iContactManagerHandler = NULL; |
|
68 } |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // RESMRStatic::ConnectL |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C void RESMRStatic::ConnectL( ) |
|
76 { |
|
77 FUNC_LOG; |
|
78 if (iStaticData ) |
|
79 { |
|
80 // already connected |
|
81 return; |
|
82 } |
|
83 |
|
84 // Retrieve Tls pointer |
|
85 iStaticData = (TESMRStaticData*) Dll::Tls(); |
|
86 |
|
87 // If Tls pointer was not set, create new static stuct |
|
88 // with NULL values |
|
89 if ( !iStaticData ) |
|
90 { |
|
91 iStaticData = new (ELeave) TESMRStaticData(); |
|
92 memset ( iStaticData, 0, sizeof( TESMRStaticData) ); |
|
93 Dll::SetTls ( iStaticData ); |
|
94 } |
|
95 ++iStaticData->iInstanceCount; |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // RESMRStatic::Close |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 EXPORT_C void RESMRStatic::Close( ) |
|
103 { |
|
104 FUNC_LOG; |
|
105 if (iStaticData ) |
|
106 { |
|
107 if (iUsedTypes & EContactMenuHandler ) |
|
108 { |
|
109 --iStaticData->iContactMenuHandlerCount; |
|
110 if (iStaticData->iContactMenuHandlerCount == 0 ) |
|
111 { |
|
112 if ( iStaticData->iContactManagerHandlerCount == 0 ) |
|
113 { |
|
114 // Delete both Handlers when both are ready to delete |
|
115 // and Contact Manager Handler should be deleted last |
|
116 // because the Menu Handler has dependency to it. |
|
117 delete iStaticData->iContactMenuHandler; |
|
118 iStaticData->iContactMenuHandler = NULL; |
|
119 |
|
120 delete iStaticData->iContactManagerHandler; |
|
121 iStaticData->iContactManagerHandler = NULL; |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 // If ContactManagerHandlerL was used |
|
127 if (iUsedTypes & EContactManagerHandler ) |
|
128 { |
|
129 // Decrease counter |
|
130 --iStaticData->iContactManagerHandlerCount; |
|
131 |
|
132 // If this was last instance using pointer |
|
133 if ( iStaticData->iContactManagerHandlerCount == 0 ) |
|
134 { |
|
135 if ( iStaticData->iContactMenuHandlerCount == 0 ) |
|
136 { |
|
137 delete iStaticData->iContactMenuHandler; |
|
138 iStaticData->iContactMenuHandler = NULL; |
|
139 // Delete instance |
|
140 delete iStaticData->iContactManagerHandler; |
|
141 iStaticData->iContactManagerHandler = NULL; |
|
142 } |
|
143 } |
|
144 } |
|
145 |
|
146 // Decrease instance counter |
|
147 --iStaticData->iInstanceCount; |
|
148 |
|
149 // If this was last instance using pointer |
|
150 if (iStaticData->iInstanceCount == 0 ) |
|
151 { |
|
152 delete iStaticData; |
|
153 Dll::FreeTls ( ); |
|
154 } |
|
155 iStaticData = NULL; |
|
156 } |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // RESMRStatic::ContactManagerHandlerL |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 EXPORT_C CESMRContactManagerHandler& RESMRStatic::ContactManagerHandlerL( ) |
|
164 { |
|
165 FUNC_LOG; |
|
166 if ( !iStaticData->iContactManagerHandler ) |
|
167 { |
|
168 iStaticData->iContactManagerHandler = |
|
169 CESMRContactManagerHandler::NewL(); |
|
170 } |
|
171 |
|
172 if (!(iUsedTypes & EContactManagerHandler) ) |
|
173 { |
|
174 ++iStaticData->iContactManagerHandlerCount; |
|
175 iUsedTypes |= EContactManagerHandler; |
|
176 } |
|
177 return *iStaticData->iContactManagerHandler; |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // RESMRStatic::ContactMenuHandlerL |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 EXPORT_C CESMRContactMenuHandler& RESMRStatic::ContactMenuHandlerL( ) |
|
185 { |
|
186 FUNC_LOG; |
|
187 if ( !iStaticData->iContactMenuHandler ) |
|
188 { |
|
189 iStaticData->iContactMenuHandler = |
|
190 CESMRContactMenuHandler::NewL( ContactManagerHandlerL() ); |
|
191 } |
|
192 |
|
193 if (!(iUsedTypes & EContactMenuHandler) ) |
|
194 { |
|
195 ++iStaticData->iContactMenuHandlerCount; |
|
196 iUsedTypes |= EContactMenuHandler; |
|
197 } |
|
198 |
|
199 return *iStaticData->iContactMenuHandler; |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // RESMRStatic::CurrentFieldIndex |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 EXPORT_C TInt RESMRStatic::CurrentFieldIndex() |
|
207 { |
|
208 FUNC_LOG; |
|
209 return iStaticData->iCurrentFieldIndex; |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // RESMRStatic::SetCurrentFieldIndex |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C void RESMRStatic::SetCurrentFieldIndex(TInt aFieldIndex) |
|
217 { |
|
218 FUNC_LOG; |
|
219 iStaticData->iCurrentFieldIndex = aFieldIndex; |
|
220 } |
|
221 |
|
222 // EOF |
|
223 |