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