|
1 // Copyright (c) 2005-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 |
|
17 #include <obex.h> |
|
18 #include <obex/internal/obexinternalheader.h> |
|
19 #include "obexserverstatemachine.h" |
|
20 |
|
21 /** |
|
22 @file |
|
23 @internalComponent |
|
24 */ |
|
25 |
|
26 /** |
|
27 Called by the state machine when it has moved into the state |
|
28 Default action - do nothing and return no error |
|
29 @param aContext Reference to state machine object |
|
30 */ |
|
31 void TObexServerOperationState::Entry(CObexServerStateMachine& /*aContext*/) |
|
32 { |
|
33 } |
|
34 |
|
35 /** |
|
36 Connection packet to be processed |
|
37 Default action - fault (event should not happen for this state) |
|
38 @param aContext Reference to state machine object |
|
39 @param aPacket Connect packet |
|
40 */ |
|
41 void TObexServerOperationState::Connect(CObexServerStateMachine& /*aContext*/, CObexPacket& /*aPacket*/) |
|
42 { |
|
43 IrOBEXUtil::Fault(EConnectInBadState); |
|
44 } |
|
45 |
|
46 /** |
|
47 Disconnect packet to be processed |
|
48 Default action - fault (event should not happen for this state) |
|
49 @param aContext Reference to state machine object |
|
50 @param aPacket Disconnect packet |
|
51 */ |
|
52 void TObexServerOperationState::Disconnect(CObexServerStateMachine& /*aContext*/, CObexPacket& /*aPacket*/) |
|
53 { |
|
54 IrOBEXUtil::Fault(EDisconnectInBadState); |
|
55 } |
|
56 |
|
57 /** |
|
58 Put packet to be processed |
|
59 Default action - fault (event should not happen for this state) |
|
60 @param aContext Reference to state machine object |
|
61 @param aPacket Put packet |
|
62 */ |
|
63 void TObexServerOperationState::Put(CObexServerStateMachine& /*aContext*/, CObexPacket& /*aPacket*/) |
|
64 { |
|
65 IrOBEXUtil::Fault(EPutInBadState); |
|
66 } |
|
67 |
|
68 /** |
|
69 Get packet to be processed |
|
70 Default action - fault (event should not happen for this state) |
|
71 @param aContext Reference to state machine object |
|
72 @param aPacket Get packet |
|
73 */ |
|
74 void TObexServerOperationState::Get(CObexServerStateMachine& /*aContext*/, CObexPacket& /*aPacket*/) |
|
75 { |
|
76 IrOBEXUtil::Fault(EGetInBadState); |
|
77 } |
|
78 |
|
79 /** |
|
80 SetPath packet to be processed |
|
81 Default action - fault (event should not happen for this state) |
|
82 @param aContext Reference to state machine object |
|
83 @param aPacket SetPath packet |
|
84 */ |
|
85 void TObexServerOperationState::SetPath(CObexServerStateMachine& /*aContext*/, CObexPacket& /*aPacket*/) |
|
86 { |
|
87 IrOBEXUtil::Fault(ESetPathInBadState); |
|
88 } |
|
89 |
|
90 /** |
|
91 Abort request to be processed |
|
92 Default action - fault (event should not happen for this state) |
|
93 @param aContext Reference to state machine object |
|
94 */ |
|
95 void TObexServerOperationState::Abort(CObexServerStateMachine& /*aContext*/) |
|
96 { |
|
97 IrOBEXUtil::Fault(EAbortInBadState); |
|
98 } |
|
99 |
|
100 /** |
|
101 Transport up notification |
|
102 Default action - do nothing or fault (event should not happen for this state) |
|
103 @param aContext Reference to state machine object |
|
104 */ |
|
105 void TObexServerOperationState::TransportUp(CObexServerStateMachine& /*aContext*/) |
|
106 { |
|
107 __ASSERT_DEBUG(EFalse, IrOBEXUtil::Fault(ETransportUpInBadState)); |
|
108 } |
|
109 |
|
110 /** |
|
111 Server Start notification |
|
112 Default action - do nothing and return no error |
|
113 @param aContext Reference to state machine object |
|
114 */ |
|
115 void TObexServerOperationState::Start(CObexServerStateMachine& /*aContext*/) |
|
116 { |
|
117 } |
|
118 |
|
119 /** |
|
120 Reset notification - state machine should go back to the initial (disconnected) state |
|
121 Default action - change to Disconnected state |
|
122 @param aContext Reference to state machine object |
|
123 */ |
|
124 void TObexServerOperationState::Reset(CObexServerStateMachine& aContext) |
|
125 { |
|
126 aContext.ChangeState(CObexServerStateMachine::EDisconnected); |
|
127 } |
|
128 |
|
129 /** |
|
130 Asynchronous notification complete - the Application has return an object for the current operation |
|
131 Default action - panic as there is no operation waiting for a notification |
|
132 @param aContext Reference to state machine object |
|
133 @param aObject Pointer to object returned from the Application |
|
134 @panic ENoNotificationToComplete |
|
135 */ |
|
136 void TObexServerOperationState::RequestNotificationCompleted(CObexServerStateMachine& /*aContext*/, CObexBaseObject* /*aObject*/) |
|
137 { |
|
138 IrOBEXUtil::Panic(ENoNotificationToComplete); |
|
139 } |
|
140 |
|
141 /** |
|
142 Asynchronous notification complete - the Application has return an object for the current operation |
|
143 Default action - panic as there is no operation waiting for a notification |
|
144 @param aContext Reference to state machine object |
|
145 @param aObject Pointer to object returned from the Application |
|
146 @panic ENoNotificationToComplete |
|
147 */ |
|
148 void TObexServerOperationState::RequestNotificationCompleted(CObexServerStateMachine& /*aContext*/, TObexResponse /*aAppResponse*/) |
|
149 { |
|
150 IrOBEXUtil::Panic(ENoNotificationToComplete); |
|
151 } |
|
152 |
|
153 /** |
|
154 Asynchronous notification complete - the Application has return an object for the current operation |
|
155 Default action - panic as there is no operation waiting for a notification |
|
156 @param aContext Reference to state machine object |
|
157 @param aObject Pointer to object returned from the Application |
|
158 @panic ENoNotificationToComplete |
|
159 */ |
|
160 void TObexServerOperationState::RequestCompleteNotificationCompleted(CObexServerStateMachine& /*aContext*/, TObexResponse /*aAppResponse*/) |
|
161 { |
|
162 IrOBEXUtil::Panic(ENoNotificationToComplete); |
|
163 } |
|
164 |
|
165 |
|
166 /** |
|
167 Connection notification - an OBEX connection has been made |
|
168 Default action - panic. This should not be passed to the state machine in this state. |
|
169 @param aContext Reference to state machine object |
|
170 */ |
|
171 void TObexServerOperationState::ConnectionComplete(CObexServerStateMachine& /*aContext*/) |
|
172 { |
|
173 IrOBEXUtil::Fault(EConnectionCompleteInBadState); |
|
174 } |
|
175 |
|
176 /** |
|
177 A user has requested to override the handling of a request packet. |
|
178 @param aContext Reference to state machine object |
|
179 @param aResponse Response code to send to Obex Client (this must not be a success code) |
|
180 */ |
|
181 void TObexServerOperationState::OverrideRequestHandling(CObexServerStateMachine& /*aContext*/, TObexResponse /*aResponse*/) |
|
182 { |
|
183 IrOBEXUtil::Panic(EOverrideRequestHandlingInBadState); |
|
184 } |
|
185 |
|
186 // Utility functions - common operations performed by states |
|
187 |
|
188 /** |
|
189 Check disconnect packet for the correct connection ID (if required) and disconnect the Client |
|
190 If the check is not sucessful, return to the Idle state if there is an OBEX connection |
|
191 or the TransportConnected state otherwise |
|
192 @param aContext Reference to state machine object |
|
193 @param aPacket Disconnect packet |
|
194 */ |
|
195 /*static*/ void TObexServerOperationState::PerformDisconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket) |
|
196 { |
|
197 FLOG(_L("OnPacketReceive DisConnect OP code\r\n")); |
|
198 aContext.Owner().SetCurrentOperation(CObex::EOpDisconnect); |
|
199 |
|
200 // Check for connection ID before performing disconnect |
|
201 if (aContext.Owner().CheckPacketForConnectionId(aPacket)) |
|
202 { |
|
203 aContext.Transport().Send(ERespSuccess); |
|
204 aContext.ChangeState(CObexServerStateMachine::EDisconnecting); |
|
205 } |
|
206 else |
|
207 { |
|
208 // Incorrect connection ID - abandon current operation |
|
209 aContext.Transport().Send(ERespServiceUnavailable); |
|
210 // Target states depends on whether there is a current OBEX connection |
|
211 if (aContext.Owner().GetConnectState() == CObex::EConnObex) |
|
212 { |
|
213 aContext.ChangeState(CObexServerStateMachine::EReady); |
|
214 } |
|
215 else |
|
216 { |
|
217 aContext.ChangeState(CObexServerStateMachine::ETransportConnected); |
|
218 } |
|
219 } |
|
220 } |
|
221 |
|
222 /** |
|
223 End the current operation, sending the given response code to the Client and moving to the Idle state |
|
224 @panic ObexFault ERespondAndEndOpWithoutObexConnection if there is no OBEX connection |
|
225 @param aContext Reference to state machine object |
|
226 @param aResponseCode Response code to send to the Client |
|
227 */ |
|
228 /*static*/ void TObexServerOperationState::RespondAndEndOperation(CObexServerStateMachine& aContext, TObexResponse aResponseCode) |
|
229 { |
|
230 // This function assumes that there is an OBEX connection, so it goes back to EReady - the assert checks this |
|
231 __ASSERT_DEBUG((aContext.Owner().GetConnectState() == CObex::EConnObex),IrOBEXUtil::Fault(ERespondAndEndOpWithoutObexConnection)); |
|
232 |
|
233 aContext.Transport().Send(aResponseCode); |
|
234 aContext.ChangeState(CObexServerStateMachine::EReady); |
|
235 } |
|
236 |
|
237 TBool TObexServerOperationState::ValidResponse(TObexResponse /*aResponseCode*/) |
|
238 { |
|
239 return EFalse; |
|
240 } |
|
241 |
|
242 void TObexServerOperationState::WriteComplete(CObexServerStateMachine& /*aContext*/) |
|
243 { |
|
244 } |
|
245 |
|
246 /** |
|
247 Indicates that a new obex packet is being read. Do nothing in default state. |
|
248 */ |
|
249 void TObexServerOperationState::ReadActivityDetected(CObexServerStateMachine& /*aContext*/) |
|
250 { |
|
251 } |
|
252 |
|
253 |