|
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 // Definition of network request channel component. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 @released |
|
22 */ |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <e32debug.h> |
|
26 #include <lbs/lbslocerrors.h> |
|
27 #include "lbsdevloggermacros.h" |
|
28 #include "lbsprocessuiddefs.h" |
|
29 #include "netrequestchannel.h" |
|
30 #include "lbsnrhngmsgs.h" |
|
31 #include "LbsPsyNgMsgs.h" |
|
32 |
|
33 const TLbsNetSessionIdInt KInvalidSessionId(TUid::Uid(0xDC0DED), 999); |
|
34 const TLbsNetPosRequestQualityInt KInvalidQuality; |
|
35 const TLbsNetPosRequestMethodInt KInvalidMethod; |
|
36 const TLbsNetPosRequestPrivacyInt KInvalidRequestPrivacy; |
|
37 const TLbsExternalRequestInfo KInvalidExternalRequestInfo; |
|
38 |
|
39 |
|
40 // |
|
41 // CRequestMessageBuffer |
|
42 // |
|
43 |
|
44 /* Comparison function used to find two buffered |
|
45 messages with the same type. |
|
46 |
|
47 See RPointerArray<T>::Find() and TIdentityRelation for |
|
48 more information about how this works. |
|
49 */ |
|
50 TBool CRequestMessageBuffer::IsMsgTypeEqual( |
|
51 const TLbsNetInternalMsgBase::TLbsNetInternalMsgType* aType, |
|
52 const TLbsNetInternalMsgBase& aData) |
|
53 { |
|
54 return (*aType == aData.Type()); |
|
55 } |
|
56 |
|
57 /* Comparison function used to find two buffered |
|
58 messages with the same contents. |
|
59 |
|
60 Uses a direct memory comparison to check contents. |
|
61 |
|
62 See RPointerArray<T>::Find() and TIdentityRelation for |
|
63 more information about how this works. |
|
64 */ |
|
65 TBool CRequestMessageBuffer::IsMsgEqual( |
|
66 const TLbsNetInternalMsgBase& aData1, |
|
67 const TLbsNetInternalMsgBase& aData2) |
|
68 { |
|
69 return (Mem::Compare( |
|
70 (const TUint8*)&aData1, aData1.Size(), |
|
71 (const TUint8*)&aData2, aData2.Size()) == 0); |
|
72 } |
|
73 |
|
74 CRequestMessageBuffer::~CRequestMessageBuffer() |
|
75 { |
|
76 iBuffer.ResetAndDestroy(); |
|
77 } |
|
78 |
|
79 CRequestMessageBuffer* CRequestMessageBuffer::NewL() |
|
80 { |
|
81 CRequestMessageBuffer* self = new (ELeave) CRequestMessageBuffer; |
|
82 CleanupStack::PushL(self); |
|
83 self->ConstructL(); |
|
84 CleanupStack::Pop(self); |
|
85 return self; |
|
86 } |
|
87 |
|
88 void CRequestMessageBuffer::ConstructL() |
|
89 { |
|
90 } |
|
91 |
|
92 TInt CRequestMessageBuffer::BufferMessage(const TLbsNetInternalMsgBase& aMessage) |
|
93 { |
|
94 LBSLOG(ELogP1, "CRequestMessageBuffer::BufferMessage:"); |
|
95 LBSLOG2(ELogP2, "Buffering message : Type %d", aMessage.Type()); |
|
96 |
|
97 TInt err(KErrNoMemory); |
|
98 TLbsNetInternalMsgBase* msg(NULL); |
|
99 |
|
100 // Network Request Handler has not read the message, so buffer it until it has finished |
|
101 switch (aMessage.Type()) |
|
102 { |
|
103 case TLbsNetInternalMsgBase::ELocationRequest: |
|
104 { |
|
105 msg = new TLbsNetLocationRequestMsg( |
|
106 KInvalidSessionId, EFalse, |
|
107 TLbsNetworkEnumInt::EServiceNone, |
|
108 KInvalidQuality, KInvalidMethod); |
|
109 |
|
110 if (msg != NULL) |
|
111 { |
|
112 *(static_cast<TLbsNetLocationRequestMsg*>(msg)) = |
|
113 static_cast<const TLbsNetLocationRequestMsg&>(aMessage); |
|
114 err = KErrNone; |
|
115 } |
|
116 break; |
|
117 } |
|
118 |
|
119 case TLbsNetInternalMsgBase::EPrivacyRequest: |
|
120 { |
|
121 msg = new TLbsNetMtLrRequestMsg( |
|
122 KInvalidSessionId, EFalse, |
|
123 KInvalidRequestPrivacy, |
|
124 KInvalidExternalRequestInfo); |
|
125 if (msg != NULL) |
|
126 { |
|
127 *(static_cast<TLbsNetMtLrRequestMsg*>(msg)) = |
|
128 static_cast<const TLbsNetMtLrRequestMsg&>(aMessage); |
|
129 err = KErrNone; |
|
130 } |
|
131 break; |
|
132 } |
|
133 |
|
134 case TLbsNetInternalMsgBase::ESessionComplete: |
|
135 { |
|
136 msg = new TLbsNetSessionCompleteMsg( |
|
137 KInvalidSessionId, KErrUnknown); |
|
138 if (msg != NULL) |
|
139 { |
|
140 *(static_cast<TLbsNetSessionCompleteMsg*>(msg)) = |
|
141 static_cast<const TLbsNetSessionCompleteMsg&>(aMessage); |
|
142 err = KErrNone; |
|
143 } |
|
144 break; |
|
145 } |
|
146 |
|
147 case TLbsNetInternalMsgBase::ENetworkLocationUpdate: |
|
148 { |
|
149 TPositionInfo info; |
|
150 TTime time; |
|
151 msg = new TLbsNetLocationUpdateMsg( |
|
152 KInvalidSessionId, KErrUnknown, |
|
153 info, time); |
|
154 |
|
155 if (msg != NULL) |
|
156 { |
|
157 *(static_cast<TLbsNetLocationUpdateMsg*>(msg)) = |
|
158 static_cast<const TLbsNetLocationUpdateMsg&>(aMessage); |
|
159 err = KErrNone; |
|
160 } |
|
161 break; |
|
162 } |
|
163 |
|
164 case TLbsNetInternalMsgBase::ECellLocationResponse: |
|
165 { |
|
166 TPositionInfo info; |
|
167 TTime time; |
|
168 msg = new TLbsCellLocationResponseMsg( |
|
169 KInvalidSessionId, KErrUnknown, |
|
170 info); |
|
171 |
|
172 if (msg != NULL) |
|
173 { |
|
174 *(static_cast<TLbsCellLocationResponseMsg*>(msg)) = |
|
175 static_cast<const TLbsCellLocationResponseMsg&>(aMessage); |
|
176 err = KErrNone; |
|
177 } |
|
178 break; |
|
179 } |
|
180 |
|
181 default: |
|
182 { |
|
183 err = KErrAccessDenied; |
|
184 break; |
|
185 } |
|
186 } |
|
187 |
|
188 // Only buffer the message if it was created successfully. |
|
189 if (err == KErrNone) |
|
190 { |
|
191 err = iBuffer.Append(msg); |
|
192 if (err != KErrNone) |
|
193 { |
|
194 delete msg; |
|
195 } |
|
196 } |
|
197 |
|
198 LBSLOG2(ELogP2, "Number of messages in buffer is : %d", iBuffer.Count()); |
|
199 return err; |
|
200 } |
|
201 |
|
202 const TLbsNetInternalMsgBase* CRequestMessageBuffer::PeekNextMessage() |
|
203 { |
|
204 if (iBuffer.Count() > 0) |
|
205 { |
|
206 return iBuffer[0]; |
|
207 } |
|
208 else |
|
209 { |
|
210 return NULL; |
|
211 } |
|
212 } |
|
213 |
|
214 void CRequestMessageBuffer::RemoveMessage( |
|
215 const TLbsNetInternalMsgBase* aMessage) |
|
216 { |
|
217 TInt index = iBuffer.Find(aMessage, IsMsgEqual); |
|
218 if (index != KErrNotFound) |
|
219 { |
|
220 TLbsNetInternalMsgBase* msg = iBuffer[index]; |
|
221 iBuffer.Remove(index); |
|
222 delete msg; |
|
223 } |
|
224 } |
|
225 |