|
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 location channel component. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 @released |
|
22 */ |
|
23 |
|
24 #include <e32base.h> |
|
25 #include "lbsdevloggermacros.h" |
|
26 #include "lbsprocessuiddefs.h" |
|
27 #include "netlocationchannel.h" |
|
28 |
|
29 |
|
30 // |
|
31 // CNetworkLocationChannel |
|
32 // |
|
33 |
|
34 CNetworkLocationChannel::CNetworkLocationChannel(MNetworkLocationObserver& aObserver) : |
|
35 CActive(EPriorityStandard), |
|
36 iObserver(aObserver) |
|
37 { |
|
38 CActiveScheduler::Add(this); |
|
39 } |
|
40 |
|
41 CNetworkLocationChannel::~CNetworkLocationChannel() |
|
42 { |
|
43 Cancel(); |
|
44 iFinalPositionUpdates.Close(); |
|
45 iReferencePositionUpdates.Close(); |
|
46 iLocationResponses.Close(); |
|
47 iLocationRequests.Close(); |
|
48 } |
|
49 |
|
50 CNetworkLocationChannel* CNetworkLocationChannel::NewL(MNetworkLocationObserver& aObserver) |
|
51 { |
|
52 CNetworkLocationChannel* self = new (ELeave) CNetworkLocationChannel(aObserver); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop(self); |
|
56 return self; |
|
57 } |
|
58 |
|
59 void CNetworkLocationChannel::ConstructL() |
|
60 { |
|
61 iLocationRequests.OpenL(RProcess().SecureId()); |
|
62 iLocationResponses.OpenL(RProcess().SecureId()); |
|
63 iReferencePositionUpdates.OpenL(RLbsNetworkPositionUpdates::ENetworkPositionReference); |
|
64 iFinalPositionUpdates.OpenL(RLbsNetworkPositionUpdates::ENetworkPositionFinal); |
|
65 NotifyNetworkLocationRequestUpdate(); |
|
66 } |
|
67 |
|
68 void CNetworkLocationChannel::RunL() |
|
69 { |
|
70 User::LeaveIfError(iStatus.Int()); |
|
71 |
|
72 NotifyNetworkLocationRequestUpdate(); |
|
73 TLbsNetLocMsgBase msg; |
|
74 iLocationRequests.GetNetworkLocationRequest(msg); |
|
75 iObserver.ProcessNetworkLocationMessage(msg); |
|
76 } |
|
77 |
|
78 void CNetworkLocationChannel::DoCancel() |
|
79 { |
|
80 iLocationRequests.CancelNotifyNetworkLocationRequestUpdate(); |
|
81 } |
|
82 |
|
83 TInt CNetworkLocationChannel::RunError(TInt aError) |
|
84 { |
|
85 return aError; |
|
86 } |
|
87 |
|
88 const TPositionInfoBase & CNetworkLocationChannel::GetLastReferencePosition() |
|
89 { |
|
90 return iRefPosInfo; |
|
91 } |
|
92 |
|
93 void CNetworkLocationChannel::SendNetworkLocationMessage(const TLbsNetLocMsgBase& aMessage) |
|
94 { |
|
95 iLocationResponses.SetNetworkLocationResponse(aMessage); |
|
96 } |
|
97 |
|
98 void CNetworkLocationChannel::NotifyNetworkLocationRequestUpdate() |
|
99 { |
|
100 __ASSERT_DEBUG(!IsActive(), User::Invariant()); |
|
101 iLocationRequests.NotifyNetworkLocationRequestUpdate(iStatus); |
|
102 SetActive(); |
|
103 } |
|
104 |
|
105 /* Store the latest position to be sent in from the network. |
|
106 |
|
107 The network can send two types of position: |
|
108 1) A 'reference' position - this is sent in before each location request. |
|
109 it is usually a fairly inaccurate position, e.g. the area of error |
|
110 can be as large as the size of one cell. |
|
111 2) A 'final' position - this is sent at the end of a location request, before |
|
112 the final 'session complete' closes the request. It represents a position |
|
113 returned from the network and may be more accurate than the position |
|
114 the terminal sent to the network in reply to the original location request. |
|
115 |
|
116 Both types of location are published on an internal interface so that |
|
117 other LBS components can access them. |
|
118 */ |
|
119 void CNetworkLocationChannel::SetNetworkPosition(const TLbsNetSessionIdInt& aSessionId, const TPositionInfoBase& aPosition) |
|
120 { |
|
121 // Check that aPosition is a valid TPositionInfoBase type |
|
122 TUint32 type = aPosition.PositionClassType(); |
|
123 if (((type & EPositionInfoUnknownClass) != EPositionInfoUnknownClass) |
|
124 && ((type & EPositionInfoClass) != EPositionInfoClass) |
|
125 && ((type & EPositionCourseInfoClass) != EPositionCourseInfoClass) |
|
126 && ((type & EPositionSatelliteInfoClass) != EPositionSatelliteInfoClass) |
|
127 && ((type & EPositionExtendedSatelliteInfoClass) != EPositionExtendedSatelliteInfoClass)) |
|
128 { |
|
129 // If the aPosition is not a supported positionInfo type, ignore it. |
|
130 // (Panic in debug builds) |
|
131 __ASSERT_DEBUG(EFalse, User::Panic(_L("LbsNetGateway"), 1)); |
|
132 return; |
|
133 } |
|
134 |
|
135 // Treat the position as a reference position or final position based |
|
136 // on the technology type. |
|
137 switch (aPosition.PositionMode()) |
|
138 { |
|
139 case TPositionModuleInfo::ETechnologyNetwork: |
|
140 { |
|
141 SetReferenceNetworkPosition(aSessionId, aPosition); |
|
142 break; |
|
143 } |
|
144 case (TPositionModuleInfo::ETechnologyTerminal): |
|
145 // this will only happen if PM / AGPS module not setting the 'assisted' bit as they should |
|
146 __ASSERT_DEBUG(EFalse, User::Panic(_L("LbsNetGateway"), 1)); |
|
147 // drop through |
|
148 case (TPositionModuleInfo::ETechnologyNetwork |
|
149 | TPositionModuleInfo::ETechnologyAssisted): |
|
150 case (TPositionModuleInfo::ETechnologyTerminal |
|
151 | TPositionModuleInfo::ETechnologyAssisted): |
|
152 { |
|
153 SetFinalNetworkPosition(aSessionId, aPosition); |
|
154 break; |
|
155 } |
|
156 default: |
|
157 { |
|
158 // Default to treating network positions as a reference position |
|
159 SetReferenceNetworkPosition(aSessionId, aPosition); |
|
160 break; |
|
161 } |
|
162 } |
|
163 } |
|
164 |
|
165 void CNetworkLocationChannel::SetReferenceNetworkPosition(const TLbsNetSessionIdInt& aSessionId, const TPositionInfoBase& aLocation) |
|
166 { |
|
167 // Store the most recent reference position, so that it can be |
|
168 // read when sending a location request to the NRH. |
|
169 |
|
170 // The TPositionInfoBase is just the base class, so we need to copy over |
|
171 // the data from the actual concrete class type. |
|
172 __ASSERT_DEBUG(aLocation.PositionClassSize() <= sizeof(TPositionExtendedSatelliteInfo), User::Invariant()); |
|
173 Mem::Copy(&iRefPosInfo, &aLocation, aLocation.PositionClassSize()); |
|
174 |
|
175 // Broadcast the reference position to the other LBS components. |
|
176 TTime actualTime; |
|
177 actualTime.UniversalTime(); |
|
178 iReferencePositionUpdates.SetPositionInfo(aSessionId, KErrNone, aLocation, actualTime); |
|
179 } |
|
180 |
|
181 void CNetworkLocationChannel::SetFinalNetworkPosition(const TLbsNetSessionIdInt& aSessionId, const TPositionInfoBase& aLocation) |
|
182 { |
|
183 // Set the moduleID based on the PositionMode() of the position info |
|
184 // Make a copy so we don't change the posInfo that is owned by the protocol module. |
|
185 __ASSERT_DEBUG(iFinalPosInfo.PositionClassSize() >= aLocation.PositionClassSize(), |
|
186 User::Invariant()); |
|
187 Mem::Copy(&iFinalPosInfo, &aLocation, aLocation.PositionClassSize()); |
|
188 switch (iFinalPosInfo.PositionMode()) |
|
189 { |
|
190 case (TPositionModuleInfo::ETechnologyTerminal |
|
191 | TPositionModuleInfo::ETechnologyAssisted): |
|
192 { |
|
193 iFinalPosInfo.SetModuleId(KLbsGpsLocManagerUid); |
|
194 break; |
|
195 } |
|
196 case (TPositionModuleInfo::ETechnologyNetwork |
|
197 | TPositionModuleInfo::ETechnologyAssisted): |
|
198 { |
|
199 iFinalPosInfo.SetModuleId(KLbsNetLocManagerUid); |
|
200 break; |
|
201 } |
|
202 default: |
|
203 { |
|
204 LBSLOG_WARN2(ELogP3, "Unrecognised PositionMode() for a Final Network Position (%d), ignoring update", iFinalPosInfo.PositionMode()); |
|
205 break; |
|
206 } |
|
207 } |
|
208 |
|
209 // Broadcast the final position to the other LBS components. |
|
210 TTime actualTime; |
|
211 actualTime.UniversalTime(); |
|
212 iFinalPositionUpdates.SetPositionInfo(aSessionId, KErrNone, iFinalPosInfo, actualTime); |
|
213 } |