|
1 /* |
|
2 * Copyright (c) 2006 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: Converts asynchronous call to synchronous. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cphcntasynctosync.h" |
|
20 |
|
21 // ======== MEMBER FUNCTIONS ======== |
|
22 |
|
23 // --------------------------------------------------------------------------- |
|
24 // Constructor |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 CPhCntAsyncToSync::CPhCntAsyncToSync() |
|
28 { |
|
29 } |
|
30 |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // Second phase constructor. |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 void CPhCntAsyncToSync::BaseConstructL() |
|
37 { |
|
38 iWait = new( ELeave )CActiveSchedulerWait(); |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // Destructor |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CPhCntAsyncToSync::~CPhCntAsyncToSync() |
|
46 { |
|
47 delete iWait; |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Converts asyncrhonous call to synchronous. |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 TInt CPhCntAsyncToSync::MakeAsyncRequest() |
|
55 { |
|
56 iResponseReceived = EFalse; |
|
57 // Return KErrInUse, if iWait is active. |
|
58 TInt err( IsActive() ? KErrInUse : KErrNone ); |
|
59 if ( !err ) |
|
60 { |
|
61 TRAP( err, DoMakeAsyncRequestL() ); |
|
62 } |
|
63 if( !err ) |
|
64 { |
|
65 // Check that response is not already received, we cannot |
|
66 // start the scheduler if response is received, otherwise |
|
67 // scheduler waits forever. |
|
68 if( !iResponseReceived ) |
|
69 { |
|
70 iWait->Start(); |
|
71 } |
|
72 err = iResponseError; |
|
73 } |
|
74 return err; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // Indication that response has been received from async request. |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CPhCntAsyncToSync::ResponseReceived( TInt aErrorCode ) |
|
82 { |
|
83 iResponseReceived = ETrue; |
|
84 iResponseError = aErrorCode; |
|
85 if( iWait->IsStarted() ) |
|
86 { |
|
87 iWait->AsyncStop(); |
|
88 } |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // Checks if there are pending asynchronous requests available. |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 TBool CPhCntAsyncToSync::IsActive() |
|
96 { |
|
97 return iWait->IsStarted(); |
|
98 } |
|
99 |