| 
sl@0
 | 
     1  | 
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
  | 
| 
sl@0
 | 
     2  | 
// All rights reserved.
  | 
| 
sl@0
 | 
     3  | 
// This component and the accompanying materials are made available
  | 
| 
sl@0
 | 
     4  | 
// under the terms of "Eclipse Public License v1.0"
  | 
| 
sl@0
 | 
     5  | 
// which accompanies this distribution, and is available
  | 
| 
sl@0
 | 
     6  | 
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
  | 
| 
sl@0
 | 
     7  | 
//
  | 
| 
sl@0
 | 
     8  | 
// Initial Contributors:
  | 
| 
sl@0
 | 
     9  | 
// Nokia Corporation - initial contribution.
  | 
| 
sl@0
 | 
    10  | 
//
  | 
| 
sl@0
 | 
    11  | 
// Contributors:
  | 
| 
sl@0
 | 
    12  | 
//
  | 
| 
sl@0
 | 
    13  | 
// Description:
  | 
| 
sl@0
 | 
    14  | 
// surface manager API
  | 
| 
sl@0
 | 
    15  | 
// 
  | 
| 
sl@0
 | 
    16  | 
//
  | 
| 
sl@0
 | 
    17  | 
  | 
| 
sl@0
 | 
    18  | 
#include "tsmgmultprocessshared.h"
  | 
| 
sl@0
 | 
    19  | 
#include <e32def_private.h>
  | 
| 
sl@0
 | 
    20  | 
  | 
| 
sl@0
 | 
    21  | 
/**
  | 
| 
sl@0
 | 
    22  | 
Creates a wrapper object for a shared chunk between processes
  | 
| 
sl@0
 | 
    23  | 
*/
  | 
| 
sl@0
 | 
    24  | 
CChunkWrapper* CChunkWrapper::CreateL(const TDesC& aName, TInt aSize, TInt aMaxSize)
  | 
| 
sl@0
 | 
    25  | 
	{
 | 
| 
sl@0
 | 
    26  | 
	CChunkWrapper* self = new(ELeave) CChunkWrapper();
  | 
| 
sl@0
 | 
    27  | 
	CleanupStack::PushL(self);
  | 
| 
sl@0
 | 
    28  | 
	self->CreateConstructL(aName, aSize, aMaxSize);
  | 
| 
sl@0
 | 
    29  | 
	CleanupStack::Pop(self);
  | 
| 
sl@0
 | 
    30  | 
	return self;
  | 
| 
sl@0
 | 
    31  | 
	}
  | 
| 
sl@0
 | 
    32  | 
  | 
| 
sl@0
 | 
    33  | 
/**
  | 
| 
sl@0
 | 
    34  | 
Second phase creation of the shared chunk wrapper
  | 
| 
sl@0
 | 
    35  | 
*/
  | 
| 
sl@0
 | 
    36  | 
void CChunkWrapper::CreateConstructL(const TDesC& aName, TInt aSize, TInt aMaxSize)
  | 
| 
sl@0
 | 
    37  | 
	{
 | 
| 
sl@0
 | 
    38  | 
	User::LeaveIfError(iChunk.CreateGlobal(aName, aSize, aMaxSize));
  | 
| 
sl@0
 | 
    39  | 
	}
  | 
| 
sl@0
 | 
    40  | 
  | 
| 
sl@0
 | 
    41  | 
/**
  | 
| 
sl@0
 | 
    42  | 
Opens an alerady created wrapper for a chunk that we share between processes
  | 
| 
sl@0
 | 
    43  | 
*/
  | 
| 
sl@0
 | 
    44  | 
CChunkWrapper* CChunkWrapper::OpenL(const TDesC& aName, TBool aIsReadOnly)
  | 
| 
sl@0
 | 
    45  | 
	{
 | 
| 
sl@0
 | 
    46  | 
	CChunkWrapper* self = new(ELeave) CChunkWrapper();
  | 
| 
sl@0
 | 
    47  | 
	CleanupStack::PushL(self);
  | 
| 
sl@0
 | 
    48  | 
	self->OpenConstructL(aName, aIsReadOnly);
  | 
| 
sl@0
 | 
    49  | 
	CleanupStack::Pop(self);
  | 
| 
sl@0
 | 
    50  | 
	return self;
  | 
| 
sl@0
 | 
    51  | 
	}
  | 
| 
sl@0
 | 
    52  | 
  | 
| 
sl@0
 | 
    53  | 
/**
  | 
| 
sl@0
 | 
    54  | 
Second phase opening a previously created chunk
  | 
| 
sl@0
 | 
    55  | 
*/	
  | 
| 
sl@0
 | 
    56  | 
void CChunkWrapper::OpenConstructL(const TDesC& aName, TBool aIsReadOnly)
  | 
| 
sl@0
 | 
    57  | 
	{
 | 
| 
sl@0
 | 
    58  | 
	User::LeaveIfError(iChunk.OpenGlobal(aName, aIsReadOnly));
  | 
| 
sl@0
 | 
    59  | 
	}
  | 
| 
sl@0
 | 
    60  | 
  | 
