|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // CLASS HEADER |
|
24 #include "testconsumer.h" |
|
25 |
|
26 // INTERNAL INCLUDES |
|
27 #include "senhostletconnectionbctest.h" |
|
28 |
|
29 #include "SenTransportProperties.h" |
|
30 |
|
31 //namespace |
|
32 // { |
|
33 // _LIT8(KHostletEndpoint, "hostlet://UnitTestHostlet"); |
|
34 // _LIT8(KHostletContract, "urn:nokia.com.serene:unit-test-hostlet"); |
|
35 // } |
|
36 |
|
37 |
|
38 CTestConsumer* CTestConsumer::NewL(CSenHostletConnectionBCTest* aTestSuite, |
|
39 void (*p2HandleMessageL) (CSenHostletConnectionBCTest*, const TDesC8&), |
|
40 void (*p2HandleErrorL) (CSenHostletConnectionBCTest*, const TInt, const TDesC8&), |
|
41 void (*p2SetStatus) (CSenHostletConnectionBCTest*, const TInt)) |
|
42 { |
|
43 CTestConsumer* pSelf = CTestConsumer::NewLC(aTestSuite, p2HandleMessageL, |
|
44 p2HandleErrorL, p2SetStatus); |
|
45 CleanupStack::Pop(pSelf); |
|
46 |
|
47 return pSelf; |
|
48 } |
|
49 |
|
50 CTestConsumer* CTestConsumer::NewLC(CSenHostletConnectionBCTest* aTestSuite, |
|
51 void (*p2HandleMessageL) (CSenHostletConnectionBCTest*, const TDesC8&), |
|
52 void (*p2HandleErrorL) (CSenHostletConnectionBCTest*, const TInt, const TDesC8&), |
|
53 void (*p2SetStatus) (CSenHostletConnectionBCTest*, const TInt)) |
|
54 { |
|
55 CTestConsumer* pSelf = new (ELeave) CTestConsumer(aTestSuite, p2HandleMessageL, |
|
56 p2HandleErrorL, p2SetStatus); |
|
57 CleanupStack::PushL(pSelf); |
|
58 |
|
59 return pSelf; |
|
60 } |
|
61 |
|
62 CTestConsumer::CTestConsumer(CSenHostletConnectionBCTest* aTestSuite, |
|
63 void (*p2HandleMessageL) (CSenHostletConnectionBCTest*, const TDesC8&), |
|
64 void (*p2HandleErrorL) (CSenHostletConnectionBCTest*, const TInt, const TDesC8&), |
|
65 void (*p2SetStatus) (CSenHostletConnectionBCTest*, const TInt)) |
|
66 : ipTestSuite(aTestSuite), |
|
67 ip2HandleMessageL(p2HandleMessageL), |
|
68 ip2HandleErrorL(p2HandleErrorL), |
|
69 ip2SetStatus(p2SetStatus) |
|
70 { |
|
71 |
|
72 } |
|
73 |
|
74 CTestConsumer::~CTestConsumer() |
|
75 { |
|
76 iResponses.ResetAndDestroy(); |
|
77 iResponseProperties.ResetAndDestroy(); |
|
78 iResponseCodes.Reset(); |
|
79 } |
|
80 |
|
81 void CTestConsumer::HandleMessageL(const TDesC8& aMessage) |
|
82 { |
|
83 iErrorCode = KErrNone; |
|
84 iTxnId = ipTestSuite->ipConnection->TxnId(); |
|
85 |
|
86 MSenMessage* pResponse = ipTestSuite->ipConnection->Response(); |
|
87 if( pResponse ) |
|
88 { |
|
89 MSenProperties* pProperties = pResponse->Properties(); |
|
90 if( pProperties ) |
|
91 { |
|
92 CSenTransportProperties* pTransportProperties = NULL; |
|
93 if( pProperties->IsSafeToCast(MSenProperties::ESenTransportProperties)) |
|
94 { |
|
95 pTransportProperties = (CSenTransportProperties*)pProperties; |
|
96 |
|
97 CSenTransportProperties* pClone = (CSenTransportProperties*)pTransportProperties->CloneL(); |
|
98 if( pClone ) |
|
99 { |
|
100 CleanupStack::PushL(pClone); |
|
101 TInt appendError = iResponseProperties.Append(pClone); |
|
102 if( appendError ) |
|
103 { |
|
104 CleanupStack::PopAndDestroy(pClone); |
|
105 } |
|
106 else |
|
107 { |
|
108 // OK, pClone is now owned by ipResponseProperties |
|
109 CleanupStack::Pop(pClone); |
|
110 } |
|
111 } |
|
112 } |
|
113 } |
|
114 } |
|
115 |
|
116 |
|
117 iResponseCodes.Append(KErrNone); |
|
118 iResponses.Append(aMessage.AllocL()); |
|
119 if ( ip2HandleMessageL ) |
|
120 { |
|
121 (*ip2HandleMessageL)(ipTestSuite, aMessage); |
|
122 } |
|
123 ipTestSuite->StopActiveScheduler(); |
|
124 } |
|
125 |
|
126 void CTestConsumer::HandleErrorL(const TInt aErrorCode, const TDesC8& aMessage) |
|
127 { |
|
128 iErrorCode = aErrorCode; |
|
129 iTxnId = ipTestSuite->ipConnection->TxnId(); |
|
130 |
|
131 MSenMessage* pResponse = ipTestSuite->ipConnection->Response(); |
|
132 if( pResponse ) |
|
133 { |
|
134 MSenProperties* pProperties = pResponse->Properties(); |
|
135 if( pProperties ) |
|
136 { |
|
137 CSenTransportProperties* pTransportProperties = NULL; |
|
138 if( pProperties->IsSafeToCast(MSenProperties::ESenTransportProperties)) |
|
139 { |
|
140 pTransportProperties = (CSenTransportProperties*)pProperties; |
|
141 |
|
142 CSenTransportProperties* pClone = (CSenTransportProperties*)pTransportProperties->CloneL(); |
|
143 if( pClone ) |
|
144 { |
|
145 CleanupStack::PushL(pClone); |
|
146 TInt appendError = iResponseProperties.Append(pClone); |
|
147 if( appendError ) |
|
148 { |
|
149 CleanupStack::PopAndDestroy(pClone); |
|
150 } |
|
151 else |
|
152 { |
|
153 // OK, pClone is now owned by ipResponseProperties |
|
154 CleanupStack::Pop(pClone); |
|
155 } |
|
156 } |
|
157 } |
|
158 } |
|
159 } |
|
160 |
|
161 iResponseCodes.Append(aErrorCode); |
|
162 HBufC8* pMessage = aMessage.AllocL(); |
|
163 CleanupStack::PushL(pMessage); |
|
164 TInt appendError2 = iResponses.Append(pMessage); |
|
165 if( appendError2 ) |
|
166 { |
|
167 CleanupStack::PopAndDestroy(pMessage); |
|
168 } |
|
169 else |
|
170 { |
|
171 CleanupStack::Pop(pMessage); |
|
172 } |
|
173 |
|
174 if ( ip2HandleErrorL ) |
|
175 { |
|
176 (*ip2HandleErrorL)(ipTestSuite, aErrorCode, aMessage); |
|
177 } |
|
178 ipTestSuite->StopActiveScheduler(); |
|
179 } |
|
180 |
|
181 void CTestConsumer::SetStatus(const TInt aStatus) |
|
182 { |
|
183 iConnectionStatus = aStatus; |
|
184 |
|
185 |
|
186 if ( ip2SetStatus ) |
|
187 { |
|
188 (*ip2SetStatus)(ipTestSuite, aStatus); // func call via ptr |
|
189 } |
|
190 else |
|
191 { |
|
192 // Active Scheduler was NOT stopped by static function (func call via ptr above) |
|
193 switch( aStatus ) |
|
194 { |
|
195 case KSenConnectionStatusReady: |
|
196 { |
|
197 ipTestSuite->StopActiveScheduler(); // otherwise failed SC construction is reported via HandleErrorL(!) |
|
198 } |
|
199 break; |
|
200 case KSenConnectionStatusNew: |
|
201 case KSenConnectionStatusExpired: |
|
202 default: |
|
203 break; |
|
204 } |
|
205 |
|
206 } |
|
207 } |
|
208 |
|
209 // END OF FILE |