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