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