|
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 "CFlightModeInfo.h" |
|
17 |
|
18 /** |
|
19 Factory constructor. |
|
20 |
|
21 @param aController Pointer to MExecAsync object passed to constructor of CISVAPIBase |
|
22 @return Instance of CFlightModeInfo class |
|
23 */ |
|
24 CFlightModeInfo* CFlightModeInfo::NewL(MExecAsync* aController) |
|
25 { |
|
26 CFlightModeInfo* self = new(ELeave) CFlightModeInfo(aController); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(); |
|
29 CleanupStack::Pop(self); |
|
30 return self; |
|
31 } |
|
32 |
|
33 /** |
|
34 Destructor. |
|
35 Calls Cancel() to cancel outstanding requests. |
|
36 */ |
|
37 CFlightModeInfo::~CFlightModeInfo() |
|
38 { |
|
39 Cancel(); |
|
40 } |
|
41 |
|
42 /** |
|
43 Gets the flight mode status and stores it in the iFlightModeV1Pckg. |
|
44 */ |
|
45 void CFlightModeInfo::DoStartRequestL() |
|
46 { |
|
47 iRequestNotify = EFalse; |
|
48 |
|
49 // Retrieves the current flight mode status. |
|
50 iTelephony->GetFlightMode(iStatus, iFlightModeV1Pckg); |
|
51 SetActive(); |
|
52 } |
|
53 |
|
54 /** |
|
55 Constructor, called by the CFlightModeInfo::NewL() factory constructor. |
|
56 |
|
57 @param aController Pointer to an MExecAsync object passed to constructor of |
|
58 CISVAPIBase |
|
59 */ |
|
60 CFlightModeInfo::CFlightModeInfo(MExecAsync* aController) |
|
61 : CISVAPIAsync(aController, KFlightModeInfo) |
|
62 , iFlightModeV1Pckg(iFlightModeV1) |
|
63 { |
|
64 // Empty method |
|
65 } |
|
66 |
|
67 /** |
|
68 Second phase constructor. |
|
69 */ |
|
70 void CFlightModeInfo::ConstructL() |
|
71 { |
|
72 // Empty method |
|
73 } |
|
74 |
|
75 /** |
|
76 Displays the flight mode status if there is no error. |
|
77 */ |
|
78 void CFlightModeInfo::RunL() |
|
79 { |
|
80 if(iStatus != KErrNone) |
|
81 { |
|
82 iConsole->Printf(KError); |
|
83 |
|
84 // Print the error status code |
|
85 iConsole->Printf(_L("%d\n"), iStatus.Int()); |
|
86 } |
|
87 else |
|
88 { |
|
89 // Active object completed with no error, therefore, print out the |
|
90 // flight mode status to the console. |
|
91 CTelephony::TFlightModeV1 FlightMode = iFlightModeV1; |
|
92 CTelephony::TFlightModeStatus aFlightModeStatus = FlightMode.iFlightModeStatus; |
|
93 if (iRequestNotify) |
|
94 { |
|
95 iConsole->ClearScreen(); |
|
96 iConsole->Printf(_L("~*THIS IS A NOTIFICATION*~\n")); |
|
97 } |
|
98 switch (aFlightModeStatus) |
|
99 { |
|
100 case CTelephony::EFlightModeOff: |
|
101 iConsole->Printf(_L("Flight Status is Off, Signal Strength can be Monitored!\n")); |
|
102 ExampleComplete(); |
|
103 break; |
|
104 case CTelephony::EFlightModeOn: |
|
105 iConsole->Printf(_L("Flight Status is On, Signal Strength cannot be Monitored!\n")); |
|
106 RequestNotificationL(); |
|
107 ExampleNotify(); |
|
108 break; |
|
109 default: |
|
110 iConsole->Printf(KError); |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 /** |
|
116 Requests to receive notifications of change in the flight mode. |
|
117 */ |
|
118 void CFlightModeInfo::DoRequestNotificationL() |
|
119 { |
|
120 // Panic if this object is already performing an asynchronous operation. |
|
121 // Application will panic if you call SetActive() on an already active object. |
|
122 _LIT( KNotifyPanic, "CFlightModeInfo Notify Method" ); |
|
123 __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 )); |
|
124 iRequestNotify = ETrue; |
|
125 |
|
126 // Registers interest in receiving change notifications for events. |
|
127 iTelephony->NotifyChange(iStatus, |
|
128 CTelephony::EFlightModeChange, |
|
129 iFlightModeV1Pckg ); |
|
130 SetActive(); |
|
131 } |
|
132 |
|
133 /** |
|
134 Cancels asynchronous request to CTelephony::GetFlightMode(). |
|
135 */ |
|
136 void CFlightModeInfo::DoCancel() |
|
137 { |
|
138 // Cancels an outstanding asynchronous request. |
|
139 iTelephony->CancelAsync(CTelephony::EFlightModeChangeCancel); |
|
140 } |