|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <versittls.h> |
|
17 |
|
18 // User includes |
|
19 #include <vutil.h> |
|
20 #include "VersitAdditionalStorage.h" |
|
21 |
|
22 /*CVersitTlsData*/ |
|
23 |
|
24 /* |
|
25 * Note: If you are going to create a parser and delete it again soon afterwards and repeat this many times it would be advantagous |
|
26 * to get your own handle to the Versit TLS data as this will stop the TLS data being repeatedly created and destroyed. |
|
27 * |
|
28 * Returns a reference to the TLS and increments the count of accesser |
|
29 */ |
|
30 EXPORT_C CVersitTlsData& CVersitTlsData::VersitTlsDataL() |
|
31 /** Returns a reference to the current Thread Local Storage (TLS) object or, if |
|
32 there isn't one, it creates one. |
|
33 |
|
34 If a new TLS object is being created, the object also creates (and owns) a |
|
35 Unicode utilities object, and creates a Unicode converter using this object. |
|
36 |
|
37 If creating a new object, it calls the CVersitUnicodeUtils constructor followed |
|
38 by CVersitUnicodeUtils::CreateConverterL(). |
|
39 |
|
40 @return The current Thread Local Storage object. */ |
|
41 { |
|
42 CVersitTlsData* self = static_cast<CVersitTlsData*>(Dll::Tls()); |
|
43 if (!self) |
|
44 self = NewL(); |
|
45 ++self->iRefCount; |
|
46 return *self; |
|
47 } |
|
48 |
|
49 /* |
|
50 * Close the Thread Local Storage |
|
51 * |
|
52 * Deletes the data from TLS if the number of user is none. |
|
53 * |
|
54 * Note: Only use this static version if you don't have a handle to a <code>CVersitTlsData<\code> class. |
|
55 */ |
|
56 EXPORT_C void CVersitTlsData::CloseVersitTlsData() |
|
57 { |
|
58 CVersitTlsData* self = static_cast<CVersitTlsData*>(Dll::Tls()); |
|
59 if (self) |
|
60 self->VersitTlsDataClose(); |
|
61 } |
|
62 |
|
63 EXPORT_C void CVersitTlsData::VersitTlsDataClose() |
|
64 /** Frees all resources owned by the object if there are no parsers left (i.e. |
|
65 created and not destroyed), prior to its destruction. */ |
|
66 { |
|
67 if (--iRefCount<=0) |
|
68 { |
|
69 delete this; |
|
70 } |
|
71 } |
|
72 |
|
73 CVersitTlsData* CVersitTlsData::NewL() |
|
74 { |
|
75 CVersitTlsData* self = new(ELeave) CVersitTlsData(); |
|
76 CleanupStack::PushL(self); |
|
77 self->ConstructL(); |
|
78 CleanupStack::Pop(self); |
|
79 Dll::SetTls(self); |
|
80 self->iRefCount=0; //Defensive code |
|
81 return self; |
|
82 } |
|
83 |
|
84 |
|
85 CVersitTlsData::~CVersitTlsData() |
|
86 { |
|
87 Dll::SetTls(NULL); |
|
88 delete iUnicodeUtils; |
|
89 delete iAdditionalStorage; |
|
90 } |
|
91 |
|
92 |
|
93 void CVersitTlsData::ConstructL() |
|
94 { |
|
95 iUnicodeUtils = new(ELeave) CVersitUnicodeUtils(); |
|
96 iUnicodeUtils->CreateConverterL(); |
|
97 iAdditionalStorage = CVersitAdditionalStorage::NewL(); |
|
98 } |