datacommsserver/esockserver/ssock/ss_subconnprov.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 SS_SUBCONNPROV.CPP
       
    18 */
       
    19 #include "ss_subconnprov.h"
       
    20 
       
    21 
       
    22 #include <ss_std.h>
       
    23 #include <cs_subconevents.h>
       
    24 #include <comms-infras/ss_mcprnodemessages.h>
       
    25 #include <comms-infras/ss_log.h>
       
    26 #include <es_ini.h>
       
    27 #include <comms-infras/ss_connprov.h>
       
    28 #include <ss_glob.h>
       
    29 #include <comms-infras/ss_subconnflow.h>
       
    30 
       
    31 #include <comms-infras/ss_nodemessages_subconn.h>
       
    32 #include <comms-infras/ss_nodemessages_factory.h>
       
    33 
       
    34 #include <elements/nm_signatures.h>
       
    35 #include <comms-infras/ss_nodemessages_legacy.h>
       
    36 
       
    37 
       
    38 #ifdef _DEBUG
       
    39 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    40 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    41 _LIT(KSpecAssert_ESockSSocksbcnpr, "ESockSSocksbcnpr");
       
    42 #endif
       
    43 
       
    44 using namespace ESock;
       
    45 using namespace Messages;
       
    46 using namespace MeshMachine;
       
    47 using namespace Factories;
       
    48 
       
    49 
       
    50 EXPORT_C CSubConnectionFactoryContainer* CSubConnectionFactoryContainer::NewL()
       
    51 /** Create a new instance of a sub-connection factory container
       
    52 
       
    53 @exception Leaves in out of memory conditions
       
    54 @return Pointer to new instance of a sub-connection factory container
       
    55 */
       
    56 	{
       
    57 	TCFLegacyMessage::RegisterL();
       
    58 	return new (ELeave) CSubConnectionFactoryContainer();
       
    59 	}
       
    60 
       
    61 void CSubConnectionFactoryContainer::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& /* aRecipient */, TSignatureBase& aMessage)
       
    62 	{
       
    63 	if (aMessage.IsMessage<TCFFactory::TFindOrCreatePeer>())
       
    64 		{
       
    65 		TCFFactory::TFindOrCreatePeer& msg = message_cast<TCFFactory::TFindOrCreatePeer>(aMessage);
       
    66 		CCommsFactoryBase* factory = static_cast<CCommsFactoryBase*>(FindOrCreateFactoryL(msg.iUid));
       
    67 	    CSubConnectionProviderBase* provider = static_cast<CSubConnectionProviderBase*>(factory->FindOrCreateObjectL(*(msg.iQuery)));
       
    68 	    if (provider)
       
    69 	    	{
       
    70      	    CleanupStack::PushL(provider);
       
    71 	    	// Second parameters is the Flags to be used for this Node:
       
    72 	    	//	check if a "Default DataClient" was requested
       
    73 	    	//	and set Flags accordingly     	    
       
    74 	    	const TDefaultSCPRFactoryQuery& query = static_cast<const TDefaultSCPRFactoryQuery&>(*(msg.iQuery));
       
    75 	    	TCFClientType::TFlags flags = ((TSubConnOpen::TSubConnType)query.iSCPRType == TSubConnOpen::EAttachToDefault) ? 
       
    76 	    					      TCFClientType::EDefault : (TCFClientType::TFlags) 0;
       
    77  		    provider->AddClientL(address_cast<TNodeId>(aSender), TClientType(TCFClientType::ECtrlProvider, flags));
       
    78  	#ifndef __GCCXML__
       
    79  		    RClientInterface::OpenPostMessageClose(Id(), aSender, TCFFactory::TPeerFoundOrCreated(provider->Id(), flags).CRef());
       
    80  	#endif
       
    81      	    CleanupStack::Pop(provider);
       
    82 	    	}
       
    83 	    else
       
    84             {
       
    85 			RClientInterface::OpenPostMessageClose(Id(), aSender, TCFFactory::TPeerFoundOrCreated(TNodeId::NullId(), 0).CRef());
       
    86             }
       
    87 		aMessage.ClearMessageId();
       
    88 		}
       
    89 	else
       
    90 		{
       
    91 		NM_LOG_START_BLOCK(KESockSubConnectionTag, _L8("CSubConnectionFactoryContainer:ReceivedL"));
       
    92 		NM_LOG((KESockSubConnectionTag, _L8("ERROR: KErrNotSupported [this=0x%08x] "), this));
       
    93 		NM_LOG_MESSAGE(KESockSubConnectionTag, aMessage);
       
    94 		NM_LOG_END_BLOCK(KESockSubConnectionTag, _L8("CSubConnectionFactoryContainer:ReceivedL"));
       
    95 
       
    96 		__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockSSocksbcnpr, 1)); //For debug configurations
       
    97 		User::Leave(KErrNotSupported); //For release configurations
       
    98 		}
       
    99 	}
       
   100 
       
   101 
       
   102 CSubConnectionFactoryContainer::~CSubConnectionFactoryContainer()
       
   103 /** Empty Sub-connection factory container destructor */
       
   104 	{
       
   105 	TCFLegacyMessage::DeRegister();
       
   106 	LOG_NODE_DESTROY(KESockSubConnectionTag, CSubConnectionFactoryContainer);
       
   107 	}
       
   108 
       
   109 CSubConnectionFactoryContainer::CSubConnectionFactoryContainer()
       
   110 :CCommsFactoryContainer((CCommsFactoryContainer::TContaineeType)CSubConnectionFactoryContainer::EId)
       
   111 /** Empty Sub-connection factory container constructor */
       
   112 	{
       
   113 	LOG_NODE_CREATE(KESockSubConnectionTag, CSubConnectionFactoryContainer);
       
   114 	}
       
   115 
       
   116 CSubConnectionProviderFactoryBase* CSubConnectionFactoryContainer::Factory( TInt aIndex ) const
       
   117 	{
       
   118 	return static_cast<CSubConnectionProviderFactoryBase*>(CCommsFactoryContainer::Factory(aIndex));
       
   119 	}
       
   120 
       
   121 //==========================================================
       
   122 
       
   123 EXPORT_C CSubConnectionProviderFactoryBase::~CSubConnectionProviderFactoryBase()
       
   124 /** Empty Sub-connection factory base destructor */
       
   125 	{
       
   126 	}
       
   127 
       
   128 EXPORT_C CSubConnectionProviderFactoryBase::CSubConnectionProviderFactoryBase(TUid aFactoryId, CSubConnectionFactoryContainer& aParentContainer)
       
   129 /** Sub-connection provider factory constructor
       
   130 
       
   131 @param aFactoryId Unique Integer Identifier of the sub-connection provider factory
       
   132 @param aParentContainer Container to add the factory to */
       
   133 	: CCommsFactoryBase(aFactoryId, aParentContainer)
       
   134 	{
       
   135 	}
       
   136 
       
   137 EXPORT_C ACommsFactoryNodeId* CSubConnectionProviderFactoryBase::DoFindOrCreateObjectL(TFactoryQueryBase& aQuery)
       
   138 /** Default implementation of the Find or Create functionality
       
   139 
       
   140 @param aQuery The match/creation criteria for the sub-connection to be returned
       
   141 @return The sub-connection provider found or created
       
   142 @exception KErrNoMemory in out of memeory conditions, other system errors based on the specialised factory */
       
   143 	{
       
   144 	ACommsFactoryNodeId* subConnProvider = static_cast<ACommsFactoryNodeId*>(FindObject(aQuery));
       
   145 	if (!subConnProvider)
       
   146 		{
       
   147 		const TDefaultSCPRFactoryQuery& query = static_cast<const TDefaultSCPRFactoryQuery&>(aQuery);
       
   148 		__ASSERT_DEBUG(!query.iControlProvider.IsNull(), User::Panic(KSpecAssert_ESockSSocksbcnpr, 2));
       
   149 		subConnProvider = CreateL(aQuery);
       
   150 		}
       
   151 	return subConnProvider;
       
   152 	}
       
   153 
       
   154 EXPORT_C ACommsFactoryNodeId* CSubConnectionProviderFactoryBase::DoCreateObjectL(TFactoryQueryBase& /*aQuery*/)
       
   155 	{
       
   156 	__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockSSocksbcnpr, 3));
       
   157 	User::Leave(KErrNotSupported);
       
   158 	return NULL;
       
   159 	}
       
   160 
       
   161 EXPORT_C ACommsFactoryNodeId* CSubConnectionProviderFactoryBase::CreateL(TFactoryQueryBase& aQuery)
       
   162 /** Create an instance of a sub-connection provider
       
   163 
       
   164 @param aConnectionProviderBase The connection provider for the sub-connection
       
   165 @param aSubConnType The sub-connection type to create, e.g. attach to default or create a new one
       
   166 @return The new sub-connection provider created
       
   167 @exception KErrNoMemory in out of memeory conditions, other system errors based on the specialised factory */
       
   168 	{
       
   169 	CSubConnectionProviderBase* provider = static_cast<CSubConnectionProviderBase*>(DoCreateObjectL(aQuery));
       
   170 	CleanupStack::PushL(provider);
       
   171 
       
   172 	const TDefaultSCPRFactoryQuery& query = static_cast<const TDefaultSCPRFactoryQuery&>(aQuery);	
       
   173 
       
   174 	TFactoryObjectEntry& entry = AddManagedObjectL(*provider);
       
   175 	entry.iFlag |= query.iSCPRType;
       
   176 
       
   177 	CleanupStack::Pop(provider);
       
   178 
       
   179 	return provider;
       
   180 	}
       
   181 
       
   182 //=============================================================================
       
   183 // Downcalls from control client (Implemented via pure virtual methods below)
       
   184 //=============================================================================
       
   185 
       
   186 EXPORT_C CSubConnectionProviderBase::CSubConnectionProviderBase(CSubConnectionProviderFactoryBase& aFactory,
       
   187                                                                 const MeshMachine::TNodeActivityMap& aActivityMap)
       
   188 : CMMCommsProviderBase(aFactory,aActivityMap)
       
   189 /** Constructor
       
   190 
       
   191 @param aFactory he factory that created and owns this object
       
   192 @param aConnProvider Connection Provider the sub-connection provider is a member of */
       
   193 	{
       
   194 	LOG(ESockLog::Printf(KESockCtrlFactTag, _L("CSubConnectionProviderBase %08x:\tcreated [%d], factory Uid %x"),
       
   195 						 this, sizeof(CSubConnectionProviderBase), Factory().Uid().iUid));
       
   196 	}
       
   197 
       
   198 
       
   199 EXPORT_C void CSubConnectionProviderBase::NotifyClientsL(const CSubConNotificationEvent& aEvent)
       
   200     {
       
   201 	LOG(ESockLog::Printf(KESockCtrlFactTag, _L("[%08x] CSubConnectionProviderBase::NotifyClientsL ([%d])"),
       
   202 					 this, aEvent.Id()));
       
   203     TClientIter<TDefaultClientMatchPolicy> iter = GetClientIter<TDefaultClientMatchPolicy>(TClientType(TCFClientType::ECtrl));
       
   204     if (iter[0] == NULL)
       
   205         {
       
   206         delete &aEvent;
       
   207         return;
       
   208         }
       
   209 
       
   210 	CRefCountOwnedSubConNotification* eventNode = new (ELeave) CRefCountOwnedSubConNotification(&aEvent);
       
   211     RNodeInterface* ctl = NULL;
       
   212 	while ((ctl = iter++) != NULL)
       
   213 		{
       
   214 		ctl->PostMessage(Id(), TCFSubConnControlClient::TSubConnNotification(eventNode).CRef());
       
   215 		eventNode->Open();
       
   216 		}
       
   217     }
       
   218 
       
   219 EXPORT_C CSubConnectionProviderBase::~CSubConnectionProviderBase()
       
   220 /** Destructor */
       
   221 	{
       
   222 #ifndef SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
   223 	if(!iParameterBundle.IsNull())
       
   224 		{
       
   225 		iParameterBundle.Close();
       
   226 		}
       
   227 #endif // SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
   228 	LOG(ESockLog::Printf(KESockCtrlFactTag, _L("~CSubConnectionProviderBase %08x:\tFactory Uid %x"),
       
   229 						 this, Factory().Uid().iUid));
       
   230 	}
       
   231 
       
   232