installationservices/swinstallationfw/source/siftransportserver.cpp
branchRCL_3
changeset 25 7333d7932ef7
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
       
     1 /*
       
     2 * Copyright (c) 2008 - 2010 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 #include "sifnotification_internal.h"
       
    24 #include "scrclient.inl"
       
    25 
       
    26 using namespace Usif;
       
    27 
       
    28 CSifTransportServer* CSifTransportServer::NewLC(const TDesC& aServerName, const TVersion& aVersion,
       
    29 									TransportTaskFactory::GenerateTask aTaskFactory, TInt aShutdownPeriodUs)
       
    30 /**
       
    31 	Factory function allocates new, initialized instance of
       
    32 	CSifServer which is left on the cleanup stack.
       
    33 
       
    34 	@return					New, initialized instance of CSifServer
       
    35 							which is left on the cleanup stack.
       
    36  */
       
    37 	{
       
    38 	CSifTransportServer* self = new (ELeave) CSifTransportServer(aVersion, aTaskFactory);
       
    39 	CleanupStack::PushL(self);
       
    40 	self->ConstructL(aServerName, aShutdownPeriodUs);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 CSifTransportServer::CSifTransportServer(const TVersion& aVersion, TransportTaskFactory::GenerateTask aTaskFactory)
       
    45 /**
       
    46 	Initializes the superclass with this server's version.
       
    47  */
       
    48 	:	CScsServer(aVersion), iTaskFactory(aTaskFactory)
       
    49 	{
       
    50 	}
       
    51 
       
    52 void CSifTransportServer::ConstructL(const TDesC& aServerName, TInt aShutdownPeriodUs)
       
    53 /**
       
    54 	Second-phase construction initializes the superclass and
       
    55 	starts the server.
       
    56  */
       
    57 	{
       
    58 	// Define a key (KSifOperationKey) which would be used to notify the client of any new operations.
       
    59     TInt ret = RProperty::Define(KUidSystemCategory, KSifOperationKey, RProperty::EByteArray, KSecurityPolicyWDD, KSecurityPolicyNone,(sizeof(TInt) * KMaxNumberOfOperations));
       
    60     if (ret != KErrAlreadyExists && ret != KErrNone)
       
    61         {
       
    62         User::Leave(ret);
       
    63         }
       
    64 
       
    65     if(ret == KErrNone)
       
    66         {
       
    67         // Create a empty CSifOperationKey object and publish it.
       
    68         CSifOperationKey* nullKey = CSifOperationKey::NewL();
       
    69         CleanupStack::PushL(nullKey);
       
    70         RBuf8 nullKeyBuffer;
       
    71         nullKeyBuffer.CleanupClosePushL();
       
    72         ExternalizeRefObjectL(*nullKey, nullKeyBuffer);
       
    73         User::LeaveIfError(RProperty::Set(KUidSystemCategory, KSifOperationKey, nullKeyBuffer));
       
    74 		CleanupStack::PopAndDestroy(2, nullKey);
       
    75         }
       
    76     
       
    77     CScsServer::ConstructL(aShutdownPeriodUs);
       
    78 	StartL(aServerName);
       
    79 	}
       
    80 
       
    81 
       
    82 CSifTransportServer::~CSifTransportServer()
       
    83 /**
       
    84 	Cleanup the server, in particular close the RFs session.
       
    85  */
       
    86 	{
       
    87 	RProperty::Delete(Usif::KSifOperationKey);
       
    88 	}
       
    89 
       
    90 CScsSession* CSifTransportServer::DoNewSessionL(const RMessage2& /*aMessage*/)
       
    91 /**
       
    92 	Implement CScsServer by allocating a new instance of CSifSession.
       
    93 
       
    94 	@param	aMessage	Standard server-side handle to message.	 Not used.
       
    95 	@return			New instance of CSifSession which is owned by the
       
    96 					caller.
       
    97  */
       
    98 	{
       
    99 	return CSifTransportSession::NewL(*this, iTaskFactory);
       
   100 	}
       
   101 
       
   102 namespace
       
   103 	{
       
   104 	struct TServerStartupInfo
       
   105 		{
       
   106 		const TDesC* iServerName;
       
   107 		const TVersion* iVersion;
       
   108 		TransportTaskFactory::GenerateTask iTaskFactory;
       
   109 		TInt iShutdownPeriodUs;
       
   110 		};
       
   111 	}
       
   112 
       
   113 EXPORT_C CScsServer* CSifTransportServer::NewSifTransportServerLC()
       
   114 /**
       
   115 	This factory function is called by SCS.  It allocates
       
   116 	the server object and leaves it on the cleanup stack.
       
   117 
       
   118 	@return	New initialized instance of CScsTestServer.
       
   119 			On return this is on the cleanup stack.
       
   120 */ 
       
   121 	{
       
   122 	TServerStartupInfo* ssi = static_cast<TServerStartupInfo*>(Dll::Tls());
       
   123 	return CSifTransportServer::NewLC(*ssi->iServerName, *ssi->iVersion, ssi->iTaskFactory, ssi->iShutdownPeriodUs);
       
   124 	}
       
   125 
       
   126 namespace Usif
       
   127 	{
       
   128 	EXPORT_C TInt StartTransportServer(const TDesC& aServerName, const TVersion& aVersion, TransportTaskFactory::GenerateTask aTaskFactory,  TInt aShutdownPeriodUs)
       
   129 		{
       
   130 		// A local object can be used with TLS here because it is read by CSifTransportServer::NewSifTransportServerLC()
       
   131 		// before we leave the scope of this function. This is because CSifTransportServer::NewSifTransportServerLC() is a callback
       
   132 		// function called by the SCS Server in response to StartScsServer().
       
   133 		TServerStartupInfo ssi = {&aServerName, &aVersion, aTaskFactory, aShutdownPeriodUs};
       
   134 		Dll::SetTls(&ssi);
       
   135 		TInt err = StartScsServer(CSifTransportServer::NewSifTransportServerLC);
       
   136 		return err;
       
   137 		}
       
   138 	}