syncmlfw/common/sosserver_clientapi/src/NSmlClientContactSuiteAPIActiveCallback.cpp
changeset 0 b497e44ab2fc
child 23 4af31167ea77
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Implementation for event/progress notifiers
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // This define should be moved somewhere else (symbian headers) !!
       
    20 #include <s32mem.h>
       
    21 #include <SyncMLObservers.h>
       
    22 
       
    23 #include "NSmlClientAPIDefs.h"
       
    24 #include "NSmlClientAPIUtils.h"
       
    25 #include "NSmlClientAPIActiveCallback.h"
       
    26 #include "NSmlClientContactSuiteAPIActiveCallback.h"
       
    27 #include "nsmlsosserverdefs.h"
       
    28 #include "NSmlErrorCodeConversion.h"
       
    29 
       
    30 
       
    31 //
       
    32 // CSmlActiveContactSuiteProgressCallback
       
    33 //
       
    34 
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CSmlActiveContactSuiteProgressCallback::NewL(
       
    38 // Two-phase construction.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CSmlActiveContactSuiteProgressCallback* CSmlActiveContactSuiteProgressCallback::NewL( const CSmlContactSuiteActiveCallback* aCallback )
       
    42     {
       
    43     CSmlActiveContactSuiteProgressCallback* self = new (ELeave) CSmlActiveContactSuiteProgressCallback( aCallback );
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL();
       
    46     CleanupStack::Pop(); // self
       
    47     return self;
       
    48     }
       
    49     
       
    50 // -----------------------------------------------------------------------------
       
    51 // CSmlActiveContactSuiteProgressCallback::~CSmlActiveContactSuiteProgressCallback()
       
    52 // Destructor.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CSmlActiveContactSuiteProgressCallback::~CSmlActiveContactSuiteProgressCallback()
       
    56     {
       
    57     Cancel();
       
    58     if ( iRequesting )
       
    59         {
       
    60         CancelProgress();
       
    61         }
       
    62     
       
    63     delete iBuf;
       
    64     iBuf = NULL;
       
    65     }
       
    66     
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSmlActiveContactSuiteProgressCallback::SetObserver()
       
    69 // Sets the observer to be notified. Starts requesting progress 
       
    70 // events if it is not yet started.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CSmlActiveContactSuiteProgressCallback::SetObserver( MSyncMLProgressObserver& aObserver )
       
    74     {
       
    75     iObserver = &aObserver;
       
    76     
       
    77     if ( !iRequesting )
       
    78         {
       
    79         iRequesting = ETrue;
       
    80         Request();
       
    81         }
       
    82     }
       
    83     
       
    84 // -----------------------------------------------------------------------------
       
    85 // CSmlActiveContactSuiteProgressCallback::CancelProgress()
       
    86 // Cancels progress notification.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CSmlActiveContactSuiteProgressCallback::CancelProgress()
       
    90     {
       
    91     DoCancel();
       
    92     }
       
    93     
       
    94 // -----------------------------------------------------------------------------
       
    95 // CSmlActiveContactSuiteProgressCallback::DoCancel()
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CSmlActiveContactSuiteProgressCallback::DoCancel()
       
    99     {
       
   100     // cancel request to server
       
   101     iCallback->SendReceive( ECmdContactSuiteProgressRequestCancel );
       
   102     iRequesting = EFalse;
       
   103     }
       
   104     
       
   105 // -----------------------------------------------------------------------------
       
   106 // CSmlActiveContactSuiteProgressCallback::RunL()
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CSmlActiveContactSuiteProgressCallback::RunL()
       
   110     {
       
   111     // check status
       
   112     if ( iStatus.Int() == KErrNone )
       
   113         {
       
   114         // open a readstream to iEventBuf's data
       
   115         RDesReadStream readStream( iBufPtr );
       
   116         CleanupClosePushL( readStream );
       
   117         
       
   118         // read the fist interger in databuffer -> the type of message
       
   119         TInt8 type = readStream.ReadInt8L();
       
   120         if ( type != ENSmlTypeProgressEvent )
       
   121             {
       
   122             User::Panic( KNSmlClientAPIPanic, KErrArgument );
       
   123             }
       
   124 
       
   125         // check which progress event was received, and notify observer
       
   126         TNSmlProgressEventType eventType = (TNSmlProgressEventType)readStream.ReadInt8L();
       
   127         switch( eventType )
       
   128             {
       
   129             case ENSmlSyncError:
       
   130                 NotifyErrorL( readStream );
       
   131                 break;
       
   132             case ENSmlSyncProgress:
       
   133                 NotifyProgressL( readStream );
       
   134                 break;
       
   135             case ENSmlModifications:
       
   136                 NotifyModificationsL( readStream );
       
   137                 break;
       
   138             default:
       
   139                 User::Panic( KNSmlClientAPIPanic, KErrArgument );
       
   140                 break;
       
   141             }
       
   142         
       
   143         CleanupStack::PopAndDestroy(); // readStream
       
   144         
       
   145         if ( iRequesting )
       
   146             {
       
   147             Request();
       
   148             }
       
   149         }
       
   150 #ifdef __CLIENT_API_MT_
       
   151     else
       
   152         {
       
   153         CActiveScheduler::Stop();
       
   154         }
       
   155 #endif
       
   156     }
       
   157     
       
   158 // -----------------------------------------------------------------------------
       
   159 // CSmlActiveContactSuiteProgressCallback::Request()
       
   160 // Sends asynchronous progress event request to server.
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CSmlActiveContactSuiteProgressCallback::Request()
       
   164     {
       
   165     iBufPtr.Zero();
       
   166     
       
   167     if ( !IsActive() )
       
   168         {
       
   169         SetActive();
       
   170         }
       
   171     
       
   172     if ( iCallback )
       
   173         {
       
   174         iCallback->SendReceive( ECmdContactSuiteProgressRequest, TIpcArgs( &iBufPtr ), iStatus );
       
   175         }
       
   176     }
       
   177     
       
   178 // -----------------------------------------------------------------------------
       
   179 // CSmlActiveContactSuiteProgressCallback::ConstructL()
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CSmlActiveContactSuiteProgressCallback::ConstructL()
       
   183     {
       
   184     iBuf = HBufC8::NewL( KNSmlMaxProgressMessageLength );
       
   185     iBufPtr.Set( iBuf->Des() );
       
   186     }
       
   187     
       
   188 // -----------------------------------------------------------------------------
       
   189 // CSmlActiveContactSuiteProgressCallback::CSmlActiveContactSuiteProgressCallback()
       
   190 // Contructor.
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 CSmlActiveContactSuiteProgressCallback::CSmlActiveContactSuiteProgressCallback( const CSmlContactSuiteActiveCallback* aCallback )
       
   194     : CActive( EPriorityStandard ), iRequesting( EFalse ), iBufPtr( 0, NULL, 0 ), iCallback( aCallback )
       
   195     {
       
   196     CActiveScheduler::Add( this );
       
   197     }
       
   198     
       
   199 // -----------------------------------------------------------------------------
       
   200 // CSmlActiveContactSuiteProgressCallback::NotifyErrorL()
       
   201 // Reads progress error related data and notifies observer.
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 void CSmlActiveContactSuiteProgressCallback::NotifyErrorL( RReadStream& aStream ) const
       
   205     {
       
   206     TInt8 errorLevel = aStream.ReadInt8L();
       
   207     TInt32 error = aStream.ReadInt32L();
       
   208     TInt32 taskId = aStream.ReadInt32L();
       
   209     TInt32 info1 = aStream.ReadInt32L();
       
   210     TInt32 info2 = aStream.ReadInt32L();
       
   211     
       
   212     TNSmlErrorConversion errorconv( error );
       
   213     error = errorconv.Convert();
       
   214     
       
   215     iObserver->OnSyncMLSyncError( (MSyncMLProgressObserver::TErrorLevel)errorLevel, error, taskId, info1, info2 );
       
   216     }
       
   217     
       
   218 // -----------------------------------------------------------------------------
       
   219 // CSmlActiveContactSuiteProgressCallback::NotifyProgressL()
       
   220 // Reads progress event related data and notifies observer.
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 void CSmlActiveContactSuiteProgressCallback::NotifyProgressL( RReadStream& aStream ) const
       
   224     {
       
   225     TInt8 status = aStream.ReadInt8L();
       
   226     TInt32 info1 = aStream.ReadInt32L();
       
   227     TInt32 info2 = aStream.ReadInt32L();
       
   228     
       
   229     iObserver->OnSyncMLSyncProgress( (MSyncMLProgressObserver::TStatus)status, info1, info2 );
       
   230     }
       
   231     
       
   232 // -----------------------------------------------------------------------------
       
   233 // CSmlActiveContactSuiteProgressCallback::NotifyModificationsL()
       
   234 // Reads progress information of modifications and notifies 
       
   235 // observer.
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 void CSmlActiveContactSuiteProgressCallback::NotifyModificationsL( RReadStream& aStream )
       
   239     {
       
   240 #ifdef SYNCML_V3
       
   241     TInt32 taskId = aStream.ReadInt32L();
       
   242     
       
   243     iClientMods.iNumAdded = aStream.ReadInt32L();
       
   244     iClientMods.iNumReplaced = aStream.ReadInt32L();
       
   245     iClientMods.iNumMoved = aStream.ReadInt32L();
       
   246     iClientMods.iNumDeleted = aStream.ReadInt32L();
       
   247     iClientMods.iNumFailed = aStream.ReadInt32L();
       
   248     
       
   249     iServerMods.iNumAdded = aStream.ReadInt32L();
       
   250     iServerMods.iNumReplaced = aStream.ReadInt32L();
       
   251     iServerMods.iNumMoved = aStream.ReadInt32L();
       
   252     iServerMods.iNumDeleted = aStream.ReadInt32L();
       
   253     iServerMods.iNumFailed = aStream.ReadInt32L();
       
   254     
       
   255     iObserver->OnSyncMLDataSyncModifications( taskId, iClientMods, iServerMods );
       
   256 #endif
       
   257     }
       
   258 // -----------------------------------------------------------------------------
       
   259 // CSmlActiveCallback::CSmlActiveCallback()
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 CSmlContactSuiteActiveCallback::CSmlContactSuiteActiveCallback( RSyncMLSession& aSession )
       
   263     : iContactSuiteSession( aSession ), iActiveCallback(aSession)
       
   264     {
       
   265     }
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CSmlActiveCallback::~CSmlActiveCallback()
       
   269 // Destructor.
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 CSmlContactSuiteActiveCallback::~CSmlContactSuiteActiveCallback()
       
   273     {
       
   274     //delete iEventCallback; iEventCallback = NULL;
       
   275     delete iProgressCallback; iProgressCallback = NULL;
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CSmlActiveCallback::SetProgressObserverL()
       
   280 // Sets the progress observer.
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CSmlContactSuiteActiveCallback::SetProgressObserverL( MSyncMLProgressObserver& aObserver )
       
   284     {
       
   285     if ( !iProgressCallback )
       
   286         {
       
   287         iProgressCallback = CSmlActiveContactSuiteProgressCallback::NewL( this );
       
   288         }
       
   289     
       
   290     iProgressCallback->SetObserver( aObserver );
       
   291     }
       
   292 
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CSmlActiveCallback::CancelProgress()
       
   296 // Cancels progress notification.
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 void CSmlContactSuiteActiveCallback::CancelProgress()
       
   300     {
       
   301     if ( iProgressCallback )
       
   302         {
       
   303         iProgressCallback->CancelProgress();
       
   304         delete iProgressCallback; iProgressCallback = NULL;
       
   305         }
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CSmlActiveCallback::SendReceive()
       
   310 // Makes an asynchronous IPC call to server. Used by event and progress 
       
   311 // notifier objects.
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 void CSmlContactSuiteActiveCallback::SendReceive( TInt aCmd, const TIpcArgs& aArgs, TRequestStatus& aStatus ) const
       
   315     {
       
   316     iActiveCallback.SendReceive( aCmd, aArgs , aStatus );    
       
   317     }
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // CSmlActiveCallback::SendReceive()
       
   321 // Makes a synchronous IPC call to server. Used by event and progress 
       
   322 // notifier objects.
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CSmlContactSuiteActiveCallback::SendReceive( TInt aCmd ) const
       
   326     {
       
   327     iActiveCallback.SendReceive( aCmd );    
       
   328     }