installationservices/swinstallationfw/source/siftransportserver.cpp
changeset 24 84a16765cd86
child 33 8110bf1194d1
equal deleted inserted replaced
6:aba6b8104af3 24:84a16765cd86
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * This file implements the SIF Transport Server.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "siftransportserver.h"
       
    21 #include "siftransportcommon.h"
       
    22 #include <e32property.h>
       
    23 
       
    24 using namespace Usif;
       
    25 
       
    26 CSifTransportServer* CSifTransportServer::NewLC(const TDesC& aServerName, const TVersion& aVersion,
       
    27 									TransportTaskFactory::GenerateTask aTaskFactory, TInt aShutdownPeriodUs)
       
    28 /**
       
    29 	Factory function allocates new, initialized instance of
       
    30 	CSifServer which is left on the cleanup stack.
       
    31 
       
    32 	@return					New, initialized instance of CSifServer
       
    33 							which is left on the cleanup stack.
       
    34  */
       
    35 	{
       
    36 	CSifTransportServer* self = new (ELeave) CSifTransportServer(aVersion, aTaskFactory);
       
    37 	CleanupStack::PushL(self);
       
    38 	self->ConstructL(aServerName, aShutdownPeriodUs);
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 CSifTransportServer::CSifTransportServer(const TVersion& aVersion, TransportTaskFactory::GenerateTask aTaskFactory)
       
    43 /**
       
    44 	Initializes the superclass with this server's version.
       
    45  */
       
    46 	:	CScsServer(aVersion), iTaskFactory(aTaskFactory)
       
    47 	{
       
    48 	}
       
    49 
       
    50 void CSifTransportServer::ConstructL(const TDesC& aServerName, TInt aShutdownPeriodUs)
       
    51 /**
       
    52 	Second-phase construction initializes the superclass and
       
    53 	starts the server.
       
    54  */
       
    55 	{
       
    56 	CScsServer::ConstructL(aShutdownPeriodUs);
       
    57 
       
    58 	StartL(aServerName);
       
    59 	}
       
    60 
       
    61 
       
    62 CSifTransportServer::~CSifTransportServer()
       
    63 /**
       
    64 	Cleanup the server, in particular close the RFs session.
       
    65  */
       
    66 	{
       
    67 	}
       
    68 
       
    69 CScsSession* CSifTransportServer::DoNewSessionL(const RMessage2& /*aMessage*/)
       
    70 /**
       
    71 	Implement CScsServer by allocating a new instance of CSifSession.
       
    72 
       
    73 	@param	aMessage	Standard server-side handle to message.	 Not used.
       
    74 	@return			New instance of CSifSession which is owned by the
       
    75 					caller.
       
    76  */
       
    77 	{
       
    78 	return CSifTransportSession::NewL(*this, iTaskFactory);
       
    79 	}
       
    80 
       
    81 namespace
       
    82 	{
       
    83 	struct TServerStartupInfo
       
    84 		{
       
    85 		const TDesC* iServerName;
       
    86 		const TVersion* iVersion;
       
    87 		TransportTaskFactory::GenerateTask iTaskFactory;
       
    88 		TInt iShutdownPeriodUs;
       
    89 		};
       
    90 	}
       
    91 
       
    92 EXPORT_C CScsServer* CSifTransportServer::NewSifTransportServerLC()
       
    93 /**
       
    94 	This factory function is called by SCS.  It allocates
       
    95 	the server object and leaves it on the cleanup stack.
       
    96 
       
    97 	@return	New initialized instance of CScsTestServer.
       
    98 			On return this is on the cleanup stack.
       
    99 */ 
       
   100 	{
       
   101 	TServerStartupInfo* ssi = static_cast<TServerStartupInfo*>(Dll::Tls());
       
   102 	return CSifTransportServer::NewLC(*ssi->iServerName, *ssi->iVersion, ssi->iTaskFactory, ssi->iShutdownPeriodUs);
       
   103 	}
       
   104 
       
   105 namespace Usif
       
   106 	{
       
   107 	EXPORT_C TInt StartTransportServer(const TDesC& aServerName, const TVersion& aVersion, TransportTaskFactory::GenerateTask aTaskFactory,  TInt aShutdownPeriodUs)
       
   108 		{
       
   109 		// A local object can be used with TLS here because it is read by CSifTransportServer::NewSifTransportServerLC()
       
   110 		// before we leave the scope of this function. This is because CSifTransportServer::NewSifTransportServerLC() is a callback
       
   111 		// function called by the SCS Server in response to StartScsServer().
       
   112 		TServerStartupInfo ssi = {&aServerName, &aVersion, aTaskFactory, aShutdownPeriodUs};
       
   113 		Dll::SetTls(&ssi);
       
   114 		TInt err = StartScsServer(CSifTransportServer::NewSifTransportServerLC);
       
   115 		return err;
       
   116 		}
       
   117 	}