|
1 /* |
|
2 * Copyright (c) 2002 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 the CProfileUtilitySingletonImpl. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CProfileUtilitySingletonImpl.h" |
|
22 #include "MProfilesLocalFeatures.h" |
|
23 #include "CProfilesLocalFeatures.h" |
|
24 #include "ProfilesDebug.h" |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CProfileUtilitySingletonImpl::CProfileUtilitySingletonImpl |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CProfileUtilitySingletonImpl::CProfileUtilitySingletonImpl() |
|
35 { |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CProfileUtilitySingletonImpl::ConstructL |
|
40 // Symbian 2nd phase constructor can leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 void CProfileUtilitySingletonImpl::ConstructL() |
|
44 { |
|
45 iLocalFeatures = CProfilesLocalFeatures::NewL(); |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CProfileUtilitySingletonImpl::NewL |
|
50 // |
|
51 // (other items were commented in a header). |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CProfileUtilitySingletonImpl* CProfileUtilitySingletonImpl::NewL() |
|
55 { |
|
56 CProfileUtilitySingletonImpl* self |
|
57 = new ( ELeave ) CProfileUtilitySingletonImpl(); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(); // self |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CProfileUtilitySingletonImpl::ProfilesLocalFeatures |
|
66 // |
|
67 // (other items were commented in a header). |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 MProfilesLocalFeatures& CProfileUtilitySingletonImpl::ProfilesLocalFeatures() |
|
71 { |
|
72 return *iLocalFeatures; |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CProfileUtilitySingletonImpl::IncrementReferences |
|
77 // |
|
78 // (other items were commented in a header). |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CProfileUtilitySingletonImpl::IncrementReferences() |
|
82 { |
|
83 ++iReferences; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CProfileUtilitySingletonImpl::DecrementReferences |
|
88 // |
|
89 // (other items were commented in a header). |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TBool CProfileUtilitySingletonImpl::DecrementReferences() |
|
93 { |
|
94 return ( --iReferences <= 0 ); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CProfileUtilitySingletonImpl::~CProfileUtilitySingletonImpl |
|
99 // |
|
100 // (other items were commented in a header). |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 CProfileUtilitySingletonImpl::~CProfileUtilitySingletonImpl() |
|
104 { |
|
105 delete iLocalFeatures; |
|
106 } |
|
107 |
|
108 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // ProfileUtilityInstanceL creates an implementation of MProfileUtilitySingleton |
|
112 // if needed, increments the reference count and returns a reference to the only |
|
113 // instance of it. |
|
114 // Returns a reference to the only instance of MProfileUtilitySingleton. |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C MProfileUtilitySingleton& ProfileUtilityInstanceL() |
|
118 { |
|
119 CProfileUtilitySingletonImpl* instance = |
|
120 static_cast<CProfileUtilitySingletonImpl*>( Dll::Tls() ); |
|
121 if( instance == NULL ) |
|
122 { |
|
123 instance = CProfileUtilitySingletonImpl::NewL(); |
|
124 TInt err( Dll::SetTls( instance ) ); |
|
125 if( err ) |
|
126 { |
|
127 delete instance; |
|
128 //delete static_cast<CProfileUtilitySingletonImpl*>( instance ); |
|
129 User::Leave( err ); |
|
130 } |
|
131 } |
|
132 instance->IncrementReferences(); |
|
133 //return static_cast<MProfileUtilitySingleton&>( instance ); |
|
134 return *instance; |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // ReleaseProfileUtility decrements the count of references to the only instance |
|
139 // of MProfileUtilitySingleton implementation and releases the resources if |
|
140 // there are no more references to it. |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 EXPORT_C void ReleaseProfileUtility() |
|
144 { |
|
145 TAny* instance = Dll::Tls(); |
|
146 if( instance != NULL ) |
|
147 { |
|
148 CProfileUtilitySingletonImpl* singleton = |
|
149 static_cast<CProfileUtilitySingletonImpl*>( instance ); |
|
150 if( singleton->DecrementReferences() ) |
|
151 { |
|
152 delete singleton; |
|
153 Dll::SetTls( NULL ); |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 // End of File |
|
159 |
|
160 |