mtpfws/mtpfw/dataproviders/dputility/inc/cmtprequestprocessor.h
changeset 0 d0791faffa3f
child 1 f8e15b44d440
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-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  @file
       
    18  @internalTechnology
       
    19 */
       
    20 
       
    21 #ifndef __CMTPREQUESTPROCESSOR_H__
       
    22 #define __CMTPREQUESTPROCESSOR_H__
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <mtp/mtpdataproviderapitypes.h>
       
    26 #include <mtp/mtpprotocolconstants.h>
       
    27 #include <mtp/tmtptyperesponse.h>
       
    28 #include <mtp/tmtptypenull.h>
       
    29 #include "cmtprequestchecker.h"
       
    30 #include "mtpdebug.h"
       
    31 
       
    32 class MMTPConnection;
       
    33 class TMTPTypeRequest;
       
    34 class CMTPDataProviderPlugin;
       
    35 class MMTPDataProviderFramework;
       
    36 class TMTPTypeEvent;
       
    37 class CMTPObjectInfo;
       
    38 
       
    39 /** 
       
    40 Defines a request processor interface
       
    41 
       
    42 @internalTechnology
       
    43 */	
       
    44 class MMTPRequestProcessor
       
    45 	{
       
    46 public:	
       
    47 	/**
       
    48 	Process a request from the initiator
       
    49 	@param aRequest	The request to be processed
       
    50 	@param aPhase	The transaction phase of the request
       
    51 	@return ETrue to signal that the processor object can be deleted, EFalse to keep the processor object
       
    52 	*/
       
    53 	virtual TBool HandleRequestL(const TMTPTypeRequest& aRequest, TMTPTransactionPhase aPhase) = 0;
       
    54 	
       
    55 	/**
       
    56 	Process an event from the initiator
       
    57 	@param aEvent	The event to be processed
       
    58 	*/
       
    59 	virtual void HandleEventL(const TMTPTypeEvent& aEvent) = 0;
       
    60 	
       
    61 	/**
       
    62 	delete the request processor object
       
    63 	*/
       
    64 	virtual void Release() = 0;
       
    65 	
       
    66 	/**
       
    67 	Check if the processor matches the request on the connection
       
    68 	@param aRequest	The request to be checked
       
    69 	@param aConnection The connection from which the request comes
       
    70 	@return ETrue to indicate the processor can handle the request, otherwise, EFalse
       
    71 	*/
       
    72 	virtual TBool Match(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) const = 0;
       
    73 
       
    74 	/**
       
    75 	Check if the processor matches the event on the connection
       
    76 	@param aEvent The event to be checked
       
    77 	@param aConnection The connection from which the event comes
       
    78 	@return ETrue to indicate the processor can handle the event, otherwise, EFalse
       
    79 	*/	
       
    80 	virtual TBool Match(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection) const = 0;
       
    81 	
       
    82 	/**
       
    83 	Get the request object which the processor is currently handling
       
    84 	@return the request object which the processor is currently handling
       
    85 	*/
       
    86 	virtual const TMTPTypeRequest& Request() const = 0;
       
    87 	
       
    88 	/**
       
    89 	Get the connection object associated with the current request object
       
    90 	@return the connection object associated with the current request object
       
    91 	*/
       
    92 	virtual MMTPConnection& Connection() const = 0;
       
    93     /**
       
    94     Get the Session ID associated with the current request object
       
    95     @return Session ID associated with the current request object
       
    96     */	
       
    97 	virtual TUint32 SessionId() = 0;
       
    98 	
       
    99 	};
       
   100 
       
   101 /** 
       
   102 Defines a processor factory function pointer
       
   103 
       
   104 @internalTechnology
       
   105 */
       
   106 typedef MMTPRequestProcessor* (*TMTPRequestProcessorCreateFunc)(
       
   107 																MMTPDataProviderFramework& aFramework, 
       
   108 																MMTPConnection& aConnection);
       
   109 
       
   110 /** 
       
   111 Defines an entry which maps from operation code to the request processor
       
   112 
       
   113 @internalTechnology
       
   114 */																
       
   115 typedef struct 
       
   116 	{
       
   117 	TUint16							iOperationCode;
       
   118 	TMTPRequestProcessorCreateFunc	iCreateFunc;
       
   119 	}TMTPRequestProcessorEntry;
       
   120 
       
   121 
       
   122 /** 
       
   123 Defines a generic request processor interface from which all processors derive
       
   124 
       
   125 @internalTechnology
       
   126 */		
       
   127 class CMTPRequestProcessor : public CActive, public MMTPRequestProcessor
       
   128 	{
       
   129 protected:	
       
   130 	IMPORT_C CMTPRequestProcessor(
       
   131 						MMTPDataProviderFramework& aFramework,
       
   132 						MMTPConnection& aConnection,
       
   133 						TInt aElementCount,
       
   134 						const TMTPRequestElementInfo* aElements);
       
   135 	IMPORT_C virtual ~CMTPRequestProcessor();	
       
   136 
       
   137 protected:	//utility methods	
       
   138 	IMPORT_C void SendResponseL(TMTPResponseCode aResponseCode, TInt aParameterCount = 0, TUint32* aParams = NULL);
       
   139 	IMPORT_C void CompleteRequestL();
       
   140 	IMPORT_C void SendDataL(const MMTPType& aData);
       
   141 	IMPORT_C void ReceiveDataL(MMTPType& aData);
       
   142 		
       
   143 protected:	//	from MMTPRequestProcessor	
       
   144 	IMPORT_C virtual TBool HandleRequestL(const TMTPTypeRequest& aRequest, TMTPTransactionPhase aPhase);
       
   145 	IMPORT_C virtual void HandleEventL(const TMTPTypeEvent& aEvent);
       
   146 	
       
   147 	IMPORT_C virtual void Release();
       
   148 
       
   149 	IMPORT_C virtual TBool Match(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) const;
       
   150 	IMPORT_C virtual TBool Match(const TMTPTypeEvent& aEvent, MMTPConnection& aConnection) const;
       
   151 		
       
   152 	IMPORT_C virtual const TMTPTypeRequest& Request() const;
       
   153 	IMPORT_C virtual MMTPConnection& Connection() const;
       
   154 	   
       
   155     IMPORT_C virtual TUint32 SessionId();
       
   156 
       
   157 protected:	// from CActive
       
   158 	IMPORT_C virtual void RunL();
       
   159 	IMPORT_C virtual void DoCancel();
       
   160 	IMPORT_C virtual TInt RunError(TInt aError);
       
   161 	
       
   162 protected:	//new virtuals 	
       
   163 	IMPORT_C virtual TBool DoHandleRequestPhaseL();
       
   164 	IMPORT_C virtual TBool DoHandleDataIToRPhaseL();
       
   165 	IMPORT_C virtual TBool DoHandleRToIPhaseL();
       
   166 	IMPORT_C virtual TBool DoHandleResponsePhaseL();
       
   167 	IMPORT_C virtual TBool DoHandleCompletingPhaseL();
       
   168 	IMPORT_C virtual TMTPResponseCode CheckRequestL();
       
   169 	IMPORT_C virtual TBool HasDataphase() const;
       
   170 	
       
   171 	/**
       
   172 	service a request at request phase
       
   173 	*/
       
   174 	IMPORT_C virtual void ServiceL() = 0;
       
   175 
       
   176 
       
   177 private:
       
   178 	void ExtractSessionTransactionId();					
       
   179 	
       
   180 protected:
       
   181 	MMTPDataProviderFramework&	    iFramework;
       
   182 	const TMTPTypeRequest*		    iRequest;			//the pending requst object
       
   183 	MMTPConnection&				    iConnection;		//the connection from which the request comes
       
   184 	TMTPTypeResponse			    iResponse;			//the response object to send to the initiator
       
   185 	TBool						    iCancelled;			//indicates whether the data phase (send/receive) has been cancelled
       
   186 	CMTPRequestChecker*		    	iRequestChecker;	//a utility class providing generic request verification service
       
   187 	TInt					    	iElementCount;		//number of verification elements used for request checker
       
   188 	const TMTPRequestElementInfo*	iElements;	 		//pointer to an array of verification elements
       
   189 	TUint32						    iSessionId;			//session id for the pending request
       
   190 	TUint32						    iTransactionCode;	//transaction code for the pending request
       
   191 
       
   192 private:
       
   193 	TMTPResponseCode 				iResponseCode;		// contains response from CheckRequestL call
       
   194 	RBuf8 							iNullBuffer; 		// buffer to receive data from discarded data phase
       
   195 	TMTPTypeNull 					iNull;
       
   196 	/**
       
   197     FLOGGER debug trace member variable.
       
   198     */
       
   199     __FLOG_DECLARATION_MEMBER_MUTABLE;
       
   200 	};
       
   201 	
       
   202 #endif // __CMTPREQUESTPROCESSOR_H__
       
   203