|
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 "ssmcommandbase.h" |
|
17 #include "ssmpanic.h" |
|
18 #include "ssmdebug.h" |
|
19 |
|
20 #include <ssm/ssmconditionalcallback.h> |
|
21 |
|
22 CSsmCommandBase::CSsmCommandBase() |
|
23 :CActive(EPriorityStandard), iSeverity(ECmdIgnoreFailure) |
|
24 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
25 , iPriority(KDefaultCommandPriority) |
|
26 #endif |
|
27 { |
|
28 CActiveScheduler::Add(this); |
|
29 } |
|
30 |
|
31 CSsmCommandBase::CSsmCommandBase(TCmdErrorSeverity aSeverity) |
|
32 : CActive(EPriorityStandard), iSeverity(aSeverity) |
|
33 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
34 , iPriority (KDefaultCommandPriority) |
|
35 #endif |
|
36 { |
|
37 CActiveScheduler::Add(this); |
|
38 } |
|
39 |
|
40 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
41 CSsmCommandBase::CSsmCommandBase(TCmdErrorSeverity aSeverity, const TUint16 aPriority) |
|
42 : CActive(EPriorityStandard), iSeverity(aSeverity), iPriority(aPriority) |
|
43 { |
|
44 CActiveScheduler::Add(this); |
|
45 } |
|
46 #endif |
|
47 |
|
48 /** |
|
49 */ |
|
50 CSsmCommandBase::~CSsmCommandBase() |
|
51 { |
|
52 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
53 iCmdResourceFileName.Close(); |
|
54 #endif |
|
55 } |
|
56 |
|
57 void CSsmCommandBase::SetUtilProvider(CSsmCommandUtilProvider& aUtilProvider) |
|
58 { |
|
59 iUtilProvider = &aUtilProvider; |
|
60 } |
|
61 |
|
62 TBool CSsmCommandBase::IsDeferred() const |
|
63 { |
|
64 return EFalse; |
|
65 } |
|
66 |
|
67 TSsmExecutionBehaviour CSsmCommandBase::ExecutionBehaviour() const |
|
68 { |
|
69 return ESsmWaitForSignal; |
|
70 } |
|
71 |
|
72 TCmdErrorSeverity CSsmCommandBase::Severity() const |
|
73 { |
|
74 return iSeverity; |
|
75 } |
|
76 |
|
77 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE |
|
78 TUint16 CSsmCommandBase::Priority() const |
|
79 { |
|
80 return iPriority; |
|
81 } |
|
82 |
|
83 void CSsmCommandBase::SetCommandResourceFileNameL(const TDesC& aFileName) |
|
84 { |
|
85 if (iCmdResourceFileName.MaxLength() < aFileName.Length()) |
|
86 { |
|
87 iCmdResourceFileName.ReAllocL(aFileName.Length()); |
|
88 } |
|
89 iCmdResourceFileName.Copy(aFileName); |
|
90 } |
|
91 |
|
92 const TDesC& CSsmCommandBase::GetCommandResourceFileName() const |
|
93 { |
|
94 return iCmdResourceFileName; |
|
95 } |
|
96 |
|
97 TInt CSsmCommandBase::GetCommandResourceFileNameLength() const |
|
98 { |
|
99 return iCmdResourceFileName.Length(); |
|
100 } |
|
101 #endif |
|
102 |
|
103 TInt CSsmCommandBase::CompletionStatus() const |
|
104 { |
|
105 __ASSERT_ALWAYS(0, PanicNow(KPanicSsmCommand, EIllegalMethodCallInClass)); |
|
106 return KErrNotSupported; |
|
107 } |
|
108 |
|
109 void CSsmCommandBase::RegisterCompletionObserver(TRequestStatus& /*aStatus*/) |
|
110 { |
|
111 __ASSERT_ALWAYS(0, PanicNow(KPanicSsmCommand, EIllegalMethodCallInClass)); |
|
112 } |
|
113 |
|
114 void CSsmCommandBase::RegisterCompletionObserverCancel() |
|
115 { |
|
116 __ASSERT_ALWAYS(0, PanicNow(KPanicSsmCommand, EIllegalMethodCallInClass)); |
|
117 } |
|
118 |
|
119 void CSsmCommandBase::CompleteExecuteRequest(TInt aReason) |
|
120 { |
|
121 if (iExecuteRequest && (iExecuteRequest->Int() == KRequestPending)) |
|
122 { |
|
123 DEBUGVERBOSE3A("Severity %d Errorcode %d", Severity(), aReason); |
|
124 if (Severity()==ECmdIgnoreFailure && aReason!=KErrCancel) |
|
125 { |
|
126 aReason = KErrNone; |
|
127 } |
|
128 CompleteRequest(*iExecuteRequest, aReason); |
|
129 } |
|
130 iExecuteRequest = NULL; |
|
131 } |
|
132 |
|
133 void CSsmCommandBase::CompleteRequest(TRequestStatus& aStatus, TInt aReason) |
|
134 { |
|
135 DEBUGPRINT2A("Completing command with errorcode %d", aReason); |
|
136 TRequestStatus* status = &aStatus; |
|
137 User::RequestComplete(status, aReason); |
|
138 } |
|
139 |
|
140 TBool CSsmCommandBase::EvaluateCondition(MSsmConditionalCallback* aCallback, CResourceFile* aResourceFile) |
|
141 { |
|
142 if(aCallback && aResourceFile && iConditionalResourceId) |
|
143 { |
|
144 // All the information is available to perform a condition evaluation |
|
145 TBool response = ETrue; |
|
146 TRAPD(err, response = aCallback->ConditionalCommandAllowedL(*aResourceFile, iConditionalResourceId)); |
|
147 if(err != KErrNone) |
|
148 { |
|
149 // Failed to get any response information, so don't execute this command |
|
150 response = EFalse; |
|
151 } |
|
152 return response; |
|
153 } |
|
154 // Otherwise return true as conditional information has not been specified |
|
155 // If the conditional information isn't set then a command defaults to being |
|
156 // unconditional so therefore should always return ETrue in that situation. |
|
157 // |
|
158 // If no callback is provided or if no resource file is specified then |
|
159 // this command has not been created from a resource file so therefore |
|
160 // all commands are treated as unconditional, so again ETrue is returned. |
|
161 return ETrue; |
|
162 } |
|
163 |
|
164 void CSsmCommandBase::SetConditionalInformation(TInt aConditionalInformation) |
|
165 { |
|
166 iConditionalResourceId = aConditionalInformation; |
|
167 } |
|
168 |
|
169 TInt CSsmCommandBase::ConditionalInformation() const |
|
170 { |
|
171 return iConditionalResourceId; |
|
172 } |