|
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 "CNetworkRegInfo.h" |
|
18 |
|
19 /** |
|
20 Factory constructor. |
|
21 |
|
22 @param aController Pointer to MExecAsync object passed to constructor of |
|
23 CISVAPIBase |
|
24 @return Instance of CNetworkRegInfo class |
|
25 */ |
|
26 CNetworkRegInfo* CNetworkRegInfo::NewL(MExecAsync* aController) |
|
27 { |
|
28 CNetworkRegInfo* self = new(ELeave) CNetworkRegInfo(aController); |
|
29 CleanupStack::PushL(self); |
|
30 self->ConstructL(); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 /** |
|
36 Destructor. |
|
37 */ |
|
38 CNetworkRegInfo::~CNetworkRegInfo() |
|
39 { |
|
40 Cancel(); |
|
41 } |
|
42 |
|
43 /** |
|
44 Gets the network registration status and stores it in the iNetworkRegV1Pckg |
|
45 package. |
|
46 */ |
|
47 void CNetworkRegInfo::DoStartRequestL() |
|
48 { |
|
49 iRequestNotify = EFalse; |
|
50 |
|
51 // Retrieves the current network registration status |
|
52 iTelephony->GetNetworkRegistrationStatus(iStatus, iNetworkRegV1Pckg); |
|
53 SetActive(); |
|
54 } |
|
55 |
|
56 /** |
|
57 Constructor. |
|
58 |
|
59 @param aController Pointer to an MExecAsync object passed to constructor of |
|
60 CISVAPIBase |
|
61 */ |
|
62 CNetworkRegInfo::CNetworkRegInfo(MExecAsync* aController) |
|
63 : CISVAPIAsync(aController, KNetworkRegInfo), |
|
64 iNetworkRegV1Pckg(iNetworkRegV1) |
|
65 { |
|
66 // Empty method |
|
67 } |
|
68 |
|
69 /** |
|
70 Second phase constructor. |
|
71 */ |
|
72 void CNetworkRegInfo::ConstructL() |
|
73 { |
|
74 iRequestNotify = EFalse; |
|
75 } |
|
76 |
|
77 /** |
|
78 Checks status of the active object and prints the network registration status |
|
79 to the console. |
|
80 */ |
|
81 void CNetworkRegInfo::RunL() |
|
82 { |
|
83 if(iStatus != KErrNone) |
|
84 { |
|
85 iConsole->Printf(KError); |
|
86 |
|
87 // Print the output to console if there is no error |
|
88 iConsole->Printf(_L("%d\n"), iStatus.Int()); |
|
89 } |
|
90 else |
|
91 { |
|
92 TBuf<30> theStatus; |
|
93 iConsole->Printf(KNetworkRegMsg); |
|
94 switch(iNetworkRegV1.iRegStatus) |
|
95 { |
|
96 case CTelephony::ERegistrationUnknown: |
|
97 theStatus.Append(_L("ERegistrationUnknown\n")); |
|
98 break; |
|
99 case CTelephony::ENotRegisteredNoService: |
|
100 theStatus.Append(_L("ENotRegisteredNoService\n")); |
|
101 break; |
|
102 case CTelephony::ENotRegisteredEmergencyOnly: |
|
103 theStatus.Append(_L("ENotRegisteredEmergencyOnly\n")); |
|
104 break; |
|
105 case CTelephony::ENotRegisteredSearching: |
|
106 theStatus.Append(_L("ENotRegisteredSearching\n")); |
|
107 break; |
|
108 case CTelephony::ERegisteredBusy: |
|
109 theStatus.Append(_L("ERegisteredBusy\n")); |
|
110 break; |
|
111 case CTelephony::ERegisteredOnHomeNetwork: |
|
112 theStatus.Append(_L("ERegisteredOnHomeNetwork\n")); |
|
113 break; |
|
114 case CTelephony::ERegistrationDenied: |
|
115 theStatus.Append(_L("ERegistrationDenied\n")); |
|
116 break; |
|
117 case CTelephony::ERegisteredRoaming: |
|
118 theStatus.Append(_L("ERegisteredRoaming\n")); |
|
119 break; |
|
120 default: |
|
121 break; |
|
122 } |
|
123 iConsole->Printf(theStatus); |
|
124 } |
|
125 if (iNetworkRegV1.iRegStatus == CTelephony::ERegisteredOnHomeNetwork) |
|
126 { |
|
127 ExampleNotify(); |
|
128 } |
|
129 else |
|
130 { |
|
131 RequestNotificationL(); |
|
132 } |
|
133 } |
|
134 |
|
135 /** |
|
136 Requests to receive notifications of changes in the network registration |
|
137 status. |
|
138 */ |
|
139 void CNetworkRegInfo::DoRequestNotificationL() |
|
140 { |
|
141 // Panic if this object is already performing an asynchronous operation. |
|
142 // Application will panic if you call SetActive() on an already active object. |
|
143 _LIT( KNotifyPanic, "CNetworkReg Notify Method" ); |
|
144 __ASSERT_ALWAYS( !IsActive(), User::Panic( KNotifyPanic, 1 )); |
|
145 iRequestNotify = ETrue; |
|
146 |
|
147 // Registers interest in receiving change notifications for events. |
|
148 iTelephony->NotifyChange( iStatus, |
|
149 CTelephony::ENetworkRegistrationStatusChange, |
|
150 iNetworkRegV1Pckg ); |
|
151 SetActive(); |
|
152 } |
|
153 |
|
154 /** |
|
155 Cancels asynchronous request to CTelephony::GetNetworkRegistrationStatus() |
|
156 */ |
|
157 void CNetworkRegInfo::DoCancel() |
|
158 { |
|
159 iRequestNotify = EFalse; |
|
160 |
|
161 // Cancels an outstanding asynchronous request |
|
162 iTelephony->CancelAsync(CTelephony::ENetworkRegistrationStatusChangeCancel); |
|
163 } |