installationservices/swi/test/tuiscriptadaptors/sisregistryaccess_client.cpp
changeset 0 ba25891c3a9e
child 25 7333d7932ef7
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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 * SisRegistryAccess - client interface implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file 
       
    22  @test
       
    23  @internalComponent
       
    24 */
       
    25  
       
    26 #include "sisregistryaccess_client.h"
       
    27 #include "sisregistryaccess_common.h"
       
    28 
       
    29 static TInt StartSisRegistryAccessServer()
       
    30 	{
       
    31 	const TUidType serverUid(KNullUid, KNullUid, KSisRegistryAccessServerUid3);
       
    32 	RProcess server;
       
    33 	TInt err = server.Create(KSisRegistryAccessServerBinary, KNullDesC, serverUid);
       
    34 	if (err != KErrNone)
       
    35 		{
       
    36 		return err;
       
    37 		}
       
    38 	TRequestStatus stat;
       
    39 	server.Rendezvous(stat);
       
    40 	if (stat != KRequestPending)
       
    41 		{
       
    42 		server.Kill(0);		// abort startup
       
    43 		}
       
    44 	else
       
    45 		{
       
    46 		server.Resume();	// logon OK - start the server
       
    47 		}
       
    48 	User::WaitForRequest(stat);		// wait for start or death
       
    49 	// we can't use the 'exit reason' if the server panicked as this
       
    50 	// is the panic 'reason' and may be '0' which cannot be distinguished
       
    51 	// from KErrNone
       
    52 	err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
       
    53 	server.Close();
       
    54 	return err;
       
    55 	}
       
    56 
       
    57 //
       
    58 // Connect to the server, attempting to start it if necessary
       
    59 //
       
    60 TInt RSisRegistryAccessSession::Connect()
       
    61 	{
       
    62 	TInt retry = 2;
       
    63 	for (;;)
       
    64 		{
       
    65 		TInt err = CreateSession(KSisRegistryAccessServerName, TVersion(0, 0, 0), 2);
       
    66 		if (err != KErrNotFound && err != KErrServerTerminated)
       
    67 			{
       
    68 			return err;
       
    69 			}
       
    70 		if (--retry == 0)
       
    71 			{
       
    72 			return err;
       
    73 			}
       
    74 		err = StartSisRegistryAccessServer();
       
    75 		if (err != KErrNone && err != KErrAlreadyExists)
       
    76 			{
       
    77 			return err;
       
    78 			}
       
    79 		}
       
    80 	}
       
    81 
       
    82 void RSisRegistryAccessSession::AddEntryL(const TDesC8& aControllerData, TInt& aSpentTimeInMillisecond)
       
    83 	{
       
    84 	TPckg<TInt> time(aSpentTimeInMillisecond);
       
    85 	User::LeaveIfError(SendReceive(EAddEntry, TIpcArgs(&aControllerData, &time)));
       
    86 	}
       
    87 
       
    88 void RSisRegistryAccessSession::UpdateEntryL(const TDesC8& aControllerData, TInt& aSpentTimeInMillisecond)
       
    89 	{
       
    90 	TPckg<TInt> time(aSpentTimeInMillisecond);
       
    91 	User::LeaveIfError(SendReceive(EUpdateEntry, TIpcArgs(&aControllerData, &time)));
       
    92 	}
       
    93 
       
    94 TInt RSisRegistryAccessSession::DeleteEntryL(Swi::CSisRegistryPackage& aPackage, TInt& aSpentTimeInMillisecond)
       
    95 	{
       
    96 	TPckgC<TUid> packageUid(aPackage.Uid());
       
    97 	TInt index = aPackage.Index();
       
    98 	TPckg<TInt> time(aSpentTimeInMillisecond);
       
    99 	return SendReceive(EDeleteEntry, TIpcArgs(index, &packageUid, &time));
       
   100 	}
       
   101