commsfwsupport/commselements/NetSubscribe/src/NetSubscribe.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 
       
    21 #include "NetPSSignal.h"
       
    22 
       
    23 using namespace NetSubscribe;
       
    24 
       
    25 /**
       
    26  * @internalTechnology
       
    27  */
       
    28 EXPORT_C void TEvent::SubscribeL(CNetSubscribe& aSubscribe, const SSignalId& aSignalId )
       
    29 	{
       
    30 	TEventClientData data( *this );
       
    31 	aSubscribe.RegisterSignalL( data, aSignalId );
       
    32 	};
       
    33 
       
    34 /**
       
    35  * @internalTechnology
       
    36  */
       
    37 EXPORT_C void TEvent::Cancel(CNetSubscribe& aSubscribe)
       
    38 	{
       
    39 	aSubscribe.DeRegisterSignal( this );
       
    40 	}
       
    41 
       
    42 /**
       
    43  * @internalTechnology
       
    44  */
       
    45 EXPORT_C CNetSubscribe* CNetSubscribe::NewL( const Meta::STypeId& aTransportId )
       
    46 	{
       
    47 	if ( aTransportId.iUid.iUid != KTransportUid )
       
    48 		{
       
    49 		User::Leave(KErrNotFound);
       
    50 		}
       
    51 	
       
    52 	CNetSubscribe* newInst = NULL;
       
    53 		
       
    54 	switch (aTransportId.iType)
       
    55 		{
       
    56 		case EPublishSubscribe:
       
    57 			newInst = new(ELeave)CPSSubscribe();
       
    58 			break;
       
    59 		default:
       
    60 			User::Leave(KErrNotFound);
       
    61 		}
       
    62 	return newInst;
       
    63 	}
       
    64 
       
    65 /**
       
    66  * @internalTechnology
       
    67  */
       
    68 CNetSubscribe::CNetSubscribe()
       
    69 	{
       
    70 	}
       
    71 
       
    72 /**
       
    73  * @internalTechnology
       
    74  */
       
    75 EXPORT_C CNetSubscribe::~CNetSubscribe()
       
    76 	{
       
    77 	while ( iSignals.Count() )
       
    78 		{
       
    79 		TInt n = iSignals.Count() - 1;
       
    80 		XSignal* pSignal = iSignals[n];
       
    81 		delete pSignal;
       
    82 		iSignals.Remove(n);
       
    83 		}
       
    84 	iSignals.Close();
       
    85 	}
       
    86 
       
    87 /**
       
    88  * @internalTechnology
       
    89  */
       
    90 void CNetSubscribe::DeRegisterSignal(TEventBase* aEvent)
       
    91 	{
       
    92 	TInt count = iSignals.Count();
       
    93 	for (TInt n = count - 1; n >= 0; n--)
       
    94 		{
       
    95 		XSignal* pSignal = iSignals[n];
       
    96 		if ( pSignal->DeRegisterClient( aEvent ) == 0 )
       
    97 			{
       
    98 			iSignals.Remove(n);
       
    99 			count--;
       
   100 			delete pSignal;
       
   101 			}
       
   102 		}
       
   103 	}
       
   104 
       
   105 /**
       
   106  * @internalTechnology
       
   107  */
       
   108 void CNetSubscribe::RegisterSignalL(TEventClientData& aData, const SSignalId& aSignalId )
       
   109 	{
       
   110 	TInt count = iSignals.Count();
       
   111 	for (TInt n = 0; n < count;n++)
       
   112 		{
       
   113 		XSignal* pSignal = iSignals[n];
       
   114 		if ( aSignalId == pSignal->GetSignalId() )
       
   115 			{
       
   116 			pSignal->RegisterClientL( aData );
       
   117 			return;
       
   118 			}
       
   119 		}
       
   120 	RegisterNewSignalL(aData, aSignalId);
       
   121 	}
       
   122 
       
   123