datacommsserver/esockserver/ssock/ss_tiermanager.cpp
changeset 0 dfb7c4ff071f
child 14 4ccf8e394726
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2005-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_METACONNPROV.CPP
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include <comms-infras/ss_log.h>
       
    23 #include <elements/factory.h>
       
    24 #include <comms-infras/ss_connselect.h>
       
    25 #include "ss_flowrequest.h"
       
    26 #include <ss_glob.h>
       
    27 #include <comms-infras/ss_thread.h>
       
    28 #include <comms-infras/ss_roles.h>
       
    29 #include <in_sock.h> //KAfInet
       
    30 #include <comms-infras/ss_metaconnprov.h>
       
    31 #include <comms-infras/ss_nodemessages.h>
       
    32 #include <comms-infras/ss_nodemessages_internal_esock.h>
       
    33 #include <comms-infras/ss_nodemessages_factory.h>
       
    34 #include <comms-infras/ss_nodemessages_tiermanagerfactory.h>
       
    35 #include <comms-infras/ss_tiermanager_internal.h>
       
    36 #include <comms-infras/ss_tiermanagerutils.h>
       
    37 
       
    38 
       
    39 #ifdef _DEBUG
       
    40 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    41 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    42 _LIT(KSpecAssert_ESockSSockstrmng, "ESockSSockstrmng");
       
    43 #endif
       
    44 
       
    45 using namespace ESock;
       
    46 using namespace Messages;
       
    47 using namespace Factories;
       
    48 
       
    49 //
       
    50 
       
    51 //CTierManagerBase
       
    52 EXPORT_C CTierManagerBase::CTierManagerBase(CTierManagerFactoryBase& aFactory,
       
    53                                             const MeshMachine::TNodeActivityMap& aActivityMap)
       
    54 :	ACommsFactoryNodeId(aFactory),
       
    55 	ACFMMNodeBase(aActivityMap, ANodeId::Id())
       
    56 /**
       
    57 Constructor for CTierManagerBase
       
    58 @param aFactory Parent container for the tier manager
       
    59 @param aActivityMap Activity map for the tier manager
       
    60 */
       
    61 	{
       
    62 	LOG(ESockLog::Printf(KESockTierTag, _L("CTierManagerBase 0x%08x:\tcreated, factory Uid 0x%08x"),
       
    63 		 this, Factory().Uid().iUid));
       
    64 	}
       
    65 
       
    66 EXPORT_C CTierManagerBase::~CTierManagerBase()
       
    67 /**
       
    68 Destructor for CTierManagerBase.
       
    69 */
       
    70 	{
       
    71 	iMetaConnectionProviders.Reset();
       
    72 	}
       
    73 
       
    74 EXPORT_C void CTierManagerBase::AddMetaConnectionProviderL(const CMetaConnectionProviderBase* aMetaConnectionProvider)
       
    75 	{
       
    76 	iMetaConnectionProviders.AppendL(aMetaConnectionProvider);
       
    77 	}
       
    78 
       
    79 EXPORT_C void CTierManagerBase::RemoveMetaConnectionProvider(const CMetaConnectionProviderBase* aMetaConnectionProvider)
       
    80 	{
       
    81 	TInt index = iMetaConnectionProviders.Find(aMetaConnectionProvider);
       
    82 	if (index != KErrNotFound)
       
    83 		{
       
    84 		iMetaConnectionProviders.Remove(index);
       
    85 		}
       
    86 	}
       
    87 
       
    88 EXPORT_C NetInterfaces::TInterfaceControl* CTierManagerBase::FetchNodeInterfaceControlL(TInt aInterfaceId)
       
    89 	{
       
    90 	return ACFMMNodeBase::FetchNodeInterfaceControlL (aInterfaceId);
       
    91 	}
       
    92 
       
    93 EXPORT_C TUid CTierManagerBase::TierId() const
       
    94 	{
       
    95 	TUid temp = TierImplId();
       
    96 	return static_cast<CTierManagerFactoryBase&>(Factory()).TierTypeId();
       
    97 	}
       
    98 
       
    99 EXPORT_C TUid CTierManagerBase::TierImplId() const
       
   100 	{
       
   101 	return Factory().Uid();
       
   102 	}
       
   103 //
       
   104 //Factories - Container
       
   105 CTierManagerFactoryContainer* CTierManagerFactoryContainer::NewL()
       
   106 	{
       
   107 	CTierManagerFactoryContainer* container = new (ELeave) CTierManagerFactoryContainer();
       
   108 	return container;
       
   109 	}
       
   110 
       
   111 void CTierManagerFactoryContainer::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage)
       
   112 	{	
       
   113 	if (aMessage.IsMessage<TCFInternalEsock::TCreateCSR>())
       
   114 		{
       
   115 		TCFInternalEsock::TCreateCSR& msg = message_cast<TCFInternalEsock::TCreateCSR>(aMessage);
       
   116 		// Maps Tier to ImplId For ECOM since ImplId is used in Factory
       
   117 		CommsDat::CMDBSession* dbs = CommsDat::CMDBSession::NewLC(KCDVersion1_2);
       
   118 		msg.iUid= TierManagerUtils::MapTierIdtoTierImplIdL(msg.iUid, *dbs);
       
   119 		CleanupStack::PopAndDestroy(dbs);
       
   120 		CCommsFactoryBase* factory = static_cast<CCommsFactoryBase*>(FindOrCreateFactoryL(msg.iUid));
       
   121 		TAlwaysFindFactoryQuery query;
       
   122 		CSelectionRequest* sr = CSelectionRequest::NewL(address_cast<TNodeId>(aSender), factory->FindOrCreateObjectL(query)->Id());
       
   123 		RClientInterface::OpenPostMessageClose(Id(), aSender, TCFInternalEsock::TCSRCreated(sr->Id()).CRef());
       
   124 		aMessage.ClearMessageId();
       
   125 		}
       
   126 	else if (aMessage.IsMessage<TCFFactory::TFindOrCreatePeer>())
       
   127 		{
       
   128 		TCFFactory::TFindOrCreatePeer& msg = message_cast<TCFFactory::TFindOrCreatePeer>(aMessage);
       
   129 		// Maps Tier to ImplId For ECOM since ImplId is used in Factory
       
   130 		CommsDat::CMDBSession* dbs = CommsDat::CMDBSession::NewLC(KCDVersion1_2);
       
   131 		msg.iUid= TierManagerUtils::MapTierIdtoTierImplIdL(msg.iUid, *dbs);
       
   132 		CleanupStack::PopAndDestroy(dbs);
       
   133 		CCommsFactoryContainer::ReceivedL(aSender, aRecipient, msg);
       
   134 		}
       
   135 	else
       
   136 		{
       
   137 		NM_LOG_START_BLOCK(KESockTierTag, _L8("CTierManagerFactoryContainer::ReceivedL"));
       
   138 		NM_LOG((KESockTierTag, _L8("ERROR: KErrNotSupported [this=0x%08x]"), this));
       
   139 		NM_LOG_MESSAGE_EXT(KESockTierTag, aMessage, _L8("Msg:"));
       
   140 		NM_LOG_ADDRESS_EXT(KESockTierTag, aSender, _L8("From:"));
       
   141 		NM_LOG_END_BLOCK(KESockTierTag, KNullDesC8);
       
   142 
       
   143 		__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockSSockstrmng, 1)); //For debug configurations
       
   144 		User::Leave(KErrNotSupported); //For release configurations
       
   145 		}
       
   146 
       
   147 	}
       
   148 
       
   149 
       
   150 CTierManagerFactoryBase* CTierManagerFactoryContainer::Factory(TInt aIndex) const
       
   151 	{
       
   152 	return static_cast<CTierManagerFactoryBase*>(CCommsFactoryContainer::Factory(aIndex));
       
   153 	}
       
   154 
       
   155 EXPORT_C CTierManagerFactoryContainer::~CTierManagerFactoryContainer()
       
   156 /** Tier manager factory container destructor */
       
   157 	{
       
   158 	LOG_NODE_DESTROY(KESockTierTag, CTierManagerFactoryContainer);
       
   159 	}
       
   160 
       
   161 CTierManagerFactoryContainer::CTierManagerFactoryContainer()
       
   162 :CCommsFactoryContainer((CCommsFactoryContainer::TContaineeType)CTierManagerFactoryContainer::EId)
       
   163 /** Tier manager factory container constructor */
       
   164 	{
       
   165 	LOG_NODE_CREATE(KESockTierTag, CTierManagerFactoryContainer);
       
   166 	}
       
   167 
       
   168 
       
   169 
       
   170 //
       
   171 //Factories
       
   172 EXPORT_C CTierManagerFactoryBase::CTierManagerFactoryBase(TUid aTierTypeId, TUid aFactoryUid, CTierManagerFactoryContainer& aParentContainer)
       
   173 :	CCommsFactoryBase(aFactoryUid,aParentContainer), iTierTypeId(aTierTypeId)
       
   174 	{
       
   175 // derived classes must do this for best info	LOG(ESockLog::Printf(KESockMetaConnectionTag, _L("CTierManagerFactoryBase %08x:\tCTierManagerFactoryBase(%08x)"), this, aFactoryUid.iUid));
       
   176 	}
       
   177 
       
   178 EXPORT_C CTierManagerFactoryBase::~CTierManagerFactoryBase()
       
   179 /** Tier manager factory base destructor */
       
   180 	{
       
   181 	LOG(ESockLog::Printf(KESockMetaConnectionTag, _L("CTierManagerFactoryBase %08x:\t~CTierManagerFactoryBase()"), this));
       
   182 	}
       
   183 
       
   184 EXPORT_C ACommsFactoryNodeId* CTierManagerFactoryBase::DoCreateObjectL(TFactoryQueryBase& /* aQuery */)
       
   185 	{
       
   186 	__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockSSockstrmng, 2));
       
   187 	User::Leave(KErrNotSupported);
       
   188 	return NULL;
       
   189 	}
       
   190 	
       
   191 EXPORT_C ACommsFactoryNodeId* CTierManagerFactoryBase::DoFindOrCreateObjectL(TFactoryQueryBase& aQuery)
       
   192 	{
       
   193 	ACommsFactoryNodeId* tiermgrobject = static_cast<ACommsFactoryNodeId*>(FindObject(aQuery));
       
   194 	if (tiermgrobject == NULL)
       
   195 		{
       
   196 		tiermgrobject = CreateObjectL (aQuery);
       
   197 		TlsGlobals::Get().AddPersistentItf(tiermgrobject->Id()); //@TODO: global lookup (TLS)! Remove when factories have proper getter functions.
       
   198 		}
       
   199 	return tiermgrobject;
       
   200 	}
       
   201 
       
   202 EXPORT_C TUid CTierManagerFactoryBase::TierTypeId() const
       
   203 	{
       
   204 	return iTierTypeId;
       
   205 	}
       
   206