|
1 // Copyright (c) 2008-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 <e32const.h> |
|
17 |
|
18 #include "ssmdeferreddeleter.h" |
|
19 #include "ssmcommandlistimpl.h" |
|
20 #include <ssm/ssmcommand.h> |
|
21 #include "ssmdebug.h" |
|
22 #include "ssmpanic.h" |
|
23 |
|
24 #ifdef _DEBUG |
|
25 const TInt KMilliSecondsInOneSecond = 1000000; |
|
26 const TInt KMilliSecondsInFiveSeconds = 5000000; |
|
27 #endif |
|
28 |
|
29 CSsmDeferredDeleter* CSsmDeferredDeleter::NewL() |
|
30 { |
|
31 CSsmDeferredDeleter* self = new (ELeave) CSsmDeferredDeleter; |
|
32 #ifdef _DEBUG |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(self); |
|
36 #endif |
|
37 return self; |
|
38 } |
|
39 |
|
40 CSsmDeferredDeleter::~CSsmDeferredDeleter() |
|
41 { |
|
42 Cancel(); |
|
43 delete iCommandList; |
|
44 #ifdef _DEBUG |
|
45 DEBUGPRINT1A("All deferred commands completed and command list is deleted."); |
|
46 delete iTimer; |
|
47 #endif |
|
48 } |
|
49 |
|
50 void CSsmDeferredDeleter::RunL() |
|
51 { |
|
52 TInt indexOfPendingCommand = iCommandList->PendingCommandIndex(); |
|
53 if (KErrNotFound == indexOfPendingCommand) |
|
54 { |
|
55 // all commands are finished |
|
56 delete this; |
|
57 } |
|
58 else |
|
59 { |
|
60 //register for pending command |
|
61 SetActive(); |
|
62 MSsmCommand* cmd = (MSsmCommand*)((*iCommandList)[indexOfPendingCommand]); |
|
63 // if cmd is NULL then this object would register for next pending command when RunL() is called next time. |
|
64 if (cmd) |
|
65 { |
|
66 cmd->RegisterCompletionObserver(iStatus); |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 void CSsmDeferredDeleter::DoCancel() |
|
72 { |
|
73 #ifdef _DEBUG |
|
74 if (iTimer) |
|
75 { |
|
76 iTimer->Cancel(); |
|
77 } |
|
78 #endif |
|
79 } |
|
80 |
|
81 CSsmDeferredDeleter::CSsmDeferredDeleter() |
|
82 : CActive(EPriorityIdle) |
|
83 { |
|
84 } |
|
85 |
|
86 /** |
|
87 @panic ECmdNullPtr if the information used to create command is null |
|
88 */ |
|
89 void CSsmDeferredDeleter::DeferredDelete(CSsmCommandListImpl* aCommandList) |
|
90 { |
|
91 __ASSERT_DEBUG(aCommandList, PanicNow(KPanicDeferredDeleter, ECmdNullPtr)); |
|
92 iCommandList = aCommandList; |
|
93 CActiveScheduler::Add(this); |
|
94 SetActive(); |
|
95 TRequestStatus* status = &iStatus; |
|
96 User::RequestComplete(status, KErrNone); |
|
97 } |
|
98 |
|
99 #ifdef _DEBUG |
|
100 TInt CSsmDeferredDeleter::TimeoutCallback(TAny* aSelf) |
|
101 { |
|
102 if (aSelf) |
|
103 { |
|
104 static_cast<CSsmDeferredDeleter*>(aSelf)->PrintWarning(); |
|
105 } |
|
106 return KErrNone; |
|
107 } |
|
108 |
|
109 void CSsmDeferredDeleter::PrintWarning() |
|
110 { |
|
111 DEBUGPRINT1A("Warning: Deferred deleter is waiting for pending command!!!"); |
|
112 } |
|
113 |
|
114 void CSsmDeferredDeleter::ConstructL() |
|
115 { |
|
116 if (IsAdded()) |
|
117 { |
|
118 iTimer = CPeriodic::NewL(EPriorityNormal); |
|
119 iTimer->Start(KMilliSecondsInFiveSeconds, KMilliSecondsInOneSecond, TCallBack(CSsmDeferredDeleter::TimeoutCallback, this)); |
|
120 } |
|
121 } |
|
122 |
|
123 |
|
124 #endif |