|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "stunassert.h" |
|
22 #include "tstuncallbackinfo.h" |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 // TSTUNCallbackInfo::TSTUNCallbackInfo |
|
26 // ----------------------------------------------------------------------------- |
|
27 // |
|
28 TSTUNCallbackInfo::TSTUNCallbackInfo( TSTUNCallbackInfo::TFunction aFunction, |
|
29 const CBinding* aBinding, |
|
30 TInt aErrorCode, |
|
31 const CSTUNClient* aClient ) : |
|
32 iLink(), |
|
33 iFunction( aFunction ), |
|
34 iBinding( aBinding ), |
|
35 iErrorCode( aErrorCode ), |
|
36 iClient( aClient ) |
|
37 { |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // TSTUNCallbackInfo::TSTUNCallbackInfo |
|
42 // Dummy implementation. Default constructor is declared private and not used. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 TSTUNCallbackInfo::TSTUNCallbackInfo() : |
|
46 iLink(), |
|
47 iFunction( EInitCompleted ), |
|
48 iBinding( NULL ), |
|
49 iErrorCode( KErrNone ), |
|
50 iClient( NULL ) |
|
51 { |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // TSTUNCallbackInfo::TSTUNCallbackInfo |
|
56 // Dummy implementation, as copy constructor is declared private and not used. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 TSTUNCallbackInfo::TSTUNCallbackInfo( |
|
60 const TSTUNCallbackInfo& /*aCallbackInfo*/ ) : |
|
61 iLink(), |
|
62 iFunction( EInitCompleted ), |
|
63 iBinding( NULL ), |
|
64 iErrorCode( KErrNone ), |
|
65 iClient( NULL ) |
|
66 { |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // TSTUNCallbackInfo::Validate |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 TBool TSTUNCallbackInfo::Validate() const |
|
74 { |
|
75 switch ( iFunction ) |
|
76 { |
|
77 case EInitCompleted: |
|
78 return iClient && !iBinding; |
|
79 |
|
80 case EEventAddressResolvedL: |
|
81 case EEventCredentialsRejected: |
|
82 case EEventActiveDestinationSet: |
|
83 case EEventTCPConnectOk: |
|
84 return iBinding && ( iErrorCode == KErrNone ) && !iClient; |
|
85 |
|
86 case EErrorOccurred: |
|
87 return iBinding && ( iErrorCode != KErrNone ) && !iClient; |
|
88 |
|
89 default: |
|
90 return EFalse; |
|
91 } |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // TSTUNCallbackInfo::Execute |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void TSTUNCallbackInfo::Execute( MSTUNClientObserver& aObserver ) const |
|
99 { |
|
100 __STUN_ASSERT_RETURN( Validate(), KErrGeneral ); |
|
101 |
|
102 switch ( iFunction ) |
|
103 { |
|
104 case EInitCompleted: |
|
105 __STUN_ASSERT_L( iClient != NULL, KErrNotFound ); |
|
106 aObserver.STUNClientInitCompleted( *iClient, iErrorCode ); |
|
107 break; |
|
108 |
|
109 case EEventAddressResolvedL: |
|
110 PassBindingEvent( aObserver, |
|
111 MSTUNClientObserver::EPublicAddressResolved ); |
|
112 break; |
|
113 |
|
114 case EEventCredentialsRejected: |
|
115 PassBindingEvent( aObserver, |
|
116 MSTUNClientObserver::ECredentialsRejected ); |
|
117 break; |
|
118 |
|
119 case EEventActiveDestinationSet: |
|
120 PassBindingEvent( aObserver, |
|
121 MSTUNClientObserver::EActiveDestinationSet ); |
|
122 break; |
|
123 |
|
124 case EEventTCPConnectOk: |
|
125 PassBindingEvent( aObserver, |
|
126 MSTUNClientObserver::ETCPConnectOk ); |
|
127 break; |
|
128 |
|
129 case EErrorOccurred: |
|
130 __STUN_ASSERT_L( iBinding != NULL, KErrNotFound ); |
|
131 aObserver.STUNBindingErrorOccurred( *iBinding, iErrorCode ); |
|
132 break; |
|
133 |
|
134 default: |
|
135 __STUN_FAILURE_RETURN( KErrGeneral ); |
|
136 } |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // TSTUNCallbackInfo::PassBindingEvent |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void TSTUNCallbackInfo::PassBindingEvent( |
|
144 MSTUNClientObserver& aObserver, |
|
145 MSTUNClientObserver::TSTUNBindingEvent aEvent ) const |
|
146 { |
|
147 __STUN_ASSERT_L( iBinding != NULL, KErrGeneral ); |
|
148 TRAP_IGNORE( aObserver.STUNBindingEventOccurredL( aEvent, *iBinding ) ); |
|
149 } |