|
1 // Copyright (c) 2008-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 @InternalComponent |
|
19 */ |
|
20 |
|
21 #include "crefdatabus.h" |
|
22 #include "lbsdevloggermacros.h" |
|
23 #include "mdatabusobserver.h" |
|
24 |
|
25 #ifdef _DEBUG |
|
26 _LIT(KRefDataBus, "CRefDataBus"); |
|
27 #endif |
|
28 |
|
29 /** |
|
30 Create a reference data bus, this should be called from the location cache |
|
31 |
|
32 @return The pointer to the reference data bus |
|
33 @see CLocationCache |
|
34 */ |
|
35 CRefDataBus* CRefDataBus::NewL(MDataBusObserver& aObserver) |
|
36 { |
|
37 CRefDataBus* self = new (ELeave) CRefDataBus(aObserver); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 /** |
|
45 constructor, note the reference data bus is owned by location cache and used by CRequestQ, and it is a module-based CActive object. |
|
46 Set the data bus as standard priority by default. |
|
47 Add itself to Active Scheduler |
|
48 |
|
49 @see CRequestQ |
|
50 @see CLocationCache |
|
51 */ |
|
52 CRefDataBus::CRefDataBus(MDataBusObserver& aObserver) : CActive(CActive::EPriorityStandard), iObs(aObserver) |
|
53 { |
|
54 CActiveScheduler::Add(this); |
|
55 } |
|
56 |
|
57 /** |
|
58 Open the RProperty object wrappered by the data bus. |
|
59 Reference data bus is implemented as Publish & Subscribe mechanism. |
|
60 */ |
|
61 void CRefDataBus::ConstructL() |
|
62 { |
|
63 iRefDataBus.OpenL(RLbsNetworkPositionUpdates::ENetworkPositionReference); |
|
64 } |
|
65 |
|
66 /** |
|
67 Cancel any outstanding request to the CActive object. |
|
68 Close the RProperty. |
|
69 */ |
|
70 CRefDataBus::~CRefDataBus() |
|
71 { |
|
72 Cancel(); |
|
73 iRefDataBus.Close(); |
|
74 } |
|
75 |
|
76 /** |
|
77 Subscribe to the data bus. It will be called by objects which listen to the data bus. |
|
78 It will eventually call RProperty::Subscribe() |
|
79 Set active the data bus active object |
|
80 Panic if there are no data bus observers already set. |
|
81 */ |
|
82 void CRefDataBus::Subscribe() |
|
83 { |
|
84 if(!IsActive()) |
|
85 { |
|
86 iRefDataBus.NotifyNetworkLocationUpdate(iStatus); |
|
87 SetActive(); |
|
88 } |
|
89 } |
|
90 |
|
91 /** |
|
92 Cancel the subscribe to the data bus. Cancel any outstanding request to the CActive object. |
|
93 Panic if there are no data bus observers already set. |
|
94 */ |
|
95 void CRefDataBus::UnSubscribe() |
|
96 { |
|
97 Cancel(); |
|
98 } |
|
99 |
|
100 /** |
|
101 Get the last position from the bus |
|
102 */ |
|
103 TInt CRefDataBus::GetLastPositionInfo(TPositionInfo& aRefInfo, TTime& aActualTime) |
|
104 { |
|
105 TLbsNetSessionIdInt sessionId; |
|
106 TTime targetTime; |
|
107 |
|
108 TInt error = iRefDataBus.GetPositionInfo(sessionId, aRefInfo, targetTime, aActualTime); |
|
109 |
|
110 return error; |
|
111 } |
|
112 |
|
113 /** |
|
114 from CActive, the main event processing loop |
|
115 Whenever there is a new event, i.e. the position info data is published to the data bus, notify the data bus observer by ReferenceDataAvailableL() |
|
116 */ |
|
117 void CRefDataBus::RunL() |
|
118 { |
|
119 TLbsNetSessionIdInt sessionId;//Not used |
|
120 TTime targetTime; |
|
121 TTime actualTime; |
|
122 |
|
123 TInt error = iRefDataBus.GetPositionInfo(sessionId, iPositionInfo, targetTime, actualTime); |
|
124 |
|
125 iObs.DataUpdate(iPositionInfo, iStatus.Int(), error, actualTime); |
|
126 |
|
127 } |
|
128 |
|
129 /** |
|
130 from CActive |
|
131 Cancels the request for position update notification |
|
132 It will eventually cancel an outstanding subscription request for this property handle. |
|
133 |
|
134 */ |
|
135 void CRefDataBus::DoCancel() |
|
136 { |
|
137 iRefDataBus.CancelNotifyNetworkLocationUpdate(); |
|
138 } |
|
139 |
|
140 /** |
|
141 from CActive |
|
142 Simply fwds any errors to the observers |
|
143 */ |
|
144 TInt CRefDataBus::RunError(TInt aError) |
|
145 { |
|
146 return iObs.DataError(aError, iStatus.Int()); |
|
147 } |
|
148 |