serviceproviders/sapi_calendar/src/calendarcallback.cpp
changeset 19 989d2f495d90
child 22 fc9cf246af83
equal deleted inserted replaced
14:a36b1e19a461 19:989d2f495d90
       
     1 /*
       
     2 * Copyright (c) 2007 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 the License "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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include "calendarcallback.h"
       
    19 #include "calendarconstants.h"
       
    20 #include "calendarinterface.h"
       
    21 
       
    22 // ---------------------------------------------------------------------------
       
    23 // Two-phase Constructor
       
    24 // ---------------------------------------------------------------------------
       
    25 //
       
    26 CCalCallbackBaseBuffer* CCalCallbackBaseBuffer::NewL( MLiwNotifyCallback *aPtrNotifyCallback, 
       
    27 													const CLiwGenericParamList& aPtrInParamList, 
       
    28 													TInt32 aTransactionId  )
       
    29 	{
       
    30 	return new (ELeave)	CCalCallbackBaseBuffer( aPtrNotifyCallback, aPtrInParamList, aTransactionId );
       
    31 	}
       
    32 	
       
    33 // ---------------------------------------------------------------------------
       
    34 //  Constructor
       
    35 // ---------------------------------------------------------------------------
       
    36 //	
       
    37 CCalCallbackBaseBuffer::CCalCallbackBaseBuffer( MLiwNotifyCallback *aPtrNotifyCallback, 
       
    38 													const CLiwGenericParamList& aPtrInParamList, 
       
    39 													TInt32 aTransactionId  )
       
    40 	{
       
    41 	iPtrNotifyCallback = aPtrNotifyCallback; 
       
    42 	iPtrInParamList = &aPtrInParamList;
       
    43 	iTransactionId = aTransactionId;
       
    44 	}
       
    45 	
       
    46 // ---------------------------------------------------------------------------
       
    47 // Gives the result of asynchronous SAPI for Export
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 void CCalCallbackBaseBuffer::NotifyResultL( TInt aErrCode, TAny* aResult )
       
    51 	{
       
    52 	CleanupStack::PushL( this );
       
    53 
       
    54 	CLiwGenericParamList* outParams = CLiwGenericParamList::NewL();
       
    55 
       
    56 	CleanupStack::PushL( outParams );
       
    57 
       
    58 	outParams->AppendL( TLiwGenericParam(KErrorCode, 
       
    59 							TLiwVariant(CCalendarInterface::ErrCodeConversion(aErrCode))));		
       
    60 
       
    61 	// Will be NULL if exported to file
       
    62 	if ( aResult )
       
    63 		{
       
    64 		outParams->AppendL( TLiwGenericParam( KReturnValue, TLiwVariant( *(HBufC8*)aResult ) ) );
       
    65 		}
       
    66 	
       
    67 	TInt event = KLiwEventCompleted;
       
    68 	
       
    69 	if ( aErrCode == KErrCancel )
       
    70 		{
       
    71 		event = KLiwEventCanceled;
       
    72 		}
       
    73 	else if ( aErrCode != KErrNone )
       
    74 		{
       
    75 		event = KLiwEventStopped;
       
    76 		outParams->AppendL( TLiwGenericParam(KErrorMessage, 
       
    77 							TLiwVariant(_L("Calendar:Export:Error exporting entries"))));		
       
    78 		}
       
    79 
       
    80 	((MLiwNotifyCallback*)iPtrNotifyCallback)->HandleNotifyL( iTransactionId, 
       
    81 												 event, 
       
    82 												 *outParams, 
       
    83 												 *((CLiwGenericParamList*)iPtrInParamList) ); 
       
    84 											 
       
    85 	CleanupStack::PopAndDestroy( 2, this );
       
    86 	}
       
    87 	
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // Two-phase Constructor
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CCalCallbackBaseUIDSet* CCalCallbackBaseUIDSet::NewL( MLiwNotifyCallback *aPtrNotifyCallback, 
       
    94 												const CLiwGenericParamList& aPtrInParamList, 
       
    95 												TInt32 aTransactionId  )
       
    96 	{
       
    97 	return new (ELeave)	CCalCallbackBaseUIDSet( aPtrNotifyCallback, aPtrInParamList, aTransactionId );
       
    98 	}
       
    99 	
       
   100 // ---------------------------------------------------------------------------
       
   101 //  Constructor
       
   102 // ---------------------------------------------------------------------------
       
   103 //	
       
   104 CCalCallbackBaseUIDSet::CCalCallbackBaseUIDSet( MLiwNotifyCallback *aPtrNotifyCallback, 
       
   105 												const CLiwGenericParamList& aPtrInParamList, 
       
   106 												TInt32 aTransactionId )
       
   107 	{
       
   108 	iPtrNotifyCallback = aPtrNotifyCallback; 
       
   109 	iPtrInParamList = &aPtrInParamList;
       
   110 	iTransactionId = aTransactionId;
       
   111 	}
       
   112 	
       
   113 // ---------------------------------------------------------------------------
       
   114 // Gives the result of asynchronous SAPI for Import
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CCalCallbackBaseUIDSet::NotifyResultL( TInt aErrCode, TAny* aResult )
       
   118 	{
       
   119 	CleanupStack::PushL( this );
       
   120 	
       
   121 	CLiwGenericParamList* outParams = CLiwGenericParamList::NewL();
       
   122 
       
   123 	CleanupStack::PushL( outParams );
       
   124 
       
   125 	outParams->AppendL(TLiwGenericParam(KErrorCode, 
       
   126 							TLiwVariant(CCalendarInterface::ErrCodeConversion(aErrCode))));		
       
   127 
       
   128 	CCalendarInterface::SetImportOutputL( *(RPointerArray<TUIDSet>*)( aResult ), *outParams );	
       
   129 		
       
   130 	TInt event = KLiwEventCompleted;
       
   131 	
       
   132 	if ( aErrCode == KErrCancel )
       
   133 		{
       
   134 		event = KLiwEventCanceled;
       
   135 		}
       
   136 	else if ( aErrCode != KErrNone )
       
   137 		{
       
   138 		event = KLiwEventStopped;
       
   139 		outParams->AppendL( TLiwGenericParam(KErrorMessage, 
       
   140 							TLiwVariant(_L("Calendar:Import:Error importing entries"))));		
       
   141 		}
       
   142 
       
   143 	((MLiwNotifyCallback*)iPtrNotifyCallback)->HandleNotifyL( iTransactionId, 
       
   144 												 event, 
       
   145 												 *outParams, 
       
   146 												 *((CLiwGenericParamList*)iPtrInParamList) ); 
       
   147 											 
       
   148 	CleanupStack::PopAndDestroy( 2, this );
       
   149 	}
       
   150 
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // Two-phase Constructor
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 CCalCallbackInt* CCalCallbackInt::NewL( MLiwNotifyCallback *aPtrNotifyCallback, 
       
   157 													const CLiwGenericParamList& aPtrInParamList, 
       
   158 													TInt32 aTransactionId  )
       
   159 	{
       
   160 	return new (ELeave)	CCalCallbackInt( aPtrNotifyCallback, aPtrInParamList, aTransactionId );
       
   161 	}
       
   162 	
       
   163 // ---------------------------------------------------------------------------
       
   164 //  Constructor
       
   165 // ---------------------------------------------------------------------------
       
   166 //	
       
   167 CCalCallbackInt::CCalCallbackInt( MLiwNotifyCallback *aPtrNotifyCallback, 
       
   168 													const CLiwGenericParamList& aPtrInParamList, 
       
   169 													TInt32 aTransactionId  )
       
   170 	{
       
   171 	iPtrNotifyCallback = aPtrNotifyCallback; 
       
   172 	iPtrInParamList = &aPtrInParamList;
       
   173 	iTransactionId = aTransactionId;
       
   174 	}
       
   175 	
       
   176 // ---------------------------------------------------------------------------
       
   177 // Gives the result of asynchronous SAPI for Delete
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void CCalCallbackInt::NotifyResultL( TInt aErrCode, TAny* /*aResult*/ )
       
   181 	{
       
   182 	CleanupStack::PushL( this );
       
   183 
       
   184 	CLiwGenericParamList* outParams = CLiwGenericParamList::NewL();
       
   185 
       
   186 	CleanupStack::PushL( outParams );
       
   187 
       
   188 	outParams->AppendL( TLiwGenericParam( KErrorCode, 
       
   189 							TLiwVariant( CCalendarInterface::ErrCodeConversion( aErrCode ))));		
       
   190 
       
   191 	TInt event = KLiwEventCompleted;
       
   192 	
       
   193 	if ( aErrCode == KErrCancel )
       
   194 		{
       
   195 		event = KLiwEventCanceled;
       
   196 		}
       
   197 	else if ( aErrCode != KErrNone )
       
   198 		{
       
   199 		event = KLiwEventStopped;
       
   200 		outParams->AppendL( TLiwGenericParam(KErrorMessage, 
       
   201 							TLiwVariant(_L("Calendar:Delete:Error deleting entries"))));		
       
   202 		}
       
   203 
       
   204 	((MLiwNotifyCallback*)iPtrNotifyCallback)->HandleNotifyL( iTransactionId, 
       
   205 												 event, 
       
   206 												 *outParams, 
       
   207 												 *((CLiwGenericParamList*)iPtrInParamList) ); 
       
   208 											 
       
   209 	CleanupStack::PopAndDestroy( 2, this );
       
   210 	}
       
   211 
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // Two-phase Constructor
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 CCalCallbackChangeNotify* CCalCallbackChangeNotify::NewL( MLiwNotifyCallback *aPtrNotifyCallback, 
       
   218 													const CLiwGenericParamList& aPtrInParamList, 
       
   219 													TInt32 aTransactionId  )
       
   220 	{
       
   221 	return new (ELeave)	CCalCallbackChangeNotify( aPtrNotifyCallback, aPtrInParamList, aTransactionId );
       
   222 	}
       
   223 	
       
   224 // ---------------------------------------------------------------------------
       
   225 //  Constructor
       
   226 // ---------------------------------------------------------------------------
       
   227 //	
       
   228 CCalCallbackChangeNotify::CCalCallbackChangeNotify( MLiwNotifyCallback *aPtrNotifyCallback, 
       
   229 													const CLiwGenericParamList& aPtrInParamList, 
       
   230 													TInt32 aTransactionId  )
       
   231 	{
       
   232 	iPtrNotifyCallback = aPtrNotifyCallback; 
       
   233 	iPtrInParamList = &aPtrInParamList;
       
   234 	iTransactionId = aTransactionId;
       
   235 	}
       
   236 	
       
   237 // ---------------------------------------------------------------------------
       
   238 // Gives the result of asynchronous SAPI for Change Notification
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CCalCallbackChangeNotify::NotifyResultL( TInt aErrCode, TAny* aResult )
       
   242 	{
       
   243 	CleanupStack::PushL( this );
       
   244 
       
   245 	CLiwGenericParamList* outParams = CLiwGenericParamList::NewL();
       
   246 
       
   247 	CleanupStack::PushL( outParams );
       
   248 
       
   249 	outParams->AppendL( TLiwGenericParam(KErrorCode, 
       
   250 							TLiwVariant( CCalendarInterface::ErrCodeConversion( aErrCode ))));	
       
   251 						
       
   252 	if ( aResult )
       
   253 		{
       
   254 		RArray<TCalChangeEntry>& outputChangeSet = *((RArray<TCalChangeEntry>*)aResult);
       
   255 		CCalendarInterface::SetNotifyOutputL( outputChangeSet, *outParams );	
       
   256 		}
       
   257 		
       
   258 	TInt event = KLiwEventInProgress;
       
   259 	
       
   260 	if ( aErrCode == KErrCancel )
       
   261 		{
       
   262 		event = KLiwEventCanceled;
       
   263 		}
       
   264 	else if ( aErrCode != KErrNone )
       
   265 		{
       
   266 		event = KLiwEventCompleted;
       
   267 		outParams->AppendL( TLiwGenericParam(KErrorMessage, 
       
   268 							TLiwVariant(_L("Calendar:RequestNotification:Notification stopped"))));		
       
   269 		}
       
   270 
       
   271 	((MLiwNotifyCallback*)iPtrNotifyCallback)->HandleNotifyL( iTransactionId, 
       
   272 												 event, 
       
   273 												 *outParams, 
       
   274 												 *((CLiwGenericParamList*)iPtrInParamList) ); 
       
   275 											 
       
   276 	CleanupStack::PopAndDestroy( outParams );
       
   277 
       
   278 	// Only in case of cancel the object is no more required
       
   279 	if ( aErrCode == KErrCancel || event == KLiwEventCompleted )
       
   280 		{
       
   281 		CleanupStack::PopAndDestroy( this );
       
   282 		}
       
   283 	else
       
   284 		{
       
   285 		CleanupStack::Pop( this );
       
   286 		}
       
   287 	}
       
   288 	
       
   289