|
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 "adaptationbase.h" |
|
17 #include "clayerpanic.h" |
|
18 |
|
19 #include "ssmdebug.h" |
|
20 #include "startupadaptationadapter.h" |
|
21 |
|
22 /** |
|
23 * Frees any resources allocated to this class |
|
24 * |
|
25 * @internalComponent |
|
26 */ |
|
27 CAdaptationBase::~CAdaptationBase() |
|
28 { |
|
29 |
|
30 } |
|
31 |
|
32 /** |
|
33 * Constructor for CAdaptationBase |
|
34 * |
|
35 * Does not take ownership of the CStartupAdaptationAdapter passed in |
|
36 * |
|
37 * @internalComponent |
|
38 */ |
|
39 CAdaptationBase::CAdaptationBase(CStartupAdaptationAdapter* aAdapter) |
|
40 : iAdapter(aAdapter), |
|
41 iRequestStatus(NULL), |
|
42 iDispatched(EFalse), |
|
43 iCommandId(static_cast<StartupAdaptation::TCommand>(0)) |
|
44 { |
|
45 |
|
46 |
|
47 } |
|
48 |
|
49 |
|
50 /** |
|
51 * Sets the dispatch status of this adaptation. |
|
52 * |
|
53 * An adaptation is dispatched if it has had a command issued to |
|
54 * the startup adaptation but is waiting for a response. |
|
55 * |
|
56 * @internalComponent |
|
57 */ |
|
58 void CAdaptationBase::SetDispatched(TBool aDispatched) |
|
59 { |
|
60 iDispatched = aDispatched; |
|
61 } |
|
62 |
|
63 /** |
|
64 * Returns the dispatch status of this adaptation. |
|
65 * |
|
66 * An adaptation is dispatched if it has had a command issued to |
|
67 * the startup adaptation but is waiting for a response. |
|
68 * |
|
69 * @internalComponent |
|
70 */ |
|
71 TBool CAdaptationBase::Dispatched() |
|
72 { |
|
73 return iDispatched; |
|
74 } |
|
75 |
|
76 /** |
|
77 * Sets the command ID for the next command that this adaptation wishes to issue. |
|
78 * |
|
79 * @internalComponent |
|
80 */ |
|
81 void CAdaptationBase::SetCommandId(StartupAdaptation::TCommand aCommandId) |
|
82 { |
|
83 iCommandId = aCommandId; |
|
84 } |
|
85 |
|
86 |
|
87 /** |
|
88 * Returns the command ID for the next command that this adaptation wishes to issue. |
|
89 * |
|
90 * @internalComponent |
|
91 */ |
|
92 StartupAdaptation::TCommand CAdaptationBase::CommandId() |
|
93 { |
|
94 return iCommandId; |
|
95 } |
|
96 |
|
97 /** |
|
98 * Returns true if this adaptation is busy. |
|
99 * |
|
100 * An adaptation is busy if it has a command request queued or |
|
101 * has dispatched a command request but is waiting for the reply. |
|
102 * |
|
103 * @internalComponent |
|
104 */ |
|
105 TBool CAdaptationBase::Busy() |
|
106 { |
|
107 return iRequestStatus != NULL; |
|
108 } |
|
109 |
|
110 /** |
|
111 * Sets the request status for this adaptation object to the |
|
112 * supplied parameter |
|
113 * |
|
114 * @internalComponent |
|
115 */ |
|
116 void CAdaptationBase::SetRequestStatus(TRequestStatus* aStatus) |
|
117 { |
|
118 __ASSERT_DEBUG(iRequestStatus == NULL, CLAYER_PANIC(EClayerOutstandingRequest)); |
|
119 iRequestStatus = aStatus; |
|
120 } |
|
121 |
|
122 /** |
|
123 * Completes the outstanding request for this adaptation with the given value |
|
124 * and sets this adaptation to not be busy and not dispatched. |
|
125 * |
|
126 * @internalComponent |
|
127 */ |
|
128 void CAdaptationBase::CompleteRequestStatus(TInt aValue) |
|
129 { |
|
130 __ASSERT_DEBUG(iRequestStatus != NULL, CLAYER_PANIC(ECLayerCompletingNull)); |
|
131 if(iRequestStatus != NULL) |
|
132 { |
|
133 User::RequestComplete(iRequestStatus, aValue); |
|
134 iRequestStatus = NULL; |
|
135 iDispatched = EFalse; |
|
136 } |
|
137 } |
|
138 |
|
139 /** |
|
140 * Cancels any outstanding request and completes the status with KErrCancel |
|
141 * |
|
142 * @internalComponent |
|
143 */ |
|
144 void CAdaptationBase::CancelRequest() |
|
145 { |
|
146 if(Busy()) |
|
147 { |
|
148 if (Dispatched()) |
|
149 { |
|
150 // Cancel and remove dispatched |
|
151 TRAPD(err, iAdapter->CancelDispatchedL(this)); |
|
152 if(err != KErrNone) |
|
153 { |
|
154 DEBUGPRINT2A("SAA - failed to cancel dispatch with error: %d", err); |
|
155 // return immediately and don't attempt to complete it, it should be completed later |
|
156 return; |
|
157 } |
|
158 } |
|
159 else |
|
160 { |
|
161 // Remove from queue |
|
162 iAdapter->RemoveFromDispatchQueue(this); |
|
163 } |
|
164 CompleteRequestStatus(KErrCancel); |
|
165 } |
|
166 // Nothing to do if not busy |
|
167 } |