installationservices/swi/test/tsisfile/tocspserver.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2004-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 * tocsp.cpp
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "log.h"
       
    21 #include "tocspserver.h"
       
    22 #include "tocspclientserver.h"
       
    23 
       
    24 using Swi::Test::COcspServer;
       
    25 using Swi::Test::COcspSession;
       
    26 using Swi::Test::COcspServerShutdown;
       
    27 
       
    28 static void PanicClient(const RMessagePtr2& aMessage, 
       
    29 						Swi::Test::TOcspServerPanic aPanic)
       
    30 	{
       
    31 	aMessage.Panic(Swi::Test::KOcspServerName, aPanic);
       
    32 	}
       
    33 
       
    34 /////
       
    35 ///// TOCSP Server
       
    36 /////
       
    37 
       
    38 /*static*/ COcspServer* COcspServer::NewLC()
       
    39 	{
       
    40 	COcspServer* self = new(ELeave) COcspServer();
       
    41 	CleanupStack::PushL(self);
       
    42 	self->ConstructL();
       
    43 	return self;
       
    44 	}
       
    45 	
       
    46 void COcspServer::AddSession()
       
    47 	{
       
    48 	FLOG(_L("Console Server added session"));
       
    49 	++iSessionCount;
       
    50 	iShutdown->Cancel();
       
    51 	}
       
    52 	
       
    53 void COcspServer::DropSession()
       
    54 	{
       
    55 	FLOG(_L("Console Server dropped session"));
       
    56 	if (--iSessionCount==0)
       
    57 		{
       
    58 		iShutdown->Start();
       
    59 		FLOG(_L("Console Server shutting down"))
       
    60 		}
       
    61 	}
       
    62 
       
    63 COcspServer::~COcspServer()
       
    64 	{
       
    65 	delete iShutdown;
       
    66 	delete iConsole;
       
    67 	FLOG(_L("Console Server destructor"))
       
    68 	}
       
    69 
       
    70 COcspServer::COcspServer() : CServer2(EPriorityNormal, ESharableSessions)
       
    71 	{
       
    72 	}
       
    73 
       
    74 void COcspServer::ConstructL()
       
    75 	{
       
    76 	StartL(Swi::Test::KConsoleServerName);
       
    77 	iConsole = Console::NewL(_L("SWI Console Server Test"), TSize(KDefaultConsWidth, KDefaultConsHeight));
       
    78 	iShutdown = COcspServerShutdown::NewL();
       
    79 	// Ensure that the server still exits even if the 1st client fails to
       
    80 	// connect
       
    81 	iShutdown->Start();
       
    82 	}
       
    83 
       
    84 CSession2* COcspServer::NewSessionL(const TVersion& /*aVersion*/, 
       
    85 									   const RMessage2& /*aMessage*/) const
       
    86 	{
       
    87 	return new(ELeave) COcspSession(*iConsole);
       
    88 	}
       
    89 
       
    90 void COcspSession::CreateL()
       
    91 	{
       
    92 	Server().AddSession();
       
    93 	}
       
    94 
       
    95 COcspSession::COcspSession(CConsoleBase& aConsole) : CSession2(), iConsole(aConsole)
       
    96 	{
       
    97 	}
       
    98 
       
    99 COcspSession::~COcspSession()
       
   100 	{
       
   101 	Server().DropSession();
       
   102 	}
       
   103 
       
   104 COcspServer& COcspSession::Server()
       
   105 	{
       
   106 	return *static_cast<COcspServer*>(
       
   107 		const_cast<CServer2*>(CSession2::Server()));
       
   108 	}
       
   109 
       
   110 /////
       
   111 ///// COcspSession		
       
   112 /////
       
   113 	
       
   114 void COcspSession::ServiceL(const RMessage2& aMessage)
       
   115 	{
       
   116 	switch (aMessage.Function())
       
   117 		{
       
   118 		/*case EPrint:
       
   119 		{
       
   120 		FLOG(_L("COcspSession::ServiceL(EPrint)"));
       
   121 		TInt length = User::LeaveIfError(aMessage.GetDesMaxLength(0));
       
   122 		HBufC* string = HBufC::NewMaxLC(length);
       
   123 		TPtr stringBuffer(string->Des());
       
   124 		aMessage.Read(0, stringBuffer);
       
   125 		iConsole.Printf(*string); 
       
   126 		aMessage.Complete(KErrNone);
       
   127 		break;
       
   128 		}
       
   129 	case EGet:
       
   130 		{
       
   131 		FLOG(_L("COcspSession::ServiceL(EGet)"));
       
   132 		aMessage.Complete(iConsole.Getch());
       
   133 		break;
       
   134 		}*/
       
   135 	default:
       
   136 		{
       
   137 		FLOG(_L("COcspSession::ServiceL(): unknown function"));
       
   138 		PanicClient(aMessage, Swi::Test::EPanicOcspServerIllegalFunction);
       
   139 		break;
       
   140 		}
       
   141 		}
       
   142 	}
       
   143 
       
   144 void COcspSession::ServiceError(const RMessage2& aMessage, TInt aError)
       
   145 	{
       
   146 	if (aError==KErrBadDescriptor)
       
   147 		{
       
   148 		PanicClient(aMessage, Swi::Test::EPanicConsoleServerBadDescriptor);
       
   149 		}
       
   150 	CSession2::ServiceError(aMessage, aError);
       
   151 	}
       
   152 
       
   153 /////
       
   154 ///// CInstallServerShutdown
       
   155 /////
       
   156 		
       
   157 inline COcspServerShutdown::COcspServerShutdown() : CTimer(-1)
       
   158 	{
       
   159 	CActiveScheduler::Add(this);
       
   160 	}
       
   161 
       
   162 inline void COcspServerShutdown::ConstructL()
       
   163 	{
       
   164 	CTimer::ConstructL();
       
   165 	}
       
   166 
       
   167 inline void COcspServerShutdown::Start()
       
   168 	{
       
   169 	After(KShutdownDelay);
       
   170 	}
       
   171 
       
   172 /*static*/ COcspServerShutdown* COcspServerShutdown::NewL()
       
   173 	{
       
   174 	COcspServerShutdown* self = new(ELeave) COcspServerShutdown();
       
   175 	CleanupStack::PushL(self);
       
   176 	self->ConstructL();
       
   177 	CleanupStack::Pop(self);
       
   178 	return self;
       
   179 	}
       
   180 
       
   181 // Initiate server exit when the timer expires
       
   182 void COcspServerShutdown::RunL()
       
   183 	{
       
   184 	FLOG(_L("COcspServerShutdown::RunL(): stopping Test Console Server"));
       
   185 	CActiveScheduler::Stop();
       
   186 	}