|
1 /* |
|
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Task handler for listening to the real interface |
|
15 * |
|
16 */ |
|
17 |
|
18 // @file realiapconnobserver.cpp |
|
19 |
|
20 #include "realiapconnobserver.h" |
|
21 #include "log.h" |
|
22 |
|
23 CRealIapConnObserver* CRealIapConnObserver::NewL(MTaskHandlerManager* aManager, |
|
24 const TTaskArrivedEventData& aTaskInfo) |
|
25 { |
|
26 CRealIapConnObserver* self = new (ELeave) CRealIapConnObserver(aManager, aTaskInfo); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(); |
|
29 CleanupStack::Pop(); // self |
|
30 return self; |
|
31 } |
|
32 |
|
33 CRealIapConnObserver::CRealIapConnObserver(MTaskHandlerManager* aManager, |
|
34 const TTaskArrivedEventData& aTaskInfo) |
|
35 : CTaskHandler(aManager, aTaskInfo, EObserveRealIapConnCancelEvent, &iEventSpecDes) |
|
36 { |
|
37 } |
|
38 |
|
39 void CRealIapConnObserver::ConstructL() |
|
40 { |
|
41 CActiveScheduler::Add(this); |
|
42 User::LeaveIfError(iEventMediator.Connect()); |
|
43 } |
|
44 |
|
45 CRealIapConnObserver::~CRealIapConnObserver() |
|
46 { |
|
47 Cancel(); |
|
48 iEventMediator.Close(); |
|
49 } |
|
50 |
|
51 void CRealIapConnObserver::StartTaskHandling() |
|
52 { |
|
53 GotoState(KStateStartObserving); |
|
54 } |
|
55 |
|
56 void CRealIapConnObserver::ChangeStateL() |
|
57 { |
|
58 switch (NextState()) |
|
59 { |
|
60 case KStateStartObserving: |
|
61 StateStartObservingL(); |
|
62 break; |
|
63 |
|
64 case KStateFinishObserving: |
|
65 StateFinishObserving(); |
|
66 break; |
|
67 |
|
68 default: |
|
69 User::Panic(KSitName, EPanicInvalidTaskHandlerState); |
|
70 } |
|
71 } |
|
72 |
|
73 void CRealIapConnObserver::CancelOngoingOperation() |
|
74 { |
|
75 TPckg<TUint32> connInfoDes(iEventSpecDes().iVpnIapId); |
|
76 |
|
77 switch (CurrState()) |
|
78 { |
|
79 case KStateStartObserving: |
|
80 // Cancel connection observation |
|
81 iEventMediator.CancelListening(EKmdRealIapConnDownEvent, connInfoDes); |
|
82 break; |
|
83 |
|
84 case KStateFinishObserving: |
|
85 // There's no ongoing external request to cancel |
|
86 break; |
|
87 |
|
88 default: |
|
89 User::Panic(KSitName, EPanicInvalidTaskHandlerState); |
|
90 } |
|
91 } |
|
92 |
|
93 void CRealIapConnObserver::StateStartObservingL() |
|
94 { |
|
95 SetCurrState(KStateStartObserving); |
|
96 |
|
97 TPckg<TUint32> connInfoDes(iEventSpecDes().iVpnIapId); |
|
98 iEventMediator.ListenToEvent(EKmdRealIapConnDownEvent, connInfoDes, *this); |
|
99 } |
|
100 |
|
101 void CRealIapConnObserver::EventOccured(TInt aStatus, TEventType aType, TDesC8* aData) |
|
102 { |
|
103 LOG(Log::Printf(_L("CRealIapConnObserver::EventOccured\n"))); |
|
104 |
|
105 if (aType == EKmdRealIapConnDownEvent) |
|
106 { |
|
107 // An erroneous aStatus would indicate that the event listening |
|
108 // itself would have failed somehow. We interpret that so that |
|
109 // in that case we just wouldn't get a notice if the real IAP |
|
110 // connection goes down. If it would go down, application |
|
111 // data would cease to move and the application or the user |
|
112 // would notice that at some point and close the VPN connection. |
|
113 if (aStatus == KErrNone) |
|
114 { |
|
115 LOG(Log::Printf(_L("CRealIapConnObserver::EventOccured (KMD informed that real IAP is down\n"))); |
|
116 |
|
117 TEventData eventData; |
|
118 TPckg<TEventData> eventDataDes(eventData); |
|
119 eventDataDes.Copy(*aData); |
|
120 |
|
121 iStatus = eventData.iTaskStatus; |
|
122 |
|
123 GotoState(KStateFinishObserving); |
|
124 } |
|
125 } |
|
126 else |
|
127 { |
|
128 // Call the base class implementation to handle the event |
|
129 CTaskHandler::EventOccured(aStatus, aType, aData); |
|
130 } |
|
131 } |
|
132 |
|
133 void CRealIapConnObserver::StateFinishObserving() |
|
134 { |
|
135 SetCurrState(KStateFinishObserving); |
|
136 |
|
137 TaskComplete(iStatus.Int()); |
|
138 } |
|
139 |
|
140 void CRealIapConnObserver::ReportResult(TInt aStatus) |
|
141 { |
|
142 // Report the connection shutdown with status |
|
143 // information to the Event Mediator |
|
144 |
|
145 TObserveRealIapConnEventData eventData; |
|
146 |
|
147 eventData.iTaskStatus = aStatus; |
|
148 |
|
149 TPckg<TObserveRealIapConnEventData> eventDataDes(eventData); |
|
150 ReportEvent(EObserveRealIapConnEvent, iEventSpecDes, eventDataDes); |
|
151 } |