commsfwsupport/commselements/serverden/src/sd_apiextensionregister.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2006-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 // SS_APIEXT_REGISTER.CPP
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <ecom/ecom.h>
       
    19 #include "sd_std.h"
       
    20 #include "sd_apiextension.h"
       
    21 #include "sd_apiextensionregister.h"
       
    22 #include <e32base.h>
       
    23 
       
    24 
       
    25 #ifdef _DEBUG
       
    26 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    27 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    28 _LIT(KSpecAssert_ElemSvrDenApiXRC, "ElemSvrDenApiXRC");
       
    29 #endif
       
    30 
       
    31 using namespace Den;
       
    32 //using namespace Messages;
       
    33 
       
    34 TInt CompareApiExtIdentifications(const TApiExtIdentification& aExtItfId1, const TApiExtIdentification& aExtItfId2)
       
    35 	{
       
    36 	return Mem::Compare(aExtItfId1.Ptr(), sizeof(TInt)+sizeof(TInt), aExtItfId2.Ptr(), sizeof(TInt)+sizeof(TInt));
       
    37 	}
       
    38 
       
    39 TApiExtRegister::~TApiExtRegister()
       
    40 	{
       
    41 	//We should not have anything to cleanup here.
       
    42 	//Every session and subsession must close all
       
    43 	//remaining extensions from their destructors.
       
    44 	__ASSERT_DEBUG(iApiExtList.Count()==0, User::Panic(KSpecAssert_ElemSvrDenApiXRC, 1)); //Panic in debug
       
    45 	iApiExtList.Close();
       
    46 	}
       
    47 
       
    48 void TApiExtRegister::CleanupInterfaceRegistration(TAny* aSelf)
       
    49 	{
       
    50 	TApiExtRegister* reg = static_cast<TApiExtRegister*>(aSelf);
       
    51 	__ASSERT_DEBUG(reg->iClenupInfoExtItfId, User::Panic(KSpecAssert_ElemSvrDenApiXRC, 2)); //We have just added..
       
    52 	TLinearOrder<TApiExtIdentification> order(CompareApiExtIdentifications);
       
    53 	TInt index = reg->iApiExtList.FindInOrder(*reg->iClenupInfoExtItfId, order);
       
    54 	__ASSERT_DEBUG(index!=KErrNotFound, User::Panic(KSpecAssert_ElemSvrDenApiXRC, 3)); //We have just added..
       
    55 	reg->iApiExtList.Remove(index);
       
    56 	}
       
    57 
       
    58 void TApiExtRegister::CleanupInterfaceDeregistrationPushL(const TApiExtIdentification& aExtItfId)
       
    59 	{
       
    60 	//Never call this fn twice without a Pop() in between
       
    61 	TLinearOrder<TApiExtIdentification> order(CompareApiExtIdentifications);
       
    62 	TInt index = iApiExtList.FindInOrder(aExtItfId, order);
       
    63 	__ASSERT_DEBUG(index!=KErrNotFound, User::Panic(KSpecAssert_ElemSvrDenApiXRC, 4)); //We have just added..
       
    64 	iClenupInfoExtItfId = &iApiExtList[index];
       
    65 	CleanupStack::PushL(TCleanupItem(TApiExtRegister::CleanupInterfaceRegistration, this));
       
    66 	}
       
    67 
       
    68 void TApiExtRegister::RegisterOpenInterfaceLC(const TApiExtIdentification& aExtItfId)
       
    69 	{
       
    70 	//Never call this fn twice without a Pop() in between
       
    71 	TLinearOrder<TApiExtIdentification> order(CompareApiExtIdentifications);
       
    72 	TInt index = iApiExtList.FindInOrder(aExtItfId, order);
       
    73 	User::LeaveIfError(index!=KErrNotFound? KErrAlreadyExists : KErrNone);
       
    74 	iApiExtList.InsertInOrderL(aExtItfId, order);
       
    75 	CleanupInterfaceDeregistrationPushL(aExtItfId);
       
    76 	}
       
    77 
       
    78 void TApiExtRegister::DeregisterClosedInterface(const TApiExtIdentification& aExtItfId)
       
    79 	{
       
    80 	TLinearOrder<TApiExtIdentification> order(CompareApiExtIdentifications);
       
    81 	TInt index = iApiExtList.FindInOrder(aExtItfId, order);
       
    82 	__ASSERT_DEBUG(index!=KErrNotFound, User::Panic(KSpecAssert_ElemSvrDenApiXRC, 5)); //UDEB
       
    83 	if (index!=KErrNotFound)
       
    84 		{
       
    85 		iApiExtList.Remove(index);
       
    86 		}
       
    87 	}
       
    88 
       
    89 TBool TApiExtRegister::IsOpened(const TApiExtIdentification& aExtItfId)
       
    90 	{
       
    91 	TLinearOrder<TApiExtIdentification> order(CompareApiExtIdentifications);
       
    92 	return KErrNotFound==iApiExtList.FindInOrder(aExtItfId, order)?
       
    93 		EFalse : ETrue;
       
    94 	}
       
    95 
       
    96 const TApiExtIdentification& TApiExtRegister::operator[](TInt aIndex)
       
    97 	{
       
    98 	__ASSERT_DEBUG(aIndex>=0 && aIndex<iApiExtList.Count(), User::Panic(KSpecAssert_ElemSvrDenApiXRC, 6));
       
    99 	return iApiExtList[aIndex];
       
   100 	}
       
   101 
       
   102