mtptransports/mtpptpiptransport/ptpipcontroller/inc/cptpipcontroller.h
changeset 0 d0791faffa3f
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 // This file defines the API for cptpipcontroller.dll
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef __CPTPIPCONTROLLER_H__
       
    24 #define __CPTPIPCONTROLLER_H__
       
    25 
       
    26 #include <e32base.h>	
       
    27 
       
    28 #include <e32property.h>
       
    29 #include "centralrepository.h"
       
    30 #include "cptpipsockethandler.h"
       
    31 #include <mtp/cptpiphostfilterinterface.h>
       
    32 #include <mtp/rmtpclient.h>
       
    33 #include "mptpipcontroller.h"
       
    34 #include "cptpipinitcmdreq.h"
       
    35 #include "cptpipinitcmdack.h"
       
    36 #include "tptpipinitevtreq.h"
       
    37 #include "tptpipinitfailed.h"
       
    38 #include <mtp/cmtptypestring.h>
       
    39 #include "cptpiptimer.h"
       
    40 #include "mtpdebug.h"
       
    41 
       
    42 
       
    43   enum TInitFailReason
       
    44         {
       
    45         /**
       
    46         Responder impliments a device bonding mechanism and initiator requesting 
       
    47         the connection is not one of the 'allowed' device. see annex 5.3 for more 
       
    48         detail on bonding mechanism.
       
    49         */
       
    50         EInitFailRejected,        
       
    51         /**
       
    52          Responder has too many active connections. The Initiator  may try to 
       
    53          establish a connection latter.
       
    54         */
       
    55         EInitFailBusy,
       
    56         /**
       
    57         Covers all other rejection cases.
       
    58         */
       
    59         EInitFailUnSpecified,
       
    60 
       
    61  		};
       
    62  		
       
    63 enum TParameter
       
    64 {
       
    65 	/*
       
    66 	This parameter defines the Device Friendly Name MTP device property 
       
    67 	value. It is implemented as a string and has a maximum length of 254 
       
    68 	characters. The parameter value specified in the initialisation file 
       
    69 	may be overwritten in the course of MTP operational processing, if an 
       
    70 	MTP SetDevicePropValue specifying the Device Friendly Name device 
       
    71 	property is received.
       
    72 	*/
       
    73 	EDeviceFriendlyName  = 0x00000000
       
    74 }; 		
       
    75 
       
    76 
       
    77 class CPTPIPController : public MPTPIPController,public CActive
       
    78 {
       
    79 public:	 
       
    80 	IMPORT_C static CPTPIPController* NewL();
       
    81 	IMPORT_C static CPTPIPController* NewLC();
       
    82 	IMPORT_C ~CPTPIPController();
       
    83 			
       
    84 	IMPORT_C void SocketAccepted(TRequestStatus& aStatus);		
       
    85 	IMPORT_C void StopTransport();						
       
    86 	IMPORT_C TInt SetDeviceGUID(TDesC8& aDeviceGUID);
       
    87 	IMPORT_C void SetDeviceFriendlyName(TDesC16* aDeviceFriendlyName);
       
    88 	IMPORT_C RSocket& NewSocketL();
       
    89 			
       
    90 	IMPORT_C void OnTimeOut();
       
    91 										
       
    92 private:
       
    93 	TBool CompareHost(RSocket& aSocket);				
       
    94 	TInt PublishSocketNamePair();		
       
    95 	void CheckAndHandleErrorL(TInt aError);
       
    96 	TInt EnableSocketTransfer();		
       
    97 	TBool Validate();
       
    98 	void Schedule();
       
    99 			
       
   100 	TInt ParseInitPacketL();
       
   101 	TInt ParseEvtPacket();
       
   102 			
       
   103 	void RunL();
       
   104 	void DoCancel();	    	    
       
   105 	TInt RunError(TInt aErr);
       
   106 			
       
   107 	void CheckInitFailL(TInt aError);	    
       
   108 	CPTPIPController();
       
   109 	void ConstructL();
       
   110 	void BuildInitAckL();
       
   111 	void BuildInitFailL(TInitFailReason aReason);
       
   112 	void StartTimer(TInt aSecond);
       
   113 	TInt CheckMTPConnection();
       
   114 	void Reset();
       
   115 			
       
   116 	 enum TPTPIPControllerStates
       
   117 		{
       
   118 		/*EIdle:The Controller just got constructed, and any time
       
   119 		Listener will notify about new socket. */ 
       
   120 		EIdle,
       
   121 		
       
   122 	  /*EInitCommandAwaited:When SocketHandler is waiting for 
       
   123 	   InitCommandRequest to be sent over Command socket
       
   124 	   No socket connection request is validated at this state*/
       
   125 		EInitCommandAwaited,
       
   126 	 
       
   127 	 /*EInitCommandRead:When the InitCommandRequest is successfully
       
   128 	  read from the socket
       
   129 	  */
       
   130 		EInitCommandRead,
       
   131 		
       
   132 		
       
   133 		/*EFilterConsentAwaited:Controller is waiting for approval from Filter*/
       
   134 		EFilterConsentAwaited,
       
   135 		
       
   136 		
       
   137 		/*EWaitForInitFail:Filter has rejected the Connection request.Init Nack
       
   138 		built,Wait for Init NAck to be written and failure to connect reported*/
       
   139 		EWaitForInitFail,
       
   140 		
       
   141 		/*EWaitForInitCommandAck:Filter has accepted the conenction request.InitAck
       
   142 		built,Wait for Init Ack to be written*/
       
   143 		EWaitForInitCommandAck,       		                            
       
   144 		
       
   145 	 
       
   146 	  /*EInitEvtAwaited:When Socket Handler is waiting for InitEventRequest
       
   147 	   * No socket connection request is validated at this state*/
       
   148 		EInitEvtAwaited,
       
   149 		
       
   150 	  
       
   151 	 /*EInitEventRead:InitEventRequest read
       
   152 	  *No socket connection request is validated at this state */           
       
   153 		EInitEventRead,       		       	       	 
       
   154 						
       
   155 						 
       
   156 	 /*EConnected:Socket connection requests are not to be validated in this 
       
   157 	  state and the message Device Busy to be sent*/
       
   158 		EPTPIPConnected           
       
   159 		};
       
   160 		   
       
   161 private:
       
   162 		
       
   163 	CPTPIPSocketHandler* iCmdHandler,*iEvtHandler;
       
   164 	CPTPIPHostFilterInterface* iFilter;
       
   165 	TPTPIPControllerStates iCtrlState;
       
   166 	RProperty iProperty,iConnectionState;		
       
   167 	RMTPClient iMTP;
       
   168 	TBool iIsConnectedToMTP;
       
   169 	TMTPTypeUint128 iHostGUID;	
       
   170 	TDesC* iHostFriendlyName;							
       
   171 	TRequestStatus* iCallerStatus;		
       
   172 	CPTPIPInitCmdRequest* iInitCmdReq;
       
   173 	TPTPIPInitEvtRequest iInitEvtReq;
       
   174 	TPTPIPInitFailed iInitFailed;
       
   175 	CPTPIPInitCmdAck* iInitCmdAck;	
       
   176 	CRepository* iRepository;							
       
   177 	TMTPTypeUint128 iDeviceGUID;
       
   178 	HBufC16* iDeviceFriendlyName;		
       
   179 	RSocket iDummySocket;
       
   180 	TInt iCounter;
       
   181 	CPTPIPTimer* iTimer;
       
   182 	TUid iTransportId;			
       
   183 			
       
   184 	/**
       
   185 	FLOGGER debug trace member variable.
       
   186 	*/
       
   187 	__FLOG_DECLARATION_MEMBER;    
       
   188 			
       
   189 };
       
   190 
       
   191 
       
   192 #endif  // __CPTPIPCONTROLLER_H__
       
   193 
       
   194