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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <coemain.h> |
|
20 #include <e32svr.h> |
|
21 |
|
22 // User includes |
|
23 #include "cradioenginelogger.h" |
|
24 #include "cradioenginetls.h" |
|
25 |
|
26 const int KUidRadioEngineTls = 0x10281CB8; |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // Returns the CRadioEngineTls instance from TLS |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CRadioEngineTls& CRadioEngineTls::Instance() |
|
36 { |
|
37 return *static_cast<CRadioEngineTls*>( UserSvr::DllTls( KUidRadioEngineTls ) ); |
|
38 } |
|
39 |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 void CRadioEngineTls::InitializeL( RFs* aFs ) |
|
46 { |
|
47 if ( !UserSvr::DllTls( KUidRadioEngineTls ) ) |
|
48 { |
|
49 CRadioEngineTls* self = new ( ELeave ) CRadioEngineTls( aFs ); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL(); |
|
52 User::LeaveIfError( UserSvr::DllSetTls( KUidRadioEngineTls, self ) ); |
|
53 CleanupStack::Pop( self ); |
|
54 } |
|
55 } |
|
56 |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CRadioEngineTls::CRadioEngineTls( RFs* aFs ) |
|
63 : iFs( aFs ) |
|
64 { |
|
65 } |
|
66 |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 void CRadioEngineTls::ConstructL() |
|
73 { |
|
74 if ( !iFs || !iFs->Handle() ) |
|
75 { |
|
76 iFsOwned = ETrue; |
|
77 iFs = new ( ELeave ) RFs; |
|
78 User::LeaveIfError( iFs->Connect() ); |
|
79 } |
|
80 |
|
81 |
|
82 #ifdef LOGGING_ENABLED |
|
83 iLogger = CRadioEngineLogger::NewL( *iFs ); |
|
84 #endif // LOGGING_ENABLED |
|
85 |
|
86 } |
|
87 |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 CRadioEngineTls::~CRadioEngineTls() |
|
94 { |
|
95 UserSvr::DllFreeTls( KUidRadioEngineTls ); |
|
96 |
|
97 #ifdef LOGGING_ENABLED |
|
98 delete iLogger; |
|
99 #endif |
|
100 |
|
101 if ( iFs && iFsOwned ) |
|
102 { |
|
103 iFs->Close(); |
|
104 delete iFs; |
|
105 } |
|
106 } |
|
107 |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // Return the logger storage if logging is enabled |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 MRadioEngineLogger* CRadioEngineTls::Logger() |
|
114 { |
|
115 #ifdef LOGGING_ENABLED |
|
116 return CRadioEngineTls::Instance().iLogger; |
|
117 #else |
|
118 return NULL; |
|
119 #endif |
|
120 } |
|
121 |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // Returns the file server session |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 RFs& CRadioEngineTls::FsSession() |
|
128 { |
|
129 return *CRadioEngineTls::Instance().iFs; |
|
130 } |
|
131 |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // CRadioEngineTls::AddRef |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 void CRadioEngineTls::AddRef() |
|
138 { |
|
139 ++iRefs; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CRadioEngineTls::Release |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CRadioEngineTls::Release() |
|
147 { |
|
148 __ASSERT_DEBUG( iRefs > 0 , User::Panic( _L( "CRadioEngineTls" ), KErrCorrupt ) ); |
|
149 if ( !--iRefs ) |
|
150 { |
|
151 delete this; |
|
152 } |
|
153 } |
|