linklayerprotocols/tunnelnif/src/tunnelmcpr.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     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 // Tunnel MCPR
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <comms-infras/ss_log.h>
       
    24 #include <comms-infras/ss_tiermanagerutils.h>
       
    25 #include <comms-infras/coremcpractivities.h>
       
    26 #include <comms-infras/agentmcpractivities.h>
       
    27 #include "tunnelProvision.h"
       
    28 #include "TunnelAgentHandler.h"
       
    29 #include "tunnelmcpr.h"
       
    30 #include <comms-infras/ss_msgintercept.h>
       
    31 
       
    32 #define KTunnelMCprTag KESockMetaConnectionTag
       
    33 
       
    34 using namespace Messages;
       
    35 using namespace MeshMachine;
       
    36 using namespace ESock;
       
    37 using namespace NetStateMachine;
       
    38 using namespace MCprActivities;
       
    39 
       
    40 
       
    41 // No Bearer Activity
       
    42 namespace TunnelMCPRNoBearerActivity
       
    43 {
       
    44 DECLARE_DEFINE_NODEACTIVITY(ECFActivityNoBearer, activity, TCFControlProvider::TNoBearer)
       
    45 	FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingNoBearer, MeshMachine::TNoTag)
       
    46 	LAST_NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TSendBearer)
       
    47 NODEACTIVITY_END()
       
    48 }
       
    49 
       
    50 
       
    51 // Activity Map
       
    52 namespace TunnelMCprStates
       
    53 {
       
    54 DECLARE_DEFINE_ACTIVITY_MAP(stateMap)
       
    55    ACTIVITY_MAP_ENTRY(TunnelMCPRNoBearerActivity, activity)
       
    56 ACTIVITY_MAP_END_BASE(AgentMCprActivities, agentMCprActivities)
       
    57 } // namespace TunnelMCprStates
       
    58 
       
    59 //-=========================================================
       
    60 //
       
    61 //CTunnelMetaConnectionProvider implementation
       
    62 //
       
    63 //-=========================================================
       
    64 
       
    65 CTunnelMetaConnectionProvider* CTunnelMetaConnectionProvider::NewL(ESock::CMetaConnectionProviderFactoryBase& aFactory, const ESock::TProviderInfo& aProviderInfo)
       
    66     {
       
    67     // coverity[alloc_fn] coverity[alias] coverity[assign]
       
    68     CTunnelMetaConnectionProvider* tunnel = new (ELeave) CTunnelMetaConnectionProvider(aFactory, aProviderInfo);
       
    69     // coverity[push]
       
    70     CleanupStack::PushL(tunnel);
       
    71     // coverity[alias] coverity[double_push]
       
    72     tunnel->ConstructL();
       
    73     CleanupStack::Pop(tunnel);
       
    74     return tunnel;
       
    75     }
       
    76 
       
    77 
       
    78 CTunnelMetaConnectionProvider::CTunnelMetaConnectionProvider(CMetaConnectionProviderFactoryBase& aFactory, const ESock::TProviderInfo& aProviderInfo)
       
    79 :	CAgentMetaConnectionProvider(aFactory, aProviderInfo, TunnelMCprStates::stateMap::Self())
       
    80 	{
       
    81 	LOG_NODE_CREATE(KTunnelMCprTag, CTunnelMetaConnectionProvider);
       
    82 	}
       
    83 
       
    84 CTunnelMetaConnectionProvider::~CTunnelMetaConnectionProvider()
       
    85 	{
       
    86 	// Cleanup up Agent Notification Handler
       
    87 	SetAgentNotificationHandlerL(NULL);
       
    88 	delete iAgentHandler;
       
    89 
       
    90 	LOG_NODE_DESTROY(KTunnelMCprTag, CTunnelMetaConnectionProvider);
       
    91 	}
       
    92 
       
    93 void CTunnelMetaConnectionProvider::ConstructL()
       
    94     {
       
    95     CAgentMetaConnectionProvider::ConstructL();
       
    96 	SetAccessPointConfigFromDbL();
       
    97 	}
       
    98 
       
    99 
       
   100 void CTunnelMetaConnectionProvider::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage)
       
   101     {
       
   102 	__CFLOG_VAR((KTunnelMCprTag, KTunnelMCprSubTag, _L8("CTunnelMetaConnectionProvider %08x:\tReceivedL() aCFMessage=%d"),
       
   103 	   this, aMessage.MessageId()));
       
   104 
       
   105 	ESOCK_DEBUG_MESSAGE_INTERCEPT(aSender, aMessage, aRecipient);
       
   106 
       
   107 	TNodeContext<CTunnelMetaConnectionProvider> ctx(*this, aMessage, aSender, aRecipient);
       
   108     CCoreMetaConnectionProvider::Received(ctx);
       
   109     User::LeaveIfError(ctx.iReturn);
       
   110 	}
       
   111 
       
   112 void CTunnelMetaConnectionProvider::SetAccessPointConfigFromDbL()
       
   113 /**
       
   114 Setup the provisioning information required by the Tunnel CFProtocol.
       
   115 */
       
   116     {
       
   117     RMetaExtensionContainer mec;
       
   118     mec.Open(AccessPointConfig());
       
   119     CleanupClosePushL(mec);
       
   120 
       
   121 	TTunnelProvision* tp = new (ELeave) TTunnelProvision;
       
   122     CleanupStack::PushL(tp);
       
   123 
       
   124     // Open an IAP specific view on CommsDat
       
   125 	CCommsDatIapView* iapView = OpenIapViewLC();
       
   126 	tp->InitialiseConfigL(iapView);
       
   127 	CleanupStack::PopAndDestroy();			// CloseIapView();
       
   128 
       
   129 	// Presumptions:
       
   130 	// - none of the extensions can already exist in the AccessPointConfig array.  AppendExtensionL()
       
   131 	//   is presumed to panic if adding the same extension a second time.
       
   132 	// - if we have added several extensions to the AccessPointConfig array before getting a failure
       
   133 	//   and leaving, it is presumed that the MCPr will be destroyed and AccessPointConfig destructor
       
   134 	//   will clean up the extensions immediately afterwards.
       
   135 
       
   136 	// Append the provisioning object to the CAccessPointConfig array
       
   137 	mec.AppendExtensionL(tp);
       
   138 	CleanupStack::Pop(tp);					// ownership transferred
       
   139 
       
   140 	AccessPointConfig().Close();
       
   141 	AccessPointConfig().Open(mec);
       
   142 	CleanupStack::PopAndDestroy(&mec);
       
   143 	
       
   144 	// Setup Tunnel Agent Notification handler in order to retrieve TSY and connection speed
       
   145 	// information from the Agent once ConnectComplete() occurs.
       
   146 	ASSERT(iAgentHandler == NULL);
       
   147 	iAgentHandler = new (ELeave) CTunnelAgentHandler(tp->iInfo);
       
   148 	SetAgentNotificationHandlerL(iAgentHandler);	// ownership NOT transferred
       
   149     }