installationservices/swcomponentregistry/test/tscraccessor/source/tscraccessor_client.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     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 * Scr Accessor - client interface implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file 
       
    22  @test
       
    23  @internalComponent
       
    24 */
       
    25  
       
    26 #include "tscraccessor_client.h"
       
    27 #include "tscraccessor_common.h"
       
    28 
       
    29 static TInt StartScrAccessServer()
       
    30 	{
       
    31 	const TUidType serverUid(KNullUid, KNullUid, KScrAccessServerUid3);
       
    32 	RProcess server;
       
    33 	TInt err = server.Create(KScrAccessServerBinary, 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 RScrAccessor::Connect()
       
    61 	{
       
    62 	TInt retry = 2;
       
    63 	for (;;)
       
    64 		{
       
    65 		TInt err = CreateSession(KScrAccessServerName, 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 = StartScrAccessServer();
       
    75 		if (err != KErrNone && err != KErrAlreadyExists)
       
    76 			{
       
    77 			return err;
       
    78 			}
       
    79 		}
       
    80 	}
       
    81 
       
    82 void RScrAccessor::AddSoftwareTypeL(TAccessorOperationType aOpType, TAccessorOperationResult& aOpResult, TInt& aSpentTimeInMillisecond)
       
    83 	{
       
    84 	TPckg<TAccessorOperationResult> opResult(aOpResult);
       
    85 	TPckg<TInt> time(aSpentTimeInMillisecond);
       
    86 	User::LeaveIfError(SendReceive(EAddSoftwareType, TIpcArgs(aOpType, &opResult, &time)));
       
    87 	}
       
    88 
       
    89 void RScrAccessor::DeleteSoftwareTypeL(TAccessorOperationResult& aOpResult, TInt& aSpentTimeInMillisecond)
       
    90 	{
       
    91 	TPckg<TAccessorOperationResult> opResult(aOpResult);
       
    92 	TPckg<TInt> time(aSpentTimeInMillisecond);
       
    93 	User::LeaveIfError(SendReceive(EDeleteSoftwareType, TIpcArgs(&opResult, &time)));
       
    94 	}
       
    95 
       
    96 TInt RScrAccessor::DeleteFile(const TDesC& aFilePath)
       
    97 	{
       
    98 	return SendReceive(EDeleteFile, TIpcArgs(&aFilePath));
       
    99 	}
       
   100 
       
   101 TInt RScrAccessor::CopyFile(const TDesC& aSourceFilePath, const TDesC& aDestinationFilePath)
       
   102 	{
       
   103 	return SendReceive(ECopyFile, TIpcArgs(&aSourceFilePath, &aDestinationFilePath));
       
   104 	}
       
   105