|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Implements Target Selector Plugin used by Symbian's Remote |
|
15 * Control Framework. TSP controls sending of operations between |
|
16 * Series 60 components and remote targets (e.g. headset). |
|
17 * |
|
18 * This version doesn't really self specify receiver for |
|
19 * a message but accepts all receivers suggested by RemCon server. |
|
20 * |
|
21 * |
|
22 */ |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include "RemConDebug.h" |
|
27 #include "remcontspcontroller.h" |
|
28 #include <remcontargetselectorpluginobserver.h> |
|
29 #include <remconaddress.h> |
|
30 #include <clientinfo.h> |
|
31 #include <bearersecurity.h> |
|
32 #include <remconextensionapi.h> |
|
33 #include <ctsydomainpskeys.h> |
|
34 |
|
35 // EXTERNAL DATA STRUCTURES |
|
36 |
|
37 // EXTERNAL FUNCTION PROTOTYPES |
|
38 |
|
39 // CONSTANTS |
|
40 #ifdef __ACCESSORY_FW |
|
41 |
|
42 // UID3 of process (Accessory Server) which loads PhoneCmdHandler.dll |
|
43 const TUint32 KUid3 = 0x10205030; |
|
44 |
|
45 #else |
|
46 |
|
47 // UID3 of process (Phone) which loads PhoneCmdHandler.dll |
|
48 const TUint32 KUid3 = 0x100058B3; |
|
49 |
|
50 #endif |
|
51 |
|
52 const TUint32 KUid3MusicPlayer = 0x102072C3; |
|
53 |
|
54 |
|
55 // MACROS |
|
56 |
|
57 // LOCAL CONSTANTS AND MACROS |
|
58 |
|
59 // MODULE DATA STRUCTURES |
|
60 |
|
61 // LOCAL FUNCTION PROTOTYPES |
|
62 |
|
63 // FORWARD DECLARATIONS |
|
64 |
|
65 // ============================= LOCAL FUNCTIONS =============================== |
|
66 |
|
67 // ============================ MEMBER FUNCTIONS =============================== |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CRemConTspController::CRemConTspController |
|
71 // C++ default constructor can NOT contain any code, that |
|
72 // might leave. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 |
|
76 CRemConTspController::CRemConTspController( |
|
77 MRemConTargetSelectorPluginObserver& aObserver ) |
|
78 : CRemConTargetSelectorPlugin( aObserver ) |
|
79 { |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CRemConTspController::NewL |
|
84 // Two-phased constructor. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CRemConTspController* CRemConTspController::NewL( |
|
88 MRemConTargetSelectorPluginObserver& aObserver ) |
|
89 { |
|
90 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::NewL()" ); |
|
91 |
|
92 CRemConTspController* self = new(ELeave) CRemConTspController( aObserver ); |
|
93 return self; |
|
94 } |
|
95 |
|
96 // Destructor |
|
97 CRemConTspController::~CRemConTspController() |
|
98 { |
|
99 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::~CRemConTspController()" ); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CRemConTspController::GetInterface |
|
104 // Provides implementation of this (TSP) interface. |
|
105 // (other items were commented in a header). |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 TAny* CRemConTspController::GetInterface( TUid aUid ) |
|
109 { |
|
110 COM_TRACE_2( "[REMCONTSPCONTROLLER] CRemConTspController::GetInterface() this=%d, aUid=%d", this, aUid ); |
|
111 |
|
112 TAny* ret = NULL; |
|
113 |
|
114 // TSP interface is asked ? |
|
115 if ( aUid == TUid::Uid( KRemConTargetSelectorInterface1 ) ) |
|
116 { |
|
117 // convert this object to TAny |
|
118 ret = reinterpret_cast< TAny* >( |
|
119 static_cast< MRemConTargetSelectorPluginInterface*>(this) ); |
|
120 } |
|
121 else if ( aUid == TUid::Uid(KRemConTargetSelectorInterface2) ) |
|
122 { |
|
123 ret = reinterpret_cast<TAny*>( |
|
124 static_cast<MRemConTargetSelectorPluginInterfaceV2*>(this) |
|
125 ); |
|
126 } |
|
127 |
|
128 COM_TRACE_1( "[REMCONTSPCONTROLLER] CRemConTspController::GetInterface() this=%d", ret ); |
|
129 return ret; |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CRemConTspController::AddressOutgoingCommand |
|
134 // Defines bearers (represents remote target) to which command will be sent. |
|
135 // (other items were commented in a header). |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CRemConTspController::AddressOutgoingCommand( |
|
139 TUid aInterfaceUid, |
|
140 TUint aOperationId, |
|
141 const TClientInfo& aSender, |
|
142 TSglQue<TRemConAddress>& aConnections, |
|
143 TSglQue<TBearerSecurity>& aBearerSecurity) |
|
144 { |
|
145 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::AddressOutgoingCommand() starts" ); |
|
146 |
|
147 // Avoid warnings for unused parameters |
|
148 (void)aInterfaceUid; |
|
149 (void)aOperationId; |
|
150 (void)aSender; |
|
151 |
|
152 TInt err = KErrNotFound; |
|
153 TSglQueIter<TBearerSecurity> iter( aBearerSecurity ); |
|
154 TBearerSecurity* sec = iter; |
|
155 |
|
156 // Go through all bearers |
|
157 while( sec ) |
|
158 { |
|
159 // No security check in this version. |
|
160 // Could maybe be smth like "if ( sec->SecurityPolicy().CheckPolicy( aSender.Message() ) )" |
|
161 |
|
162 // Address command to all given bearers |
|
163 TRemConAddress* conn = NULL; |
|
164 conn = new TRemConAddress; |
|
165 if ( conn ) |
|
166 { |
|
167 COM_TRACE_1( "[REMCONTSPCONTROLLER] Sender's secure id = %d", aSender.SecureId().iId ); |
|
168 COM_TRACE_1( "[REMCONTSPCONTROLLER] Command sent to bearer %d", sec->BearerUid().iUid ); |
|
169 |
|
170 conn->BearerUid().iUid = sec->BearerUid().iUid; |
|
171 // No connection-specific data for this bearer. |
|
172 // Ownership of conn is passed back to RemCon. |
|
173 aConnections.AddLast( *conn ); |
|
174 err = KErrNone; |
|
175 } |
|
176 else |
|
177 { |
|
178 COM_TRACE_1( "[REMCONTSPCONTROLLER] Memory allocation failed for bearer %d", sec->BearerUid().iUid ); |
|
179 |
|
180 err = KErrNoMemory; |
|
181 break; // Get out from while() and return KErrNoMemory |
|
182 } |
|
183 iter++; |
|
184 sec = iter; |
|
185 } |
|
186 |
|
187 COM_TRACE_1( "[REMCONTSPCONTROLLER] CRemConTspController::AddressOutgoingCommand() err=%d", err ); |
|
188 Observer().OutgoingCommandAddressed( err ); |
|
189 |
|
190 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::AddressOutgoingCommand() ends" ); |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CRemConTspController::PermitOutgoingCommand |
|
195 // Defines whether connection-oriented controller can send a command to bearer. |
|
196 // (other items were commented in a header). |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void CRemConTspController::PermitOutgoingCommand( |
|
200 TUid aInterfaceUid, |
|
201 TUint aOperationId, |
|
202 const TClientInfo& aSender, |
|
203 const TRemConAddress& aConnection ) |
|
204 { |
|
205 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::PermitOutgoingCommand()" ); |
|
206 |
|
207 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::PermitOutgoingCommand() start" ); |
|
208 COM_TRACE_2( "[REMCONTSPCONTROLLER] aInterfaceUid = %d, aOperationId = %d", aInterfaceUid.iUid, aOperationId ); |
|
209 COM_TRACE_1( "[REMCONTSPCONTROLLER] sender's secure id =%d", aSender.SecureId().iId ); |
|
210 |
|
211 // Avoid warnings for unused parameters |
|
212 (void)aInterfaceUid; |
|
213 (void)aOperationId; |
|
214 (void)aSender; |
|
215 (void)aConnection; |
|
216 |
|
217 // Permit all connection oriented controllers to send commands |
|
218 Observer().OutgoingCommandPermitted( ETrue ); |
|
219 |
|
220 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::PermitOutgoingCommand() ends" ); |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CRemConTspController::CancelOutgoingCommand |
|
225 // Cancels the current AddressOutgoingCommand or PermitOutgoingCommand command. |
|
226 // (other items were commented in a header). |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 void CRemConTspController::CancelOutgoingCommand() |
|
230 { |
|
231 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::CancelOutgoingCommand()" ); |
|
232 // Nothing to do until AddressOutgoingCommand() and/or PermitOutgoingCommand() |
|
233 // will be implemented asynchronously. |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CRemConTspController::AddressIncomingCommand |
|
238 // Defines remote targets to which command will be sent. |
|
239 // (other items were commented in a header). |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 void CRemConTspController::AddressIncomingCommand( |
|
243 TUid aInterfaceUid, |
|
244 TUint aOperationId, |
|
245 TSglQue<TClientInfo>& aClients ) |
|
246 { |
|
247 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::AddressIncomingCommand() start" ); |
|
248 COM_TRACE_2( "[REMCONTSPCONTROLLER] aInterfaceUid = %d, aOperationId = %d", aInterfaceUid.iUid, aOperationId ); |
|
249 |
|
250 #ifdef _DEBUG |
|
251 |
|
252 // For debuging purpose write all remote target ids to trace |
|
253 TSglQueIter<TClientInfo> iter( aClients ); |
|
254 TClientInfo* target = iter; |
|
255 TInt number(0); |
|
256 |
|
257 while( target ) |
|
258 { |
|
259 COM_TRACE_2( "[REMCONTSPCONTROLLER] %d. client secureId = %d", ++number, target->SecureId().iId ); |
|
260 iter++; |
|
261 target = iter; |
|
262 } |
|
263 |
|
264 #endif |
|
265 |
|
266 TInt err( KErrNone ); |
|
267 |
|
268 // This version sends operation to all existing clients with following |
|
269 // exception: If there's an incoming or ongoing voice call, |
|
270 // RemConExtensionApi's command ERemConExtAnswerEnd is sent only to |
|
271 // PhoneCmdHandler. |
|
272 if( aInterfaceUid.iUid == KRemConExtCallHandlingApiUid && |
|
273 aOperationId == ERemConExtAnswerEnd |
|
274 ) |
|
275 { |
|
276 TInt callState( EPSCTsyCallStateUninitialized ); |
|
277 TInt err( KErrNone ); |
|
278 err = iProperty.Get( KPSUidCtsyCallInformation, |
|
279 KCTsyCallState, |
|
280 callState ); |
|
281 |
|
282 if( ( err == KErrNone ) && |
|
283 ( callState == EPSCTsyCallStateRinging || |
|
284 callState == EPSCTsyCallStateConnected ) |
|
285 ) |
|
286 { |
|
287 TSglQueIter<TClientInfo> iter( aClients ); |
|
288 TClientInfo* target = iter; |
|
289 |
|
290 while( target ) |
|
291 { |
|
292 if( target->SecureId().iId == KUid3 ) |
|
293 { |
|
294 COM_TRACE_1( "[REMCONTSPCONTROLLER] Command is sent only to PhoneCmdHandler running in process identified by secure id=%d", target->SecureId().iId ); |
|
295 |
|
296 // Add PhoneCmdHandler as the only remote target to |
|
297 // receive ERemConExtAnswerEnd command. |
|
298 aClients.Reset(); |
|
299 aClients.AddFirst( *target ); |
|
300 break; // get out from while-loop |
|
301 } |
|
302 iter++; |
|
303 target = iter; |
|
304 } |
|
305 } |
|
306 } |
|
307 |
|
308 Observer().IncomingCommandAddressed( err ); |
|
309 |
|
310 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::AddressIncomingCommand() ends" ); |
|
311 } |
|
312 |
|
313 |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // CRemConTspController::PermitOutgoingResponse |
|
317 // Defines which client can send a response to a command to bearer. |
|
318 // (other items were commented in a header). |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 void CRemConTspController::PermitOutgoingResponse( |
|
322 TUid aInterfaceUid, |
|
323 TUint aOperationId, |
|
324 const TClientInfo& aClient, |
|
325 TClientInfoConstIter& aClients) |
|
326 { |
|
327 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::PermitOutgoingResponse()" ); |
|
328 |
|
329 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::PermitOutgoingResponse() start" ); |
|
330 COM_TRACE_2( "[REMCONTSPCONTROLLER] aInterfaceUid = %d, aOperationId = %d", aInterfaceUid.iUid, aOperationId ); |
|
331 |
|
332 // Avoid warnings for unused parameters |
|
333 (void)aInterfaceUid; |
|
334 (void)aOperationId; |
|
335 (void)aClient; |
|
336 (void)aClients; |
|
337 |
|
338 Observer().OutgoingResponsePermitted(ETrue); |
|
339 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::PermitOutgoingResponse() ends" ); |
|
340 } |
|
341 |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CRemConTspController::CancelOutgoingResponse |
|
345 // Called by RemCon to cancel the current PermitOutgoingResponse request. |
|
346 // (other items were commented in a header). |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 void CRemConTspController::CancelOutgoingResponse() |
|
350 { |
|
351 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::CancelOutgoingCommand()" ); |
|
352 // Nothing to do until PermitOutgoingResponse() |
|
353 // will be implemented asynchronously. |
|
354 } |
|
355 |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CRemConTspController::AddressIncomingNotify |
|
359 // Defines remote targets to which notify will be sent. |
|
360 // (other items were commented in a header). |
|
361 // ----------------------------------------------------------------------------- |
|
362 // |
|
363 void CRemConTspController::AddressIncomingNotify( |
|
364 TUid aInterfaceUid, |
|
365 TUint aOperationId, |
|
366 TSglQue<TClientInfo>& aClients) |
|
367 { |
|
368 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::AddressIncomingNotify() start" ); |
|
369 COM_TRACE_2( "[REMCONTSPCONTROLLER] aInterfaceUid = %d, aOperationId = %d", aInterfaceUid.iUid, aOperationId ); |
|
370 (void)aInterfaceUid; |
|
371 (void)aOperationId; |
|
372 |
|
373 TClientInfo* clientInfo = aClients.First(); |
|
374 TSglQueIter<TClientInfo> iter( aClients ); |
|
375 TClientInfo* target = iter; |
|
376 |
|
377 while( target ) |
|
378 { |
|
379 if( target->SecureId().iId == KUid3MusicPlayer ) |
|
380 { |
|
381 COM_TRACE_1( "[REMCONTSPCONTROLLER] Command is sent only to PlaybackUI running in process identified by secure id=%d", target->SecureId().iId ); |
|
382 break; // get out from while-loop |
|
383 } |
|
384 iter++; |
|
385 target = iter; |
|
386 } |
|
387 |
|
388 Observer().IncomingNotifyAddressed(target, KErrNone); |
|
389 |
|
390 COM_TRACE_( "[REMCONTSPCONTROLLER] CRemConTspController::AddressIncomingCommand() ends" ); |
|
391 |
|
392 } |
|
393 |
|
394 |
|
395 |
|
396 // |
|
397 // End of file |