serviceproviders/sapi_contacts_vpbk/contactservice/src/contactsyncapi.cpp
changeset 22 fc9cf246af83
parent 19 989d2f495d90
--- a/serviceproviders/sapi_contacts_vpbk/contactservice/src/contactsyncapi.cpp	Fri Jul 03 15:51:24 2009 +0100
+++ b/serviceproviders/sapi_contacts_vpbk/contactservice/src/contactsyncapi.cpp	Thu Aug 27 07:43:07 2009 +0300
@@ -35,7 +35,8 @@
         	    						const TDesC& aSearchVal,
         	    						CSearchFields* aSearchFields,
         	    						TOrder aSortOrder,
-        	    						const TDesC& aStoreUri)
+        	    						const TDesC& aStoreUri,
+        	    						TCmdType aval)
     {    
     //create the callback object internally
     CContactSyncCallback* callback = new(ELeave) CContactSyncCallback();    
@@ -53,7 +54,8 @@
         			   aSearchVal,
         			   aSearchFields,
         			   aSortOrder,
-        			   aStoreUri));
+        			   aStoreUri,
+        			   aval));
     //TRAP harness is used to unset the sync flag in leaving condition
     //since we r using the same async apis for sync implementation       			   
     if(KErrNone != err)    
@@ -77,7 +79,63 @@
     }
 
 
+/*
+-----------------------------------------------------------------------------
+    CContactService     :: GetIdsL
+    Description          : synchronous implementation of GetIds api.                        
+    Return values        : RPointerArray<HBufC8>&
+-----------------------------------------------------------------------------
+*/
 
+EXPORT_C
+RPointerArray<HBufC8>& CContactService::GetIdsL(Ttype atype,                                     
+                                        const TDesC& aSearchVal,
+                                        CSearchFields* aSearchFields,
+                                        TOrder aSortOrder,
+                                        const TDesC& aStoreUri,
+                                        TCmdType aval)
+    {    
+    //create the callback object internally
+    CContactSyncCallback* callback = new(ELeave) CContactSyncCallback();    
+    CleanupStack::PushL(callback);
+    //create the wait scheduler instance
+    CActiveSchedulerWait* waitScheduler = new(ELeave) CActiveSchedulerWait(); 
+    CleanupStack::PushL(waitScheduler); 
+    //needed to stop the scheduler by the callback instance       
+    callback->SetWaitScheduler(waitScheduler);  
+    //call the asynch sapi with all the params  
+    TRAPD(err,GetListL(callback,
+                       0,
+                       atype,
+                       KNullDesC8,                     
+                       aSearchVal,
+                       aSearchFields,
+                       aSortOrder,
+                       aStoreUri,
+                       aval));
+    //TRAP harness is used to unset the sync flag in leaving condition
+    //since we r using the same async apis for sync implementation                     
+    if(KErrNone != err)    
+        {
+        User::Leave(err);
+        }                  
+    //start the wait scheduler and wait untill the operation finishes
+    waitScheduler->Start();
+    //Unset the callbak pointer     
+    callback->SetWaitScheduler(NULL);   
+    //check for any errors 
+    TInt error = callback->GetErrorCode();
+    if(KErrNone != error)    
+        {
+        User::Leave(error);
+        }
+    RPointerArray<HBufC8>* tempArray = new (ELeave) RPointerArray<HBufC8>;
+    //get the array of ids of contacts/groups
+    callback->GetArray(tempArray);
+    CleanupStack::PopAndDestroy(waitScheduler);
+    CleanupStack::PopAndDestroy(callback);
+    return *tempArray;           
+    }
 /*
 -----------------------------------------------------------------------------
     CContactService     :: AddL
@@ -87,7 +145,7 @@
 */
 
 EXPORT_C
-void CContactService:: AddL( CSingleContact* aContact,
+HBufC8* CContactService:: AddL( CSingleContact* aContact,        
     						 const TDesC8& aGroupId,
     						 const TDesC& aGroupLabel,
     						 const TDesC& aStoreUri)
@@ -128,8 +186,13 @@
             }
         User::Leave(error);
         }
-    CleanupStack::PopAndDestroy(waitScheduler);    
-    CleanupStack::PopAndDestroy(callback);
+   
+	    HBufC8* cntIdVal = callback->GetId();
+        
+       CleanupStack::PopAndDestroy(waitScheduler);    
+       CleanupStack::PopAndDestroy(callback);
+       return cntIdVal;
+	   
     }