obex/obexprotocol/obex/inc/obexserveroperationstates.h
changeset 54 4dc88a4ac6f4
parent 52 866b4af7ffbe
child 57 f6055a57ae18
equal deleted inserted replaced
52:866b4af7ffbe 54:4dc88a4ac6f4
     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 #ifndef OBEX_SERVER_OPERATION_STATES_H
       
    17 #define OBEX_SERVER_OPERATION_STATES_H
       
    18 
       
    19 /**
       
    20 @file
       
    21 @internalComponent
       
    22 
       
    23 Defines base state class and derived state classes for each operation
       
    24 */
       
    25 
       
    26 #include <obextypes.h>
       
    27 #include "logger.h"
       
    28 
       
    29 static const TInt KMaxStatenameLength = 32;
       
    30 
       
    31 /**
       
    32 Defines the state class interface and default operations for events
       
    33 Also provides utility functions for common actions
       
    34 @see CObexServerStateMachine
       
    35 */
       
    36 NONSHARABLE_CLASS(TObexServerOperationState)
       
    37 	{
       
    38 public:
       
    39 	// Default implementation of events
       
    40 	virtual void Entry(CObexServerStateMachine& aContext);
       
    41 	
       
    42 	virtual void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
    43 	
       
    44 	virtual void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
    45 	
       
    46 	virtual void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
    47 	
       
    48 	virtual void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
    49 	
       
    50 	virtual void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
    51 	
       
    52 	virtual void Abort(CObexServerStateMachine& aContext);
       
    53 	
       
    54 	virtual void TransportUp(CObexServerStateMachine& aContext);
       
    55 	
       
    56 	virtual void Start(CObexServerStateMachine& aContext);
       
    57 	
       
    58 	virtual void Reset(CObexServerStateMachine& aContext);
       
    59 	
       
    60 	virtual void RequestNotificationCompleted(CObexServerStateMachine& aContext, CObexBaseObject* aObject);
       
    61 
       
    62 	virtual void RequestNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse);
       
    63 
       
    64 	virtual void RequestCompleteNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse);
       
    65 	
       
    66 	virtual void ConnectionComplete(CObexServerStateMachine& aContext);
       
    67 	
       
    68 	virtual void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
    69 
       
    70 	virtual TBool ValidResponse(TObexResponse aResponseCode);
       
    71 
       
    72 	virtual void WriteComplete(CObexServerStateMachine& aContext);
       
    73 	
       
    74 	virtual void ReadActivityDetected(CObexServerStateMachine& aContext);
       
    75 
       
    76 
       
    77 protected:
       
    78 	// Utility functions
       
    79 	static void PerformDisconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
    80 	static void RespondAndEndOperation(CObexServerStateMachine& aContext, TObexResponse aResponseCode);
       
    81 
       
    82 #ifdef __FLOG_ACTIVE
       
    83 public:
       
    84 	TBuf8<KMaxStatenameLength> iName;
       
    85 #endif
       
    86 	};
       
    87 
       
    88 
       
    89 // State class definitions - defines methods for all the non-default events
       
    90 // default events are provided by TObexServerOperationState
       
    91 
       
    92 /**
       
    93 Initial unconnected state
       
    94 @see TObexServerOperationState
       
    95 @see CObexServerStateMachine
       
    96 */
       
    97 NONSHARABLE_CLASS(TObexServerStateDisconnected) : public TObexServerOperationState
       
    98 	{
       
    99 public:
       
   100 	TObexServerStateDisconnected();
       
   101 	void Entry(CObexServerStateMachine& aContext);
       
   102 	void TransportUp(CObexServerStateMachine& aContext);
       
   103 	void Reset(CObexServerStateMachine& aContext);
       
   104 	};
       
   105 
       
   106 /**
       
   107 Idle transport connected state (no OBEX connection)
       
   108 @see TObexServerOperationState
       
   109 @see CObexServerStateMachine
       
   110 */
       
   111 NONSHARABLE_CLASS(TObexServerStateTransportConnected) : public TObexServerOperationState
       
   112 	{
       
   113 public:
       
   114 	TObexServerStateTransportConnected();
       
   115 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   116 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   117 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   118 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   119 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   120 	void Abort(CObexServerStateMachine& aContext);
       
   121 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   122 	};
       
   123 
       
   124 /**
       
   125 Processes an OBEX connection attempt
       
   126 @see TObexServerOperationState
       
   127 @see CObexServerStateMachine
       
   128 */
       
   129 NONSHARABLE_CLASS(TObexServerStateObexConnecting) : public TObexServerOperationState
       
   130 	{
       
   131 public:
       
   132 	//Failure cases
       
   133 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   134 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   135 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   136 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   137 	
       
   138 	//Functional
       
   139 	TObexServerStateObexConnecting();
       
   140 	void Entry(CObexServerStateMachine& aContext);
       
   141 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   142 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   143 	void Abort(CObexServerStateMachine& aContext);
       
   144 	};
       
   145 
       
   146 /**
       
   147 Waits for a password from the Application as part of connection attempt
       
   148 @see TObexServerOperationState
       
   149 @see CObexServerStateMachine
       
   150 */
       
   151 NONSHARABLE_CLASS(TObexServerStateWaitForUserPassword) : public TObexServerOperationState
       
   152 	{
       
   153 public:
       
   154 	//Failure
       
   155 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   156 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   157 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   158 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   159 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   160 	void Abort(CObexServerStateMachine& aContext);
       
   161 	void Start(CObexServerStateMachine& aContext);
       
   162 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   163 	//Functional
       
   164 	TObexServerStateWaitForUserPassword();
       
   165 	void ConnectionComplete(CObexServerStateMachine& aContext);
       
   166 	};
       
   167 
       
   168 /**
       
   169 Idle OBEX connected state
       
   170 @see TObexServerOperationState
       
   171 @see CObexServerStateMachine
       
   172 */
       
   173 NONSHARABLE_CLASS(TObexServerStateReady) : public TObexServerOperationState
       
   174 	{
       
   175 public:
       
   176 	TObexServerStateReady();
       
   177 	void Entry(CObexServerStateMachine& aContext);
       
   178 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   179 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   180 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   181 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   182 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   183 	void Abort(CObexServerStateMachine& aContext);
       
   184 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   185 	void ReadActivityDetected(CObexServerStateMachine& aContext);
       
   186 	};
       
   187 
       
   188 /**
       
   189 Waits for object to return to Client as part of PUT operation
       
   190 @see TObexServerOperationState
       
   191 @see CObexServerStateMachine
       
   192 */
       
   193 NONSHARABLE_CLASS(TObexServerStatePutOpWaitForUser) : public TObexServerOperationState
       
   194 	{
       
   195 public:
       
   196 	//Failure cases
       
   197 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   198 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   199 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   200 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   201 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   202 	void Abort(CObexServerStateMachine& aContext);
       
   203 	void Start(CObexServerStateMachine& aContext);
       
   204 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   205 	
       
   206 	//Functional
       
   207 	TObexServerStatePutOpWaitForUser();
       
   208 	void Entry(CObexServerStateMachine& aContext);
       
   209 	void Reset(CObexServerStateMachine& aContext);
       
   210 	void RequestNotificationCompleted(CObexServerStateMachine& aContext, CObexBaseObject* aObject);
       
   211 	void RequestNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse);
       
   212 	TBool ValidResponse(TObexResponse aResponseCode);
       
   213 	
       
   214 	// Call-back function used by asynchronous one-shot
       
   215 	static TInt ProcessNotification(TAny* aPtr);
       
   216 	static TInt ProcessErrorNotification(TAny* aPtr);
       
   217 	};
       
   218 
       
   219 /**
       
   220 Receives object from Client as part of PUT operation
       
   221 @see TObexServerOperationState
       
   222 @see CObexServerStateMachine
       
   223 */
       
   224 NONSHARABLE_CLASS(TObexServerStatePutOpReceiveObject) : public TObexServerOperationState
       
   225 	{
       
   226 public:
       
   227 	//Failure cases
       
   228 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   229 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   230 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   231 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   232 	//Functional
       
   233 	TObexServerStatePutOpReceiveObject();
       
   234 	void Entry(CObexServerStateMachine& aContext);
       
   235 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   236 	void Abort(CObexServerStateMachine& aContext);
       
   237 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   238 	};
       
   239 
       
   240 /**
       
   241 Recevies from Client specification of object to GET
       
   242 @see TObexServerOperationState
       
   243 @see CObexServerStateMachine
       
   244 */
       
   245 NONSHARABLE_CLASS(TObexServerStateGetOpReceiveSpecification) : public TObexServerOperationState
       
   246 	{
       
   247 public:
       
   248 	//Failure cases
       
   249 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   250 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   251 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   252 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   253 	//Functional
       
   254 	TObexServerStateGetOpReceiveSpecification();
       
   255 	void Entry(CObexServerStateMachine& aContext);
       
   256 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   257 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   258 	void Abort(CObexServerStateMachine& aContext);
       
   259 	};
       
   260 
       
   261 /**
       
   262 Waits for object to return to Client as part of GET operation
       
   263 @see TObexServerOperationState
       
   264 @see CObexServerStateMachine
       
   265 */
       
   266 NONSHARABLE_CLASS(TObexServerStateGetOpWaitForUser) : public TObexServerOperationState
       
   267 	{
       
   268 public:
       
   269 	//Failure cases
       
   270 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   271 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   272 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   273 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   274 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   275 	void Abort(CObexServerStateMachine& aContext);
       
   276 	void Start(CObexServerStateMachine& aContext);
       
   277 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   278 	
       
   279 	//Functional
       
   280 	TObexServerStateGetOpWaitForUser();
       
   281 	void Entry(CObexServerStateMachine& aContext);
       
   282 	void Reset(CObexServerStateMachine& aContext);
       
   283 	void RequestNotificationCompleted(CObexServerStateMachine& aContext, CObexBaseObject* aObject);
       
   284 	void RequestNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse);
       
   285 	TBool ValidResponse(TObexResponse aResponseCode);
       
   286 	
       
   287 	// Call-back function used by asynchronous one-shot
       
   288 	static TInt ProcessNotification(TAny* aPtr);
       
   289 	static TInt ProcessErrorNotification(TAny* aPtr);
       
   290 	};
       
   291 
       
   292 /**
       
   293 Returns requested object to Client as part of GET operation
       
   294 @see TObexServerOperationState
       
   295 @see CObexServerStateMachine
       
   296 */
       
   297 NONSHARABLE_CLASS(TObexServerStateGetOpSendObject) : public TObexServerOperationState
       
   298 	{
       
   299 public:
       
   300 	//Failure cases
       
   301 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   302 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   303 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   304 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   305 	
       
   306 	//Functional
       
   307 	TObexServerStateGetOpSendObject();
       
   308 	void Entry(CObexServerStateMachine& aContext);
       
   309 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   310 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   311 	void Abort(CObexServerStateMachine& aContext);
       
   312 	};
       
   313 
       
   314 /**
       
   315 Performs SETPATH operation and waits for user interaction
       
   316 @see TObexServerOperationState
       
   317 @see CObexServerStateMachine
       
   318 */
       
   319 NONSHARABLE_CLASS(TObexServerStateSetPathOp) : public TObexServerOperationState
       
   320 	{
       
   321 public:
       
   322 	//Failure cases
       
   323 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   324 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   325 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   326 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   327 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   328 	void Abort(CObexServerStateMachine& aContext);
       
   329 	void Start(CObexServerStateMachine& aContext);
       
   330 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   331 	
       
   332 	//Functional
       
   333 	TObexServerStateSetPathOp();
       
   334 	void Entry(CObexServerStateMachine& aContext);
       
   335 	void Reset(CObexServerStateMachine& aContext);
       
   336 	void RequestCompleteNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse);
       
   337 	TBool ValidResponse(TObexResponse aResponseCode);
       
   338 	
       
   339 	static TInt ProcessNotification(TAny* aPtr);
       
   340 	};
       
   341 
       
   342 /**
       
   343 Waits for user interaction after receiving the final PUT
       
   344 @see TObexServerOperationState
       
   345 @see CObexServerStateMachine
       
   346 */
       
   347 NONSHARABLE_CLASS(TObexServerStatePutOpFinal) : public TObexServerOperationState
       
   348 	{
       
   349 public:
       
   350 	//Failure cases	
       
   351 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   352 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   353 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   354 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   355 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   356 	void Abort(CObexServerStateMachine& aContext);
       
   357 	void Start(CObexServerStateMachine& aContext);
       
   358 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   359 	
       
   360 	//Functional
       
   361 	TObexServerStatePutOpFinal();
       
   362 	void Entry(CObexServerStateMachine& aContext);
       
   363 	void Reset(CObexServerStateMachine& aContext);
       
   364 	void RequestCompleteNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse);
       
   365 	TBool ValidResponse(TObexResponse aResponseCode);
       
   366 	
       
   367 	static TInt ProcessNotification(TAny* aPtr);
       
   368 private:
       
   369 	static void PrepareFinalResponseHeaderSet(CObexHeader* aHeader, CObexHeaderSet& aHeaderSet, CObexPacket& aPacket);
       
   370 	};
       
   371 
       
   372 /**
       
   373 Waits for user interaction after receiving the final Get
       
   374 @see TObexServerOperationState
       
   375 @see CObexServerStateMachine
       
   376 */
       
   377 NONSHARABLE_CLASS(TObexServerStateGetOpFinal) : public TObexServerOperationState
       
   378 	{
       
   379 public:
       
   380 	
       
   381 	//Failure cases
       
   382 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   383 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   384 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   385 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   386 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   387 	void Abort(CObexServerStateMachine& aContext);
       
   388 	void Start(CObexServerStateMachine& aContext);
       
   389 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   390 	
       
   391 	//Fucntional
       
   392 	TObexServerStateGetOpFinal();
       
   393 	void Reset(CObexServerStateMachine& aContext);
       
   394 	void Entry(CObexServerStateMachine& aContext);
       
   395 	void RequestCompleteNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse);
       
   396 	TBool ValidResponse(TObexResponse aResponseCode);
       
   397 	
       
   398 	static TInt ProcessNotification(TAny* aPtr);
       
   399 	};
       
   400 		
       
   401 /**
       
   402 Disconnecting state
       
   403 @see TObexServerOperationState
       
   404 @see CObexServerStateMachine
       
   405 */
       
   406 NONSHARABLE_CLASS(TObexServerStateDisconnecting) : public TObexServerOperationState
       
   407 	{
       
   408 public:
       
   409 	TObexServerStateDisconnecting();
       
   410 	
       
   411 	//Failure cases
       
   412 	void Connect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   413 	void Disconnect(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   414 	void Put(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   415 	void Get(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   416 	void SetPath(CObexServerStateMachine& aContext, CObexPacket& aPacket);
       
   417 	void Abort(CObexServerStateMachine& aContext);
       
   418 	void OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse aResponse);
       
   419 
       
   420 	//Functional
       
   421 	void WriteComplete(CObexServerStateMachine& aContext);
       
   422 	};
       
   423 
       
   424 #endif	// OBEX_SERVER_OPERATION_STATES_H
       
   425