|
1 /* |
|
2 * Copyright (c) 2006, 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: These classes implement dps states. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32debug.h> |
|
19 #include "dpsstate.h" |
|
20 #include "dpsstatemachine.h" |
|
21 #include "dpstransaction.h" |
|
22 #include "dpsscriptreceiver.h" |
|
23 #include <pictbridge.h> |
|
24 |
|
25 #ifdef _DEBUG |
|
26 # define IF_DEBUG(t) {RDebug::t;} |
|
27 #else |
|
28 # define IF_DEBUG(t) |
|
29 #endif |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 TDpsIdleState::TDpsIdleState(CDpsStateMachine* aStateMachine) : |
|
36 iStateMachine(aStateMachine) {} |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 void TDpsIdleState::ScriptSentNotifyL(TBool /*aReply*/) |
|
43 { |
|
44 IF_DEBUG(Print(_L("TDpsIdleState::ScriptSentNotify"))); |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 void TDpsIdleState::ScriptReceivedNotifyL(TBool aReply) |
|
52 { |
|
53 if (!aReply) |
|
54 { |
|
55 IF_DEBUG(Print(_L("TDpsIdleState::ScriptReceived request got"))); |
|
56 iStateMachine->Trader()->ParseScriptL(aReply); |
|
57 iStateMachine->SetState(iStateMachine->SendingRepState()); |
|
58 } |
|
59 else |
|
60 { |
|
61 IF_DEBUG(Print(_L( |
|
62 "TDpsIdleState::ScriptReceived should not get reply!!!"))); |
|
63 } |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 void TDpsIdleState::Error(TInt aErr) |
|
71 { |
|
72 IF_DEBUG(Print(_L("TDpsIdleState::Error %d"), aErr)); |
|
73 if ((aErr != KErrCancel) && (aErr != KErrNotReady)) |
|
74 { |
|
75 iStateMachine->Trader()->HandleHostRequestError(aErr); |
|
76 iStateMachine->SetState(iStateMachine->SendingRepState()); |
|
77 } |
|
78 |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 TDpsSendingReqState::TDpsSendingReqState(CDpsStateMachine* aStateMachine) : |
|
86 iStateMachine(aStateMachine) {} |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void TDpsSendingReqState::ScriptSentNotifyL(TBool aReply) |
|
93 { |
|
94 if (!aReply) |
|
95 { |
|
96 IF_DEBUG(Print(_L("TDpsSendingReqState::ScriptSent request"))); |
|
97 iStateMachine->SetState(iStateMachine->WaitingRepState()); |
|
98 } |
|
99 else |
|
100 { |
|
101 IF_DEBUG(Print(_L( |
|
102 "TDpsSendingReqState::ScriptSent should not get reply!!"))); |
|
103 } |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 void TDpsSendingReqState::ScriptReceivedNotifyL(TBool /*aReply*/) |
|
111 { |
|
112 IF_DEBUG(Print(_L("TDpsSendingReqState::ScriptReceived"))); |
|
113 IF_DEBUG(Print(_L("**should not reply to the request/reply from host"))); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void TDpsSendingReqState::Error(TInt aErr) |
|
121 { |
|
122 User::RequestComplete(iStateMachine->DpsEngine()->OperationRequest(), |
|
123 aErr); |
|
124 iStateMachine->Initialize(); |
|
125 return; |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 TDpsWaitingRepState::TDpsWaitingRepState(CDpsStateMachine* aStateMachine) : |
|
133 iStateMachine(aStateMachine) {} |
|
134 |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 void TDpsWaitingRepState::ScriptSentNotifyL(TBool /*aReply*/) |
|
141 { |
|
142 IF_DEBUG(Print(_L("TDpsWaitingRepState::ScriptSent"))); |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void TDpsWaitingRepState::ScriptReceivedNotifyL(TBool aReply) |
|
150 { |
|
151 if (aReply) |
|
152 { |
|
153 IF_DEBUG(Print(_L("WaitingRepState reply"))) |
|
154 |
|
155 iStateMachine->Trader()->ParseScriptL(aReply); |
|
156 User::RequestComplete( |
|
157 iStateMachine->DpsEngine()->OperationRequest(), KErrNone); |
|
158 iStateMachine->Initialize(); |
|
159 } |
|
160 else |
|
161 { |
|
162 IF_DEBUG(Print(_L("WaitingRepState should not get request"))); |
|
163 // collision happened, we do nothing because the host will |
|
164 // eventually handle this by sending the correct response. but we need |
|
165 // to subscribe for the event again. |
|
166 iStateMachine->ScriptReceiver()->WaitForReceive(); |
|
167 } |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 void TDpsWaitingRepState::Error(TInt aErr) |
|
175 { |
|
176 // this is not tested |
|
177 User::RequestComplete(iStateMachine->DpsEngine()->OperationRequest(), |
|
178 aErr); |
|
179 iStateMachine->Initialize(); |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 TDpsSendingRepState::TDpsSendingRepState(CDpsStateMachine* aStateMachine) : |
|
187 iStateMachine(aStateMachine) {} |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 void TDpsSendingRepState::ScriptSentNotifyL(TBool aReply) |
|
194 { |
|
195 if (aReply) |
|
196 { |
|
197 IF_DEBUG(Print(_L("TDpsSendingRepState::ScriptSent reply"))); |
|
198 if (KErrNone == iStateMachine->CurError()) |
|
199 { |
|
200 // this is the normal situation, inform the client |
|
201 User::RequestComplete(iStateMachine->DpsEngine()->EventRequest(), |
|
202 KErrNone); |
|
203 } |
|
204 else |
|
205 { |
|
206 // this is the error situation, do not inform the client. and |
|
207 // we need to subscribe for the new event. |
|
208 iStateMachine->ScriptReceiver()->WaitForReceive(); |
|
209 } |
|
210 iStateMachine->Initialize(); |
|
211 } |
|
212 else |
|
213 { |
|
214 IF_DEBUG(Print(_L( |
|
215 "TDpsSendingRepState::ScriptSent shoul not get request!!!"))); |
|
216 } |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 void TDpsSendingRepState::ScriptReceivedNotifyL(TBool /*aReply*/) |
|
224 { |
|
225 IF_DEBUG(Print(_L("TDpsSendingRepState::ScriptReceived"))); |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 void TDpsSendingRepState::Error(TInt /*aErr*/) |
|
233 { |
|
234 return; |
|
235 } |