|
1 // Copyright (c) 2007-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 <etelmm.h> |
|
17 #include <comms-infras/es_availability.h> |
|
18 #include <comms-infras/ss_mcprnodemessages.h> |
|
19 #include "csdavailabilitylistener.h" |
|
20 #include <elements/nm_messages_base.h> |
|
21 #include <comms-infras/ss_nodemessages_availability.h> |
|
22 |
|
23 using namespace Messages; |
|
24 using namespace ESock; |
|
25 |
|
26 static void GetPhoneInfoL(RTelServer& aTelServer, const TDesC& aLoadedTsyName, RTelServer::TPhoneInfo& aInfo) |
|
27 { |
|
28 TInt count; |
|
29 User::LeaveIfError(aTelServer.EnumeratePhones(count)); |
|
30 if (count<=0) |
|
31 { |
|
32 User::Leave(KErrNotFound); |
|
33 } |
|
34 |
|
35 TBool found = EFalse; |
|
36 for (TInt i=0; i < count; i++) |
|
37 { |
|
38 TBuf<KCommsDbSvrMaxFieldLength> currentTsyName; |
|
39 User::LeaveIfError(aTelServer.GetTsyName(i,currentTsyName)); |
|
40 |
|
41 TInt r=currentTsyName.Locate('.'); |
|
42 if (r!=KErrNotFound) |
|
43 { |
|
44 currentTsyName.SetLength(r); |
|
45 } |
|
46 if (currentTsyName.CompareF(aLoadedTsyName)==KErrNone) |
|
47 { |
|
48 User::LeaveIfError(aTelServer.GetPhoneInfo(i,aInfo)); |
|
49 found = ETrue; |
|
50 break; |
|
51 } |
|
52 } |
|
53 |
|
54 if (!found) |
|
55 { |
|
56 User::Leave(KErrNotFound); |
|
57 } |
|
58 } |
|
59 |
|
60 CCsdAvailabilityListener* CCsdAvailabilityListener::NewL(const TNodeCtxId& aAvailabilityActivity, const CPppTsyConfig& aTsyProvision, TUint aApId) |
|
61 { |
|
62 CCsdAvailabilityListener* self = new (ELeave) CCsdAvailabilityListener(aAvailabilityActivity, aTsyProvision, aApId); |
|
63 CleanupStack::PushL(self); |
|
64 self->StartL(); |
|
65 CleanupStack::Pop(self); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // CActive |
|
70 void CCsdAvailabilityListener::RunL() |
|
71 { |
|
72 User::LeaveIfError(iStatus.Int()); |
|
73 |
|
74 |
|
75 switch (iState) |
|
76 { |
|
77 case EInitialising: |
|
78 iPhone.GetNetworkRegistrationStatus(iStatus, iRegStatus); |
|
79 iState = EChecking; |
|
80 SetActive(); |
|
81 break; |
|
82 case EChecking: |
|
83 //Fall through to EAttached / EUnAttached |
|
84 case EAvailable: |
|
85 case EUnAvailable: |
|
86 if (iRegStatus == RMobilePhone::ERegisteredOnHomeNetwork |
|
87 || iRegStatus == RMobilePhone::ERegisteredRoaming) |
|
88 { |
|
89 if (iState!=EAvailable) //Could be EUnAvailable or EChecking |
|
90 { |
|
91 TAvailabilityStatus availabilityStatus(TAvailabilityStatus::EMaxAvailabilityScore); |
|
92 RClientInterface::OpenPostMessageClose(Id(), iAvailabilityActivity, TCFAvailabilityControlClient::TAvailabilityNotification(availabilityStatus).CRef()); |
|
93 iState = EAvailable; |
|
94 } |
|
95 } |
|
96 else |
|
97 { |
|
98 if (iState!=EUnAvailable) //Could be EAttached or EChecking |
|
99 { |
|
100 TAvailabilityStatus availabilityStatus(TAvailabilityStatus::EMinAvailabilityScore); |
|
101 RClientInterface::OpenPostMessageClose(Id(), iAvailabilityActivity, TCFAvailabilityControlClient::TAvailabilityNotification(availabilityStatus).CRef()); |
|
102 iState = EUnAvailable; |
|
103 } |
|
104 } |
|
105 |
|
106 iPhone.NotifyNetworkRegistrationStatusChange(iStatus, iRegStatus); |
|
107 SetActive(); |
|
108 break; |
|
109 |
|
110 default: |
|
111 ASSERT(EFalse); |
|
112 } |
|
113 } |
|
114 |
|
115 TInt CCsdAvailabilityListener::RunError(TInt aError) |
|
116 { |
|
117 RClientInterface::OpenPostMessageClose(Id(), iAvailabilityActivity, |
|
118 TEBase::TError(TCFAvailabilityProvider::TAvailabilityNotificationRegistration::Id(), aError).CRef()); |
|
119 |
|
120 return KErrNone; |
|
121 } |
|
122 |
|
123 void CCsdAvailabilityListener::DoCancel() |
|
124 { |
|
125 switch (iState) |
|
126 { |
|
127 case EInitialising: |
|
128 iPhone.InitialiseCancel(); |
|
129 break; |
|
130 case EChecking: |
|
131 iPhone.CancelAsyncRequest(EMobilePhoneGetNetworkRegistrationStatus); |
|
132 //Fall through to EAttached / EUnAttached |
|
133 case EAvailable: |
|
134 case EUnAvailable: |
|
135 iPhone.CancelAsyncRequest(EMobilePhoneNotifyNetworkRegistrationStatusChange); |
|
136 break; |
|
137 default: |
|
138 ASSERT(EFalse); |
|
139 } |
|
140 } |
|
141 |
|
142 CCsdAvailabilityListener::~CCsdAvailabilityListener() |
|
143 { |
|
144 Cancel(); |
|
145 iPhone.Close(); |
|
146 iTelServer.Close(); |
|
147 } |
|
148 |
|
149 CCsdAvailabilityListener::CCsdAvailabilityListener(const TNodeCtxId& aAvailabilityActivity, const CPppTsyConfig& aTsyProvision, TUint aApId) |
|
150 : CActive(EPriorityNormal), |
|
151 iAvailabilityActivity(aAvailabilityActivity), |
|
152 iTsyProvision(&aTsyProvision), |
|
153 iApId(aApId), |
|
154 iState(EInitialising) |
|
155 { |
|
156 CActiveScheduler::Add(this); |
|
157 } |
|
158 |
|
159 void CCsdAvailabilityListener::StartL() |
|
160 { |
|
161 User::LeaveIfError(iTelServer.Connect()); |
|
162 User::LeaveIfError(iTelServer.LoadPhoneModule(iTsyProvision->TsyName())); |
|
163 User::LeaveIfError(iTelServer.SetExtendedErrorGranularity(RTelServer::EErrorExtended)); |
|
164 |
|
165 RTelServer::TPhoneInfo phoneInfo; |
|
166 GetPhoneInfoL(iTelServer, iTsyProvision->TsyName(), phoneInfo); |
|
167 User::LeaveIfError (iPhone.Open(iTelServer, phoneInfo.iName)); |
|
168 |
|
169 RPhone::TStatus phoneStatus; |
|
170 iPhone.GetStatus(phoneStatus); |
|
171 |
|
172 if(phoneStatus.iMode==RPhone::EModeUnknown) |
|
173 { |
|
174 iPhone.Initialise(iStatus); |
|
175 } |
|
176 else |
|
177 { |
|
178 TRequestStatus* status = &iStatus; |
|
179 User::RequestComplete(status, KErrNone); |
|
180 } |
|
181 SetActive(); |
|
182 } |
|
183 |
|
184 void CCsdAvailabilityListener::ReceivedL(const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage) |
|
185 { |
|
186 (void)aMessage; |
|
187 ASSERT(TEBase::ERealmId == aMessage.MessageId().Realm()); |
|
188 ASSERT(TEBase::TCancel::EId == aMessage.MessageId().MessageId()); |
|
189 delete this; |
|
190 }; |
|
191 |