|
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 "nm_common.h" |
|
21 #include "nm_interfaces.h" |
|
22 #include <elements/nm_transport.h> |
|
23 #include <elements/nm_address_internal.h> |
|
24 #include "nm_signals.h" |
|
25 |
|
26 |
|
27 #ifdef _DEBUG |
|
28 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
29 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
30 _LIT(KSpecAssert_ElemNodeMessIntC, "ElemNodeMessIntC"); |
|
31 #endif |
|
32 |
|
33 using namespace Messages; |
|
34 using namespace Meta; |
|
35 |
|
36 // |
|
37 //TClientType |
|
38 namespace Mem4NullType |
|
39 { |
|
40 static const TUint8 mem[sizeof(TClientType)] = {0}; |
|
41 } |
|
42 |
|
43 EXPORT_C const TClientType& TClientType::NullType() {return *reinterpret_cast<const TClientType*>(Mem4NullType::mem);} |
|
44 |
|
45 /****************************************************************************************************** |
|
46 * |
|
47 * |
|
48 * RClientInterface |
|
49 * |
|
50 * |
|
51 *******************************************************************************************************/ |
|
52 EXPORT_C RClientInterface::RClientInterface() |
|
53 : iTransportSender(NULL) |
|
54 { |
|
55 Mem::FillZ(iRecipientAddress, sizeof(iRecipientAddress)); |
|
56 } |
|
57 |
|
58 EXPORT_C RClientInterface::~RClientInterface() |
|
59 { |
|
60 } |
|
61 |
|
62 EXPORT_C void RClientInterface::Open(const TRuntimeCtxId& aPostTo, MTransportSender* aSender) |
|
63 { |
|
64 iTransportSender = aSender? aSender : &TlsGlobals::Get().TransportSender(); |
|
65 RecipientRef() = aPostTo; //This a deep copy |
|
66 } |
|
67 |
|
68 EXPORT_C void RClientInterface::Close() |
|
69 { |
|
70 iTransportSender = NULL; |
|
71 Mem::FillZ(iRecipientAddress, sizeof(iRecipientAddress)); |
|
72 } |
|
73 |
|
74 EXPORT_C TBool RClientInterface::IsOpen() const |
|
75 { |
|
76 return iTransportSender != NULL; |
|
77 } |
|
78 |
|
79 |
|
80 EXPORT_C /*static*/ void RClientInterface::OpenPostMessageClose(const TRuntimeCtxId& aPostFrom, const TRuntimeCtxId& aPostTo, const TSignalBase& aMessage) |
|
81 { |
|
82 RClientInterface client; |
|
83 client.Open(aPostTo); |
|
84 client.PostMessage(aPostFrom, aMessage); |
|
85 client.Close(); |
|
86 } |
|
87 |
|
88 EXPORT_C void RClientInterface::PostMessage(const TRuntimeCtxId& aPostFrom, const TSignalBase& aMessage) const |
|
89 { |
|
90 PostMessage(aPostFrom, RecipientId(), aMessage); |
|
91 } |
|
92 |
|
93 EXPORT_C TBool RClientInterface::operator==(const TRuntimeCtxId& aRHS) const |
|
94 { |
|
95 return RecipientRef() == aRHS; |
|
96 } |
|
97 |
|
98 EXPORT_C TBool RClientInterface::operator==(const RClientInterface& aRHS) const |
|
99 { |
|
100 return RecipientRef() == aRHS.RecipientRef(); |
|
101 } |
|
102 |
|
103 void RClientInterface::PostMessage(const TRuntimeCtxId& aPostFrom, const TRuntimeCtxId& aPostTo, const TSignalBase& aMessage) const |
|
104 { |
|
105 __ASSERT_DEBUG(iTransportSender, User::Panic(KMessagesPanic, ETransportNotOpened)); // Interface not properly initialised; needs transport for this sending thread |
|
106 __ASSERT_DEBUG(aPostTo.Size() > 0, User::Panic(KMessagesPanic, EAddressNotValidPanic)); |
|
107 |
|
108 iTransportSender->PostMessage(aPostFrom, aPostTo, aMessage); |
|
109 } |
|
110 |
|
111 /****************************************************************************************************** |
|
112 * |
|
113 * |
|
114 * RNodeInterface |
|
115 * |
|
116 * |
|
117 *******************************************************************************************************/ |
|
118 EXPORT_C void RNodeInterface::Open(TNodeId aPostTo, const TClientType& aClientType, MTransportSender* aSender) |
|
119 /* |
|
120 Opens 'this'. |
|
121 aPostTo by value on purpose as clients may be calling ::Open with subclasses of TNodeId, we must trunkate. |
|
122 */ |
|
123 { |
|
124 RClientInterface::Open(aPostTo, aSender); |
|
125 iClientType = aClientType; |
|
126 } |
|
127 |
|
128 EXPORT_C void RNodeInterface::Close() |
|
129 { |
|
130 RClientInterface::Close(); |
|
131 iClientType = TClientType::NullType(); |
|
132 } |
|
133 |
|
134 |
|
135 EXPORT_C void RNodeInterface::PostMessage(const TRuntimeCtxId& aPostFrom, const TNodeId::TRemainder& aPostTo, const TSignalBase& aMessage) const |
|
136 { |
|
137 TUint8 postTo[__Align8(TRuntimeCtxId::KMaxInlineAddressSize)]; |
|
138 Mem::Copy(postTo, &RecipientId(), sizeof(TNodeId)); |
|
139 Mem::Copy(postTo + sizeof(TNodeId), aPostTo.iRemainder, aPostTo.Size()); |
|
140 postTo[0] = aPostTo.Size() + sizeof(TNodeId); |
|
141 postTo[0] |= TRuntimeCtxId::KIsNullMask8; |
|
142 |
|
143 RClientInterface::PostMessage(aPostFrom, *reinterpret_cast<TRuntimeCtxId*>(postTo), aMessage); |
|
144 } |
|
145 |
|
146 |
|
147 EXPORT_C TBool RNodeInterface::operator==(const RNodeInterface& aRHS) const |
|
148 { |
|
149 return RecipientId() == aRHS.RecipientId(); |
|
150 } |
|
151 |
|
152 /****************************************************************************************************** |
|
153 * |
|
154 * |
|
155 * TClientIterBase |
|
156 * |
|
157 * |
|
158 *******************************************************************************************************/ |
|
159 EXPORT_C RNodeInterface* TClientIterBase::operator[](TInt aInd) |
|
160 { |
|
161 // assuming at present that array indices start from beginning of array |
|
162 // rather than current location of iterator, and array access doesn't |
|
163 // change location of iterator. |
|
164 TInt prevIndex = iIndex; |
|
165 TInt start = 0; |
|
166 RNodeInterface* cli = Find(start, +1, aInd + 1); |
|
167 iIndex = prevIndex; |
|
168 return cli; |
|
169 } |
|
170 |
|
171 EXPORT_C RNodeInterface* TClientIterBase::Find(TInt& aInd, TInt aDir, TInt aCount) |
|
172 { |
|
173 while (aInd >= 0 && aInd < iClients.Count()) |
|
174 { |
|
175 RNodeInterface* ctl = iClients[aInd]; |
|
176 if (TypeMatch(*ctl) && --aCount <= 0) |
|
177 { |
|
178 iIndex = aInd; |
|
179 return ctl; |
|
180 } |
|
181 aInd += aDir; |
|
182 } |
|
183 return NULL; |
|
184 } |
|
185 |
|
186 |
|
187 /****************************************************************************************************** |
|
188 * |
|
189 * |
|
190 * RRequestOriginator |
|
191 * |
|
192 * |
|
193 *******************************************************************************************************/ |
|
194 EXPORT_C TInt RRequestOriginator::Open(Messages::RNodeInterface& aNode, const Messages::TRuntimeCtxId& aRequestOriginator) |
|
195 { |
|
196 if (aNode == aRequestOriginator) |
|
197 { |
|
198 iNode = &aNode; |
|
199 iRemainder = aRequestOriginator; |
|
200 return KErrNone; |
|
201 } |
|
202 return KErrArgument; |
|
203 } |
|
204 |
|
205 EXPORT_C void RRequestOriginator::Open(RRequestOriginator& aOriginalRequest) |
|
206 { |
|
207 __ASSERT_DEBUG(aOriginalRequest.IsOpen(), User::Panic(KSpecAssert_ElemNodeMessIntC, 1)); |
|
208 iNode = aOriginalRequest.iNode; |
|
209 iRemainder = aOriginalRequest.iRemainder; |
|
210 aOriginalRequest.Close(); |
|
211 } |
|
212 |
|
213 EXPORT_C TBool RRequestOriginator::IsOpen() const |
|
214 { |
|
215 return iNode != NULL; |
|
216 } |
|
217 |
|
218 EXPORT_C TBool RRequestOriginator::operator==(const RRequestOriginator& aRHS) const |
|
219 { |
|
220 return (Node().RecipientId() == aRHS.Node().RecipientId()) && (iRemainder == aRHS.iRemainder); |
|
221 } |
|
222 |
|
223 EXPORT_C TBool RRequestOriginator::operator==(const TRuntimeCtxId& aRHS) const |
|
224 { |
|
225 return (iNode->RecipientId() == aRHS) && (iRemainder == aRHS); |
|
226 } |
|
227 |
|
228 EXPORT_C void RRequestOriginator::Close() |
|
229 { |
|
230 iNode = NULL; |
|
231 } |
|
232 |
|
233 EXPORT_C void RRequestOriginator::PostMessage(const Messages::TRuntimeCtxId& aPostFrom, const Messages::TSignalBase& aMessage) const |
|
234 { |
|
235 __ASSERT_DEBUG(IsOpen(), User::Panic(KMessagesPanic, EClientNotValidPanic)); |
|
236 iNode->PostMessage(aPostFrom, iRemainder, aMessage); |
|
237 } |
|
238 |
|
239 EXPORT_C void RRequestOriginator::ReplyTo(const Messages::TRuntimeCtxId& aReplyFrom, const Messages::TSignalBase& aMessage) |
|
240 { |
|
241 PostMessage(aReplyFrom, aMessage); |
|
242 Close(); |
|
243 } |
|
244 |