|
1 // Copyright (c) 2006-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 // Source file for the api for talking to the stub protocol module. |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <e32property.h> |
|
20 #include <s32mem.h> |
|
21 #include <e32debug.h> |
|
22 #include "lbsnetgatewayprotocoltestapi.h" |
|
23 #include "lbsdevloggermacros.h" |
|
24 |
|
25 // Hard-coded Uid of the gateway. This is the process that |
|
26 // should always create the properties, if it isn't then |
|
27 // there is a problem. |
|
28 const TUid KLbsNetGatewayUid = { 0x10281D46 }; |
|
29 |
|
30 // |
|
31 // Listener AO |
|
32 // |
|
33 |
|
34 NONSHARABLE_CLASS(CNetProtocolMessageListener) : public CActive |
|
35 { |
|
36 public: |
|
37 static CNetProtocolMessageListener* NewL(TUid aCategory, |
|
38 TUint aRxKey, |
|
39 MNetGatewayProtocolTestObserver& aObserver); |
|
40 ~CNetProtocolMessageListener(); |
|
41 |
|
42 void RunL(); |
|
43 void DoCancel(); |
|
44 |
|
45 void NotifyNextMessage(); |
|
46 |
|
47 private: |
|
48 CNetProtocolMessageListener(MNetGatewayProtocolTestObserver& aObserver); |
|
49 void ConstructL(TUid aCategory, TUint aRxKey); |
|
50 |
|
51 private: |
|
52 RProperty iRxProperty; |
|
53 RProperty iRxAckProperty; |
|
54 MNetGatewayProtocolTestObserver& iObserver; |
|
55 RBuf8 iAgpsDataBuffer; |
|
56 RProperty iAgpsDataSetProperty; |
|
57 RLbsAssistanceDataBuilderSet iAgpsDataBuilderSet; |
|
58 TNetGatewayMsg iNetGatMsg; |
|
59 }; |
|
60 |
|
61 // |
|
62 |
|
63 CNetProtocolMessageListener::CNetProtocolMessageListener(MNetGatewayProtocolTestObserver& aObserver) : |
|
64 CActive(EPriorityNormal), |
|
65 iObserver(aObserver) |
|
66 { |
|
67 LBSLOG(ELogP1, "CNetProtocolMessageListener::CNetProtocolMessageListener()"); |
|
68 CActiveScheduler::Add(this); |
|
69 } |
|
70 |
|
71 CNetProtocolMessageListener::~CNetProtocolMessageListener() |
|
72 { |
|
73 LBSLOG(ELogP1, "CNetProtocolMessageListener::~CNetProtocolMessageListener()"); |
|
74 Cancel(); |
|
75 iAgpsDataSetProperty.Close(); |
|
76 iAgpsDataBuilderSet.Close(); |
|
77 iAgpsDataBuffer.Close(); |
|
78 iRxAckProperty.Close(); |
|
79 iRxProperty.Close(); |
|
80 } |
|
81 |
|
82 CNetProtocolMessageListener* CNetProtocolMessageListener::NewL(TUid aCategory, |
|
83 TUint aRxKey, |
|
84 MNetGatewayProtocolTestObserver& aObserver) |
|
85 { |
|
86 LBSLOG(ELogP1, "CNetProtocolMessageListener::NewL()"); |
|
87 CNetProtocolMessageListener* self = new (ELeave) CNetProtocolMessageListener(aObserver); |
|
88 CleanupStack::PushL(self); |
|
89 self->ConstructL(aCategory, aRxKey); |
|
90 CleanupStack::Pop(); |
|
91 return self; |
|
92 } |
|
93 |
|
94 void CNetProtocolMessageListener::ConstructL(TUid aCategory, TUint aRxKey) |
|
95 { |
|
96 LBSLOG(ELogP1, "CNetProtocolMessageListener::ConstructL()"); |
|
97 __ASSERT_DEBUG(iRxProperty.Handle() == NULL, User::Invariant()); |
|
98 |
|
99 User::LeaveIfError(iRxProperty.Attach(aCategory, aRxKey)); |
|
100 User::LeaveIfError(iRxAckProperty.Attach(aCategory, (aRxKey + KChannelAckOffset))); |
|
101 |
|
102 // Allocate a buffer to store the Externalize'd assistance data set data. |
|
103 iAgpsDataBuffer.CreateL(RLbsAssistanceDataBuilderSet::MaxExternalizedBufferSize()); |
|
104 iAgpsDataBuilderSet.OpenL(); |
|
105 User::LeaveIfError(iAgpsDataSetProperty.Attach(KLbsNetGatewayUid, KAgpsDataSetKey)); |
|
106 } |
|
107 |
|
108 void CNetProtocolMessageListener::RunL() |
|
109 { |
|
110 LBSLOG(ELogP1, "CNetProtocolMessageListener::RunL()"); |
|
111 |
|
112 |
|
113 User::LeaveIfError(iStatus.Int()); |
|
114 |
|
115 NotifyNextMessage(); |
|
116 TPckg<TNetGatewayMsg> pckg(iNetGatMsg); |
|
117 User::LeaveIfError(iRxProperty.Get(pckg)); |
|
118 |
|
119 // if the message contains assistance data then |
|
120 // we need to read it out of the separate property |
|
121 // and Internalize it into a local buffer. |
|
122 if (iNetGatMsg.iType == ENetMsgProcessAssistanceData) |
|
123 { |
|
124 User::LeaveIfError(iAgpsDataSetProperty.Get(iAgpsDataBuffer)); |
|
125 RDesReadStream rstream(iAgpsDataBuffer); |
|
126 CleanupClosePushL(rstream); |
|
127 iAgpsDataBuilderSet.InternalizeL(rstream); |
|
128 CleanupStack::PopAndDestroy(); |
|
129 SNetMsgProcessAssistanceData* data = reinterpret_cast<SNetMsgProcessAssistanceData*>(iNetGatMsg.Data()); |
|
130 // Note: there is no operator = for RLbsAssistanceDataBuilderSet, so |
|
131 // we force a byte-wise copy of the buffered one into the message |
|
132 Mem::Copy(&data->iData, &iAgpsDataBuilderSet, sizeof(RLbsAssistanceDataBuilderSet)); |
|
133 } |
|
134 |
|
135 User::LeaveIfError(iRxAckProperty.Set(KErrNone)); |
|
136 iObserver.ProcessNetProtocolMessage(iNetGatMsg); |
|
137 } |
|
138 |
|
139 void CNetProtocolMessageListener::DoCancel() |
|
140 { |
|
141 LBSLOG(ELogP1, "CNetProtocolMessageListener::DoCancel()"); |
|
142 iRxProperty.Cancel(); |
|
143 } |
|
144 |
|
145 void CNetProtocolMessageListener::NotifyNextMessage() |
|
146 { |
|
147 LBSLOG(ELogP1, "CNetProtocolMessageListener::NotifyNextMessage()"); |
|
148 iRxProperty.Subscribe(iStatus); |
|
149 SetActive(); |
|
150 } |
|
151 |
|
152 // |
|
153 // Transmitter AO |
|
154 // |
|
155 |
|
156 NONSHARABLE_CLASS(CNetProtocolMessageTransmitter) : public CActive |
|
157 { |
|
158 public: |
|
159 static CNetProtocolMessageTransmitter* NewL(TUid aCategory, |
|
160 TUint aTxKey); |
|
161 ~CNetProtocolMessageTransmitter(); |
|
162 |
|
163 void RunL(); |
|
164 void DoCancel(); |
|
165 |
|
166 void NotifyMessageRead(); |
|
167 |
|
168 void SendNetProtocolMessageL(const TNetGatewayMsg& aMessage); |
|
169 |
|
170 private: |
|
171 CNetProtocolMessageTransmitter(); |
|
172 void ConstructL(TUid aCategory, TUint aTxKey); |
|
173 |
|
174 private: |
|
175 RProperty iTxProperty; |
|
176 RProperty iTxAckProperty; |
|
177 RBuf8 iAgpsDataBuffer; |
|
178 RProperty iAgpsDataSetProperty; |
|
179 TNetGatewayMsg iNetGatMsg; |
|
180 CActiveSchedulerWait iActiveWait; |
|
181 }; |
|
182 |
|
183 // |
|
184 |
|
185 CNetProtocolMessageTransmitter::CNetProtocolMessageTransmitter() : |
|
186 CActive(EPriorityHigh) |
|
187 { |
|
188 LBSLOG(ELogP1, "CNetProtocolMessageTransmitter::CNetProtocolMessageTransmitter()"); |
|
189 CActiveScheduler::Add(this); |
|
190 } |
|
191 |
|
192 CNetProtocolMessageTransmitter::~CNetProtocolMessageTransmitter() |
|
193 { |
|
194 LBSLOG(ELogP1, "CNetProtocolMessageTransmitter::~CNetProtocolMessageTransmitter()"); |
|
195 Cancel(); |
|
196 iAgpsDataSetProperty.Close(); |
|
197 iAgpsDataBuffer.Close(); |
|
198 iTxAckProperty.Close(); |
|
199 iTxProperty.Close(); |
|
200 } |
|
201 |
|
202 CNetProtocolMessageTransmitter* CNetProtocolMessageTransmitter::NewL(TUid aCategory, |
|
203 TUint aTxKey) |
|
204 { |
|
205 LBSLOG(ELogP1, "CNetProtocolMessageTransmitter::NewL()"); |
|
206 CNetProtocolMessageTransmitter* self = new (ELeave) CNetProtocolMessageTransmitter(); |
|
207 CleanupStack::PushL(self); |
|
208 self->ConstructL(aCategory, aTxKey); |
|
209 CleanupStack::Pop(); |
|
210 return self; |
|
211 } |
|
212 |
|
213 void CNetProtocolMessageTransmitter::ConstructL(TUid aCategory, TUint aTxKey) |
|
214 { |
|
215 LBSLOG(ELogP1, "CNetProtocolMessageTransmitter::ConstructL()"); |
|
216 __ASSERT_DEBUG(iTxProperty.Handle() == NULL, User::Invariant()); |
|
217 |
|
218 User::LeaveIfError(iTxProperty.Attach(aCategory, aTxKey)); |
|
219 User::LeaveIfError(iTxAckProperty.Attach(aCategory, (aTxKey + KChannelAckOffset))); |
|
220 |
|
221 // Allocate a buffer to store the Externalize'd assistance data set data. |
|
222 iAgpsDataBuffer.CreateL(RLbsAssistanceDataBuilderSet::MaxExternalizedBufferSize()); |
|
223 User::LeaveIfError(iAgpsDataSetProperty.Attach(KLbsNetGatewayUid, KAgpsDataSetKey)); |
|
224 } |
|
225 |
|
226 void CNetProtocolMessageTransmitter::RunL() |
|
227 { |
|
228 LBSLOG(ELogP1, "CNetProtocolMessageTransmitter::RunL()"); |
|
229 |
|
230 User::LeaveIfError (iStatus.Int()); |
|
231 if (iActiveWait.IsStarted()) |
|
232 { |
|
233 iActiveWait.AsyncStop(); |
|
234 } |
|
235 } |
|
236 |
|
237 void CNetProtocolMessageTransmitter::DoCancel() |
|
238 { |
|
239 LBSLOG(ELogP1, "CNetProtocolMessageTransmitter::DoCancel()"); |
|
240 iTxAckProperty.Cancel(); |
|
241 } |
|
242 |
|
243 void CNetProtocolMessageTransmitter::NotifyMessageRead() |
|
244 { |
|
245 LBSLOG(ELogP1, "CNetProtocolMessageTransmitter::NotifyMessageRead()"); |
|
246 iTxAckProperty.Subscribe(iStatus); |
|
247 SetActive(); |
|
248 } |
|
249 |
|
250 void CNetProtocolMessageTransmitter::SendNetProtocolMessageL(const TNetGatewayMsg& aMessage) |
|
251 { |
|
252 LBSLOG(ELogP1, "CNetProtocolMessageTransmitter::SendNetProtocolMessageL()"); |
|
253 __ASSERT_DEBUG(EFalse == IsActive(), User::Invariant()); |
|
254 |
|
255 // If the message to be sent includes assistance data, that data |
|
256 // needs to be sent separately to the actual message. It is then |
|
257 // put back together again when received. |
|
258 if (aMessage.iType == ENetMsgProcessAssistanceData) |
|
259 { |
|
260 RDesWriteStream wstream(iAgpsDataBuffer); |
|
261 CleanupClosePushL(wstream); |
|
262 iNetGatMsg = aMessage; |
|
263 SNetMsgProcessAssistanceData* data = reinterpret_cast<SNetMsgProcessAssistanceData*>(iNetGatMsg.Data()); |
|
264 data->iData.ExternalizeL(wstream); |
|
265 CleanupStack::PopAndDestroy(); |
|
266 User::LeaveIfError(iAgpsDataSetProperty.Set(iAgpsDataBuffer)); |
|
267 } |
|
268 |
|
269 NotifyMessageRead(); |
|
270 TPckg<TNetGatewayMsg> pckg(aMessage); |
|
271 TInt err = iTxProperty.Set(pckg); |
|
272 if(err!=KErrNone) |
|
273 { |
|
274 Cancel(); |
|
275 User::Leave(err); |
|
276 } |
|
277 iActiveWait.Start(); |
|
278 } |
|
279 |
|
280 // |
|
281 // Channel Interface |
|
282 // |
|
283 |
|
284 |
|
285 EXPORT_C RNetGatewayProtocolTestChannel::RNetGatewayProtocolTestChannel(TUint aModuleIndex) : |
|
286 iModuleIndex(aModuleIndex) |
|
287 { |
|
288 LBSLOG(ELogP1, "RNetGatewayProtocolTestChannel::RNetGatewayProtocolTestChannel()"); |
|
289 } |
|
290 |
|
291 EXPORT_C RNetGatewayProtocolTestChannel::RNetGatewayProtocolTestChannel() : |
|
292 iModuleIndex(0) |
|
293 { |
|
294 LBSLOG(ELogP1, "RNetGatewayProtocolTestChannel::RNetGatewayProtocolTestChannel()"); |
|
295 } |
|
296 |
|
297 EXPORT_C void RNetGatewayProtocolTestChannel::InitialiseL(TUint aModuleIndex) |
|
298 { |
|
299 LBSLOG(ELogP1, "RNetGatewayProtocolTestChannel::InitialiseL()"); |
|
300 __ASSERT_DEBUG(KLbsNetGatewayUid == RProcess().SecureId(), User::Invariant()); |
|
301 |
|
302 TSecurityPolicy readPolicy(ECapabilityLocation); |
|
303 TSecurityPolicy writePolicy(ECapabilityWriteDeviceData); |
|
304 |
|
305 TInt err = RProperty::Define(KNetProtocolChannelKey + aModuleIndex, |
|
306 RProperty::ELargeByteArray, |
|
307 readPolicy, |
|
308 writePolicy, |
|
309 sizeof(TNetGatewayMsg)); |
|
310 if (KErrAlreadyExists != err) |
|
311 { |
|
312 User::LeaveIfError(err); |
|
313 } |
|
314 |
|
315 err = RProperty::Define(KNetProtocolChannelAckKey + aModuleIndex, |
|
316 RProperty::EInt, |
|
317 readPolicy, |
|
318 writePolicy); |
|
319 if (KErrAlreadyExists != err) |
|
320 { |
|
321 User::LeaveIfError(err); |
|
322 } |
|
323 |
|
324 err = RProperty::Define(KTestAppChannelKey + aModuleIndex, |
|
325 RProperty::ELargeByteArray, |
|
326 readPolicy, |
|
327 writePolicy, |
|
328 sizeof(TNetGatewayMsg)); |
|
329 if (KErrAlreadyExists != err) |
|
330 { |
|
331 User::LeaveIfError(err); |
|
332 } |
|
333 |
|
334 err = RProperty::Define(KTestAppChannelAckKey + aModuleIndex, |
|
335 RProperty::EInt, |
|
336 readPolicy, |
|
337 writePolicy); |
|
338 if (KErrAlreadyExists != err) |
|
339 { |
|
340 User::LeaveIfError(err); |
|
341 } |
|
342 |
|
343 err = RProperty::Define(KAgpsDataSetKey + aModuleIndex, |
|
344 RProperty::ELargeByteArray, |
|
345 readPolicy, |
|
346 writePolicy, |
|
347 RLbsAssistanceDataBuilderSet::MaxExternalizedBufferSize()); |
|
348 if (KErrAlreadyExists != err) |
|
349 { |
|
350 User::LeaveIfError(err); |
|
351 } |
|
352 } |
|
353 |
|
354 EXPORT_C void RNetGatewayProtocolTestChannel::Shutdown(TUint aModuleIndex) |
|
355 { |
|
356 LBSLOG(ELogP1, "RNetGatewayProtocolTestChannel::Shutdown()"); |
|
357 RProperty::Delete(KNetProtocolChannelKey + aModuleIndex); |
|
358 RProperty::Delete(KNetProtocolChannelAckKey + aModuleIndex); |
|
359 RProperty::Delete(KTestAppChannelKey + aModuleIndex); |
|
360 RProperty::Delete(KTestAppChannelAckKey + aModuleIndex); |
|
361 RProperty::Delete(KTestAppChannelKey + aModuleIndex); |
|
362 } |
|
363 |
|
364 EXPORT_C void RNetGatewayProtocolTestChannel::OpenL(TUint aTxKey, |
|
365 TUint aRxKey, |
|
366 MNetGatewayProtocolTestObserver& aRxObserver) |
|
367 { |
|
368 LBSLOG(ELogP1, "RNetGatewayProtocolTestChannel::OpenL()"); |
|
369 iTransmitter = CNetProtocolMessageTransmitter::NewL(KLbsNetGatewayUid, aTxKey + iModuleIndex); |
|
370 |
|
371 iListener = CNetProtocolMessageListener::NewL(KLbsNetGatewayUid, aRxKey + iModuleIndex, aRxObserver); |
|
372 iListener->NotifyNextMessage(); |
|
373 } |
|
374 |
|
375 EXPORT_C void RNetGatewayProtocolTestChannel::OpenL(TUint aTxKey, |
|
376 TUint aRxKey, |
|
377 MNetGatewayProtocolTestObserver& aRxObserver, |
|
378 TUint aModuleIndex) |
|
379 { |
|
380 LBSLOG(ELogP1, "RNetGatewayProtocolTestChannel::OpenL()"); |
|
381 |
|
382 iModuleIndex = aModuleIndex; |
|
383 OpenL(aTxKey, aRxKey, aRxObserver); |
|
384 } |
|
385 |
|
386 EXPORT_C void RNetGatewayProtocolTestChannel::Close() |
|
387 { |
|
388 LBSLOG(ELogP1, "RNetGatewayProtocolTestChannel::Close()"); |
|
389 |
|
390 delete iTransmitter; |
|
391 delete iListener; |
|
392 |
|
393 } |
|
394 |
|
395 EXPORT_C void RNetGatewayProtocolTestChannel::SendNetProtocolMessageL(const TNetGatewayMsg& aMessage) |
|
396 { |
|
397 LBSLOG(ELogP1, "RNetGatewayProtocolTestChannel::SendNetProtocolMessageL()"); |
|
398 iTransmitter->SendNetProtocolMessageL(aMessage); |
|
399 } |