|
1 /* |
|
2 * Copyright (c) 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: Meta data access singleton |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> // CObject |
|
20 |
|
21 #include "cmmmtpdpaccesssingleton.h" |
|
22 #include "cmmmtpdpmetadataaccesswrapper.h" |
|
23 #include "mmmtpdplogger.h" |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CMmMtpDpAccessSingleton::~CMmMtpDpAccessSingleton |
|
27 // destructor |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 CMmMtpDpAccessSingleton::~CMmMtpDpAccessSingleton() |
|
31 { |
|
32 delete iWrapper; |
|
33 } |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CMmMtpDpAccessSingleton::GetAccessWrapperL |
|
37 // get wrapper instance |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CMmMtpDpMetadataAccessWrapper& CMmMtpDpAccessSingleton::GetAccessWrapperL() |
|
41 { |
|
42 CMmMtpDpAccessSingleton* self = CMmMtpDpAccessSingleton::Instance(); |
|
43 User::LeaveIfNull( self ); |
|
44 |
|
45 return *( self->iWrapper ); |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CMmMtpDpAccessSingleton::CreateL |
|
50 // create singleton instance |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C void CMmMtpDpAccessSingleton::CreateL( RFs& aRfs, |
|
54 MMTPDataProviderFramework& aFramework ) |
|
55 { |
|
56 CMmMtpDpAccessSingleton* self = reinterpret_cast<CMmMtpDpAccessSingleton*>( Dll::Tls() ); |
|
57 |
|
58 if ( self == NULL ) |
|
59 { |
|
60 self = CMmMtpDpAccessSingleton::NewL( aRfs, aFramework ); |
|
61 Dll::SetTls( reinterpret_cast<TAny*>( self ) ); |
|
62 } |
|
63 else |
|
64 { |
|
65 self->Inc(); |
|
66 } |
|
67 |
|
68 PRINT1( _L("MM MTP <> CMmMtpDpAccessSingleton::CreateL, AccessCount: %d"), |
|
69 self->AccessCount() ); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CMmMtpDpAccessSingleton::Release |
|
74 // release singleton instance |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 EXPORT_C void CMmMtpDpAccessSingleton::Release() |
|
78 { |
|
79 CMmMtpDpAccessSingleton* self = reinterpret_cast<CMmMtpDpAccessSingleton*>( Dll::Tls() ); |
|
80 if ( self != NULL ) |
|
81 { |
|
82 PRINT1( _L("MM MTP <> CMmMtpDpAccessSingleton::Release, singleton != NULL, AccessCount: %d"), |
|
83 self->AccessCount() ); |
|
84 |
|
85 self->Dec(); |
|
86 if ( self->AccessCount() == 0 ) |
|
87 { |
|
88 PRINT( _L("MM MTP <> CMmMtpDpAccessSingleton::Release, AccessCount == 0, delete it") ); |
|
89 delete self; |
|
90 Dll::SetTls( NULL ); |
|
91 } |
|
92 } |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CMmMtpDpAccessSingleton::OpenSessionL |
|
97 // do some special process with assess DBs when receives opensession command |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 EXPORT_C void CMmMtpDpAccessSingleton::OpenSessionL() |
|
101 { |
|
102 PRINT( _L("MM MTP => CMmMtpDpAccessSingleton::OpenSessionL") ); |
|
103 CMmMtpDpAccessSingleton* self = CMmMtpDpAccessSingleton::Instance(); |
|
104 User::LeaveIfNull( self ); |
|
105 self->GetAccessWrapperL().OpenSessionL(); |
|
106 PRINT( _L("MM MTP <= CMmMtpDpAccessSingleton::OpenSessionL") ); |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CMmMtpDpAccessSingleton::CloseSessionL |
|
111 // do some special process with assess DBs when receives closesession command |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 EXPORT_C void CMmMtpDpAccessSingleton::CloseSessionL() |
|
115 { |
|
116 PRINT( _L("MM MTP => CMmMtpDpAccessSingleton::CloseSessionL") ); |
|
117 CMmMtpDpAccessSingleton* self = CMmMtpDpAccessSingleton::Instance(); |
|
118 User::LeaveIfNull( self ); |
|
119 self->GetAccessWrapperL().CloseSessionL(); |
|
120 PRINT( _L("MM MTP <= CMmMtpDpAccessSingleton::CloseSessionL") ); |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CMmMtpDpAccessSingleton::Instance |
|
125 // get singleton instance, for internal use |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 CMmMtpDpAccessSingleton* CMmMtpDpAccessSingleton::Instance() |
|
129 { |
|
130 return reinterpret_cast<CMmMtpDpAccessSingleton*>( Dll::Tls() ); |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CMmMtpDpAccessSingleton::NewL |
|
135 // two-phase construction |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 CMmMtpDpAccessSingleton* CMmMtpDpAccessSingleton::NewL( RFs& aRfs, |
|
139 MMTPDataProviderFramework& aFramework ) |
|
140 { |
|
141 CMmMtpDpAccessSingleton* self = new(ELeave) CMmMtpDpAccessSingleton; |
|
142 CleanupStack::PushL( self ); |
|
143 self->ConstructL(aRfs, aFramework); |
|
144 CleanupStack::Pop( self ); |
|
145 return self; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CMmMtpDpAccessSingleton::ConstructL |
|
150 // two-phase construction |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CMmMtpDpAccessSingleton::ConstructL( RFs& aRfs, |
|
154 MMTPDataProviderFramework& aFramework ) |
|
155 { |
|
156 iWrapper = CMmMtpDpMetadataAccessWrapper::NewL( aRfs, aFramework ); |
|
157 } |
|
158 |
|
159 |
|
160 // end of file |