phonebookui/Phonebook2/UIServices/src/CPbk2AcceptServiceMonitor.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Phonebook 2 UI Services accept service monitor.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CPbk2AcceptServiceMonitor.h"
       
    20 
       
    21 // Phonebook 2
       
    22 #include "MPbk2ConnectionObserver.h"
       
    23 #include "RPbk2UIService.h"
       
    24 
       
    25 // Unnamed namespace for local definitions
       
    26 namespace {
       
    27 
       
    28 // This is just an assumption, but in the unlikely case that this is not
       
    29 // enough the server side will complete the message with KErrOverflow
       
    30 const TInt KMaxLinkLength = 512;
       
    31 
       
    32 } /// namespace
       
    33 
       
    34 // --------------------------------------------------------------------------
       
    35 // CPbk2AcceptServiceMonitor::CPbk2AcceptServiceMonitor
       
    36 // --------------------------------------------------------------------------
       
    37 //
       
    38 CPbk2AcceptServiceMonitor::CPbk2AcceptServiceMonitor(
       
    39         RPbk2UIService& aPbk2AppService,
       
    40         MPbk2ConnectionObserver& aObserver ) :
       
    41             CActive( EPriorityStandard ),
       
    42             iPbk2AppService( aPbk2AppService ),
       
    43             iObserver(aObserver)
       
    44     {
       
    45     CActiveScheduler::Add( this );
       
    46     }
       
    47 
       
    48 // --------------------------------------------------------------------------
       
    49 // CPbk2AcceptServiceMonitor::~CPbk2AcceptServiceMonitor
       
    50 // --------------------------------------------------------------------------
       
    51 //
       
    52 CPbk2AcceptServiceMonitor::~CPbk2AcceptServiceMonitor()
       
    53     {
       
    54     Cancel();
       
    55     delete iLinkBuffer;
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // CPbk2AcceptServiceMonitor::NewL
       
    60 // --------------------------------------------------------------------------
       
    61 //
       
    62 CPbk2AcceptServiceMonitor* CPbk2AcceptServiceMonitor::NewL
       
    63         ( RPbk2UIService& aPbk2AppService,
       
    64           MPbk2ConnectionObserver& aObserver )
       
    65     {
       
    66     CPbk2AcceptServiceMonitor* self =
       
    67         new ( ELeave ) CPbk2AcceptServiceMonitor
       
    68             ( aPbk2AppService, aObserver );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CPbk2AcceptServiceMonitor::ConstructL
       
    77 // --------------------------------------------------------------------------
       
    78 //
       
    79 void CPbk2AcceptServiceMonitor::ConstructL()
       
    80     {
       
    81     iLinkBuffer = HBufC8::NewL( KMaxLinkLength );
       
    82     iPbk2AppService.AcceptRequestL
       
    83         ( iStatus, iNumContacts, *iLinkBuffer );
       
    84     SetActive();
       
    85     }
       
    86 
       
    87 // --------------------------------------------------------------------------
       
    88 // CPbk2AcceptServiceMonitor::RunL
       
    89 // --------------------------------------------------------------------------
       
    90 //
       
    91 void CPbk2AcceptServiceMonitor::RunL()
       
    92     {
       
    93     switch ( iStatus.Int() )
       
    94         {
       
    95         case KErrNone:
       
    96             {
       
    97             // Ask is the output acceptable
       
    98             TBool accept =
       
    99                 iObserver.AcceptSelectionL( iNumContacts, *iLinkBuffer );
       
   100 
       
   101             // Always request new notification
       
   102             iPbk2AppService.AcceptRequestL
       
   103                 ( iStatus, iNumContacts, *iLinkBuffer );
       
   104             SetActive();
       
   105 
       
   106             // Always complete the notification protocol
       
   107             iPbk2AppService.AcceptServiceL
       
   108                 ( accept, iLinkBuffer );
       
   109             break;
       
   110             }
       
   111         case KErrServerTerminated:
       
   112             {
       
   113             break;
       
   114             }
       
   115 
       
   116         default:
       
   117             {
       
   118             User::Leave( iStatus.Int() );
       
   119             break;
       
   120             }
       
   121         }
       
   122     }
       
   123 
       
   124 // --------------------------------------------------------------------------
       
   125 // CPbk2AcceptServiceMonitor::RunError
       
   126 // --------------------------------------------------------------------------
       
   127 //
       
   128 TInt CPbk2AcceptServiceMonitor::RunError( TInt aError )
       
   129     {
       
   130     TRAPD( err, iObserver.OperationErrorL( aError ) );
       
   131     return err;
       
   132     }
       
   133 
       
   134 // --------------------------------------------------------------------------
       
   135 // CPbk2AcceptServiceMonitor::DoCancel
       
   136 // --------------------------------------------------------------------------
       
   137 //
       
   138 void CPbk2AcceptServiceMonitor::DoCancel()
       
   139     {
       
   140     iPbk2AppService.CancelAcceptRequest();
       
   141     }
       
   142 
       
   143 // End of File