|
1 /* |
|
2 * Copyright (c) 2002-2004 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: Call Request Manager. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "CPhSrvCallRequestManager.h" |
|
22 #include "CPhSrvCallRequest.h" |
|
23 #include "CPhSrvSubSessionBase.h" |
|
24 #include "PhSrvUtils.h" |
|
25 |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // The size of the Notification manager storage. |
|
30 const TInt KPhSrvNotificationManagerPendingCallGranularity = 4; |
|
31 |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CPhSrvCallRequestManager::CPhSrvCallRequestManager |
|
37 // |
|
38 // C++ constructor. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CPhSrvCallRequestManager::CPhSrvCallRequestManager() |
|
42 { |
|
43 } |
|
44 |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CPhSrvCallRequestManager::~CPhSrvCallRequestManager |
|
48 // |
|
49 // C++ destructor. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CPhSrvCallRequestManager::~CPhSrvCallRequestManager() |
|
53 { |
|
54 if ( iOutstandingRequestsCall ) |
|
55 { |
|
56 iOutstandingRequestsCall->ResetAndDestroy(); |
|
57 iOutstandingRequestsCall->Close(); |
|
58 } |
|
59 delete iOutstandingRequestsCall; |
|
60 } |
|
61 |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CPhSrvCallRequestManager::ConstructL |
|
65 // |
|
66 // Complete construction. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CPhSrvCallRequestManager::ConstructL() |
|
70 { |
|
71 iOutstandingRequestsCall = new ( ELeave ) RPointerArray< |
|
72 CPhSrvCallRequest >( KPhSrvNotificationManagerPendingCallGranularity ); |
|
73 |
|
74 CPhSrvCallRequest* emergencyCallRequest = CPhSrvCallRequest::NewL(); |
|
75 CleanupStack::PushL( emergencyCallRequest ); |
|
76 User::LeaveIfError( |
|
77 iOutstandingRequestsCall->Append( emergencyCallRequest ) ); |
|
78 CleanupStack::Pop(); // emergencyCallRequest |
|
79 } |
|
80 |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CPhSrvCallRequestManager::NegotiatorDialL |
|
84 // |
|
85 // Initiate a dial request - called by the external call |
|
86 // interface. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CPhSrvCallRequestManager::NegotiatorDialL( |
|
90 const RMessage2& aMessage, |
|
91 CPhCltExtPhoneDialData& aArgs, |
|
92 CPhSrvSubSessionBase& aSubSession ) |
|
93 { |
|
94 // If we have no registered initiator then we can't make a call. |
|
95 if ( !iCallInitiator ) |
|
96 { |
|
97 User::Leave( KErrNotReady ); |
|
98 } |
|
99 |
|
100 if ( aArgs.TelephoneNumber() == KPhSrvUsedEmergencyCallNumber && |
|
101 ( *iOutstandingRequestsCall )[0]->SubSessionHandle() == 0 ) |
|
102 { |
|
103 ( *iOutstandingRequestsCall )[0]->UpdateEmercgencyCall( |
|
104 aMessage, |
|
105 aArgs, |
|
106 aSubSession.SubSessionUniqueHandle() ); |
|
107 } |
|
108 else |
|
109 { |
|
110 // Create pending request |
|
111 CPhSrvCallRequest* request = CPhSrvCallRequest::NewLC( |
|
112 aMessage, |
|
113 aArgs, |
|
114 aSubSession.SubSessionUniqueHandle() ); |
|
115 |
|
116 User::LeaveIfError( iOutstandingRequestsCall->Append( request ) ); |
|
117 CleanupStack::Pop( request ); |
|
118 } |
|
119 |
|
120 // Now see if the call notifier (initiator) is ready |
|
121 if ( iCallInitiator->InitiatorIsReadyToMakeCall() ) |
|
122 { |
|
123 // Ask the call initiator to make the call (basically completes the |
|
124 //phone app engine's outstanding call notifier request). |
|
125 iCallInitiator->InitiatorMakeAsynchronousCallL( aArgs ); |
|
126 } |
|
127 } |
|
128 |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CPhSrvCallRequestManager::NegotiatorDialCancel |
|
132 // |
|
133 // Cancel a pending dial request. |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CPhSrvCallRequestManager::NegotiatorDialCancelL( |
|
137 CPhSrvSubSessionBase& aSubSession ) |
|
138 { |
|
139 // Obtain the subsessions handle |
|
140 const TInt handle = aSubSession.SubSessionUniqueHandle(); |
|
141 |
|
142 // Now look for any pending requests that match. |
|
143 const TInt count = iOutstandingRequestsCall->Count(); |
|
144 for( TInt i = 0; i < count; i++ ) |
|
145 { |
|
146 CPhSrvCallRequest* entry = ( *iOutstandingRequestsCall )[i]; |
|
147 if ( entry->SubSessionHandle() == handle ) |
|
148 { |
|
149 // Found matching entry, so cancel it and clean up |
|
150 if ( i == 0 ) // 0 stands for emergency call |
|
151 { |
|
152 entry->Cancel(); |
|
153 entry->ClearEmergencyCall(); |
|
154 } |
|
155 else |
|
156 { |
|
157 iOutstandingRequestsCall->Remove( i ); |
|
158 entry->Cancel(); |
|
159 delete entry; |
|
160 } |
|
161 |
|
162 // If we have more than one item in the queue, then we |
|
163 // try and fire of the next item here. |
|
164 if ( iCallInitiator->InitiatorIsReadyToMakeCall() && |
|
165 ( iOutstandingRequestsCall->Count() > 1 || |
|
166 ( *iOutstandingRequestsCall )[0]->SubSessionHandle() != 0 ) ) |
|
167 { |
|
168 // Get the call at the top of the list (head of the queue) |
|
169 CPhSrvCallRequest* head = NULL; |
|
170 if ( ( *iOutstandingRequestsCall )[0]->SubSessionHandle() != 0 ) |
|
171 { |
|
172 head = ( *iOutstandingRequestsCall )[0]; |
|
173 } |
|
174 else |
|
175 { |
|
176 head = ( *iOutstandingRequestsCall )[1]; |
|
177 } |
|
178 |
|
179 |
|
180 iCallInitiator->InitiatorMakeAsynchronousCallL( |
|
181 head->CallArguments() ); |
|
182 } |
|
183 |
|
184 return; |
|
185 } |
|
186 } |
|
187 } |
|
188 |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CPhSrvCallRequestManager::SetNegotiatorReadyCall |
|
192 // |
|
193 // Updates the negotiator so that it knows if the notifier |
|
194 // session is able to make a call. |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CPhSrvCallRequestManager::SetNegotiatorReadyCallL( |
|
198 MPhSrvInitiatorCall& aInitiator ) |
|
199 { |
|
200 // There mustn't already be a call initiator, or the existing call |
|
201 // initiator must be the same as the new one (otherwise, panic). |
|
202 __ASSERT_ALWAYS( !iCallInitiator || &aInitiator == iCallInitiator, |
|
203 PhoneServerUtils::Panic( |
|
204 EPhoneServerPanicExistingCallInitiatorFault ) ); |
|
205 |
|
206 // Update our pointer |
|
207 iCallInitiator = &aInitiator; |
|
208 |
|
209 // If we have more than one item in the queue, then we |
|
210 // try and fire of the next item here. |
|
211 if ( iCallInitiator->InitiatorIsReadyToMakeCall() && |
|
212 ( iOutstandingRequestsCall->Count() > 1 || |
|
213 ( *iOutstandingRequestsCall )[0]->SubSessionHandle() != 0 ) ) |
|
214 { |
|
215 // Get the call at the top of the list (head of the queue) |
|
216 CPhSrvCallRequest* head = NULL; |
|
217 if ( ( *iOutstandingRequestsCall )[0]->SubSessionHandle() != 0 ) |
|
218 { |
|
219 head = ( *iOutstandingRequestsCall )[0]; |
|
220 } |
|
221 else |
|
222 { |
|
223 head = ( *iOutstandingRequestsCall )[1]; |
|
224 } |
|
225 |
|
226 iCallInitiator->InitiatorMakeAsynchronousCallL( |
|
227 head->CallArguments() ); |
|
228 } |
|
229 } |
|
230 |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CPhSrvCallRequestManager::SetNegotiatorReadyCallCancel |
|
234 // |
|
235 // Indicates that the initiator is no longer available |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 void CPhSrvCallRequestManager::SetNegotiatorReadyCallCancel( |
|
239 MPhSrvInitiatorCall& aInitiator ) |
|
240 { |
|
241 if ( iCallInitiator && iCallInitiator == &aInitiator ) |
|
242 { |
|
243 iCallInitiator = NULL; |
|
244 } |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CPhSrvCallRequestManager::SetNegotiatorAttemptedCallResponseValue |
|
249 // |
|
250 // Handle a response from the phone app engine - this is the |
|
251 // result of attempting to make a call (based upon a previous |
|
252 // clients external call request) |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CPhSrvCallRequestManager::SetNegotiatorAttemptedCallResponseValue( |
|
256 TPhCltPhoneResults aResult ) |
|
257 { |
|
258 if ( iOutstandingRequestsCall->Count() > 1 || |
|
259 ( *iOutstandingRequestsCall )[0]->SubSessionHandle() != 0 ) |
|
260 { |
|
261 // Get the first item in the list - this is the oldest, and has the |
|
262 // details of the call we had previously initiated. |
|
263 CPhSrvCallRequest* head = NULL; |
|
264 if ( ( *iOutstandingRequestsCall )[0]->SubSessionHandle() != 0 ) |
|
265 { |
|
266 head = ( *iOutstandingRequestsCall )[0]; |
|
267 } |
|
268 else |
|
269 { |
|
270 head = ( *iOutstandingRequestsCall )[1]; |
|
271 } |
|
272 // Complete the request so that the external call client knows the |
|
273 // result of the call attempt |
|
274 head->InformOfCallAttemptResult( aResult ); |
|
275 |
|
276 // Delete the pending request (now that it's been processed) and tidy |
|
277 // up |
|
278 if ( ( *iOutstandingRequestsCall )[0]->SubSessionHandle() != 0 ) |
|
279 { |
|
280 ( *iOutstandingRequestsCall )[0]->ClearEmergencyCall(); |
|
281 } |
|
282 else |
|
283 { |
|
284 iOutstandingRequestsCall->Remove( 1 ); |
|
285 delete head; |
|
286 } |
|
287 } |
|
288 } |
|
289 |
|
290 |
|
291 // End of File |