|
1 // Copyright (c) 2004-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 |
|
18 // INCLUDE FILES |
|
19 #include <e32std.h> |
|
20 #include <bacntf.h> |
|
21 |
|
22 #include "BTGPSEnvChangeHandler.h" |
|
23 #include "BTGPSRequestManager.h" |
|
24 #include "BTGPSLogging.h" |
|
25 |
|
26 // EXTERNAL DATA STRUCTURES |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // MACROS |
|
33 |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 |
|
36 // MODULE DATA STRUCTURES |
|
37 |
|
38 // LOCAL FUNCTION PROTOTYPES |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 |
|
42 // ============================= LOCAL FUNCTIONS =============================== |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CBTGPSEnvChangeHandler::NewL |
|
49 // ----------------------------------------------------------------------------- |
|
50 CBTGPSEnvChangeHandler* CBTGPSEnvChangeHandler::NewL( |
|
51 CBTGPSRequestManager& aRequestManager) |
|
52 { |
|
53 CBTGPSEnvChangeHandler* self = new (ELeave) CBTGPSEnvChangeHandler( |
|
54 aRequestManager); |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(); |
|
57 CleanupStack::Pop(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CBTGPSEnvChangeHandler::~CBTGPSEnvChangeHandler |
|
63 // ----------------------------------------------------------------------------- |
|
64 CBTGPSEnvChangeHandler::~CBTGPSEnvChangeHandler() |
|
65 { |
|
66 if(iEnvChangeNotifier!=NULL) |
|
67 { |
|
68 iEnvChangeNotifier->Cancel(); |
|
69 } |
|
70 delete iEnvChangeNotifier; |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CBTGPSEnvChangeHandler::ConstructL |
|
75 // ----------------------------------------------------------------------------- |
|
76 void CBTGPSEnvChangeHandler::ConstructL() |
|
77 { |
|
78 iEnvChangeNotifier = |
|
79 CEnvironmentChangeNotifier::NewL( |
|
80 CActive::EPriorityStandard, |
|
81 TCallBack(NotifierCallBack, this)); |
|
82 |
|
83 iEnvChangeNotifier->Start(); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CBTGPSEnvChangeHandler::CBTGPSEnvChangeHandler |
|
88 // C++ default constructor can NOT contain any code, that |
|
89 // might leave. |
|
90 // ----------------------------------------------------------------------------- |
|
91 CBTGPSEnvChangeHandler::CBTGPSEnvChangeHandler( |
|
92 CBTGPSRequestManager& aRequestManager) : |
|
93 iRequestManager(aRequestManager) |
|
94 { |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CBTGPSEnvChangeHandler::NotifierCallBack |
|
99 // ----------------------------------------------------------------------------- |
|
100 TInt CBTGPSEnvChangeHandler::NotifierCallBack(TAny* aPtr) |
|
101 { |
|
102 reinterpret_cast<CBTGPSEnvChangeHandler*>(aPtr)->HandleEnvironmentChange(); |
|
103 return KErrNone; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CBTGPSEnvChangeHandler:HandleEnvironmentChange |
|
108 // |
|
109 // Currently we are only interested of system time change. This function is also |
|
110 // called once immediately after enviroment change notifier object is |
|
111 // constructed. |
|
112 // |
|
113 // NOTE: This function can be used to detect changes in phone power supply |
|
114 // in case this information is needed to change the functionality depending of |
|
115 // whether external power supply is connected or not. |
|
116 // |
|
117 // (other items were commented in a header). |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CBTGPSEnvChangeHandler::HandleEnvironmentChange() |
|
121 { |
|
122 TRACESTRING("CBTGPSEnvChangeHandler::HandleEnvironmentChange start...") |
|
123 // This function is called once always after construction, in this |
|
124 // case we don't even need to check reason |
|
125 // --> "Filter out" this initialization |
|
126 if (!iEnvChangeNotifierInitialized) |
|
127 { |
|
128 iEnvChangeNotifierInitialized = ETrue; |
|
129 return; |
|
130 } |
|
131 |
|
132 // Get reason why this function was called |
|
133 TInt envChange = iEnvChangeNotifier->Change(); |
|
134 |
|
135 // If reason was cancel, or system time change flag is not on, then we |
|
136 // can return. |
|
137 if (envChange == KErrCancel || !(envChange & EChangesSystemTime)) |
|
138 { |
|
139 return; |
|
140 } |
|
141 |
|
142 // If system time really changed, then we set last fix time as 0 |
|
143 iRequestManager.SystemTimeChange(); |
|
144 TRACESTRING("CBTGPSEnvChangeHandler::HandleEnvironmentChange end") |
|
145 } |
|
146 |
|
147 // End of File |
|
148 |
|
149 |
|
150 |