|
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 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <commschan.h> |
|
22 #include <cfshared.h> |
|
23 using namespace CommsFW; |
|
24 #include "bm_defs.h" |
|
25 |
|
26 |
|
27 CJobTimeout* CJobTimeout::NewL(MBMNotifyTimerShot* aNotifier) |
|
28 /** Creates new CJobTimeout object |
|
29 @param aNotifier the object to notify of timeout |
|
30 @return Pointer to the new CJobTimeout object. |
|
31 @leave KErrNoMemory |
|
32 */ |
|
33 { |
|
34 CJobTimeout* pTimeout = new (ELeave) CJobTimeout(aNotifier); |
|
35 CleanupStack::PushL(pTimeout); |
|
36 pTimeout->ConstructL(); // base method - add this to scheduler |
|
37 RS_DETLOG((KLogSubSysRS, KLogCode, |
|
38 _L8("CJobTimeout::NewL &iStatus %08X"), &(pTimeout->iStatus))); |
|
39 CleanupStack::Pop(pTimeout); |
|
40 return pTimeout; |
|
41 } |
|
42 |
|
43 void CJobTimeout::RunL() |
|
44 /** Active Object virutal RunL method called when the timer expires |
|
45 @leave |
|
46 */ |
|
47 { |
|
48 RS_DETLOG((KLogSubSysRS, KLogEvent, |
|
49 _L8("CJobTimeout::RunL &iStatus %08X, status %d"), &iStatus, iStatus.Int())); |
|
50 if((iStatus == KErrNone) && (iNotifier != NULL)) |
|
51 { |
|
52 iNotifier->ModuleTimerShot(); |
|
53 } |
|
54 } |
|
55 |
|
56 |
|
57 CJobTimeout::CJobTimeout(MBMNotifyTimerShot* aNotifier) : |
|
58 CTimer(EPriorityStandard) |
|
59 /** Constrcutor for CJobTimeout |
|
60 @param aNotifier the object to notify of timeout |
|
61 */ |
|
62 { |
|
63 iNotifier = aNotifier; |
|
64 __CFLOG_1(KLogSubSysRS, KLogEvent, |
|
65 _L8("CJobTimeout &iStatus %08X"), &iStatus); |
|
66 } |
|
67 |
|
68 |
|
69 CJob* CJob::NewL(TRequestStatus& aRsStatus, MBindManagerNotify *aBindManager) |
|
70 /** Creates new CJob object |
|
71 @param aRsStatus the TRequestStatus to complete when the job is finished |
|
72 @param aBindManager the object to notify of timeout |
|
73 @return Pointer to the new CJob object. |
|
74 @leave KErrNoMemory |
|
75 */ |
|
76 { |
|
77 CJob* pJob = new (ELeave) CJob(aRsStatus, aBindManager); |
|
78 CleanupStack::PushL(pJob); |
|
79 pJob->ConstructL(); |
|
80 CleanupStack::Pop(pJob); |
|
81 __CFLOG_2(KLogSubSysRS, KLogCode, |
|
82 _L8("CJob::NewL(%08X) &iRsStatus %08X"), pJob, &aRsStatus); |
|
83 return pJob; |
|
84 } |
|
85 |
|
86 CJob::CJob(TRequestStatus& aRsStatus, MBindManagerNotify *aBindManager) : |
|
87 iRsStatus(aRsStatus), |
|
88 iBindManager(aBindManager) |
|
89 // Surplus initialisers left as documentation of deliberate intent |
|
90 // iCompletionCode(KErrNone) |
|
91 // iCancelled(EFalse) |
|
92 // iTimeout(NULL) |
|
93 /** Constructor for CJob |
|
94 @param aRsStatus the TRequestStatus to complete when the job is finished |
|
95 @param aBindManager the object to notify of timeout |
|
96 */ |
|
97 { |
|
98 iRsStatus = KRequestPending; |
|
99 } |
|
100 |
|
101 CJob::~CJob() |
|
102 /** Destructor for CJob |
|
103 */ |
|
104 { |
|
105 __CFLOG_1(KLogSubSysRS, KLogCode, _L8("CJob::~CJob(%08X)"), this); |
|
106 Dequeue(); |
|
107 delete iTimeout; |
|
108 iTaskDataList.Close(); |
|
109 } |
|
110 |
|
111 void CJob::ConstructL() |
|
112 /** Second phase constructor for CJob |
|
113 */ |
|
114 { |
|
115 iTimeout = CJobTimeout::NewL(this); |
|
116 CActiveScheduler::Add(iTimeout); |
|
117 } |
|
118 |
|
119 void CJob::ModuleTimerShot() |
|
120 /** Virtual method called by timeout member |
|
121 */ |
|
122 { |
|
123 RS_DETLOG((KLogSubSysRS, KLogCode, |
|
124 _L8("CJob(%08X)::ModuleTimeShot - informing bindmanager"), this)); |
|
125 iCompletionCode = KErrRSRequestTimedOut; |
|
126 |
|
127 // now tell bindmanager about each task that must be considered to have failed |
|
128 TInt i; |
|
129 for (i=0; i<iTaskDataList.Count(); i++) |
|
130 { |
|
131 iBindManager->JobTimedOut(iTaskDataList[i].iModule, |
|
132 iTaskDataList[i].iTaskId); |
|
133 } |
|
134 } |
|
135 |
|
136 void CJob::Dequeue() |
|
137 /** Remove this from the linked list |
|
138 */ |
|
139 { |
|
140 iLink.Deque(); |
|
141 } |
|
142 |
|
143 void CJob::AddTaskL(TUint aTaskId, const TCFModuleNameF &aModule) |
|
144 /** Add a task to this job |
|
145 @param aTaskId the task identifier to add |
|
146 @param aModule the name of the module which owns the task |
|
147 @leave KErrNoMemory |
|
148 */ |
|
149 { |
|
150 TTaskData newTask(aTaskId, aModule); |
|
151 User::LeaveIfError(iTaskDataList.Append(newTask)); |
|
152 RS_DETLOG((KLogSubSysRS, KLogCode, _L8("CJob(%08x)::AddTaskL(%d, %S, ptr=%X)"), this, aTaskId, &aModule, aModule.Ptr())); |
|
153 } |
|
154 |
|
155 void CJob::StartTimeout(TUint aMicroseconds) |
|
156 /** Start the timeout for this job |
|
157 @param aMicroseconds the length of the timeout |
|
158 */ |
|
159 { |
|
160 iTimeout->After(aMicroseconds); |
|
161 } |
|
162 |
|
163 void CJob::TaskCompleted(const TCFModuleNameF& aModuleName, |
|
164 const TUint aTaskId, |
|
165 const TInt aStatus) |
|
166 /** Method called by bindmanager when a task is completed. If all of the tasks on |
|
167 a job complete then the client's request will be completed and the job |
|
168 deleted |
|
169 @param aModuleName the name of the module that owns the completed task |
|
170 @param aTaskId the identifier of the completed task |
|
171 @param aStatus the completion code for the task |
|
172 */ |
|
173 { |
|
174 // compare with all tasks |
|
175 RS_DETLOG((KLogSubSysRS, KLogCode, _L8("CJob(%08x)::TaskCompleted - checking for (%S, %d)"), this, &aModuleName, aTaskId)); |
|
176 TInt i; |
|
177 for (i=0; i<iTaskDataList.Count(); i++) |
|
178 { |
|
179 if (iTaskDataList[i].iTaskId == aTaskId && |
|
180 iTaskDataList[i].iModule == aModuleName) |
|
181 { |
|
182 __CFLOG_2(KLogSubSysRS, KLogCode, |
|
183 _L8("CJob::TaskCompleted - removing task entry %S:%d"), |
|
184 &aModuleName, aTaskId); |
|
185 RS_DETLOG((KLogSubSysRS, KLogCode, _L8("--- matched at %d"), i)); |
|
186 iTaskDataList.Remove(i); |
|
187 |
|
188 // record any error status if one has't already been noted |
|
189 if (KErrNone == iCompletionCode) |
|
190 { |
|
191 iCompletionCode = aStatus; |
|
192 } |
|
193 break; |
|
194 } |
|
195 } |
|
196 if (0 == iTaskDataList.Count()) |
|
197 { |
|
198 __CFLOG_1(KLogSubSysRS, KLogCode, |
|
199 _L8("CJob::TaskCompleted - completing request %08X"), &iRsStatus); |
|
200 iTimeout->Cancel(); |
|
201 if (!iCancelled) |
|
202 { |
|
203 TRequestStatus *status = &iRsStatus; |
|
204 User::RequestComplete(status, iCompletionCode); |
|
205 } |
|
206 delete this; |
|
207 } |
|
208 } |
|
209 |
|
210 void CJob::Cancel() |
|
211 /** Cancels the job |
|
212 */ |
|
213 { |
|
214 TRequestStatus *status = &iRsStatus; |
|
215 iRsStatus = KErrCancel; |
|
216 User::RequestComplete(status, KErrCancel); |
|
217 iCancelled = ETrue; |
|
218 } |
|
219 |
|
220 TBool CJob::HasStatus(const TRequestStatus& aRsStatus) const |
|
221 /** Indicates whether this job will complete the supplied status request when the |
|
222 job completes |
|
223 @param aRsStatus the comparator |
|
224 @return true if the status match |
|
225 */ |
|
226 { |
|
227 return (&aRsStatus == &iRsStatus); |
|
228 } |
|
229 |
|
230 |