datacommsserver/esockserver/MobilityCoreProviders/src/mobilitycpr.cpp
changeset 0 dfb7c4ff071f
child 18 9644881fedd0
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2007-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 // Mobility Connection Provider implementation
       
    15 // 
       
    16 //
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent
       
    22 */
       
    23 
       
    24 #include <comms-infras/corecprstates.h>
       
    25 #include <comms-infras/corecpractivities.h>
       
    26 #include "mobilitycpr.h"
       
    27 #include <comms-infras/ss_log.h>
       
    28 #include <comms-infras/api_ext_list.h>
       
    29 
       
    30 #include <comms-infras/ss_msgintercept.h>
       
    31 
       
    32 
       
    33 #ifdef _DEBUG
       
    34 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    35 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    36 _LIT(KSpecAssert_ESockMbCrCPR, "ESockMbCrCPR");
       
    37 #endif
       
    38 
       
    39 #ifdef SYMBIAN_TRACE_ENABLE
       
    40 #define KIPCprTag KESockConnectionTag
       
    41 // _LIT8(KIPCprSubTag, "mobilitycpr");
       
    42 #endif // SYMBIAN_TRACE_ENABLE
       
    43 
       
    44 using namespace ESock;
       
    45 using namespace NetStateMachine;
       
    46 using namespace Messages;
       
    47 using namespace MeshMachine;
       
    48 
       
    49 //We reserve space for two preallocated activities that may start concurrently on the CPR
       
    50 //node: destroy and data client stop.
       
    51 static const TUint KDefaultMaxPreallocatedActivityCount = 2;
       
    52 static const TUint KMaxPreallocatedActivitySize = sizeof(MeshMachine::CNodeRetryParallelActivity) + sizeof(MeshMachine::APreallocatedOriginators<4>);
       
    53 static const TUint KMobilityCPRPreallocatedActivityBufferSize = KDefaultMaxPreallocatedActivityCount * KMaxPreallocatedActivitySize;
       
    54 
       
    55 //-=========================================================
       
    56 //
       
    57 // CMobilityConnectionProvider methods
       
    58 //
       
    59 //-=========================================================
       
    60 EXPORT_C CMobilityConnectionProvider* CMobilityConnectionProvider::NewL(CConnectionProviderFactoryBase& aFactory, const MeshMachine::TNodeActivityMap& aActivityMap)
       
    61     {
       
    62     CMobilityConnectionProvider* provider = new (ELeave) CMobilityConnectionProvider(aFactory, aActivityMap);
       
    63     CleanupStack::PushL(provider);
       
    64     provider->ConstructL(KMobilityCPRPreallocatedActivityBufferSize);
       
    65     CleanupStack::Pop(provider);
       
    66 	return provider;
       
    67     }
       
    68 
       
    69 EXPORT_C CMobilityConnectionProvider::CMobilityConnectionProvider(CConnectionProviderFactoryBase& aFactory, const MeshMachine::TNodeActivityMap& aActivityMap)
       
    70 :	CCoreConnectionProvider(aFactory, aActivityMap),
       
    71 	TIfStaticFetcherNearestInHierarchy(this)
       
    72     {
       
    73     LOG_NODE_CREATE(KIPCprTag, CMobilityConnectionProvider);
       
    74     }
       
    75 
       
    76 EXPORT_C CMobilityConnectionProvider::~CMobilityConnectionProvider()
       
    77     {
       
    78     LOG_NODE_DESTROY(KIPCprTag, CMobilityConnectionProvider);
       
    79     }
       
    80 
       
    81 EXPORT_C void CMobilityConnectionProvider::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage)
       
    82 	{
       
    83 	ESOCK_DEBUG_MESSAGE_INTERCEPT(aSender, aMessage, aRecipient);
       
    84 	CCoreConnectionProvider::ReceivedL(aSender, aRecipient, aMessage);
       
    85 	}
       
    86 
       
    87 EXPORT_C void CMobilityConnectionProvider::ReturnInterfacePtrL(AMobilityProtocolReq*& aInterface)
       
    88 	{
       
    89 	aInterface = this;
       
    90 	}
       
    91 
       
    92 EXPORT_C void CMobilityConnectionProvider::OpenExtensionInterface(TSubSessionUniqueId aClientId, const Messages::TRuntimeCtxId& aControlClient, CCommsApiExtResponder* aResponder)
       
    93 	{
       
    94 	__ASSERT_DEBUG(aResponder, User::Panic(KSpecAssert_ESockMbCrCPR, 1)); //Responder must be valid here
       
    95 	__ASSERT_DEBUG(aClientId != 0, User::Panic(KSpecAssert_ESockMbCrCPR, 2)); //Client id must be valid here.
       
    96 
       
    97 	if (iMobilityActivity)
       
    98 		{
       
    99 		//Only one mobility client is supported by this implementation,
       
   100 		//and this client has already opened the interface.
       
   101 		CCommsApiExtResponder::Complete(aResponder,KErrInUse);
       
   102 		return;
       
   103 		}
       
   104 
       
   105 	TCFMobilityProvider::TStartMobility msg(aResponder, aClientId);
       
   106 	__ASSERT_DEBUG_NO_LEAVE(ReceivedL(aControlClient, Id(), msg)); //ReceivedL can never leave on MM nodes
       
   107 
       
   108 	if (iMobilityActivity==NULL)
       
   109 		{
       
   110 		CCommsApiExtResponder::Complete(aResponder,KErrNoMemory);
       
   111 		}
       
   112 	}
       
   113 
       
   114 EXPORT_C void CMobilityConnectionProvider::CloseExtensionInterface(TSubSessionUniqueId aClientId)
       
   115 	{
       
   116 	//Ignore all close requests for any other client than ours
       
   117 	if (iMobilityActivity==NULL || iMobilityActivity->iClientId!=aClientId)
       
   118 		{
       
   119 		return;
       
   120 		}
       
   121 
       
   122 	//The activity has no originators, cancel it explicitly
       
   123 	TNodeNullContext ctx(*this,iMobilityActivity);
       
   124 	iMobilityActivity->Cancel(ctx);
       
   125 	iMobilityActivity = NULL; //New mobility interface can be opened now
       
   126 	}
       
   127 
       
   128 EXPORT_C void CMobilityConnectionProvider::SubscribeForMessage(TSubSessionUniqueId aClientId, CCommsMobilitySrvResp* aRespExt)
       
   129 	{
       
   130 	__ASSERT_DEBUG(aRespExt, User::Panic(KSpecAssert_ESockMbCrCPR, 3)); //Responder must be valid here
       
   131 	//If the interface was opened successfuly, iMobilityActivity is set.
       
   132 	//It could only be cleared again if:
       
   133 	//1) The mobility activity generated or not handled received error message.
       
   134 	//But the activity is supposed to do that.
       
   135 	//2) The node received and is currently processing TDestroy before this
       
   136 	//activity was terminated, which can never happen, as the Control Client
       
   137 	//would cancel it before leaving or it would be aborted on the Control Client
       
   138 	//leaving (so before sending TDataClientIdle).
       
   139 	__ASSERT_DEBUG(iMobilityActivity, User::Panic(KSpecAssert_ESockMbCrCPR, 4));
       
   140 	__ASSERT_DEBUG(iMobilityActivity->iClientId==aClientId, User::Panic(KSpecAssert_ESockMbCrCPR, 5));
       
   141 	(void)(iMobilityActivity->iClientId==aClientId);   //keep compiler happy
       
   142 	iMobilityActivity->SetResponder(*aRespExt);
       
   143 	}
       
   144 
       
   145 EXPORT_C void CMobilityConnectionProvider::CancelSubscription(TSubSessionUniqueId aClientId)
       
   146 	{
       
   147 	//Ignore all cancel requests for any other client than ours
       
   148 	if (iMobilityActivity==NULL || iMobilityActivity->iClientId!=aClientId)
       
   149 		{
       
   150 		return;
       
   151 		}
       
   152 
       
   153 	__ASSERT_DEBUG(iMobilityActivity, User::Panic(KSpecAssert_ESockMbCrCPR, 7));
       
   154 	CCommsApiExtResponder::Complete(iMobilityActivity->iResponder, KErrCancel);
       
   155 	}
       
   156 
       
   157 EXPORT_C void CMobilityConnectionProvider::MigrateToPreferredCarrier(TSubSessionUniqueId aClientId)
       
   158 	{
       
   159 	//If the interface was opened successfuly, iMobilityActivity is set.
       
   160 	//It could only be cleared again if:
       
   161 	//1) The mobility activity generated or not handled received error message.
       
   162 	//But the activity is supposed to do that.
       
   163 	//2) The node received and is currently processing TDestroy before this
       
   164 	//activity was terminated, which can never happen, as the Control Client
       
   165 	//would cancel it before leaving or it would be aborted on the Control Client
       
   166 	//leaving (so before sending TDataClientIdle).
       
   167 	__ASSERT_DEBUG(iMobilityActivity, User::Panic(KSpecAssert_ESockMbCrCPR, 8));
       
   168 	__ASSERT_DEBUG(iMobilityActivity->iClientId==aClientId, User::Panic(KSpecAssert_ESockMbCrCPR, 9));
       
   169 	(void)(iMobilityActivity->iClientId==aClientId); //keep compiler happy
       
   170 	TCFMobilityProvider::TMigrationRequested msg;
       
   171 	__ASSERT_DEBUG_NO_LEAVE(ReceivedL(NodeId(), Id(), msg)); //ReceivedL can never leave on MM nodes
       
   172 	}
       
   173 
       
   174 EXPORT_C void CMobilityConnectionProvider::IgnorePreferredCarrier(TSubSessionUniqueId aClientId)
       
   175 	{
       
   176 	//If the interface was opened successfuly, iMobilityActivity is set.
       
   177 	//It could only be cleared again if:
       
   178 	//1) The mobility activity generated or not handled received error message.
       
   179 	//But the activity is supposed to do that.
       
   180 	//2) The node received and is currently processing TDestroy before this
       
   181 	//activity was terminated, which can never happen, as the Control Client
       
   182 	//would cancel it before leaving or it would be aborted on the Control Client
       
   183 	//leaving (so before sending TDataClientIdle).
       
   184 	__ASSERT_DEBUG(iMobilityActivity, User::Panic(KSpecAssert_ESockMbCrCPR, 10));
       
   185 	__ASSERT_DEBUG(iMobilityActivity->iClientId==aClientId, User::Panic(KSpecAssert_ESockMbCrCPR, 11));
       
   186 	(void)(iMobilityActivity->iClientId==aClientId); //keep compiler happy
       
   187 	TCFMobilityProvider::TMigrationRejected msg(KErrNone);
       
   188 	__ASSERT_DEBUG_NO_LEAVE(ReceivedL(NodeId(), Id(), msg)); //ReceivedL can never leave on MM nodes
       
   189 	}
       
   190 
       
   191 EXPORT_C void CMobilityConnectionProvider::NewCarrierAccepted(TSubSessionUniqueId aClientId)
       
   192 	{
       
   193 	//If the interface was opened successfuly, iMobilityActivity is set.
       
   194 	//It could only be cleared again if:
       
   195 	//1) The mobility activity generated or not handled received error message.
       
   196 	//But the activity is supposed to do that.
       
   197 	//2) The node received and is currently processing TDestroy before this
       
   198 	//activity was terminated, which can never happen, as the Control Client
       
   199 	//would cancel it before leaving or it would be aborted on the Control Client
       
   200 	//leaving (so before sending TDataClientIdle).
       
   201 	__ASSERT_DEBUG(iMobilityActivity, User::Panic(KSpecAssert_ESockMbCrCPR, 12));
       
   202 	__ASSERT_DEBUG(iMobilityActivity->iClientId==aClientId, User::Panic(KSpecAssert_ESockMbCrCPR, 13));
       
   203 	(void)(iMobilityActivity->iClientId==aClientId);//keep compiler happy
       
   204 	TCFMobilityProvider::TMigrationAccepted msg;
       
   205 	__ASSERT_DEBUG_NO_LEAVE(ReceivedL(NodeId(), Id(), msg)); //ReceivedL can never leave on MM nodes
       
   206 	}
       
   207 
       
   208 EXPORT_C void CMobilityConnectionProvider::NewCarrierRejected(TSubSessionUniqueId aClientId)
       
   209 	{
       
   210 	//If the interface was opened successfuly, iMobilityActivity is set.
       
   211 	//It could only be cleared again if:
       
   212 	//1) The mobility activity generated or not handled received error message.
       
   213 	//But the activity is supposed to do that.
       
   214 	//2) The node received and is currently processing TDestroy before this
       
   215 	//activity was terminated, which can never happen, as the Control Client
       
   216 	//would cancel it before leaving or it would be aborted on the Control Client
       
   217 	//leaving (so before sending TDataClientIdle).
       
   218 	__ASSERT_DEBUG(iMobilityActivity, User::Panic(KSpecAssert_ESockMbCrCPR, 14));
       
   219 	__ASSERT_DEBUG(iMobilityActivity->iClientId==aClientId, User::Panic(KSpecAssert_ESockMbCrCPR, 15));
       
   220 	(void)(iMobilityActivity->iClientId==aClientId);//keep compiler happy
       
   221 	TCFMobilityProvider::TMigrationRejected msg(KErrNone);
       
   222 	__ASSERT_DEBUG_NO_LEAVE(ReceivedL(NodeId(), Id(), msg)); //ReceivedL can never leave on MM nodes
       
   223 	}
       
   224 
       
   225