phoneengine/PhoneCntFinder/ContactService/src/cphcntasynctosync.cpp
changeset 0 5f000ab63145
child 1 838b0a10d15b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/phoneengine/PhoneCntFinder/ContactService/src/cphcntasynctosync.cpp	Mon Jan 18 20:18:27 2010 +0200
@@ -0,0 +1,94 @@
+/*
+* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:  Converts asynchronous call to synchronous.
+*
+*/
+
+
+#include "cphcntasynctosync.h"
+
+// ======== MEMBER FUNCTIONS ========
+
+// ---------------------------------------------------------------------------
+// Constructor
+// ---------------------------------------------------------------------------
+//
+CPhCntAsyncToSync::CPhCntAsyncToSync()
+    {
+    }
+
+
+// ---------------------------------------------------------------------------
+// Second phase constructor.
+// ---------------------------------------------------------------------------
+//
+void CPhCntAsyncToSync::BaseConstructL()
+    {
+    iWait = new( ELeave )CActiveSchedulerWait();
+    }
+
+// ---------------------------------------------------------------------------
+// Destructor
+// ---------------------------------------------------------------------------
+//
+CPhCntAsyncToSync::~CPhCntAsyncToSync()
+    {
+    delete iWait;
+    }
+
+// ---------------------------------------------------------------------------
+// Converts asyncrhonous call to synchronous.
+// ---------------------------------------------------------------------------
+//
+TInt CPhCntAsyncToSync::MakeAsyncRequest()
+    {
+    iResponseReceived = EFalse;
+    TRAPD( err, DoMakeAsyncRequestL() );
+    if( !err )
+        {
+        // Check that response is not already received, we cannot 
+        // start the scheduler if response is received, otherwise
+        // scheduler waits forever.
+        if( !iResponseReceived )
+            {
+            iWait->Start();
+            }    
+        err = iResponseError;
+        }
+    return err;
+    }
+    
+// ---------------------------------------------------------------------------
+// Indication that response has been received from async request.
+// ---------------------------------------------------------------------------
+//
+void CPhCntAsyncToSync::ResponseReceived( TInt aErrorCode )
+    {
+    iResponseReceived = ETrue;
+    iResponseError = aErrorCode;
+    if( iWait->IsStarted() )
+        {
+        iWait->AsyncStop();
+        }
+    }
+
+// ---------------------------------------------------------------------------
+// Checks if there are pending asynchronous requests available.
+// ---------------------------------------------------------------------------
+//
+TBool CPhCntAsyncToSync::IsActive()
+    {
+    return iWait->IsStarted();
+    }
+