applayerprotocols/httptransportfw/Test/t_httptransporthandler/cdriverbase.h
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2002-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 __CDRIVERBASE_H__
       
    17 #define __CDRIVERBASE_H__
       
    18 
       
    19 #include <e32base.h>
       
    20 
       
    21 #include "mdriverobserver.h"
       
    22 
       
    23 /**	@class		CDriverBase
       
    24 	The CDriverBase is an abstract class that provides command running 
       
    25 	functionality. There are two types of commands - 'Do' and 'Expect' commands.
       
    26 
       
    27 	A 'Do' command implies that the concrete driver must perform an action. The
       
    28 	concrete class is notified of the action via its override of the RunCmdL() 
       
    29 	function.
       
    30 
       
    31 	Once the 'Do' command has been performed, the next command is extracted from
       
    32 	the command stack. If it is another 'Do' command, then the driver base self-
       
    33 	completes and the RunCmdL() function is called again. For an 'Expect' command
       
    34 	the driver base waits until the concrete class it invoked.
       
    35 
       
    36 	When a concrete class is invoked on one of its APIs it can check to see if
       
    37 	that invocation was expected by asking this base class, passing the the 
       
    38 	command ID of the invoked function in the ExpecetedCmd() API.
       
    39 
       
    40 	If the invoked command was expected, the next command is extracted from the
       
    41 	command stack as described earlier.
       
    42 
       
    43 	A derived class must form the command stack using the AppendDoCmdL() and the
       
    44 	AppendExpectCmdL() APIs. The commands should be appended in running order.
       
    45 	@componentInternal		
       
    46 */
       
    47 class CDriverBase	: public CActive,
       
    48 					  public MDriverObserver
       
    49 	{
       
    50 private:	// helper class
       
    51 
       
    52 /**	@class		TCmdEntry
       
    53 	The TCmdEntry class is a helper class for CDriverBase. It encapsulates a 
       
    54 	command ID and its type.
       
    55 	@componentInternal		
       
    56 */
       
    57 	class TCmdEntry
       
    58 		{
       
    59 	public:	// enums
       
    60 
       
    61 /**	@enum		TCmdType
       
    62 	An enumeration defining the types of commands.
       
    63 */
       
    64 		enum TCmdType
       
    65 			{
       
    66 			/** A 'Do' type command. This type of command implies that the driver
       
    67 				object must perform an action.
       
    68 			*/
       
    69 			EDoCmd			=0,
       
    70 			/**	An 'Expect' type command. This type of command implies that the
       
    71 				driver expects an invocation on its API.
       
    72 			*/
       
    73 			EExpectCmd
       
    74 			};
       
    75 
       
    76 	public:	// methods
       
    77 
       
    78 		inline TCmdEntry();
       
    79 
       
    80 		inline TCmdEntry(TInt aCmd, TCmdType aType);
       
    81 
       
    82 	public:	// attributes
       
    83 
       
    84 		TInt		iCmd;
       
    85 
       
    86 		TCmdType	iType;
       
    87 
       
    88 		};
       
    89 
       
    90 public:	// methods
       
    91 
       
    92 	virtual ~CDriverBase();
       
    93 
       
    94 	void Start();
       
    95 
       
    96 private:	// methods from CActive
       
    97 
       
    98 	virtual void RunL();
       
    99 
       
   100 	virtual void DoCancel();
       
   101 
       
   102 	virtual TInt RunError(TInt aError);
       
   103 
       
   104 private:	// methods from MDriverObserver
       
   105 
       
   106 	virtual void NotifyError(TInt aError);
       
   107 
       
   108 	virtual void NotifyStart();
       
   109 
       
   110 	virtual void NotifyComplete();
       
   111 
       
   112 	virtual void Log(const TDesC& aComment);
       
   113 
       
   114 protected:	// methods
       
   115 
       
   116 	CDriverBase(MDriverObserver& aObserver);
       
   117 
       
   118 	TBool TestExpectedCmd(TInt aCmd, TInt aError);
       
   119 
       
   120 	void AppendExpectCmdL(TInt aCmd);
       
   121 
       
   122 	void AppendDoCmdL(TInt aCmd);
       
   123 
       
   124 	void DoLog(const TDesC& aComment);
       
   125 
       
   126 private:	// methods
       
   127 
       
   128 /**	@fn			RunCmdL(TInt aCmd) =0
       
   129 	Requests the command with ID aCmd is run.
       
   130 	@componentInternal		
       
   131 	@param		aCmd	The ID of the command to run.
       
   132 */
       
   133 	virtual void RunCmdL(TInt aCmd) =0;
       
   134 
       
   135 private:	// methods
       
   136 
       
   137 	void CompleteSelf();
       
   138 
       
   139 	void NextCmd();
       
   140 
       
   141 private:	// attributes
       
   142 
       
   143 	MDriverObserver&		iObserver;
       
   144 
       
   145 	TInt					iCurrentCmd;
       
   146 
       
   147 	RArray<TCmdEntry>		iCmdStack;
       
   148 
       
   149 	TInt					iNextCmd;
       
   150 
       
   151 	};
       
   152 
       
   153 inline  CDriverBase::TCmdEntry::TCmdEntry()
       
   154 /**	
       
   155 	Default constructor. Object not initialised.
       
   156 	@componentInternal		
       
   157 */
       
   158 	{
       
   159 	}
       
   160 
       
   161 inline  CDriverBase::TCmdEntry::TCmdEntry(TInt aCmd, TCmdType aType)
       
   162 : iCmd(aCmd), iType(aType)
       
   163 /**	
       
   164 	Default constructor. Object is initialised.
       
   165 	@componentInternal		
       
   166 	@param		aCmd	The command ID.
       
   167 	@param		aType	The command type.
       
   168 */
       
   169 	{
       
   170 	}
       
   171 
       
   172 #endif	// __CDRIVERBASE_H__