|
1 /* |
|
2 * Copyright (c) 2003-2007 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: Common keep alive object |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ikev2keepalive.h" |
|
20 #include "ikemsgheader.h" |
|
21 #include "ikev2pluginsession.h" |
|
22 |
|
23 CIkeV2KeepAlive* CIkeV2KeepAlive::NewL(TInt DpdKeepAlive, MIkeV2DpdHeartBeatEventHandler& aHandler) |
|
24 { |
|
25 CIkeV2KeepAlive* self = new (ELeave) CIkeV2KeepAlive(DpdKeepAlive, aHandler); |
|
26 CleanupStack::PushL(self); |
|
27 self->ConstructL(); |
|
28 CleanupStack::Pop(self); |
|
29 return self; |
|
30 } |
|
31 |
|
32 |
|
33 //Constructor |
|
34 CIkeV2KeepAlive::CIkeV2KeepAlive(TInt aDpdKeepAlive, |
|
35 MIkeV2DpdHeartBeatEventHandler& aHandler) |
|
36 : CTimer(EPriorityStandard), iCallback(aHandler), iDpdKeepAlive(aDpdKeepAlive) |
|
37 { |
|
38 __ASSERT_DEBUG(iDpdKeepAlive > 0, User::Invariant()); |
|
39 CActiveScheduler::Add(this); |
|
40 } |
|
41 |
|
42 //Destructor |
|
43 CIkeV2KeepAlive::~CIkeV2KeepAlive() |
|
44 { |
|
45 if (IsActive()) |
|
46 Cancel(); |
|
47 } |
|
48 |
|
49 |
|
50 void CIkeV2KeepAlive::ConstructL() |
|
51 { |
|
52 // |
|
53 // If NAT keepalive timoeut allocate (and initialize) a TIkeXmitBfr data buffer for |
|
54 // NAT keepalive. Allocate a data buffer for special "Echo request" |
|
55 // keepalive message, if proprietary "Nokia NAT Traversal is used". |
|
56 // Start keep alive timer |
|
57 // |
|
58 CTimer::ConstructL(); |
|
59 |
|
60 iRemainingTime = iDpdKeepAlive; |
|
61 StartTimer(); |
|
62 } |
|
63 |
|
64 |
|
65 void CIkeV2KeepAlive::DoCancel() |
|
66 { |
|
67 CTimer::DoCancel(); |
|
68 } |
|
69 |
|
70 void CIkeV2KeepAlive::RunL() |
|
71 { |
|
72 if ( iRemainingTime == 0 && iDpdKeepAlive) |
|
73 { |
|
74 iCallback.EventHandlerL(); |
|
75 iRemainingTime = iDpdKeepAlive; |
|
76 } |
|
77 StartTimer(); |
|
78 } |
|
79 |
|
80 void CIkeV2KeepAlive::StartTimer() |
|
81 { |
|
82 |
|
83 if ( iRemainingTime > KMaxTInt/1000000 ) //To avoid overflowing the Timer |
|
84 { |
|
85 iRemainingTime -= KMaxTInt/1000000; |
|
86 After(KMaxTInt); |
|
87 } |
|
88 else //No overflow |
|
89 { |
|
90 if ( iRemainingTime ) |
|
91 After(iRemainingTime*1000000); |
|
92 iRemainingTime = 0; |
|
93 } |
|
94 } |
|
95 |