networkcontrol/iptransportlayer/src/netmcprups.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     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 // User Prompt Service (UPS) support.
       
    15 // 
       
    16 //
       
    17 
       
    18 #define SYMBIAN_NETWORKING_UPS
       
    19 
       
    20 #ifdef SYMBIAN_NETWORKING_UPS
       
    21 
       
    22 #include "netmcprups.h"
       
    23 #include "netmcpractivities.h"		// for NetMCprActivities::netMCprActivities
       
    24 #include <comms-infras/ss_log.h>
       
    25 #include <comms-infras/netups.h>
       
    26 #include <comms-infras/netupsserviceid.h>
       
    27 
       
    28 #ifdef __CFLOG_ACTIVE
       
    29 #define KNetMCprTag KESockMetaConnectionTag
       
    30 _LIT8(KNetMCprSubTag, "netmcpr");
       
    31 #endif
       
    32 
       
    33 using namespace ESock;
       
    34 
       
    35 CUpsNetworkMetaConnectionProvider::CUpsNetworkMetaConnectionProvider(CMetaConnectionProviderFactoryBase& aFactory, const TProviderInfo& aProviderInfo, const MeshMachine::TNodeActivityMap& aActivityMap)
       
    36 :	CNetworkMetaConnectionProvider(aFactory,aProviderInfo,aActivityMap)
       
    37 	{
       
    38 //	LOG_NODE_CREATE(KNetMCprTag, CNetworkMetaConnectionProvider);
       
    39 	}
       
    40 
       
    41 CUpsNetworkMetaConnectionProvider* CUpsNetworkMetaConnectionProvider::NewL(CMetaConnectionProviderFactoryBase& aFactory, const TProviderInfo& aProviderInfo)
       
    42 	{
       
    43 	__CFLOG_VAR((KNetMCprTag, KNetMCprSubTag, _L8("CUpsNetworkMetaConnectionProvider:\tNewL()")));
       
    44 
       
    45 	CUpsNetworkMetaConnectionProvider* self = new (ELeave) CUpsNetworkMetaConnectionProvider(aFactory,aProviderInfo,NetMCprActivities::netMCprActivities::Self());
       
    46 	CleanupStack::PushL(self);
       
    47 	self->ConstructL();
       
    48 	CleanupStack::Pop(self);
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 CUpsNetworkMetaConnectionProvider::~CUpsNetworkMetaConnectionProvider()
       
    53 	{
       
    54 	FreeApName();
       
    55 	CloseNetUps();
       
    56 	
       
    57 	iUpsClientHandleRefCount.ResetAndDestroy();
       
    58 	iUpsClientHandleRefCount.Close();
       
    59 	}
       
    60 
       
    61 void CUpsNetworkMetaConnectionProvider::ConstructL()
       
    62 	{
       
    63 	CNetworkMetaConnectionProvider::ConstructL();
       
    64 	
       
    65 	if (!NetUps::CNetUps::UpsDisabled(NetUps::EIpServiceId))
       
    66 		{
       
    67 		RMetaExtensionContainer mec;
       
    68 		mec.Open(AccessPointConfig());
       
    69 		CleanupClosePushL(mec);
       
    70 		//
       
    71 		// UPS is enabled - provision the UPS specific Access Point Config extension to the layer
       
    72 		//
       
    73 		CUPSAccessPointConfigExt* accessPointConfigExt = CUPSAccessPointConfigExt::NewL(ETSockAddress);
       
    74 		CleanupStack::PushL(accessPointConfigExt);
       
    75 		// set UPS specific ServiceId	
       
    76 		accessPointConfigExt->SetServiceId(NetUps::EIpServiceId);
       
    77 		mec.AppendExtensionL(accessPointConfigExt);
       
    78 		CleanupStack::Pop(accessPointConfigExt);
       
    79 		
       
    80 		AccessPointConfig().Close();
       
    81 		AccessPointConfig().Open(mec);
       
    82 		CleanupStack::PopAndDestroy(&mec);
       
    83 		}
       
    84 	else
       
    85 		{
       
    86 		// UPS is disabled.
       
    87 		SetUpsDisabled(ETrue);
       
    88 		}
       
    89 	} 
       
    90 
       
    91 void CUpsNetworkMetaConnectionProvider::ShowAccessPointRecordL(CommsDat::CMDBSession* /*aSession*/, CommsDat::CCDAccessPointRecord* aApRec)
       
    92 /**
       
    93 Called from base class during reading of Access Point Record.
       
    94 
       
    95 Store away the Access Point Name locally.
       
    96 */
       
    97 	{
       
    98 	SetApNameL(aApRec->iRecordName);
       
    99 	}
       
   100 
       
   101 void CUpsNetworkMetaConnectionProvider::CloseNetUps()
       
   102 	{
       
   103 	delete NetUps();
       
   104 	SetNetUps(NULL);
       
   105 	}
       
   106 
       
   107 void  CUpsNetworkMetaConnectionProvider::AddUpsClientCommsIdL(const Messages::TNodeId& aCommsId)
       
   108 	{
       
   109 	TInt32 index = 0;
       
   110 	TInt32 count = 0;	
       
   111 	TBool found = FindUpsClientHandle(aCommsId, index, count);
       
   112 	
       
   113 	if (found == EFalse)
       
   114 		{
       
   115 		TUpsClientHandleRefCount* upsClientHandleRefCount = new (ELeave) TUpsClientHandleRefCount(aCommsId, 0);
       
   116 		CleanupStack::PushL(upsClientHandleRefCount);
       
   117 		iUpsClientHandleRefCount.AppendL(upsClientHandleRefCount);
       
   118 		CleanupStack::Pop(upsClientHandleRefCount);
       
   119 		}		
       
   120 	}
       
   121 
       
   122 TBool CUpsNetworkMetaConnectionProvider::FindUpsClientHandle(const Messages::TNodeId& aCommsId, TInt32& aIndex, TInt32& aCount)
       
   123 	{
       
   124 	TBool found = EFalse;
       
   125 	for (TInt i = iUpsClientHandleRefCount.Count() - 1; i >=0; --i)
       
   126 		{
       
   127 		if (iUpsClientHandleRefCount[i]->iCommsId == aCommsId)
       
   128 			{
       
   129 			aIndex = i;
       
   130 			aCount = iUpsClientHandleRefCount[i]->iCount;
       
   131 			found = ETrue;
       
   132 			break;
       
   133 			}
       
   134 		}
       
   135 	return found;	
       
   136 	}
       
   137 
       
   138 void CUpsNetworkMetaConnectionProvider::IncrementUpsClientHandle(const Messages::TNodeId& aCommsId)
       
   139 	{
       
   140 	TInt32 index = 0;
       
   141 	TInt32 count = 0;
       
   142 	TBool found = FindUpsClientHandle(aCommsId, index, count);
       
   143 		
       
   144 	if (found == EFalse)
       
   145 		{
       
   146 		// TODO: ADD a panic code User::Panic(KNetMCprPanic, KPanicNoConnectionHandle);
       
   147 		User::Panic(KNetMCprPanic, KPanicNoConnectionHandle);
       
   148 		}
       
   149 	else
       
   150 		{
       
   151 		++(iUpsClientHandleRefCount[index]->iCount);
       
   152 		}				
       
   153 	}
       
   154 
       
   155 void CUpsNetworkMetaConnectionProvider::DecrementUpsClientHandle(const Messages::TNodeId& aCommsId, TBool& aAllHandlesDeleted)
       
   156 	{
       
   157 	TInt32 index = 0;
       
   158 	TInt32 count = 0;	
       
   159 	TBool found = FindUpsClientHandle(aCommsId, index, count);
       
   160 	
       
   161 	if (found == EFalse)
       
   162 		{		
       
   163 		User::Panic(KNetMCprPanic, KPanicNoConnectionHandle);
       
   164 		}
       
   165 	else
       
   166 		{
       
   167 		iUpsClientHandleRefCount[index]->iCount--;
       
   168 		if (iUpsClientHandleRefCount[index]->iCount == 0)
       
   169 			{
       
   170 			delete iUpsClientHandleRefCount[index];
       
   171 			iUpsClientHandleRefCount.Remove(index);
       
   172 			}
       
   173 		}
       
   174 	aAllHandlesDeleted = (iUpsClientHandleRefCount.Count() == 0) ? ETrue : EFalse;
       
   175 	}
       
   176 
       
   177 #endif //SYMBIAN_NETWORKING_UPS