networkcontrol/commsuserpromptmgr/utils/src/netupstls.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 // This file provides the implementation of the methods for NetUps Tls
       
    15 // @internalAll
       
    16 // @prototype
       
    17 // 
       
    18 //
       
    19 
       
    20 #include <e32svr.h> // Included here, since removal of Platform headers from public headers[f32file.h] for TB92SDK 
       
    21 #include "netupstls.h"
       
    22 
       
    23 #include <e32def.h>		  			// defines TInt
       
    24 
       
    25 #ifdef __WINS__
       
    26 #include <u32hal.h>
       
    27 #endif
       
    28 
       
    29 #include "e32std.h"					// defines TLS, User
       
    30 #include "es_ini.h"					// defines CESockIniData.
       
    31 
       
    32 #include "netupsimpl.h" // is this needed here, should relevant definitions be ported
       
    33 
       
    34 #include "netupsconst.h"
       
    35 #include "netupsassert.h"
       
    36 
       
    37 namespace NetUps
       
    38 {
       
    39 __FLOG_STMT(_LIT8(KNetUpsSubsys, 	"esock");)   
       
    40 __FLOG_STMT(_LIT8(KNetUpsComponent, "NetUps");) /*esockloader*/
       
    41 
       
    42 class CNetUpsImpl;
       
    43 	
       
    44 CNetUpsTls* CNetUpsTls::NewL(TInt32 aServiceId)
       
    45 	{
       
    46 	CNetUpsTls* self = new (ELeave) CNetUpsTls();
       
    47 
       
    48 	CleanupStack::PushL(self);
       
    49 	self->ConstructL(aServiceId);
       
    50 	CleanupStack::Pop(self);
       
    51 
       
    52 	return self;		
       
    53 	}
       
    54 
       
    55 void CNetUpsTls::ConstructL(TInt32 aServiceId)
       
    56 	{
       
    57 	(void) aServiceId;
       
    58 
       
    59 #ifdef __WINS__
       
    60 
       
    61 	// for the emulator allow the constant to be patched via epoc.ini
       
    62 	TUint32 value;
       
    63 
       
    64 	TInt ret = UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty, (TAny*)"NETWORKING_UPS_DISABLE", &value);
       
    65 
       
    66 	if (ret == KErrNone)
       
    67 		{
       
    68 		if ((value == ENetUpsEnabled) || (value == ENetUpsDisabled))
       
    69 			// i.e. Net Ups Enabled.
       
    70 			{
       
    71 			iUpsIpActive = static_cast<TNetUpsEnableConst>(value);
       
    72 			if (iUpsIpActive==ENetUpsDisabled)
       
    73 				{
       
    74 				User::Leave(KErrNotSupported);
       
    75 				}
       
    76 			}	
       
    77 		else if (value == EReadStatusFromFile)
       
    78 			{
       
    79 			ReadConfigurableSettingsL(EEnabledStatus);
       
    80 			}
       
    81 		else 
       
    82 			{
       
    83 			User::Leave(KErrCorrupt);
       
    84 			}
       
    85 		}
       
    86 	else
       
    87 		{
       
    88 		iUpsIpActive = ENetUpsEnabled;
       
    89 		}
       
    90 				
       
    91 	ret = UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty, (TAny*) "NETWORKING_UPS_SESSION", &value);
       
    92 
       
    93 	if (ret == KErrNone)
       
    94 		{
       
    95 		if ((value == EProcessLifeTime) || (value == ENetworkLifeTime))
       
    96 			{
       
    97 			iUpsSessionType = static_cast<TNetUpsSessionConst>(value);
       
    98 			}
       
    99 		else if (value == EReadStatusFromFile)
       
   100 			{
       
   101 			ReadConfigurableSettingsL(ESessionMode);
       
   102 			}
       
   103 		else
       
   104 			{
       
   105 			User::Leave(KErrCorrupt);					
       
   106 			}
       
   107 		}
       
   108 	else 
       
   109 		{
       
   110 		iUpsSessionType = EProcessLifeTime;
       
   111 		}				
       
   112 
       
   113 #else // NOT WINSCW
       
   114 
       
   115 	iUpsIpActive = static_cast<TNetUpsEnableConst>(KUpsIpDisabled);
       
   116 	iUpsSessionType = static_cast<TNetUpsSessionConst>(KUpsSessionType); // validate input ?
       
   117 	if (iUpsIpActive == EReadStatusFromFile)
       
   118 		{
       
   119 #ifdef 	_DEBUG
       
   120 		ReadConfigurableSettingsL(EEnabledStatus);
       
   121 #else   // _DEBUG
       
   122 		User::Leave(KErrNotSupported);	
       
   123 #endif  // _DEBUG
       
   124 		}
       
   125 	else if (iUpsIpActive != ENetUpsEnabled)
       
   126 		{
       
   127 		User::Leave(KErrNotSupported);				
       
   128 		}
       
   129 
       
   130 	if (iUpsSessionType == EReadSessionDefFromFile)
       
   131 		{
       
   132 #ifdef 	_DEBUG
       
   133 		ReadConfigurableSettingsL(ESessionMode);
       
   134 #endif  // _DEBUG
       
   135 		}
       
   136 
       
   137 #endif // __WINS__
       
   138 
       
   139 	iNetUpsImpl = CNetUpsImpl::NewL();
       
   140 
       
   141 	if (iUpsSessionType ==  EProcessLifeTime)
       
   142 		{
       
   143 		iNetUpsImpl->SetLifeTimeMode(CNetUpsImpl::EProcessLifeTimeMode);	
       
   144 		}
       
   145 	else
       
   146 		{
       
   147 		iNetUpsImpl->SetLifeTimeMode(CNetUpsImpl::ENetworkLifeTimeMode);		
       
   148 		}
       
   149 
       
   150 	__FLOG_OPEN(KNetUpsSubsys, KNetUpsComponent);
       
   151 	__FLOG_3(_L("CNetUpsTls %08x:\tConstructL(), aServiceId = %d, iLifeTimeMode = %d"), this, aServiceId, iUpsSessionType);		
       
   152 	}
       
   153 
       
   154 void CNetUpsTls::ReadConfigurableSettingsL(TConfigurableSetting aConfigurableSetting)
       
   155 	{
       
   156 	__FLOG_1(_L("CNetUpsTls %08x:\tReadConfigurableSettingsL()"), this);	
       
   157 
       
   158 	CESockIniData* ini = NULL;
       
   159 	ini=CESockIniData::NewL(_L("netups.ini"));
       
   160 	CleanupStack::PushL(ini);
       
   161 	TInt value(0);
       
   162 
       
   163 	switch(aConfigurableSetting)
       
   164 		{
       
   165 		case EEnabledStatus:
       
   166 			if(ini->FindVar(_L("upsIpMode"),_L("NETWORKING_UPS_DISABLE"), value))
       
   167 				{
       
   168 				if (value==ENetUpsEnabled)
       
   169 					{
       
   170 					iUpsIpActive = static_cast<TNetUpsEnableConst>(value);
       
   171 					__FLOG_2(_L("CNetUpsTls %08x:\tReadConfigurableSettingsL(), iUpsIpActive = %d"), this, iUpsIpActive);	
       
   172 					}
       
   173 				else if (value==ENetUpsDisabled)
       
   174 					{
       
   175 					User::Leave(KErrNotSupported);
       
   176 					}
       
   177 				else
       
   178 					{
       
   179 					User::Leave(KErrCorrupt);
       
   180 					}
       
   181 				}
       
   182 			break;
       
   183 		case ESessionMode:
       
   184 			if(ini->FindVar(_L("upsIpMode"),_L("NETWORKING_UPS_SESSION"), value))
       
   185 				{
       
   186 				if ((value >=  EProcessLifeTime) && (value <= ENetworkLifeTime))
       
   187 					{
       
   188 					iUpsSessionType = static_cast<TNetUpsSessionConst>(value);
       
   189 					__FLOG_2(_L("CNetUpsTls %08x:\tReadConfigurableSettingsL(), iUpsSessionType = %d"), this, iUpsSessionType);	
       
   190 					}
       
   191 				else
       
   192 					{
       
   193 					User::Leave(KErrCorrupt);
       
   194 					}
       
   195 				}
       
   196 			break;
       
   197 		default:
       
   198 			User::Panic(KNetUpsPanic, KPanicInvalidLogic);
       
   199 			break;
       
   200 		}
       
   201 
       
   202 	CleanupStack::PopAndDestroy(ini);	
       
   203 	}
       
   204 
       
   205 CNetUpsTls::CNetUpsTls()
       
   206   : iUpsIpActive(ENetUpsEnabled), iUpsSessionType(EProcessLifeTime)
       
   207 	{
       
   208 	}
       
   209 	
       
   210 CNetUpsTls::~CNetUpsTls()
       
   211 	{
       
   212 	__FLOG_1(_L("CNetUpsTls %08x:\t~CNetUpsTls"), this);	
       
   213 	delete iNetUpsImpl;
       
   214 	__FLOG_CLOSE;			
       
   215 	}
       
   216 
       
   217 CNetUpsImpl* CNetUpsTls::GetNetUpsImpl()
       
   218 	{
       
   219 	__FLOG_2(_L("CNetUpsTls %08x:\tGetNetUpsImpl(), iNetUpsImpl = %08x"), this, iNetUpsImpl);	
       
   220 	return iNetUpsImpl;
       
   221 	}		
       
   222 		
       
   223 TUint32 CNetUpsTls::GetUpsIpDisabled()
       
   224 	{
       
   225 	__FLOG_2(_L("CNetUpsTls %08x:\tGetUpsIpDisabled(), iUpsIpActive = %d"), this, iUpsIpActive);	
       
   226 	return iUpsIpActive;
       
   227 	}
       
   228 
       
   229 TUint32 CNetUpsTls::GetUpsSessionType()  	
       
   230 	{
       
   231 	__FLOG_2(_L("CNetUpsTls %08x:\tGetUpsSessionType(), iUpsSessionType = %d"), this, iUpsSessionType);	
       
   232 	return iUpsSessionType;
       
   233 	}
       
   234 
       
   235 }  // end of namespace
       
   236