|
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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 */ |
|
19 |
|
20 #include <elements/nm_address_internal.h> |
|
21 #include <elements/nm_transport.h> |
|
22 |
|
23 |
|
24 #ifdef _DEBUG |
|
25 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
26 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
27 _LIT(KSpecAssert_ElemNodeMessAdrC, "ElemNodeMessAdrC"); |
|
28 #endif |
|
29 |
|
30 using namespace Messages; |
|
31 |
|
32 // |
|
33 //TRuntimeCtxId |
|
34 |
|
35 /****************************************************************************************************** |
|
36 * |
|
37 * |
|
38 * TRuntimeCtxId |
|
39 * |
|
40 * |
|
41 *******************************************************************************************************/ |
|
42 namespace Mem4NullRuntimeCtxId |
|
43 { |
|
44 static const TUint8 mem[sizeof(TRuntimeCtxId)] = { sizeof(TRuntimeCtxId) & ~TRuntimeCtxId::KIsNullMask8, 0}; |
|
45 } |
|
46 |
|
47 EXPORT_C const TRuntimeCtxId& TRuntimeCtxId::NullId() |
|
48 { |
|
49 return *reinterpret_cast<const TRuntimeCtxId *>(Mem4NullRuntimeCtxId::mem); |
|
50 } |
|
51 |
|
52 EXPORT_C TRuntimeCtxId::TRuntimeCtxId(const TRuntimeCtxId& aRuntimeCtxId) |
|
53 : iSize(sizeof(TRuntimeCtxId)) |
|
54 { |
|
55 *this = aRuntimeCtxId; |
|
56 } |
|
57 |
|
58 EXPORT_C TRuntimeCtxId::TRuntimeCtxId() |
|
59 : iSize(sizeof(TRuntimeCtxId)) |
|
60 { |
|
61 Mem::FillZ((TUint8*)this + _FOFF(TRuntimeCtxId, iSalt), sizeof(TRuntimeCtxId) - _FOFF(TRuntimeCtxId, iSalt)); |
|
62 } |
|
63 |
|
64 //protected |
|
65 EXPORT_C TRuntimeCtxId::TRuntimeCtxId(TUint8 aSize) |
|
66 : iSize(aSize) |
|
67 { |
|
68 Mem::FillZ((TUint8*)this + _FOFF(TRuntimeCtxId, iSalt), sizeof(TRuntimeCtxId) - _FOFF(TRuntimeCtxId, iSalt)); |
|
69 } |
|
70 |
|
71 EXPORT_C const TRuntimeCtxId& TRuntimeCtxId::operator=(const TRuntimeCtxId& aRHS) |
|
72 { |
|
73 if (Size()) |
|
74 { |
|
75 //Valid address already, reassign only the matching part + isnull flag |
|
76 iSize = aRHS.IsNull()? iSize & ~KIsNullMask8 : iSize | KIsNullMask8; |
|
77 } |
|
78 else |
|
79 { |
|
80 iSize = aRHS.iSize; //This will also set/not set KIsNullMask8! |
|
81 } |
|
82 |
|
83 Mem::Copy((TUint8*)this + _FOFF(TRuntimeCtxId, iSalt), (const TUint8*)&aRHS + _FOFF(TRuntimeCtxId, iSalt), Min(Size(), aRHS.Size()) - _FOFF(TRuntimeCtxId, iSalt)); |
|
84 |
|
85 return *this; |
|
86 } |
|
87 |
|
88 EXPORT_C TBool TRuntimeCtxId::operator==(const TRuntimeCtxId& aRHS) const |
|
89 { |
|
90 return ComparePart(aRHS, Size()); |
|
91 } |
|
92 |
|
93 EXPORT_C TBool TRuntimeCtxId::ComparePart(const TRuntimeCtxId& aRHS, TUint8 aSize) const |
|
94 { |
|
95 __ASSERT_DEBUG(aSize <= Size(), User::Panic(KSpecAssert_ElemNodeMessAdrC, 1)); |
|
96 |
|
97 //No need to compare bits if either or both operands are NULL. |
|
98 TInt comparesize = (IsNull() || aRHS.IsNull()) ? 0 : (Min(aSize, aRHS.Size()) - _FOFF(TRuntimeCtxId, iSalt)); |
|
99 if (comparesize>0) |
|
100 { |
|
101 return Mem::Compare((const TUint8*)this + _FOFF(TRuntimeCtxId, iSalt), comparesize, (const TUint8*)&aRHS + _FOFF(TRuntimeCtxId, iSalt), comparesize) == 0; |
|
102 } |
|
103 |
|
104 //If both are NULL, then we can say they're equal, otherwise they're not. |
|
105 return IsNull() && aRHS.IsNull(); |
|
106 } |
|
107 |
|
108 EXPORT_C TInt TRuntimeCtxId::Store(TDes8& aDes) const |
|
109 { |
|
110 if (Size() > aDes.MaxSize()) |
|
111 { |
|
112 return KErrOverflow; |
|
113 } |
|
114 aDes.Append((TUint8*)this, Size()); |
|
115 return KErrNone; |
|
116 } |
|
117 |
|
118 EXPORT_C void TRuntimeCtxId::PostTo(const TRuntimeCtxId& aPostFrom, const TSignalBase& aMessage) const |
|
119 { |
|
120 RClientInterface::OpenPostMessageClose(aPostFrom, *this, aMessage); |
|
121 } |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 /****************************************************************************************************** |
|
128 * |
|
129 * |
|
130 * TNodeId |
|
131 * |
|
132 * |
|
133 *******************************************************************************************************/ |
|
134 namespace Mem4NullNodeId |
|
135 { |
|
136 static const TUint8 mem[sizeof(TNodeId)] = { sizeof(TNodeId) & ~TRuntimeCtxId::KIsNullMask8, 0}; |
|
137 } |
|
138 |
|
139 EXPORT_C const TNodeId& TNodeId::NullId() |
|
140 { |
|
141 return *reinterpret_cast<const TNodeId *>(Mem4NullNodeId::mem); |
|
142 } |
|
143 |
|
144 EXPORT_C TNodeId::TNodeId() |
|
145 : TRuntimeCtxId(sizeof(TNodeId)), |
|
146 iPtr(NULL) |
|
147 { |
|
148 } |
|
149 |
|
150 EXPORT_C TNodeId::TNodeId(const TNodeId& aNodeId) |
|
151 : TRuntimeCtxId(sizeof(TNodeId)) |
|
152 { |
|
153 *this = aNodeId; |
|
154 } |
|
155 |
|
156 //protected |
|
157 EXPORT_C TNodeId::TNodeId(TUint8 aSize) |
|
158 : TRuntimeCtxId(aSize), |
|
159 iPtr(NULL) |
|
160 { |
|
161 } |
|
162 |
|
163 EXPORT_C const TNodeId& TNodeId::operator=(const TRuntimeCtxId& aRHS) |
|
164 { |
|
165 return address_cast<TNodeId>(TRuntimeCtxId::operator=(aRHS)); |
|
166 } |
|
167 |
|
168 /****************************************************************************************************** |
|
169 * TNodeIdRemainder |
|
170 *******************************************************************************************************/ |
|
171 EXPORT_C TNodeIdRemainder::TNodeIdRemainder(const TRuntimeCtxId& aFrom) |
|
172 { |
|
173 *this = aFrom; |
|
174 } |
|
175 |
|
176 EXPORT_C TNodeIdRemainder::TNodeIdRemainder() |
|
177 :iSize(0) |
|
178 { |
|
179 Mem::FillZ(iRemainder, sizeof(iRemainder)); |
|
180 } |
|
181 |
|
182 EXPORT_C const TNodeIdRemainder& TNodeIdRemainder::operator=(const TRuntimeCtxId& aRHS) |
|
183 { |
|
184 //Here we assign only the remainder bit off aRHS; |
|
185 iSize = aRHS.Size() - sizeof(TNodeId); |
|
186 if (iSize > 0) |
|
187 { |
|
188 //No need to assert no sizes, as no TRuntimeCtxId can exceed KMaxInlineAddressSize + sizeof(TUint) |
|
189 //and TNodeIdRemainder::EPayloadSize is calculated based on that. There will always be room. |
|
190 Mem::Copy(iRemainder, (const TUint8*)&aRHS + sizeof(TNodeId), iSize); |
|
191 } |
|
192 else |
|
193 { |
|
194 //Zero all including size |
|
195 Mem::FillZ(iRemainder, sizeof(iRemainder)); |
|
196 iSize = 0; |
|
197 } |
|
198 return *this; |
|
199 } |
|
200 |
|
201 EXPORT_C TBool TNodeIdRemainder::operator==(const TRuntimeCtxId& aRHS) const |
|
202 { |
|
203 TInt comparablePayloadSize = Min(aRHS.Size() - sizeof(TNodeId), iSize); |
|
204 return Mem::Compare(iRemainder, comparablePayloadSize, (const TUint8*)&aRHS + sizeof(TNodeId), comparablePayloadSize) == 0; |
|
205 } |
|
206 |
|
207 EXPORT_C TBool TNodeIdRemainder::operator==(const TNodeIdRemainder& aRHS) const |
|
208 { |
|
209 TInt comparablePayloadSize = Min(aRHS.Size(), iSize); |
|
210 return Mem::Compare(iRemainder, comparablePayloadSize, (const TUint8*)&aRHS.iRemainder, comparablePayloadSize) == 0; |
|
211 } |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 /****************************************************************************************************** |
|
218 * |
|
219 * |
|
220 * TNodeCtxId |
|
221 * |
|
222 * |
|
223 *******************************************************************************************************/ |
|
224 namespace Mem4NullNodeCtxId |
|
225 { |
|
226 static const TUint8 mem[sizeof(TNodeCtxId)] = { sizeof(TNodeCtxId) & ~TRuntimeCtxId::KIsNullMask8, 0}; |
|
227 } |
|
228 |
|
229 EXPORT_C const TNodeCtxId& TNodeCtxId::NullId() |
|
230 { |
|
231 return *reinterpret_cast<const TNodeCtxId *>(Mem4NullNodeCtxId::mem); |
|
232 } |
|
233 |
|
234 EXPORT_C TNodeCtxId::TNodeCtxId() |
|
235 : TNodeId(sizeof(TNodeCtxId)), |
|
236 iNodeCtx(0), |
|
237 iReserved(0) |
|
238 { |
|
239 } |
|
240 |
|
241 EXPORT_C TNodeCtxId::TNodeCtxId(TUint16 aNodeCtx, const TNodeId& aNodeId) |
|
242 : TNodeId(sizeof(TNodeCtxId)), |
|
243 iNodeCtx(aNodeCtx), |
|
244 iReserved(0) |
|
245 { |
|
246 __ASSERT_DEBUG(address_cast<TNodeCtxId>(&aNodeId)==NULL, User::Panic(KSpecAssert_ElemNodeMessAdrC, 2)); //Be careful! You are overriding your aNodeCtx! Use TNodeCtxId(const TNodeCtxId& aNodeCtxId). |
|
247 *this = aNodeId; |
|
248 } |
|
249 |
|
250 EXPORT_C TNodeCtxId::TNodeCtxId(const TNodeCtxId& aNodeCtxId) |
|
251 : TNodeId(sizeof(TNodeCtxId)) |
|
252 { |
|
253 *this = aNodeCtxId; |
|
254 } |
|
255 |
|
256 //protected |
|
257 EXPORT_C TNodeCtxId::TNodeCtxId(TUint8 aSize) |
|
258 : TNodeId(aSize), |
|
259 iNodeCtx(0) |
|
260 { |
|
261 } |
|
262 |
|
263 EXPORT_C const TNodeCtxId& TNodeCtxId::operator=(const TRuntimeCtxId& aRHS) |
|
264 { |
|
265 return address_cast<TNodeCtxId>(TRuntimeCtxId::operator=(aRHS)); |
|
266 } |
|
267 |
|
268 /****************************************************************************************************** |
|
269 * |
|
270 * |
|
271 * TNodeOid |
|
272 * |
|
273 * |
|
274 *******************************************************************************************************/ |
|
275 |
|
276 EXPORT_C TNodeOid::TNodeOid(TAny* aObj) |
|
277 { |
|
278 TNodeIdOp(*this).SetPtr(aObj); |
|
279 TlsGlobals::Get().TransportReceiver().RegisterAddress(*this); |
|
280 } |
|
281 |
|
282 EXPORT_C TNodeOid::TNodeOid(ANode& aObj) |
|
283 { |
|
284 TNodeIdOp(*this).SetPtr(static_cast<TAny*>(&aObj)); |
|
285 TlsGlobals::Get().TransportReceiver().RegisterAddress(*this); |
|
286 } |
|
287 |
|
288 EXPORT_C TNodeOid::~TNodeOid() |
|
289 { |
|
290 // We allow TNodeOid objects to be unregistered early so we have to permit null TNodeOid |
|
291 // objects to exist. We avoid the assertion that tests for null in UnregisterSelf by |
|
292 // checking to make sure that the TNodeOid is not null before calling it. |
|
293 // We do not remove the assertion because we still want to guard against repeated calls |
|
294 // to UnregisterSelf. |
|
295 if(!IsNull()) |
|
296 { |
|
297 UnregisterSelf(); |
|
298 } |
|
299 } |
|
300 |
|
301 /** Usually a node remains registered with the transport mechanism for its lifetime, however some special |
|
302 cases need to unregister early (eg to avoid registration at all). |
|
303 */ |
|
304 EXPORT_C void TNodeOid::UnregisterSelf() |
|
305 { |
|
306 __ASSERT_ALWAYS(!IsNull(), User::Panic(KMessagesPanic, EAddressNotValidPanic)); |
|
307 TlsGlobals::Get().TransportReceiver().DeregisterAddress(*this); |
|
308 } |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |