|
1 /* |
|
2 * Copyright (c) 2008-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: Sender of UDP datagrams |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <in_sock.h> |
|
20 |
|
21 #include "ikedatainterface.h" |
|
22 #include "ikedebug.h" |
|
23 #include "ikesocketdefs.h" |
|
24 #include "ikemsgheader.h" |
|
25 |
|
26 // CLASS HEADER |
|
27 #include "ikev1sender.h" |
|
28 |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // Two-phased constructor. |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CIkev1Sender* CIkev1Sender::NewL( MIkeDataInterface& aDataInterface, |
|
37 MIkev1SenderCallback& aCallback, |
|
38 MIkeDebug& aDebug ) |
|
39 { |
|
40 CIkev1Sender* self = new (ELeave) CIkev1Sender( aDataInterface, |
|
41 aCallback, |
|
42 aDebug ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // Destructor. |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CIkev1Sender::~CIkev1Sender() |
|
51 { |
|
52 HBufC8* udpData = iUdpData; |
|
53 iUdpData = NULL; |
|
54 |
|
55 // Sending is not completed via callback interface. |
|
56 Cancel(); |
|
57 |
|
58 delete udpData; |
|
59 udpData = NULL; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // Constructor. |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 CIkev1Sender::CIkev1Sender( MIkeDataInterface& aDataInterface, |
|
67 MIkev1SenderCallback& aCallback, |
|
68 MIkeDebug& aDebug ) |
|
69 : CActive( EPriorityStandard ), |
|
70 iUdpData( NULL ), |
|
71 iDataInterface( aDataInterface ), |
|
72 iCallback( aCallback ), |
|
73 iDebug( aDebug ) |
|
74 { |
|
75 CActiveScheduler::Add( this ); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Sends IKE message. |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CIkev1Sender::SendUdpData( HBufC8* aUdpData, |
|
83 const TInetAddr& aDestAddr, |
|
84 TInt aLocalPort, |
|
85 TUint8 aDscp ) |
|
86 { |
|
87 __ASSERT_DEBUG( iUdpData == NULL, |
|
88 User::Invariant() ); |
|
89 |
|
90 Cancel(); |
|
91 |
|
92 iUdpData = aUdpData; |
|
93 |
|
94 // Send IKE message. |
|
95 DEBUG_LOG( _L("CIkev1Sender::SendUdpData, sending...")); |
|
96 iDataInterface.SendUdpData( aLocalPort, |
|
97 aDestAddr, |
|
98 *aUdpData, |
|
99 aDscp, |
|
100 iStatus ); |
|
101 SetActive(); |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // From class CActive |
|
106 // Handles completion of sending. |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void CIkev1Sender::RunL() |
|
110 { |
|
111 DEBUG_LOG1( _L("CIkev1Sender::RunL, status=%d"), |
|
112 iStatus.Int() ); |
|
113 |
|
114 if ( iUdpData != NULL ) |
|
115 { |
|
116 delete iUdpData; |
|
117 iUdpData = NULL; |
|
118 |
|
119 iCallback.SendUdpDataCompleted( iStatus.Int() ); |
|
120 } |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // From class CActive |
|
125 // Handles cancellation of sending. |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 void CIkev1Sender::DoCancel() |
|
129 { |
|
130 DEBUG_LOG( _L("CIkev1Sender::DoCancel")); |
|
131 |
|
132 iDataInterface.CancelSend(); |
|
133 if ( iUdpData != NULL ) |
|
134 { |
|
135 delete iUdpData; |
|
136 iUdpData = NULL; |
|
137 } |
|
138 } |
|
139 |