|
1 /* |
|
2 * Copyright (c) 2007 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 the License "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: Singleton to hold server session* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CCRServerHandleSingleton.h" |
|
22 |
|
23 // CONSTANTS |
|
24 // None |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CCRServerHandleSingleton::CCRServerHandleSingleton() : iReferenceCount( 1 ) |
|
33 { |
|
34 // None |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CCRServerHandleSingleton::~CCRServerHandleSingleton() |
|
42 { |
|
43 iService.Close(); |
|
44 iClient.Close(); |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CCRServerHandleSingleton::ConstructL() |
|
52 { |
|
53 User::LeaveIfError( iClient.Connect() ); |
|
54 User::LeaveIfError( iService.Open( iClient ) ); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // Returns the singleton instance. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CCRServerHandleSingleton* CCRServerHandleSingleton::InstanceL() |
|
62 { |
|
63 CCRServerHandleSingleton* self = NULL; |
|
64 |
|
65 TAny* tlsPtr = Dll::Tls(); |
|
66 if ( tlsPtr == NULL ) |
|
67 { |
|
68 self = new( ELeave ) CCRServerHandleSingleton; |
|
69 CleanupStack::PushL( self ); |
|
70 self->ConstructL(); |
|
71 User::LeaveIfError( Dll::SetTls( self ) ); |
|
72 CleanupStack::Pop( self ); |
|
73 } |
|
74 else |
|
75 { |
|
76 self = static_cast<CCRServerHandleSingleton*>( tlsPtr ); |
|
77 ++self->iReferenceCount; |
|
78 } |
|
79 |
|
80 return self; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // Releases the singleton instance. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 void CCRServerHandleSingleton::Release() |
|
88 { |
|
89 TAny* tlsPtr = Dll::Tls(); |
|
90 __ASSERT_DEBUG( tlsPtr != NULL, User::Panic( _L( "CCRApiBase" ), KErrNotFound ) ); |
|
91 |
|
92 if ( tlsPtr != NULL ) |
|
93 { |
|
94 CCRServerHandleSingleton* self = static_cast<CCRServerHandleSingleton*>( tlsPtr ); |
|
95 if ( --self->iReferenceCount == 0 ) |
|
96 { |
|
97 delete self; |
|
98 Dll::FreeTls(); |
|
99 } |
|
100 } |
|
101 } |
|
102 |
|
103 // End of File |