|
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: Implementation of RBF server's CCRSession class* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CCRSession.h" |
|
22 #include "CCRServer.h" |
|
23 #include "CCREngine.h" |
|
24 #include <ipvideo/CRTypeDefs.h> |
|
25 #include "videoserviceutilsLogger.h" |
|
26 |
|
27 // CONSTANTS |
|
28 // None |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CCRSession::CCRSession() |
|
34 // C++ constructor |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CCRSession::CCRSession() : CSession2(), iResourceCount( 0 ) |
|
38 { |
|
39 __DECLARE_NAME( _S( "CCRSession" ) ); |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CCRSession::NewL() |
|
44 // Two-phased constructor. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CCRSession* CCRSession::NewL( CCRServer* aServer ) |
|
48 { |
|
49 CCRSession* self = new( ELeave ) CCRSession(); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL( aServer ); |
|
52 CleanupStack::Pop( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CCRSession::ConstructL() |
|
58 // second-phase C++ constructor |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void CCRSession::ConstructL( CCRServer* aServer ) |
|
62 { |
|
63 LOG( "CCRSession::ConstructL" ); |
|
64 |
|
65 aServer->Inc(); |
|
66 // Create new object index |
|
67 iObjects = CObjectIx::NewL(); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CCRSession::~CCRSession() |
|
72 // Destructor. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CCRSession::~CCRSession() |
|
76 { |
|
77 LOG( "CCRSession::~CCRSession" ); |
|
78 |
|
79 // Deletes objects |
|
80 delete iObjects; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CCRSession::ServiceL() |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 void CCRSession::ServiceL( const RMessage2& aMessage ) |
|
88 { |
|
89 switch ( aMessage.Function() ) |
|
90 { |
|
91 case ECRServCreateSubSession: |
|
92 case ECRServCloseSubSession: |
|
93 case ECRServCloseSession: |
|
94 { |
|
95 LOG1( "CCRSession::ServiceL(), aMessage: %d", aMessage.Function() ); |
|
96 TRAPD( err, DispatchMessageL( aMessage ) ); |
|
97 aMessage.Complete( err ); |
|
98 } |
|
99 break; |
|
100 |
|
101 default: |
|
102 { |
|
103 // Ok, but must be subsession relative |
|
104 CCREngine* engine = ( CCREngine* )iObjects->At( aMessage.Int3() ); |
|
105 if ( engine == NULL ) |
|
106 { |
|
107 LOG( "CCRSession::ServiceL(), Null engine !" ); |
|
108 aMessage.Complete( KErrBadHandle ); |
|
109 PanicClient( KErrBadHandle ); |
|
110 } |
|
111 else |
|
112 { |
|
113 // this is the normal route, |
|
114 // all engine commands go this way |
|
115 engine->GeneralServiceL( aMessage ); |
|
116 } |
|
117 } |
|
118 break; |
|
119 } |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CCRSession::DispatchMessageL() |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CCRSession::DispatchMessageL( const RMessage2& aMessage ) |
|
127 { |
|
128 // Check for session-relative requests |
|
129 switch ( aMessage.Function() ) |
|
130 { |
|
131 case ECRServCreateSubSession: |
|
132 NewObjectL( aMessage ); |
|
133 break; |
|
134 |
|
135 case ECRServCloseSubSession: |
|
136 DeleteObject( aMessage.Int3() ); |
|
137 break; |
|
138 |
|
139 case ECRServCloseSession: |
|
140 Server()->Dec(); |
|
141 break; |
|
142 |
|
143 default: |
|
144 // None |
|
145 break; |
|
146 } |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CCRSession::NewObjectL() |
|
151 // |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CCRSession::NewObjectL( const RMessage2& aMessage ) |
|
155 { |
|
156 LOG( "CCRSession::NewObjectL() in" ); |
|
157 |
|
158 CObject* obj = Server()->GetEngineObjectL(); |
|
159 TInt handle( iObjects->AddL( obj ) ); |
|
160 LOG1( "CCRSession::NewObjectL(), handle: %d", handle ); |
|
161 |
|
162 // Write the handle to client |
|
163 TPckg<TInt> handlePckg( handle ); |
|
164 TRAPD( err, aMessage.WriteL( 3, handlePckg ) ); |
|
165 if ( err ) |
|
166 { |
|
167 PanicClient( KErrBadDescriptor ); |
|
168 return; |
|
169 } |
|
170 |
|
171 // Notch up another resource |
|
172 iResourceCount++; |
|
173 LOG1( "CCRSession::NewObjectL() out, iResourceCount: %d", iResourceCount ); |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CCRSession::DeleteObject() |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CCRSession::DeleteObject( TUint aHandle ) |
|
181 { |
|
182 LOG1( "CCRSession::DeleteObject() in, aHandle: %u", aHandle ); |
|
183 |
|
184 // Panic if bad handle |
|
185 CCREngine* engine = ( CCREngine* )iObjects->At( aHandle ); |
|
186 if ( engine == NULL ) |
|
187 { |
|
188 PanicClient( KErrNotFound ); |
|
189 } |
|
190 |
|
191 // Deletes engine |
|
192 iResourceCount--; |
|
193 iObjects->Remove( aHandle ); |
|
194 |
|
195 LOG1( "CCRSession::DeleteObject() out, iResourceCount: %d", iResourceCount ); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CCRSession::CountResources() |
|
200 // |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 TInt CCRSession::CountResources() |
|
204 { |
|
205 return iResourceCount; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CCRSession::PanicClient() |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CCRSession::PanicClient( TInt aPanic ) const |
|
213 { |
|
214 _LIT( KTxtSessionPanic, "RbfSession" ); |
|
215 User::Panic( KTxtSessionPanic, aPanic ); |
|
216 } |
|
217 |
|
218 // End of File |