phonebookengines/VirtualPhonebook/VPbkSimStoreImpl/src/CWriteCmdBase.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2002-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 "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:  A command that writes a contact to (U)SIM card using
       
    15 *                ETel RMobilePhoneBookStore Write
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "CWriteCmdBase.h"
       
    23 
       
    24 #include <VPbkDebug.h>
       
    25 #include <MVPbkSimContactObserver.h>
       
    26 #include <MVPbkSimCommand.h>
       
    27 #include "CETelStoreNotification.h"
       
    28 #include "VPbkSimStoreImplError.h"
       
    29 #include <gsmerror.h>
       
    30 
       
    31 namespace VPbkSimStoreImpl {
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CWriteCmdBase::CWriteCmdBase
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CWriteCmdBase::CWriteCmdBase( CStoreBase& aStore, TInt& aSimIndex,
       
    42     MVPbkSimContactObserver& aObserver )
       
    43     : CActive( EPriorityStandard ),
       
    44       iSimIndex( aSimIndex ),
       
    45       iStoreBase( aStore ),
       
    46       iObserver( aObserver )
       
    47     {
       
    48     CActiveScheduler::Add( this );
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CWriteCmdBase::BaseConstructL
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CWriteCmdBase::BaseConstructL()
       
    57     {
       
    58     iUpdateCommand = iStoreBase.CreateUpdateCommandUsingRefL( iSimIndex );
       
    59     iUpdateCommand->AddObserverL( *this );
       
    60     }
       
    61 
       
    62 // Destructor
       
    63 CWriteCmdBase::~CWriteCmdBase()
       
    64     {
       
    65     Cancel();
       
    66     RemoveNotificationObserver();
       
    67     delete iUpdateCommand;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CWriteCmdBase::RunL
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CWriteCmdBase::RunL()
       
    75     {
       
    76     TInt result = iStatus.Int();
       
    77     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
    78         "VPbkSimStoreImpl: RMobilePhone(Book)Store::Write h%d complete %d"),
       
    79         iStoreBase.ETelStoreBase().SubSessionHandle(),result);
       
    80 
       
    81     switch ( result )
       
    82         {
       
    83         // These errors are handled when update is done
       
    84         // In those cases contact is partially saved and detail
       
    85         // which did not fit to SIM is simply discarded
       
    86         case KErrGsmSimServSneFull: // FALLTHROUGH
       
    87         case KErrGsmSimServAnrFull: // FALLTHROUGH
       
    88         case KErrGsmSimServEmailFull: 
       
    89         case KErrNone:
       
    90             {
       
    91             iUpdateCommand->Execute();
       
    92             break;
       
    93             }
       
    94         default:
       
    95             {
       
    96             HandleError( result );
       
    97             break;
       
    98             }
       
    99        }
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CWriteCmdBase::DoCancel
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CWriteCmdBase::DoCancel()
       
   107     {
       
   108     VPBK_DEBUG_PRINT(VPBK_DEBUG_STRING(
       
   109         "VPbkSimStoreImpl: RMobilePhoneStore::Write h%d Cancel"),
       
   110         iStoreBase.ETelStoreBase().SubSessionHandle());
       
   111     iStoreBase.ETelStoreBase().CancelAsyncRequest( EMobilePhoneStoreWrite );
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CWriteCmdBase::ETelStoreChanged
       
   116 // Consume the notification if it's same index that is being modified by
       
   117 // this command. Otherwise the event must not be consumed because some
       
   118 // other component caused the event by using ETel API and not VPbk API
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 TBool CWriteCmdBase::ETelStoreChanged( TInt aSimIndex, TUint32 /*aEvents*/ )
       
   122     {
       
   123     if ( iSimIndex == aSimIndex )
       
   124         {
       
   125         return ETrue;
       
   126         }
       
   127     return EFalse;
       
   128     }
       
   129   
       
   130 // -----------------------------------------------------------------------------
       
   131 // CWriteCmdBase::ETelStoreChangeError
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 TBool CWriteCmdBase::ETelStoreChangeError( TInt /*aError*/ )
       
   135     {
       
   136     return EFalse;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CWriteCmdBase::CommandDone
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CWriteCmdBase::CommandDone( MVPbkSimCommand& /*aCommand*/ )
       
   144     {
       
   145     RemoveNotificationObserver();
       
   146     TInt result = iStatus.Int();
       
   147     if ( result != KErrNone )
       
   148         {
       
   149         iObserver.ContactEventError( MVPbkSimContactObserver::ESave, NULL, 
       
   150             result ); 
       
   151         }
       
   152     else
       
   153         {
       
   154         iObserver.ContactEventComplete( MVPbkSimContactObserver::ESave, NULL );
       
   155         }
       
   156 
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CWriteCmdBase::CommandError
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CWriteCmdBase::CommandError( MVPbkSimCommand& /*aCommand*/, TInt aError )
       
   164     {
       
   165     HandleError( aError );
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CWriteCmdBase::Activate
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CWriteCmdBase::Activate()
       
   173     {
       
   174     if ( iStoreBase.ETelNotification() )
       
   175         {
       
   176         // listen to store events to consume the event if it's caused
       
   177         // by this command
       
   178         iStoreBase.ETelNotification()->SetHighPriorityObserver( *this );
       
   179         }
       
   180         
       
   181     SetActive();
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CWriteCmdBase::HandleError
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CWriteCmdBase::HandleError( TInt aError )
       
   189     {
       
   190     RemoveNotificationObserver();
       
   191     iObserver.ContactEventError( MVPbkSimContactObserver::ESave, NULL, 
       
   192         aError ); 
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CWriteCmdBase::RemoveNotificationObserver
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CWriteCmdBase::RemoveNotificationObserver()
       
   200     {
       
   201     if ( iStoreBase.ETelNotification() )
       
   202         {
       
   203         iStoreBase.ETelNotification()->RemoveHighPriorityObserver( *this );
       
   204         }
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CWriteCmdBase::CompleteCommandAsynchronously
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void CWriteCmdBase::CompleteCommandAsynchronously( TInt aResult )
       
   212     {
       
   213     TRequestStatus* st = &iStatus;
       
   214     User::RequestComplete( st, aResult );
       
   215     SetActive();
       
   216     }
       
   217 } // namespace VPbkSimStoreImpl
       
   218 //  End of File