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