|
1 // Copyright (c) 2003-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 <cflog.h> |
|
17 #include <commschan.h> |
|
18 #include <cfshared.h> |
|
19 using namespace CommsFW; |
|
20 #include "bm_defs.h" |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalComponent |
|
25 */ |
|
26 |
|
27 CTask* CTask::NewL(const TCFMessage &aMessage, const TUint aTaskId /*= 0*/) |
|
28 /** Creates new CTask object |
|
29 @param aMessage the message to be associated with the task |
|
30 @param aTaskId the tasks identifier |
|
31 @return Pointer to the new CTask object. |
|
32 @leave KErrNoMemory |
|
33 */ |
|
34 { |
|
35 CTask* pT = new(ELeave) CTask(aMessage, aTaskId); |
|
36 CleanupStack::PushL(pT); |
|
37 __CFLOG_2(KLogSubSysRS, KLogCode,_L8("CTask(%X)::NewL %d"), pT, aTaskId); |
|
38 CleanupStack::Pop(pT); |
|
39 return pT; |
|
40 } |
|
41 |
|
42 CTask::CTask(const TCFMessage &aMessage, const TUint aTaskId) : |
|
43 iTaskId(aTaskId), |
|
44 iMessage(aMessage) |
|
45 /** Constructor for CTask |
|
46 @param aMessage the message to be associated with the task |
|
47 @param aTaskId the tasks identifier |
|
48 */ |
|
49 { |
|
50 } |
|
51 |
|
52 CTask::~CTask() |
|
53 /** Destructor for CTask |
|
54 */ |
|
55 { |
|
56 __CFLOG_1(KLogSubSysRS, KLogCode,_L8("~CTask %d"), iTaskId); |
|
57 Dequeue(); |
|
58 } |
|
59 |
|
60 TUint CTask::TaskId() const |
|
61 /** Accessor method for the task id |
|
62 @return The task identifier |
|
63 */ |
|
64 { |
|
65 return iTaskId; |
|
66 } |
|
67 |
|
68 const TCFMessage& CTask::Message() const |
|
69 /** |
|
70 @internalComponent |
|
71 Accessor method for the message |
|
72 |
|
73 @return the message |
|
74 */ |
|
75 { |
|
76 return iMessage; |
|
77 } |
|
78 |
|
79 void CTask::Dequeue() |
|
80 /** Remove this from the linked list |
|
81 */ |
|
82 { |
|
83 iLink.Deque(); |
|
84 } |
|
85 |
|
86 |
|
87 TBool CTask::CheckIfSame(TCFMessage &aMessage) const |
|
88 /** Compares the message code and parameter block of the task's message with the |
|
89 message passed as a parameter and returns the result |
|
90 @param aMessage the comparator |
|
91 @return ETrue if the messages match |
|
92 */ |
|
93 { |
|
94 TBool match = ETrue; |
|
95 |
|
96 if (iMessage.Code() != aMessage.Code()) |
|
97 { |
|
98 return EFalse; |
|
99 } |
|
100 |
|
101 switch (iMessage.Code()) |
|
102 { |
|
103 case TCFCommsMessage::ECodeBind: |
|
104 { |
|
105 const TCFBindMsg& iParam = reinterpret_cast<const TCFBindMsg&>(iMessage); |
|
106 const TCFBindMsg& aParam = reinterpret_cast<const TCFBindMsg&>(aMessage); |
|
107 if (iParam.SubModule1() != aParam.SubModule1() || |
|
108 iParam.SubModule2() != aParam.SubModule2() || |
|
109 iParam.Type() != aParam.Type()) |
|
110 { |
|
111 match = EFalse; |
|
112 } |
|
113 } |
|
114 break; |
|
115 |
|
116 case TCFCommsMessage::ECodeUnbind: |
|
117 { |
|
118 const TCFUnbindMsg& iParam = reinterpret_cast<const TCFUnbindMsg&>(iMessage); |
|
119 const TCFUnbindMsg& aParam = reinterpret_cast<const TCFUnbindMsg&>(aMessage); |
|
120 if (iParam.SubModule1() != aParam.SubModule1() || |
|
121 iParam.SubModule2() != aParam.SubModule2() || |
|
122 iParam.PeerIsDead() != aParam.PeerIsDead()) |
|
123 { |
|
124 match = EFalse; |
|
125 } |
|
126 } |
|
127 break; |
|
128 |
|
129 case TCFCommsMessage::ECodeDiscover: |
|
130 case TCFCommsMessage::ECodeShutdown: |
|
131 // no params to test |
|
132 break; |
|
133 |
|
134 default: |
|
135 __ASSERT_DEBUG(EFalse, User::Panic(KBindMgrPanic, EUnsupportedCFMessage)); |
|
136 break; |
|
137 } |
|
138 |
|
139 return match; |
|
140 } |
|
141 |
|
142 |
|
143 TBool CTask::NeedReply() const |
|
144 /** Checks if the task's message should expect to receive a reply from the |
|
145 server or CPM |
|
146 @return ETrue if a reply is expected |
|
147 */ |
|
148 { |
|
149 // test message type |
|
150 TBool reply = EFalse; |
|
151 |
|
152 switch (iMessage.Code()) |
|
153 { |
|
154 case TCFCommsMessage::ECodeBind: |
|
155 case TCFCommsMessage::ECodeUnbind: |
|
156 case TCFCommsMessage::ECodeDiscover: |
|
157 reply = ETrue; |
|
158 break; |
|
159 |
|
160 case TCFCommsMessage::ECodeShutdown: |
|
161 // no reply |
|
162 break; |
|
163 |
|
164 default: |
|
165 __ASSERT_DEBUG(EFalse, User::Panic(KBindMgrPanic, EUnsupportedCFMessage)); |
|
166 break; |
|
167 } |
|
168 |
|
169 return reply; |
|
170 } |
|
171 |
|
172 TBool CTask::ReplyMatches(const TCFMessage &aMessage) const |
|
173 /** Determines if the message passed as a parameter is a reply to this task's |
|
174 message and returns the result |
|
175 @param aMessage the reply message to test |
|
176 @return ETrue if the message is the reply |
|
177 */ |
|
178 { |
|
179 // test if message is correct type and has same identifier |
|
180 TBool match = EFalse; |
|
181 |
|
182 if (NeedReply() && |
|
183 (iMessage.Code() == TCFCommsMessage::ECodeBind && aMessage.Code() == TCFCommsMessage::ECodeBindComplete) || |
|
184 (iMessage.Code() == TCFCommsMessage::ECodeUnbind && aMessage.Code() == TCFCommsMessage::ECodeUnbindComplete) || |
|
185 (iMessage.Code() == TCFCommsMessage::ECodeDiscover && aMessage.Code() == TCFCommsMessage::ECodeDiscoverResp)) |
|
186 { |
|
187 |
|
188 TId ida = *((TId*)aMessage.ParamBlock()); |
|
189 TId idi = *((TId*)iMessage.ParamBlock()); |
|
190 |
|
191 |
|
192 if (ida==idi) |
|
193 { |
|
194 match = ETrue; |
|
195 } |
|
196 } |
|
197 return match; |
|
198 } |
|
199 |
|
200 |
|
201 TBool CTask::GetMsgReturnCode(const TCFMessage &aMessage, TInt &aStatus) |
|
202 /** Extracts the result code from the message supplied and returns it in the |
|
203 status parameter |
|
204 @param aMessage the reply containing the result code |
|
205 @param aStatus the status to be filled in with the result code |
|
206 @return ETrue if the a result code was present |
|
207 */ |
|
208 { |
|
209 TBool codePresent = EFalse; |
|
210 |
|
211 if (aMessage.Code() == TCFCommsMessage::ECodeBindComplete || |
|
212 aMessage.Code() == TCFCommsMessage::ECodeUnbindComplete || |
|
213 aMessage.Code() == TCFCommsMessage::ECodeDiscoverResp) |
|
214 { |
|
215 aStatus = ((TInt*)aMessage.ParamBlock())[1]; |
|
216 codePresent = ETrue; |
|
217 } |
|
218 else |
|
219 { |
|
220 aStatus = KErrNone; |
|
221 } |
|
222 return codePresent; |
|
223 } |
|
224 |
|
225 |