plugins/networking/winsockprt/src/wsp_protocolfamily.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // wsp_protocolfamily.cpp
       
     2 // 
       
     3 // Copyright (c) 2002 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 
       
    14 #include <f32file.h>
       
    15 #undef SYMBIAN_ENABLE_SPLIT_HEADERS // More tb92 stopgaps, this time for es_sock_partner.h
       
    16 #include <winsockprt.h>
       
    17 #include <in_sock.h>
       
    18 #include "wsp_protocolfamily.h"
       
    19 #include "wsp_protocol.h"
       
    20 #include "wsp_log.h"
       
    21 
       
    22 
       
    23 CWinSockProtocolFamily::~CWinSockProtocolFamily()
       
    24 	{
       
    25 	WSP_LOG(WspLog::Write(_L("CWinSockProtocolFamily::~CWinSockProtocolFamily")));
       
    26 	if (iWin32Factory)
       
    27 		{
       
    28 		iWin32Factory->Close();
       
    29 		delete iWin32Factory;
       
    30 		}
       
    31 	WSP_LOG(WspLog::Close());
       
    32 	}
       
    33 
       
    34 CWinSockProtocolFamily::CWinSockProtocolFamily()
       
    35 	{
       
    36 	}
       
    37 
       
    38 CWinSockProtocolFamily* CWinSockProtocolFamily::NewL()
       
    39 	{
       
    40 	WSP_LOG(WspLog::Write(_L("CWinSockProtocolFamily::NewL")));
       
    41 	return new(ELeave) CWinSockProtocolFamily();
       
    42 	}
       
    43 
       
    44 TInt CWinSockProtocolFamily::Install()
       
    45 	{
       
    46 	return KErrNone;
       
    47 	}
       
    48 
       
    49 CProtocolBase* CWinSockProtocolFamily::NewProtocolL(TUint aSockType, TUint /*aProtocol*/)
       
    50 	{
       
    51 	WSP_LOG(WspLog::Printf(_L("CWinSockProtocolFamily::NewProtocolL, socket type: %d"), aSockType));
       
    52 	if (iWin32Factory == NULL)
       
    53 		{
       
    54 		RWin32Factory* factory = new(ELeave) RWin32Factory();
       
    55 		CleanupStack::PushL(factory);
       
    56 		User::LeaveIfError(factory->Open());
       
    57 		CleanupStack::Pop(factory);
       
    58 		iWin32Factory = factory;
       
    59 		}
       
    60 	return CWinSockProtocol::NewL(aSockType, *iWin32Factory);
       
    61 	}
       
    62 
       
    63 TUint CWinSockProtocolFamily::ProtocolList(TServerProtocolDesc*& aProtocolList)
       
    64 	{
       
    65 	TBool realTcpipActive(EFalse);
       
    66 	TRAP_IGNORE(realTcpipActive = RealTcpipActiveL());
       
    67 	const TInt numProtocols = realTcpipActive ? 2 : 5;
       
    68 	TRAPD(ret, aProtocolList=new(ELeave) TServerProtocolDesc[numProtocols]);
       
    69 	if (ret != KErrNone)
       
    70 		{
       
    71 		return 0;
       
    72 		}
       
    73 
       
    74 	CWinSockProtocol::ProtocolIdentity(&aProtocolList[0], KSockStream, KProtocolWinsockTcp);
       
    75 	CWinSockProtocol::ProtocolIdentity(&aProtocolList[1], KSockDatagram, KProtocolWinsockUdp);
       
    76 	if (!realTcpipActive)
       
    77 		{
       
    78 		CWinSockProtocol::ProtocolIdentity(&aProtocolList[2], KSockStream, KProtocolInetTcp);
       
    79 		CWinSockProtocol::ProtocolIdentity(&aProtocolList[3], KSockDatagram, KProtocolInetUdp);
       
    80 		CWinSockProtocol::ProtocolIdentity(&aProtocolList[4], KSockDatagram, KProtocolInetIp);
       
    81 		}
       
    82 	
       
    83 	return numProtocols;
       
    84 	}
       
    85 
       
    86 TBool CWinSockProtocolFamily::RealTcpipActiveL() const
       
    87 	{
       
    88 	RFs fs;
       
    89 	User::LeaveIfError(fs.Connect());
       
    90 	CleanupClosePushL(fs);
       
    91 	TUint att;
       
    92 	_LIT(KTcpipEskFileName, "c:\\Private\\101f7989\\esock\\ip.tcpip.esk");
       
    93 	TBool active = (fs.Att(KTcpipEskFileName, att) == KErrNone);
       
    94 	CleanupStack::PopAndDestroy(&fs);
       
    95 	return active;
       
    96 	}