serviceproviders/sapi_contacts_vpbk/contactservice/src/contactsyncapi.cpp
changeset 22 fc9cf246af83
parent 19 989d2f495d90
equal deleted inserted replaced
19:989d2f495d90 22:fc9cf246af83
    33 CContactIter* CContactService::GetListL(Ttype atype,
    33 CContactIter* CContactService::GetListL(Ttype atype,
    34         	    						const TDesC8& aContactId,        	    						
    34         	    						const TDesC8& aContactId,        	    						
    35         	    						const TDesC& aSearchVal,
    35         	    						const TDesC& aSearchVal,
    36         	    						CSearchFields* aSearchFields,
    36         	    						CSearchFields* aSearchFields,
    37         	    						TOrder aSortOrder,
    37         	    						TOrder aSortOrder,
    38         	    						const TDesC& aStoreUri)
    38         	    						const TDesC& aStoreUri,
       
    39         	    						TCmdType aval)
    39     {    
    40     {    
    40     //create the callback object internally
    41     //create the callback object internally
    41     CContactSyncCallback* callback = new(ELeave) CContactSyncCallback();    
    42     CContactSyncCallback* callback = new(ELeave) CContactSyncCallback();    
    42     CleanupStack::PushL(callback);
    43     CleanupStack::PushL(callback);
    43     //create the wait scheduler instance
    44     //create the wait scheduler instance
    51         			   atype,
    52         			   atype,
    52         			   aContactId,        			   
    53         			   aContactId,        			   
    53         			   aSearchVal,
    54         			   aSearchVal,
    54         			   aSearchFields,
    55         			   aSearchFields,
    55         			   aSortOrder,
    56         			   aSortOrder,
    56         			   aStoreUri));
    57         			   aStoreUri,
       
    58         			   aval));
    57     //TRAP harness is used to unset the sync flag in leaving condition
    59     //TRAP harness is used to unset the sync flag in leaving condition
    58     //since we r using the same async apis for sync implementation       			   
    60     //since we r using the same async apis for sync implementation       			   
    59     if(KErrNone != err)    
    61     if(KErrNone != err)    
    60         {
    62         {
    61         User::Leave(err);
    63         User::Leave(err);
    75     CleanupStack::PopAndDestroy(callback);
    77     CleanupStack::PopAndDestroy(callback);
    76 	return tempIter;           
    78 	return tempIter;           
    77     }
    79     }
    78 
    80 
    79 
    81 
    80 
    82 /*
       
    83 -----------------------------------------------------------------------------
       
    84     CContactService     :: GetIdsL
       
    85     Description          : synchronous implementation of GetIds api.                        
       
    86     Return values        : RPointerArray<HBufC8>&
       
    87 -----------------------------------------------------------------------------
       
    88 */
       
    89 
       
    90 EXPORT_C
       
    91 RPointerArray<HBufC8>& CContactService::GetIdsL(Ttype atype,                                     
       
    92                                         const TDesC& aSearchVal,
       
    93                                         CSearchFields* aSearchFields,
       
    94                                         TOrder aSortOrder,
       
    95                                         const TDesC& aStoreUri,
       
    96                                         TCmdType aval)
       
    97     {    
       
    98     //create the callback object internally
       
    99     CContactSyncCallback* callback = new(ELeave) CContactSyncCallback();    
       
   100     CleanupStack::PushL(callback);
       
   101     //create the wait scheduler instance
       
   102     CActiveSchedulerWait* waitScheduler = new(ELeave) CActiveSchedulerWait(); 
       
   103     CleanupStack::PushL(waitScheduler); 
       
   104     //needed to stop the scheduler by the callback instance       
       
   105     callback->SetWaitScheduler(waitScheduler);  
       
   106     //call the asynch sapi with all the params  
       
   107     TRAPD(err,GetListL(callback,
       
   108                        0,
       
   109                        atype,
       
   110                        KNullDesC8,                     
       
   111                        aSearchVal,
       
   112                        aSearchFields,
       
   113                        aSortOrder,
       
   114                        aStoreUri,
       
   115                        aval));
       
   116     //TRAP harness is used to unset the sync flag in leaving condition
       
   117     //since we r using the same async apis for sync implementation                     
       
   118     if(KErrNone != err)    
       
   119         {
       
   120         User::Leave(err);
       
   121         }                  
       
   122     //start the wait scheduler and wait untill the operation finishes
       
   123     waitScheduler->Start();
       
   124     //Unset the callbak pointer     
       
   125     callback->SetWaitScheduler(NULL);   
       
   126     //check for any errors 
       
   127     TInt error = callback->GetErrorCode();
       
   128     if(KErrNone != error)    
       
   129         {
       
   130         User::Leave(error);
       
   131         }
       
   132     RPointerArray<HBufC8>* tempArray = new (ELeave) RPointerArray<HBufC8>;
       
   133     //get the array of ids of contacts/groups
       
   134     callback->GetArray(tempArray);
       
   135     CleanupStack::PopAndDestroy(waitScheduler);
       
   136     CleanupStack::PopAndDestroy(callback);
       
   137     return *tempArray;           
       
   138     }
    81 /*
   139 /*
    82 -----------------------------------------------------------------------------
   140 -----------------------------------------------------------------------------
    83     CContactService     :: AddL
   141     CContactService     :: AddL
    84     Description          : synchronous implementation of AddL api.                        
   142     Description          : synchronous implementation of AddL api.                        
    85     Return values        : CContactIter*
   143     Return values        : CContactIter*
    86 -----------------------------------------------------------------------------
   144 -----------------------------------------------------------------------------
    87 */
   145 */
    88 
   146 
    89 EXPORT_C
   147 EXPORT_C
    90 void CContactService:: AddL( CSingleContact* aContact,
   148 HBufC8* CContactService:: AddL( CSingleContact* aContact,        
    91     						 const TDesC8& aGroupId,
   149     						 const TDesC8& aGroupId,
    92     						 const TDesC& aGroupLabel,
   150     						 const TDesC& aGroupLabel,
    93     						 const TDesC& aStoreUri)
   151     						 const TDesC& aStoreUri)
    94     {
   152     {
    95     iErrKey = 0;
   153     iErrKey = 0;
   126             {
   184             {
   127             iErrKey = callback->iErrKey;    
   185             iErrKey = callback->iErrKey;    
   128             }
   186             }
   129         User::Leave(error);
   187         User::Leave(error);
   130         }
   188         }
   131     CleanupStack::PopAndDestroy(waitScheduler);    
   189    
   132     CleanupStack::PopAndDestroy(callback);
   190 	    HBufC8* cntIdVal = callback->GetId();
       
   191         
       
   192        CleanupStack::PopAndDestroy(waitScheduler);    
       
   193        CleanupStack::PopAndDestroy(callback);
       
   194        return cntIdVal;
       
   195 	   
   133     }
   196     }
   134 
   197 
   135 
   198 
   136 /*
   199 /*
   137 -----------------------------------------------------------------------------
   200 -----------------------------------------------------------------------------