|
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: CSP session access container |
|
15 * This class maintain reference counted access to the CSP session |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32std.h> |
|
23 #include "CPEngAppAccessContainer.h" |
|
24 |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CPEngAppAccessContainer::CPEngAppAccessContainer |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CPEngAppAccessContainer::CPEngAppAccessContainer() |
|
35 : iReserved( 2 ) // Usually IM and PEC |
|
36 { |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CPEngAppAccessContainer::ConstructL |
|
41 // Symbian 2nd phase constructor can leave. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 void CPEngAppAccessContainer::ConstructL( |
|
45 const TDesC& aAppId ) |
|
46 { |
|
47 iAppId = aAppId.AllocL(); |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CPEngAppAccessContainer::NewL |
|
52 // Two-phased constructor. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CPEngAppAccessContainer* CPEngAppAccessContainer::NewLC( |
|
56 const TDesC& aAppId ) |
|
57 { |
|
58 CPEngAppAccessContainer* self = new( ELeave ) CPEngAppAccessContainer( ); |
|
59 |
|
60 CleanupClosePushL( *self ); |
|
61 self->ConstructL( aAppId ); |
|
62 |
|
63 return self; |
|
64 } |
|
65 |
|
66 |
|
67 // Destructor |
|
68 CPEngAppAccessContainer::~CPEngAppAccessContainer() |
|
69 { |
|
70 iReserved.Reset(); |
|
71 delete iAppId; |
|
72 } |
|
73 |
|
74 ///////////////////////////////////////////////////////////////////////////////// |
|
75 // =============== New Functions of the main class ============================= |
|
76 ///////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CPEngAppAccessContainer::AppId |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 const TDesC& CPEngAppAccessContainer::AppId() const |
|
83 { |
|
84 return *iAppId; |
|
85 } |
|
86 |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CPEngAppAccessContainer::ActiveAccessCount |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TInt CPEngAppAccessContainer::ActiveAccessCount() |
|
93 { |
|
94 return AccessCount() + iReserved.Count(); |
|
95 } |
|
96 |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CPEngAppAccessContainer::CloseAccess |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 TBool CPEngAppAccessContainer::CloseAccess() |
|
103 { |
|
104 Dec(); |
|
105 // delete if access is zero |
|
106 if ( ( 0 == AccessCount() ) && ( iReserved.Count() == 0 ) ) |
|
107 { |
|
108 delete this; |
|
109 return ETrue; |
|
110 } |
|
111 return EFalse; |
|
112 } |
|
113 |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CPEngAppAccessContainer::ReserveProcessL |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 void CPEngAppAccessContainer::ReserveProcessL( |
|
120 const TDesC& aProcessId ) |
|
121 { |
|
122 iReserved.InsertIsqL( aProcessId ); |
|
123 Dec(); |
|
124 } |
|
125 |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CPEngAppAccessContainer::ActivateProcessIdL |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 void CPEngAppAccessContainer::ActivateProcessIdL( |
|
132 const TDesC& aProcessId ) |
|
133 { |
|
134 TInt pos( KErrNotFound ); |
|
135 if ( iReserved.FindIsq( aProcessId, pos ) != KErrNone ) |
|
136 { |
|
137 User::LeaveIfError( KErrNotFound ); |
|
138 } |
|
139 |
|
140 iReserved.Delete( pos ); |
|
141 Inc(); |
|
142 } |
|
143 |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CPEngAppAccessContainer::CloseContainer |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CPEngAppAccessContainer::CloseContainer() |
|
150 { |
|
151 iReserved.Reset(); |
|
152 TInt count( AccessCount() ); |
|
153 // can we delete straight, or we need to run down access count? |
|
154 if ( count == 0 ) |
|
155 { |
|
156 delete this; |
|
157 return; |
|
158 } |
|
159 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
160 { |
|
161 Close(); |
|
162 } |
|
163 } |
|
164 |
|
165 // End of File |