installationservices/swi/test/tsisfile/tsisocspclientserver.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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include "tocspclientserver.h"
       
    21 
       
    22 using namespace Swi::Test;
       
    23 
       
    24 //
       
    25 // Starts the Ocsp Server in a new process
       
    26 //
       
    27 static TInt StartOcspServer()
       
    28 	{
       
    29 	const TUidType serverUid(KNullUid, KNullUid, KOcspServerUid3);
       
    30 	RProcess server;
       
    31 	TInt err=server.Create(Swi::Test::KOcspServerImage, KNullDesC, serverUid);
       
    32 
       
    33 	if (err!=KErrNone)
       
    34 		{
       
    35 		return err;
       
    36 		}
       
    37 
       
    38 	TRequestStatus stat;
       
    39 	server.Rendezvous(stat);
       
    40 
       
    41 	if (stat!=KRequestPending)
       
    42 		{
       
    43 		server.Kill(0); // abort startup
       
    44 		}
       
    45 	else
       
    46 		{
       
    47 		server.Resume(); // logon OK, start the server
       
    48 		}
       
    49 
       
    50 	User::WaitForRequest(stat); // wait for start or death
       
    51 	// We can't use the 'exit reason' if the server panicked as this is the
       
    52 	// panic 'reason' and may be 0 which cannot be distinguished from KErrNone.
       
    53 	err=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
       
    54 	server.Close();
       
    55 	return err;
       
    56 	}
       
    57 
       
    58 EXPORT_C TInt ROcspServerSession::Connect()
       
    59 	{
       
    60 	TInt retry=2;
       
    61 	for(;;)
       
    62 		{
       
    63 		TInt err=CreateSession(KOcspServerName, TVersion(0,0,0), 1);
       
    64 		if (err!=KErrNotFound && err!=KErrServerTerminated)
       
    65 			{
       
    66 			return err;
       
    67 			}
       
    68 
       
    69 		if (--retry==0)
       
    70 			{
       
    71 			return err;
       
    72 			}
       
    73 
       
    74 		err=StartOcspServer();
       
    75 		if (err!=KErrNone && err!=KErrAlreadyExists)
       
    76 			{
       
    77 			return err;
       
    78 			}
       
    79 		}
       
    80 	}
       
    81 
       
    82 EXPORT_C TInt ROcspServerSession::Check()
       
    83 	{
       
    84 	return SendReceive(ECheck, TIpcArgs());	
       
    85 	}