|
1 // Copyright (c) 2005-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 #include "CGetIndicator.h" |
|
17 |
|
18 /** |
|
19 Factory constructor. |
|
20 |
|
21 @param aController Pointer to MExecAsync object passed to constructor of |
|
22 CISVAPIBase |
|
23 @return Instance of CGetIndicator class |
|
24 */ |
|
25 CGetIndicator* CGetIndicator::NewL(MExecAsync* aController) |
|
26 { |
|
27 CGetIndicator* self = new(ELeave) CGetIndicator(aController); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 /** |
|
35 Destructor. |
|
36 Cancels outstanding requests. |
|
37 */ |
|
38 CGetIndicator::~CGetIndicator() |
|
39 { |
|
40 Cancel(); |
|
41 } |
|
42 |
|
43 /** |
|
44 Gets the indicator information (information regarding whether the battery |
|
45 charger is connected and stores it in the iIndicatorV1Pckg package. |
|
46 */ |
|
47 void CGetIndicator::DoStartRequestL() |
|
48 { |
|
49 _LIT(KDummyAnswerPanic, "CGetIndicator Get Method"); |
|
50 __ASSERT_ALWAYS(!IsActive(), User::Panic(KDummyAnswerPanic, 1)); |
|
51 iRequestNotify = EFalse; |
|
52 |
|
53 // Retrieves the battery charging indicator, the network availability indicator and call-in-progress indicator. |
|
54 iTelephony->GetIndicator(iStatus, iIndicatorV1Pckg); |
|
55 SetActive(); |
|
56 } |
|
57 |
|
58 /** |
|
59 Default constructor. |
|
60 |
|
61 @param aController Pointer to an MExecAsync object passed to constructor of |
|
62 CISVAPIBase |
|
63 */ |
|
64 CGetIndicator::CGetIndicator(MExecAsync* aController) |
|
65 : CISVAPIAsync(aController, KGetIndicator), |
|
66 iIndicatorV1Pckg(iIndicatorV1) |
|
67 { |
|
68 // Empty method |
|
69 } |
|
70 |
|
71 /** |
|
72 Second phase constructor. |
|
73 */ |
|
74 void CGetIndicator::ConstructL() |
|
75 { |
|
76 // Empty method |
|
77 } |
|
78 |
|
79 /** |
|
80 Checks the status of the active object and prints the inidcator information to |
|
81 the console if there is no error. |
|
82 */ |
|
83 void CGetIndicator::RunL() |
|
84 { |
|
85 // Print Indicator Info |
|
86 if(iStatus != KErrNone) |
|
87 { |
|
88 iConsole->Printf(KError); |
|
89 |
|
90 // Print the error status code |
|
91 iConsole->Printf(_L("%d\n"), iStatus.Int()); |
|
92 } |
|
93 else |
|
94 { |
|
95 if(iIndicatorV1.iCapabilities & CTelephony::KIndChargerConnected) |
|
96 { |
|
97 // We can detect when a charger is connected |
|
98 if(iIndicatorV1.iIndicator & CTelephony::KIndChargerConnected) |
|
99 { |
|
100 // Charger is connected |
|
101 iConsole->Printf(_L("Charger connected\n")); |
|
102 } |
|
103 else |
|
104 { |
|
105 // Charger is not connected |
|
106 iConsole->Printf(_L("Charger not connected\n")); |
|
107 } |
|
108 } |
|
109 else |
|
110 { |
|
111 // We do not know whether a charger is connected. |
|
112 iConsole->Printf(_L("Status of charger unknown\n")); |
|
113 } |
|
114 if (iRequestNotify) |
|
115 { |
|
116 DoRequestNotificationL(); |
|
117 } |
|
118 else |
|
119 { |
|
120 ExampleComplete(); |
|
121 } |
|
122 } |
|
123 } |
|
124 |
|
125 /** |
|
126 Requests to receive notifications of change in the indicator information. |
|
127 */ |
|
128 void CGetIndicator::DoRequestNotificationL() |
|
129 { |
|
130 // Panic if this object is already performing an asynchronous operation. |
|
131 // Application will panic if you call SetActive() on an already active object. |
|
132 _LIT( KNotifyPanic, "CGetIndicator Notify Method" ); |
|
133 __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 )); |
|
134 iRequestNotify = ETrue; |
|
135 |
|
136 // Registers interest in receiving change notifications for events. |
|
137 iTelephony->NotifyChange( iStatus, |
|
138 CTelephony::EIndicatorChange, |
|
139 iIndicatorV1Pckg ); |
|
140 SetActive(); |
|
141 } |
|
142 |
|
143 /** |
|
144 Cancels asynchronous request to CTelephony::GetIndicator(). |
|
145 */ |
|
146 void CGetIndicator::DoCancel() |
|
147 { |
|
148 // Cancels an outstanding asynchronous request. |
|
149 iTelephony->CancelAsync(CTelephony::EIndicatorChangeCancel); |
|
150 } |