| 
sl@0
 | 
    61  | 
/**
  | 
| 
sl@0
 | 
    62  | 
Destructor
  | 
| 
sl@0
 | 
    63  | 
*/	
  | 
| 
sl@0
 | 
    64  | 
CChunkWrapper::~CChunkWrapper()
  | 
| 
sl@0
 | 
    65  | 
	{
 | 
| 
sl@0
 | 
    66  | 
	iChunk.Close();
  | 
| 
sl@0
 | 
    67  | 
	}
  | 
| 
sl@0
 | 
    68  | 
/**
  | 
| 
sl@0
 | 
    69  | 
Constructor
  | 
| 
sl@0
 | 
    70  | 
*/	
  | 
| 
sl@0
 | 
    71  | 
CChunkWrapper::CChunkWrapper()
  | 
| 
sl@0
 | 
    72  | 
	{
 | 
| 
sl@0
 | 
    73  | 
	}
  | 
| 
sl@0
 | 
    74  | 
  | 
| 
sl@0
 | 
    75  | 
  | 
| 
sl@0
 | 
    76  | 
/**
  | 
| 
sl@0
 | 
    77  | 
Sets the results (bitmapped into a TInt) of all the second process tests
  | 
| 
sl@0
 | 
    78  | 
  | 
| 
sl@0
 | 
    79  | 
Second process results always reside in the first sizeof(TInt) bytes of the chunk
  | 
| 
sl@0
 | 
    80  | 
*/
  | 
| 
sl@0
 | 
    81  | 
void CChunkWrapper::SetSecondProcessResults(TInt aResult)
  | 
| 
sl@0
 | 
    82  | 
	{
 | 
| 
sl@0
 | 
    83  | 
	TUint8* ptr = iChunk.Base();
  | 
| 
sl@0
 | 
    84  | 
	TInt* intPtr = reinterpret_cast<TInt*>(ptr);
  | 
| 
sl@0
 | 
    85  | 
	*intPtr = aResult;
  | 
| 
sl@0
 | 
    86  | 
	}
  | 
| 
sl@0
 | 
    87  | 
  | 
| 
sl@0
 | 
    88  | 
/**
  | 
| 
sl@0
 | 
    89  | 
Gets the results (bitmapped into a TInt) of all the second process tests
  | 
| 
sl@0
 | 
    90  | 
  | 
| 
sl@0
 | 
    91  | 
Second process results always reside in the first sizeof(TInt) bytes of the chunk
  | 
| 
sl@0
 | 
    92  | 
*/
  | 
| 
sl@0
 | 
    93  | 
TInt CChunkWrapper::GetSecondProcessResults()
  | 
| 
sl@0
 | 
    94  | 
	{
 | 
| 
sl@0
 | 
    95  | 
	TUint8* ptr = iChunk.Base();
  | 
| 
sl@0
 | 
    96  | 
	TInt* intPtr = reinterpret_cast<TInt*>(ptr);
  | 
| 
sl@0
 | 
    97  | 
	return *intPtr; 
  | 
| 
sl@0
 | 
    98  | 
	}
  | 
| 
sl@0
 | 
    99  | 
  | 
| 
sl@0
 | 
   100  | 
/**
  | 
| 
sl@0
 | 
   101  | 
Sets the results (bitmapped into a TInt) of all the third process tests
  | 
| 
sl@0
 | 
   102  | 
  | 
| 
sl@0
 | 
   103  | 
Third process results always reside in the second sizeof(TInt) bytes of the chunk
  | 
| 
sl@0
 | 
   104  | 
*/
  | 
| 
sl@0
 | 
   105  | 
void CChunkWrapper::SetThirdProcessResults(TInt aResult)
  | 
| 
sl@0
 | 
   106  | 
	{
 | 
| 
sl@0
 | 
   107  | 
	TUint8* ptr = iChunk.Base();
  | 
| 
sl@0
 | 
   108  | 
	TInt* intPtr = reinterpret_cast<TInt*>(ptr);
  | 
| 
sl@0
 | 
   109  | 
	intPtr++; // Offset to second TInt in the chunk
  | 
| 
sl@0
 | 
   110  | 
	*intPtr = aResult;
  | 
| 
sl@0
 | 
   111  | 
	}
  | 
| 
sl@0
 | 
   112  | 
  | 
| 
sl@0
 | 
   113  | 
/**
  | 
| 
sl@0
 | 
   114  | 
Gets the results (bitmapped into a TInt) of all the second process tests
  | 
| 
sl@0
 | 
   115  | 
  | 
| 
sl@0
 | 
   116  | 
Second process results always reside in the first sizeof(TInt) bytes of the chunk
  | 
| 
sl@0
 | 
   117  | 
*/
  | 
| 
sl@0
 | 
   118  | 
TInt CChunkWrapper::GetThirdProcessResults()
  | 
