|
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <commschan.h> |
|
17 #include <cfshared.h> |
|
18 #include "bm_defs.h" |
|
19 using namespace CommsFW; |
|
20 |
|
21 CBindInfo* CBindInfo::NewL(const TRSBindType aType, |
|
22 const TCFSubModuleAddress& aSubModule1, |
|
23 const TCFSubModuleAddress& aSubModule2, |
|
24 TInt aChannel1Length, TInt aChannel2Length) |
|
25 /** |
|
26 @internalComponent |
|
27 Creates new CBindInfo object. |
|
28 |
|
29 @param aType the type of binding |
|
30 @param aSubModule1 the address of the first bound module |
|
31 @param aSubModule2 the address of the second bound module |
|
32 @param aChannel1Length xx |
|
33 @param aChannel2Length xx |
|
34 |
|
35 @return CBindInfo* Pointer to the new CBindInfo object. |
|
36 */ |
|
37 { |
|
38 CBindInfo* pBi = new(ELeave) CBindInfo(aType, aSubModule1, aSubModule2); |
|
39 CleanupStack::PushL(pBi); |
|
40 pBi->ConstructL(aChannel1Length,aChannel2Length); |
|
41 CleanupStack::Pop(pBi); |
|
42 return pBi; |
|
43 } |
|
44 |
|
45 |
|
46 CBindInfo::CBindInfo(const TRSBindType aType, |
|
47 const TCFSubModuleAddress& aSubModule1, |
|
48 const TCFSubModuleAddress& aSubModule2) : |
|
49 iType(aType), |
|
50 iSubModule1(aSubModule1), |
|
51 iSubModule2(aSubModule2) |
|
52 /** |
|
53 @internalComponent |
|
54 Constructor for CBindInfo |
|
55 |
|
56 @param aType the type of binding |
|
57 @param aSubModule1 the address of the first bound module |
|
58 @param aSubModule2 the address of the second bound module |
|
59 */ |
|
60 { |
|
61 __CFLOG_SMADDR2(( KLogSubSysRS, KLogCode, _L8("CBindInfo::CBindInfo(%X) module1 %S, module2 %S"), this, |
|
62 &SubModuleAddr1().Printable(__FullModName1), &SubModuleAddr2().Printable(__FullModName2) )); |
|
63 } |
|
64 |
|
65 CBindInfo::~CBindInfo() |
|
66 /** |
|
67 @internalComponent |
|
68 Destructor for CBindInfo |
|
69 */ |
|
70 { |
|
71 __CFLOG_SMADDR2(( KLogSubSysRS, KLogCode, _L8("CBindInfo::~CBindInfo(%X) module1 %S, module2 %S"), this, |
|
72 &SubModuleAddr1().Printable(__FullModName1), &SubModuleAddr2().Printable(__FullModName2) )); |
|
73 Dequeue(); |
|
74 iChannel1.Close(); |
|
75 iChannel2.Close(); |
|
76 } |
|
77 |
|
78 void CBindInfo::ConstructL(TInt aChannel1Length,TInt aChannel2Length) |
|
79 /** |
|
80 @internalComponent |
|
81 Second phase constructor for CBindInfo |
|
82 |
|
83 @leave |
|
84 */ |
|
85 { |
|
86 User::LeaveIfError(iChannel1.Create(aChannel1Length)); |
|
87 User::LeaveIfError(iChannel2.Create(aChannel2Length)); |
|
88 } |
|
89 CBindInfo::TSubModuleDetails::TSubModuleDetails(const TCFSubModuleAddress& aSubModule) : |
|
90 iSubModule(aSubModule), |
|
91 iState(CBindManager::EUnbound), |
|
92 iResult(KErrNone) |
|
93 /** |
|
94 @internalComponent |
|
95 Constructor for CBindInfo::TSubModuleDetails |
|
96 */ |
|
97 { |
|
98 } |
|
99 |
|
100 void CBindInfo::Dequeue() |
|
101 /** |
|
102 @internalComponent |
|
103 Remove this from the linked list |
|
104 */ |
|
105 { |
|
106 iLink.Deque(); |
|
107 } |
|
108 |
|
109 const RCFChannel& CBindInfo::Channel1() const |
|
110 /** |
|
111 @internalComponent |
|
112 Accessor method for first RCFChannel in binding |
|
113 |
|
114 @return RCFChannel& the channel requested |
|
115 */ |
|
116 { |
|
117 return iChannel1; |
|
118 } |
|
119 |
|
120 const RCFChannel& CBindInfo::Channel2() const |
|
121 /** |
|
122 @internalComponent |
|
123 Accessor method for second RCFChannel in binding |
|
124 |
|
125 @return RCFChannel& the channel requested |
|
126 */ |
|
127 { |
|
128 return iChannel2; |
|
129 } |
|
130 |
|
131 const TCFSubModuleAddress& CBindInfo::SubModuleAddr1() const |
|
132 /** |
|
133 @internalComponent |
|
134 Accessor method for first submodule address in the binding |
|
135 |
|
136 @return TCFSubModuleAddress& the address requested |
|
137 */ |
|
138 { |
|
139 return iSubModule1.iSubModule; |
|
140 } |
|
141 |
|
142 const TCFSubModuleAddress& CBindInfo::SubModuleAddr2() const |
|
143 /** |
|
144 @internalComponent |
|
145 Accessor method for second submodule address in the binding |
|
146 |
|
147 @return TCFSubModuleAddress& the address requested |
|
148 */ |
|
149 { |
|
150 return iSubModule2.iSubModule; |
|
151 } |
|
152 |
|
153 const TRSBindType& CBindInfo::BindType() const |
|
154 /** |
|
155 @internalComponent |
|
156 Accessor method for the binding type |
|
157 |
|
158 @return TRSBindType& the binding type requested |
|
159 */ |
|
160 { |
|
161 return iType; |
|
162 } |
|
163 |
|
164 CBindManager::TBMBindState CBindInfo::State1() const |
|
165 /** |
|
166 @internalComponent |
|
167 Accessor method for state of first submodule in the binding |
|
168 |
|
169 @return CBindManager::TBMBindState& the state requested |
|
170 */ |
|
171 { |
|
172 return iSubModule1.iState; |
|
173 } |
|
174 |
|
175 CBindManager::TBMBindState CBindInfo::State2() const |
|
176 /** |
|
177 @internalComponent |
|
178 Accessor method for state of second submodule in the binding |
|
179 |
|
180 @return CBindManager::TBMBindState& the state requested |
|
181 */ |
|
182 { |
|
183 return iSubModule2.iState; |
|
184 } |
|
185 |
|
186 void CBindInfo::SetState1(const CBindManager::TBMBindState aState) |
|
187 /** |
|
188 @internalComponent |
|
189 Set method for state of first submodule in the binding |
|
190 |
|
191 @param aState new state |
|
192 */ |
|
193 { |
|
194 iSubModule1.iState = aState; |
|
195 } |
|
196 |
|
197 void CBindInfo::SetState2(const CBindManager::TBMBindState aState) |
|
198 /** |
|
199 @internalComponent |
|
200 Set method for state of second submodule in the binding |
|
201 |
|
202 @param aState new state |
|
203 */ |
|
204 { |
|
205 iSubModule2.iState = aState; |
|
206 } |
|
207 |
|
208 TInt CBindInfo::Result1() const |
|
209 /** |
|
210 @internalComponent |
|
211 Accessor method for result code of first submodule in the binding |
|
212 |
|
213 @return TInt& the result code requested |
|
214 */ |
|
215 { |
|
216 return iSubModule1.iResult; |
|
217 } |
|
218 |
|
219 TInt CBindInfo::Result2() const |
|
220 /** |
|
221 @internalComponent |
|
222 Accessor method for result code of second submodule in the binding |
|
223 |
|
224 @return TInt& the result code requested |
|
225 */ |
|
226 { |
|
227 return iSubModule2.iResult; |
|
228 } |
|
229 |
|
230 void CBindInfo::SetResult1(const TInt aResult) |
|
231 /** |
|
232 @internalComponent |
|
233 Set method for result code of first submodule in the binding |
|
234 |
|
235 @param aResult the new result code |
|
236 */ |
|
237 { |
|
238 iSubModule1.iResult = aResult; |
|
239 } |
|
240 |
|
241 void CBindInfo::SetResult2(const TInt aResult) |
|
242 /** |
|
243 @internalComponent |
|
244 Set method for result code of second submodule in the binding |
|
245 |
|
246 @param aResult the new result code |
|
247 */ |
|
248 { |
|
249 iSubModule2.iResult = aResult; |
|
250 } |
|
251 |
|
252 void CBindInfo::TaskCompleted(const CTask &aTask, const TInt aStatus) |
|
253 /** |
|
254 @internalComponent |
|
255 Method called when a task has completed and therefore the state of the |
|
256 binding may need updating |
|
257 |
|
258 @param aTask the task that has completed |
|
259 @param aStatus the status code the task returned |
|
260 */ |
|
261 { |
|
262 switch(aTask.Message().Code()) |
|
263 { |
|
264 case TCFCommsMessage::ECodeBind: |
|
265 { |
|
266 const TCFBindMsg& bmsg = reinterpret_cast<const TCFBindMsg&>(aTask.Message()); |
|
267 if ((SubModuleAddr1() == *bmsg.SubModule1() && |
|
268 SubModuleAddr2() == *bmsg.SubModule2()) || |
|
269 (SubModuleAddr2() == *bmsg.SubModule1() && |
|
270 SubModuleAddr1() == *bmsg.SubModule2()) ) |
|
271 { |
|
272 // first module in msg is always source of msg, ie the one that's |
|
273 // indicated completion |
|
274 CBindManager::TBMBindState newState; |
|
275 if (aStatus == KErrNone) |
|
276 { |
|
277 newState = CBindManager::EBound; |
|
278 } |
|
279 else |
|
280 { |
|
281 newState = CBindManager::EBindError; |
|
282 } |
|
283 int portion; |
|
284 if (SubModuleAddr1() == *bmsg.SubModule1()) |
|
285 { |
|
286 // There is the singular case of binding to itself, in which we can only use the in progress |
|
287 // state to tell which end is responding |
|
288 if(SubModuleAddr1() != SubModuleAddr2()) |
|
289 { |
|
290 portion = 1; |
|
291 } |
|
292 else if(State1() == CBindManager::EBindInProgress) |
|
293 { |
|
294 portion = 1; |
|
295 } |
|
296 else |
|
297 { |
|
298 portion = 2; |
|
299 } |
|
300 } |
|
301 else |
|
302 { |
|
303 portion = 2; |
|
304 } |
|
305 if(portion == 1) |
|
306 { |
|
307 SetState1(newState); |
|
308 SetResult1(aStatus); |
|
309 } |
|
310 else |
|
311 { |
|
312 SetState2(newState); |
|
313 SetResult2(aStatus); |
|
314 } |
|
315 } |
|
316 } |
|
317 break; |
|
318 |
|
319 case TCFCommsMessage::ECodeUnbind: |
|
320 { |
|
321 const TCFUnbindMsg& ubmsg = reinterpret_cast<const TCFUnbindMsg&>(aTask.Message()); |
|
322 if ((SubModuleAddr1() == *ubmsg.SubModule1() && |
|
323 SubModuleAddr2() == *ubmsg.SubModule2()) || |
|
324 (SubModuleAddr2() == *ubmsg.SubModule1() && |
|
325 SubModuleAddr1() == *ubmsg.SubModule2()) ) |
|
326 { |
|
327 // first module in msg is always source of msg, ie the one that's |
|
328 // indicated completion |
|
329 CBindManager::TBMBindState newState; |
|
330 if (aStatus == KErrNone) |
|
331 { |
|
332 newState = CBindManager::EUnbound; |
|
333 } |
|
334 else |
|
335 { |
|
336 newState = CBindManager::EUnbindError; |
|
337 } |
|
338 int portion; |
|
339 if (SubModuleAddr1() == *ubmsg.SubModule1()) |
|
340 { |
|
341 // There is the singular case of unbinding from itself, in which we can only use the in progress |
|
342 // state to tell which end is responding |
|
343 if(SubModuleAddr1() != SubModuleAddr2()) |
|
344 portion = 1; |
|
345 else if(State1() == CBindManager::EUnbindInProgress) |
|
346 { |
|
347 portion = 1; |
|
348 } |
|
349 else |
|
350 { |
|
351 portion = 2; |
|
352 } |
|
353 } |
|
354 else |
|
355 { |
|
356 portion = 2; |
|
357 } |
|
358 if(portion == 1) |
|
359 { |
|
360 __ASSERT_DEBUG(CBindManager::EUnbindInProgress == State1(), |
|
361 User::Panic(KBindMgrPanic, EBadState)); |
|
362 SetState1(newState); |
|
363 SetResult1(aStatus); |
|
364 } |
|
365 else |
|
366 { |
|
367 __ASSERT_DEBUG(CBindManager::EUnbindInProgress == State2(), |
|
368 User::Panic(KBindMgrPanic, EBadState)); |
|
369 SetState2(newState); |
|
370 SetResult2(aStatus); |
|
371 } |
|
372 } |
|
373 // if everything is unbound, then clear up |
|
374 if (CBindManager::EUnbound == State1() && |
|
375 CBindManager::EUnbound == State2()) |
|
376 { |
|
377 delete this; |
|
378 } |
|
379 } |
|
380 break; |
|
381 |
|
382 default: |
|
383 break; |
|
384 } |
|
385 } |
|
386 |
|
387 |
|
388 |