wvuing/IMPSConnectionUI/NotifySrc/CIMPSConnUiPresEventNotifierImp.cpp
branchRCL_3
changeset 13 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
12:6ca72c0fe49a 13:a941bc465d9f
       
     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:  Event notifier implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <E32std.h>
       
    20 #include <CPEngNWSessionSlotNotifier2.h>
       
    21 #include <CPEngNWSessionSlotEvent2.h>
       
    22 #include <CPEngNWSessionSlotManager2.h>
       
    23 #include <CPEngNWSessionSlotID2.h>
       
    24 #include "CIMPSConnUiPresEventNotifierImp.h"
       
    25 #include "CnUiEventMapper.h"
       
    26 
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 // Two-phased constructor.
       
    30 CIMPSConnUiPresEventNotifierImp* CIMPSConnUiPresEventNotifierImp::NewL(
       
    31     CIMPSConnUiPresEventNotifier& aInterface )
       
    32     {
       
    33     CIMPSConnUiPresEventNotifierImp* self =
       
    34         new ( ELeave ) CIMPSConnUiPresEventNotifierImp( aInterface );
       
    35 
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop( self ); //self
       
    39 
       
    40     return self;
       
    41     }
       
    42 
       
    43 
       
    44 
       
    45 // Destructor
       
    46 CIMPSConnUiPresEventNotifierImp::~CIMPSConnUiPresEventNotifierImp()
       
    47     {
       
    48     //inform the base class that notifier is dying
       
    49     //==>stops further notifying
       
    50     Dying();
       
    51     if ( iEventNotifier )
       
    52         {
       
    53         iEventNotifier->RemoveObserver( *this );
       
    54         }
       
    55     delete iEventNotifier;
       
    56     }
       
    57 
       
    58 
       
    59 // C++ default constructor can NOT contain any code, that
       
    60 // might leave.
       
    61 //
       
    62 CIMPSConnUiPresEventNotifierImp::CIMPSConnUiPresEventNotifierImp(
       
    63     CIMPSConnUiPresEventNotifier& aInterface )
       
    64         : CIMPSConnUiPresEventNotifierImpBase( aInterface )
       
    65     {
       
    66     }
       
    67 
       
    68 
       
    69 
       
    70 // Symbian OS default constructor can leave.
       
    71 void CIMPSConnUiPresEventNotifierImp::ConstructL()
       
    72     {
       
    73 
       
    74     iEventNotifier = CPEngNWSessionSlotNotifier2::NewL();
       
    75     iEventNotifier->AddObserver( *this );
       
    76     }
       
    77 
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CIMPSConnUiPresEventNotifierImp::DoStartL()
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CIMPSConnUiPresEventNotifierImp::DoStartL(
       
    85     const TArray<TPEngNWSessionSlotEvent>& aEvents )
       
    86     {
       
    87     if ( !iEventNotifier->IsActive() )
       
    88         {
       
    89         iEventNotifier->Start( aEvents );
       
    90         }
       
    91     }
       
    92 
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CIMPSConnUiPresEventNotifierImp::DoStop()
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CIMPSConnUiPresEventNotifierImp::DoStop()
       
    99     {
       
   100     iEventNotifier->Stop();
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CIMPSConnUiPresEventNotifierImp::AppServiceStatusL()
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 const CPEngNWSessionSlotID2* CIMPSConnUiPresEventNotifierImp::AppServiceStatusL(
       
   108     TIMPSConnectionClient aClient )
       
   109     {
       
   110 
       
   111     CPEngNWSessionSlotManager2* slotManager = CPEngNWSessionSlotManager2::NewLC();
       
   112 
       
   113     CPEngNWSessionSlotID2* matchPattern = CPEngNWSessionSlotID2::NewLC();
       
   114     matchPattern->SetServiceAddressMatchAnyL();
       
   115     matchPattern->SetUserIdMatchAnyL();
       
   116 
       
   117     if ( aClient == EIMPSConnClientIM )
       
   118         {
       
   119         matchPattern->SetAppIdL( KPEngAppIdIM() );
       
   120         }
       
   121     else
       
   122         {
       
   123         matchPattern->SetAppIdL( KPEngAppIdPEC() );
       
   124         }
       
   125 
       
   126     RPointerArray< CPEngNWSessionSlotID2 > slotIDs;
       
   127     User::LeaveIfError( slotManager->GetNWSessionSlots(
       
   128                             slotIDs,
       
   129                             *matchPattern,
       
   130                             EPEngNWPresenceSessionOpen ) );
       
   131 
       
   132     CleanupStack::PopAndDestroy( 2, slotManager );
       
   133     CleanupStack::PushL( TCleanupItem( DestroyCloseModelArray, &slotIDs ) );
       
   134     CPEngNWSessionSlotID2* tempSlotID = NULL;
       
   135     tempSlotID = slotIDs[0]->CloneL();
       
   136     delete iSessionSlotID;
       
   137     iSessionSlotID = tempSlotID;
       
   138 
       
   139     CleanupStack::PopAndDestroy(); //slotIDs
       
   140     return iSessionSlotID;
       
   141     }
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CIMPSConnUiPresEventNotifierImp::HandleNWSessionSlotChangeL()
       
   146 // From PEC Engine MPEngNWSessionSlotObserver2
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 
       
   150 void CIMPSConnUiPresEventNotifierImp::HandleNWSessionSlotChangeL(
       
   151     CPEngNWSessionSlotNotifier2& /*aNotifier*/,
       
   152     CPEngNWSessionSlotEvent2& aEvent )
       
   153     {
       
   154     TIMPSPresenceServiceEvent appEvent;
       
   155     CnUiEventMapper::ConvertToAppEvent( aEvent.Event(), appEvent );
       
   156 
       
   157     TIMPSConnectionClient client;
       
   158     const CPEngNWSessionSlotID2* slotID = &aEvent.NWSessionSlotID();
       
   159 
       
   160     if ( 0 == slotID->AppId().Compare( KPEngAppIdIM() ) )
       
   161         {
       
   162         client = EIMPSConnClientIM;
       
   163         }
       
   164     else
       
   165         {
       
   166         client = EIMPSConnClientPEC;
       
   167         }
       
   168 
       
   169     NotifyObserversFromEvent( *slotID, client, appEvent );
       
   170     }
       
   171 
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CIMPSConnUiPresEventNotifierImp::HandleNWSessionSlotError()
       
   175 // From PEC Engine MPEngNWSessionSlotObserver2
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CIMPSConnUiPresEventNotifierImp::HandleNWSessionSlotError(
       
   179     TInt aError,
       
   180     CPEngNWSessionSlotNotifier2& /*aNotifier*/ )
       
   181     {
       
   182     StopAndNotifyObserversFromError( aError );
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CIMPSConnUiPresEventNotifierImp::DestroyCloseModelArray()
       
   187 //
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CIMPSConnUiPresEventNotifierImp::DestroyCloseModelArray( TAny* aObject )
       
   191     {
       
   192     reinterpret_cast< RPointerArray< CPEngNWSessionSlotID2 >* >( aObject )->ResetAndDestroy();
       
   193     }
       
   194 
       
   195 
       
   196 //  End of File
       
   197