| 
sl@0
 | 
   119  | 
	{
 | 
| 
sl@0
 | 
   120  | 
	TUint8* ptr = iChunk.Base();
  | 
| 
sl@0
 | 
   121  | 
	TInt* intPtr = reinterpret_cast<TInt*>(ptr);
  | 
| 
sl@0
 | 
   122  | 
	intPtr++; // Offset to second TInt in the chunk
  | 
| 
sl@0
 | 
   123  | 
	return *intPtr; 
  | 
| 
sl@0
 | 
   124  | 
	}
  | 
| 
sl@0
 | 
   125  | 
  | 
| 
sl@0
 | 
   126  | 
  | 
| 
sl@0
 | 
   127  | 
/**
  | 
| 
sl@0
 | 
   128  | 
Puts the surfaceId of a surface on the shared chunk
  | 
| 
sl@0
 | 
   129  | 
*/
  | 
| 
sl@0
 | 
   130  | 
void CChunkWrapper::SetId(const TSurfaceId& aId)
  | 
| 
sl@0
 | 
   131  | 
	{
 | 
| 
sl@0
 | 
   132  | 
	TUint8* ptr = iChunk.Base();
  | 
| 
sl@0
 | 
   133  | 
	TInt* intPtr = reinterpret_cast<TInt*>(ptr);
  | 
| 
sl@0
 | 
   134  | 
	intPtr += 2; // Offset past first two TInts in the chunk
  | 
| 
sl@0
 | 
   135  | 
	TUint32* uintPtr = reinterpret_cast<TUint32*>(intPtr);
  | 
| 
sl@0
 | 
   136  | 
	for(TInt ii = 0; ii < 4; ++ii, ++uintPtr)
  | 
| 
sl@0
 | 
   137  | 
		{
 | 
| 
sl@0
 | 
   138  | 
		*uintPtr = aId.iInternal[ii];
  | 
| 
sl@0
 | 
   139  | 
		}
  | 
| 
sl@0
 | 
   140  | 
	}
  | 
| 
sl@0
 | 
   141  | 
  | 
| 
sl@0
 | 
   142  | 
/**
  | 
| 
sl@0
 | 
   143  | 
Reads the surfaceId of a surface off the shared chunk
  | 
| 
sl@0
 | 
   144  | 
*/	
  | 
| 
sl@0
 | 
   145  | 
TSurfaceId CChunkWrapper::GetId()
  | 
| 
sl@0
 | 
   146  | 
	{
 | 
| 
sl@0
 | 
   147  | 
	TSurfaceId id;
  | 
| 
sl@0
 | 
   148  | 
	TUint8* ptr = iChunk.Base();
  | 
| 
sl@0
 | 
   149  | 
	TInt* intPtr = reinterpret_cast<TInt*>(ptr);
  | 
| 
sl@0
 | 
   150  | 
	intPtr += 2; // Offset past first two TInts in the chunk
  | 
| 
sl@0
 | 
   151  | 
	TUint32* uintPtr = reinterpret_cast<TUint32*>(intPtr);
  | 
| 
sl@0
 | 
   152  | 
	for(TInt ii = 0; ii < 4; ++ii, ++uintPtr)
  | 
| 
sl@0
 | 
   153  | 
		{
 | 
| 
sl@0
 | 
   154  | 
		id.iInternal[ii] = *uintPtr;
  | 
| 
sl@0
 | 
   155  | 
		}
  | 
| 
sl@0
 | 
   156  | 
	return id;
  | 
| 
sl@0
 | 
   157  | 
	}	
  | 
| 
sl@0
 | 
   158  | 
  | 
| 
sl@0
 | 
   159  | 
CTestDriver::CTestDriver()
  | 
| 
sl@0
 | 
   160  | 
	{
 | 
| 
sl@0
 | 
   161  | 
	iTestResult = 0;
  | 
| 
sl@0
 | 
   162  | 
	}
  | 
| 
sl@0
 | 
   163  | 
  | 
| 
sl@0
 | 
   164  | 
void CTestDriver::ConstructL()
  | 
| 
sl@0
 | 
   165  | 
	{
 | 
| 
sl@0
 | 
   166  | 
	User::LeaveIfError(iSurfaceManager.Open());
  | 
| 
sl@0
 | 
   167  | 
	TRAPD(err,iChunkWrapper =  CChunkWrapper::OpenL(KSharedChunkName, ETrue));
  | 
| 
sl@0
 | 
   168  | 
	if (err == KErrNotFound) //the chunk wrapper is not yet created, cant be opened
  | 
| 
sl@0
 | 
   169  | 
		{
 | 
| 
sl@0
 | 
   170  | 
		iChunkWrapper =CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
  | 
| 
sl@0
 | 
   171  | 
		}
  | 
| 
sl@0
 | 
   172  | 
	}
  | 
| 
sl@0
 | 
   173  | 
  | 
| 
sl@0
 | 
   174  | 
CTestDriver::~CTestDriver()
  | 
| 
sl@0
 | 
   175  | 
	{
 | 
| 
sl@0
 | 
   176  | 
	// Cleanup 
  | 
| 
sl@0
 | 
   177  | 
	iSurfaceManager.Close();
  | 
| 
sl@0
 | 
   178  | 
	delete iChunkWrapper;
  | 
| 
sl@0
 | 
   179  | 
	}
  |