1 // Copyright (c) 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 // Name : sipphoneregistrationmonitor.cpp |
|
15 // Part of : SIP Profile Agent / IMS Agent |
|
16 // Version : %version: 2 % |
|
17 // |
|
18 |
|
19 |
|
20 #include "sipphoneregistrationmonitor.h" |
|
21 #include "sipphoneregistrationobserver.h" |
|
22 |
|
23 // ----------------------------------------------------------------------------- |
|
24 // CSipPhoneRegistrationMonitor::NewL |
|
25 // ----------------------------------------------------------------------------- |
|
26 // |
|
27 CSipPhoneRegistrationMonitor* CSipPhoneRegistrationMonitor::NewL( |
|
28 RTelServer& aTelServer, |
|
29 const RTelServer::TPhoneInfo& aPhoneInfo, |
|
30 MSipPhoneRegistrationObserver& aObserver ) |
|
31 { |
|
32 CSipPhoneRegistrationMonitor* self |
|
33 = new( ELeave ) CSipPhoneRegistrationMonitor( aObserver ); |
|
34 CleanupStack::PushL( self ); |
|
35 self->ConstructL( aTelServer, aPhoneInfo ); |
|
36 CleanupStack::Pop( self ); |
|
37 return self; |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CSipPhoneRegistrationMonitor::CSipPhoneRegistrationMonitor |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CSipPhoneRegistrationMonitor::CSipPhoneRegistrationMonitor( |
|
45 MSipPhoneRegistrationObserver& aObserver ) |
|
46 : CActive( CActive::EPriorityStandard ), |
|
47 iObserver( aObserver ), |
|
48 iRegistrationStatus( RMobilePhone::ERegistrationUnknown ) |
|
49 { |
|
50 CActiveScheduler::Add( this ); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CSipPhoneRegistrationMonitor::ConstructL |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 #ifdef __WINSCW__ |
|
58 |
|
59 void CSipPhoneRegistrationMonitor::ConstructL( |
|
60 RTelServer& /*aTelServer*/, |
|
61 const RTelServer::TPhoneInfo& /*aPhoneInfo*/ ) |
|
62 { |
|
63 iRegistrationStatus = RMobilePhone::ERegisteredOnHomeNetwork; |
|
64 } |
|
65 |
|
66 #else |
|
67 |
|
68 void CSipPhoneRegistrationMonitor::ConstructL( |
|
69 RTelServer& aTelServer, |
|
70 const RTelServer::TPhoneInfo& aPhoneInfo ) |
|
71 { |
|
72 |
|
73 User::LeaveIfError( iPhone.Open( aTelServer, aPhoneInfo.iName ) ); |
|
74 |
|
75 // Get current status |
|
76 TRequestStatus status; |
|
77 iPhone.GetNetworkRegistrationStatus( status, iRegistrationStatus ); |
|
78 User::WaitForRequest( status ); |
|
79 User::LeaveIfError( status.Int() ); |
|
80 |
|
81 // Start to monitor the status |
|
82 MonitorStatus(); |
|
83 } |
|
84 |
|
85 #endif |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CSipPhoneRegistrationMonitor::~CSipPhoneRegistrationMonitor |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CSipPhoneRegistrationMonitor::~CSipPhoneRegistrationMonitor() |
|
92 { |
|
93 Cancel(); |
|
94 iPhone.Close(); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CSipPhoneRegistrationMonitor::Status |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 CSipPhoneRegistrationMonitor::TStatus |
|
102 CSipPhoneRegistrationMonitor::Status() const |
|
103 { |
|
104 TStatus status = ENotRegistered; |
|
105 switch ( iRegistrationStatus ) |
|
106 { |
|
107 case RMobilePhone::ERegisteredOnHomeNetwork: |
|
108 status = ERegisteredOnHomeNetwork; |
|
109 break; |
|
110 case RMobilePhone::ERegisteredRoaming: |
|
111 status = ERegisteredRoaming; |
|
112 break; |
|
113 default: |
|
114 break; |
|
115 } |
|
116 return status; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CSipPhoneRegistrationMonitor::DoCancel |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 void CSipPhoneRegistrationMonitor::DoCancel() |
|
124 { |
|
125 iPhone.CancelAsyncRequest( |
|
126 EMobilePhoneNotifyNetworkRegistrationStatusChange ); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CSipPhoneRegistrationMonitor::RunL |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CSipPhoneRegistrationMonitor::RunL() |
|
134 { |
|
135 TInt err = iStatus.Int(); |
|
136 |
|
137 if ( err ) |
|
138 { |
|
139 iObserver.PhoneRegistrationStatusError( err ); |
|
140 } |
|
141 else |
|
142 { |
|
143 MonitorStatus(); |
|
144 iObserver.PhoneRegistrationStatusChangedL(); |
|
145 } |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CSipPhoneRegistrationMonitor::RunError |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 TInt CSipPhoneRegistrationMonitor::RunError(TInt aError) |
|
153 { |
|
154 iObserver.PhoneRegistrationStatusError( aError ); |
|
155 return KErrNone; |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CSipPhoneRegistrationMonitor::MonitorStatus |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CSipPhoneRegistrationMonitor::MonitorStatus() |
|
163 { |
|
164 #ifndef __WINSCW__ |
|
165 |
|
166 // Request further notification from ETel |
|
167 iPhone.NotifyNetworkRegistrationStatusChange( iStatus, |
|
168 iRegistrationStatus ); |
|
169 SetActive(); |
|
170 |
|
171 #endif |
|
172 } |
|