1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicshwdrivers/surfacemgr/test/src/tsmgmultprocessshared.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,179 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// surface manager API
1.18 +//
1.19 +//
1.20 +
1.21 +#include "tsmgmultprocessshared.h"
1.22 +#include <e32def_private.h>
1.23 +
1.24 +/**
1.25 +Creates a wrapper object for a shared chunk between processes
1.26 +*/
1.27 +CChunkWrapper* CChunkWrapper::CreateL(const TDesC& aName, TInt aSize, TInt aMaxSize)
1.28 + {
1.29 + CChunkWrapper* self = new(ELeave) CChunkWrapper();
1.30 + CleanupStack::PushL(self);
1.31 + self->CreateConstructL(aName, aSize, aMaxSize);
1.32 + CleanupStack::Pop(self);
1.33 + return self;
1.34 + }
1.35 +
1.36 +/**
1.37 +Second phase creation of the shared chunk wrapper
1.38 +*/
1.39 +void CChunkWrapper::CreateConstructL(const TDesC& aName, TInt aSize, TInt aMaxSize)
1.40 + {
1.41 + User::LeaveIfError(iChunk.CreateGlobal(aName, aSize, aMaxSize));
1.42 + }
1.43 +
1.44 +/**
1.45 +Opens an alerady created wrapper for a chunk that we share between processes
1.46 +*/
1.47 +CChunkWrapper* CChunkWrapper::OpenL(const TDesC& aName, TBool aIsReadOnly)
1.48 + {
1.49 + CChunkWrapper* self = new(ELeave) CChunkWrapper();
1.50 + CleanupStack::PushL(self);
1.51 + self->OpenConstructL(aName, aIsReadOnly);
1.52 + CleanupStack::Pop(self);
1.53 + return self;
1.54 + }
1.55 +
1.56 +/**
1.57 +Second phase opening a previously created chunk
1.58 +*/
1.59 +void CChunkWrapper::OpenConstructL(const TDesC& aName, TBool aIsReadOnly)
1.60 + {
1.61 + User::LeaveIfError(iChunk.OpenGlobal(aName, aIsReadOnly));
1.62 + }
1.63 +
1.64 +/**
1.65 +Destructor
1.66 +*/
1.67 +CChunkWrapper::~CChunkWrapper()
1.68 + {
1.69 + iChunk.Close();
1.70 + }
1.71 +/**
1.72 +Constructor
1.73 +*/
1.74 +CChunkWrapper::CChunkWrapper()
1.75 + {
1.76 + }
1.77 +
1.78 +
1.79 +/**
1.80 +Sets the results (bitmapped into a TInt) of all the second process tests
1.81 +
1.82 +Second process results always reside in the first sizeof(TInt) bytes of the chunk
1.83 +*/
1.84 +void CChunkWrapper::SetSecondProcessResults(TInt aResult)
1.85 + {
1.86 + TUint8* ptr = iChunk.Base();
1.87 + TInt* intPtr = reinterpret_cast<TInt*>(ptr);
1.88 + *intPtr = aResult;
1.89 + }
1.90 +
1.91 +/**
1.92 +Gets the results (bitmapped into a TInt) of all the second process tests
1.93 +
1.94 +Second process results always reside in the first sizeof(TInt) bytes of the chunk
1.95 +*/
1.96 +TInt CChunkWrapper::GetSecondProcessResults()
1.97 + {
1.98 + TUint8* ptr = iChunk.Base();
1.99 + TInt* intPtr = reinterpret_cast<TInt*>(ptr);
1.100 + return *intPtr;
1.101 + }
1.102 +
1.103 +/**
1.104 +Sets the results (bitmapped into a TInt) of all the third process tests
1.105 +
1.106 +Third process results always reside in the second sizeof(TInt) bytes of the chunk
1.107 +*/
1.108 +void CChunkWrapper::SetThirdProcessResults(TInt aResult)
1.109 + {
1.110 + TUint8* ptr = iChunk.Base();
1.111 + TInt* intPtr = reinterpret_cast<TInt*>(ptr);
1.112 + intPtr++; // Offset to second TInt in the chunk
1.113 + *intPtr = aResult;
1.114 + }
1.115 +
1.116 +/**
1.117 +Gets the results (bitmapped into a TInt) of all the second process tests
1.118 +
1.119 +Second process results always reside in the first sizeof(TInt) bytes of the chunk
1.120 +*/
1.121 +TInt CChunkWrapper::GetThirdProcessResults()
1.122 + {
1.123 + TUint8* ptr = iChunk.Base();
1.124 + TInt* intPtr = reinterpret_cast<TInt*>(ptr);
1.125 + intPtr++; // Offset to second TInt in the chunk
1.126 + return *intPtr;
1.127 + }
1.128 +
1.129 +
1.130 +/**
1.131 +Puts the surfaceId of a surface on the shared chunk
1.132 +*/
1.133 +void CChunkWrapper::SetId(const TSurfaceId& aId)
1.134 + {
1.135 + TUint8* ptr = iChunk.Base();
1.136 + TInt* intPtr = reinterpret_cast<TInt*>(ptr);
1.137 + intPtr += 2; // Offset past first two TInts in the chunk
1.138 + TUint32* uintPtr = reinterpret_cast<TUint32*>(intPtr);
1.139 + for(TInt ii = 0; ii < 4; ++ii, ++uintPtr)
1.140 + {
1.141 + *uintPtr = aId.iInternal[ii];
1.142 + }
1.143 + }
1.144 +
1.145 +/**
1.146 +Reads the surfaceId of a surface off the shared chunk
1.147 +*/
1.148 +TSurfaceId CChunkWrapper::GetId()
1.149 + {
1.150 + TSurfaceId id;
1.151 + TUint8* ptr = iChunk.Base();
1.152 + TInt* intPtr = reinterpret_cast<TInt*>(ptr);
1.153 + intPtr += 2; // Offset past first two TInts in the chunk
1.154 + TUint32* uintPtr = reinterpret_cast<TUint32*>(intPtr);
1.155 + for(TInt ii = 0; ii < 4; ++ii, ++uintPtr)
1.156 + {
1.157 + id.iInternal[ii] = *uintPtr;
1.158 + }
1.159 + return id;
1.160 + }
1.161 +
1.162 +CTestDriver::CTestDriver()
1.163 + {
1.164 + iTestResult = 0;
1.165 + }
1.166 +
1.167 +void CTestDriver::ConstructL()
1.168 + {
1.169 + User::LeaveIfError(iSurfaceManager.Open());
1.170 + TRAPD(err,iChunkWrapper = CChunkWrapper::OpenL(KSharedChunkName, ETrue));
1.171 + if (err == KErrNotFound) //the chunk wrapper is not yet created, cant be opened
1.172 + {
1.173 + iChunkWrapper =CChunkWrapper::CreateL(KSharedChunkName, KSharedChunkSize, KSharedChunkSize);
1.174 + }
1.175 + }
1.176 +
1.177 +CTestDriver::~CTestDriver()
1.178 + {
1.179 + // Cleanup
1.180 + iSurfaceManager.Close();
1.181 + delete iChunkWrapper;
1.182 + }