|
1 // Copyright (c) 2007-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 "ssmdeferrablecommand.h" |
|
17 #include "ssmdebug.h" |
|
18 #include "ssmpanic.h" |
|
19 |
|
20 CSsmDeferrableCommand::CSsmDeferrableCommand() |
|
21 : iCompletionStatus(KSsmCommandPending), iExecutionBehaviour(ESsmFireAndForget) |
|
22 { |
|
23 } |
|
24 |
|
25 CSsmDeferrableCommand::CSsmDeferrableCommand(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour) |
|
26 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
27 : CSsmCommandBase(aSeverity, KDefaultCommandPriority), |
|
28 #else |
|
29 : CSsmCommandBase(aSeverity), |
|
30 #endif |
|
31 iCompletionStatus(KSsmCommandPending), iExecutionBehaviour(aExecutionBehaviour) |
|
32 { |
|
33 } |
|
34 |
|
35 CSsmDeferrableCommand::CSsmDeferrableCommand(TCmdErrorSeverity aSeverity) |
|
36 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
37 : CSsmCommandBase(aSeverity, KDefaultCommandPriority), |
|
38 #else |
|
39 : CSsmCommandBase(aSeverity), |
|
40 #endif |
|
41 iCompletionStatus(KSsmCommandPending), iExecutionBehaviour(ESsmFireAndForget) |
|
42 { |
|
43 } |
|
44 |
|
45 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
46 CSsmDeferrableCommand::CSsmDeferrableCommand(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, const TUint16 aPriority) |
|
47 : CSsmCommandBase(aSeverity, aPriority), iCompletionStatus(KSsmCommandPending), iExecutionBehaviour(aExecutionBehaviour) |
|
48 { |
|
49 } |
|
50 |
|
51 CSsmDeferrableCommand::CSsmDeferrableCommand(TCmdErrorSeverity aSeverity, const TUint16 aPriority) |
|
52 : CSsmCommandBase(aSeverity, aPriority), iCompletionStatus(KSsmCommandPending), iExecutionBehaviour(ESsmFireAndForget) |
|
53 { |
|
54 } |
|
55 |
|
56 #endif |
|
57 CSsmDeferrableCommand::~CSsmDeferrableCommand() |
|
58 { |
|
59 } |
|
60 |
|
61 TBool CSsmDeferrableCommand::IsDeferred() const |
|
62 { |
|
63 return iExecutionBehaviour != ESsmWaitForSignal; |
|
64 } |
|
65 |
|
66 TSsmExecutionBehaviour CSsmDeferrableCommand::ExecutionBehaviour() const |
|
67 { |
|
68 return iExecutionBehaviour; |
|
69 } |
|
70 |
|
71 TInt CSsmDeferrableCommand::CompletionStatus() const |
|
72 { |
|
73 return iCompletionStatus; |
|
74 } |
|
75 |
|
76 void CSsmDeferrableCommand::RegisterCompletionObserver(TRequestStatus& aStatus) |
|
77 { |
|
78 __ASSERT_ALWAYS(iCompletionObserver == NULL, PanicNow(KPanicDeferrableCommand, EInvalidDeferrebleCmdRegistration)); // guard against registering more than once |
|
79 aStatus = KRequestPending; |
|
80 iCompletionObserver = &aStatus; |
|
81 |
|
82 if (iCompletionStatus != KSsmCommandPending) |
|
83 { |
|
84 CompleteRequest(*iCompletionObserver, KErrNone); |
|
85 iCompletionObserver = NULL; |
|
86 } |
|
87 } |
|
88 |
|
89 void CSsmDeferrableCommand::RegisterCompletionObserverCancel() |
|
90 { |
|
91 if (iCompletionObserver) |
|
92 { |
|
93 // assume the request is still pending |
|
94 CompleteRequest(*iCompletionObserver, KErrCancel); |
|
95 iCompletionObserver = NULL; |
|
96 } |
|
97 } |
|
98 |
|
99 TBool CSsmDeferrableCommand::EvaluateCondition(MSsmConditionalCallback* aCallback, CResourceFile* aResourceFile) |
|
100 { |
|
101 TBool ret = CSsmCommandBase::EvaluateCondition(aCallback, aResourceFile); |
|
102 if (ret == EFalse) |
|
103 { |
|
104 // Need to set iCompletionStatus to KErrNone as this command will never run |
|
105 CompleteDeferredExecuteRequest(KErrNone); |
|
106 } |
|
107 return ret; |
|
108 } |
|
109 |
|
110 void CSsmDeferrableCommand::CompleteDeferredExecuteRequest(TInt aReason) |
|
111 { |
|
112 if (iCompletionObserver) |
|
113 { |
|
114 // notify observer of command completion |
|
115 CompleteRequest(*iCompletionObserver, KErrNone); // observer is expected to call CompletionCode() to get the error code |
|
116 iCompletionObserver = NULL; |
|
117 } |
|
118 |
|
119 if (Severity()==ECmdIgnoreFailure && aReason!=KErrCancel) |
|
120 { |
|
121 iCompletionStatus = KErrNone; |
|
122 } |
|
123 else |
|
124 { |
|
125 iCompletionStatus = aReason; |
|
126 } |
|
127 DEBUGVERBOSE2A("iCompletionStatus set to %d", iCompletionStatus); |
|
128 |
|
129 if (iExecutionBehaviour != ESsmDeferredWaitForSignal) |
|
130 { |
|
131 CompleteExecuteRequest(aReason); |
|
132 } |
|
133 } |
|
134 |
|
135 void CSsmDeferrableCommand::ValidateL() |
|
136 { |
|
137 if (iExecutionBehaviour != ESsmFireAndForget && |
|
138 iExecutionBehaviour != ESsmWaitForSignal && |
|
139 iExecutionBehaviour != ESsmDeferredWaitForSignal ) |
|
140 { |
|
141 User::Leave(KErrArgument); |
|
142 } |
|
143 } |