mtptransports/mtpptpiptransport/ptpipplugin/src/cptpipeventhandler.cpp
changeset 49 c20dd21d1eb4
parent 0 d0791faffa3f
equal deleted inserted replaced
41:2c19c7cf5550 49:c20dd21d1eb4
    20 */
    20 */
    21 
    21 
    22 #include "cptpipeventhandler.h"
    22 #include "cptpipeventhandler.h"
    23 #include "tptpipinitevtack.h"
    23 #include "tptpipinitevtack.h"
    24 #include "ptpippanic.h"
    24 #include "ptpippanic.h"
       
    25 #include "OstTraceDefinitions.h"
       
    26 #ifdef OST_TRACE_COMPILER_IN_USE
       
    27 #include "cptpipeventhandlerTraces.h"
       
    28 #endif
    25 
    29 
    26 __FLOG_STMT(_LIT8(KComponent,"CEventHandler");) 
       
    27 
    30 
    28 /**
    31 /**
    29 Creates the channel for commands. The base class constructl is called. 
    32 Creates the channel for commands. The base class constructl is called. 
    30 */
    33 */
    31 CPTPIPEventHandler* CPTPIPEventHandler::NewL(CPTPIPConnection& aConnection)
    34 CPTPIPEventHandler* CPTPIPEventHandler::NewL(CPTPIPConnection& aConnection)
    32 	{
    35 	{
       
    36 	OstTraceFunctionEntry0( CPTPIPEVENTHANDLER_NEWL_ENTRY );
    33 	
    37 	
    34 	CPTPIPEventHandler* self = new(ELeave) CPTPIPEventHandler(aConnection);
    38 	CPTPIPEventHandler* self = new(ELeave) CPTPIPEventHandler(aConnection);
    35 	CleanupStack::PushL(self);
    39 	CleanupStack::PushL(self);
    36 #ifdef __FLOG_ACTIVE    
       
    37     self->ConstructL(KComponent);
       
    38 #else
       
    39     self->ConstructL();
    40     self->ConstructL();
    40 #endif
       
    41 	CleanupStack::Pop();
    41 	CleanupStack::Pop();
       
    42 	OstTraceFunctionExit0( CPTPIPEVENTHANDLER_NEWL_EXIT );
    42 	return self;
    43 	return self;
    43 	}
    44 	}
    44 
    45 
    45 /**
    46 /**
    46 Destructor
    47 Destructor
    47 */
    48 */
    48 CPTPIPEventHandler::~CPTPIPEventHandler()
    49 CPTPIPEventHandler::~CPTPIPEventHandler()
    49 	{
    50 	{
    50 	__FLOG(_L8("Destructor - Entry"));
    51 	OstTraceFunctionEntry0( CPTPIPEVENTHANDLER_CPTPIPEVENTHANDLER_ENTRY );
    51 	__FLOG(_L8("Destructor - Exit"));
    52 	OstTraceFunctionExit0( CPTPIPEVENTHANDLER_CPTPIPEVENTHANDLER_EXIT );
    52 	}
    53 	}
    53 
    54 
    54 /**
    55 /**
    55 Constructor
    56 Constructor
    56 */
    57 */
    57 CPTPIPEventHandler::CPTPIPEventHandler(CPTPIPConnection& aConnection): 
    58 CPTPIPEventHandler::CPTPIPEventHandler(CPTPIPConnection& aConnection): 
    58 	CPTPIPSocketHandlerBase(aConnection, CActive::EPriorityUserInput )
    59 	CPTPIPSocketHandlerBase(aConnection, CActive::EPriorityUserInput )
    59 	{
    60 	{
       
    61 	OstTraceFunctionEntry0( DUP1_CPTPIPEVENTHANDLER_CPTPIPEVENTHANDLER_ENTRY );
       
    62 	OstTraceFunctionExit0( DUP1_CPTPIPEVENTHANDLER_CPTPIPEVENTHANDLER_EXIT );
    60 	}
    63 	}
    61 
    64 
    62 /**
    65 /**
    63 Sends the init ack packet, which is created in the connection class. 
    66 Sends the init ack packet, which is created in the connection class. 
    64 @param aEvtAck The packet containing the event acknowledgement to be sent to initiator.
    67 @param aEvtAck The packet containing the event acknowledgement to be sent to initiator.
    65 */
    68 */
    66 void CPTPIPEventHandler::SendInitAck(CPTPIPGenericContainer* aEvtAck)
    69 void CPTPIPEventHandler::SendInitAck(CPTPIPGenericContainer* aEvtAck)
    67 	{
    70 	{
    68 	__FLOG(_L8("SendInitAck - Entry"));
    71 	OstTraceFunctionEntry0( CPTPIPEVENTHANDLER_SENDINITACK_ENTRY );
    69 	iChunkStatus = aEvtAck->FirstReadChunk(iSendChunkData);
    72 	iChunkStatus = aEvtAck->FirstReadChunk(iSendChunkData);
    70 	iSendData.Set(iSendChunkData);
    73 	iSendData.Set(iSendChunkData);
    71 	iSocket.Send(iSendData,0,iStatus);
    74 	iSocket.Send(iSendData,0,iStatus);
    72 	SetState(EInitSendInProgress);
    75 	SetState(EInitSendInProgress);
    73 	SetActive();
    76 	SetActive();
    74 	__FLOG(_L8("SendInitAck - Exit"));
    77 	OstTraceFunctionExit0( CPTPIPEVENTHANDLER_SENDINITACK_EXIT );
    75 	}
    78 	}
    76 
    79 
    77 /**
    80 /**
    78 Initiates the sending of the event data over the event channel. The base class
    81 Initiates the sending of the event data over the event channel. The base class
    79  implements the handling of the socket to send the actual data. 
    82  implements the handling of the socket to send the actual data. 
    80 @param aData The buffer containing the event which is created by the framework to send to the initiator
    83 @param aData The buffer containing the event which is created by the framework to send to the initiator
    81 */
    84 */
    82 void CPTPIPEventHandler::SendEventL(const MMTPType& aEvent)
    85 void CPTPIPEventHandler::SendEventL(const MMTPType& aEvent)
    83     {
    86     {
    84 	__FLOG(_L8("SendEventL - Entry"));
    87 	OstTraceFunctionEntry0( CPTPIPEVENTHANDLER_SENDEVENTL_ENTRY );
    85 	
    88 	
    86 	// We need to stop listening, and send the event. 
    89 	// We need to stop listening, and send the event. 
    87 	Cancel();
    90 	Cancel();
    88 	
    91 	
    89     SendDataL(aEvent, 0);
    92     SendDataL(aEvent, 0);
    90 	__FLOG(_L8("SendEventL - Exit"));
    93     OstTraceFunctionExit0( CPTPIPEVENTHANDLER_SENDEVENTL_EXIT );
    91     }
    94     }
    92 
    95 
    93 /**
    96 /**
    94 Signals the completion of sending data over the socket, which was started by 
    97 Signals the completion of sending data over the socket, which was started by 
    95 SendEventL. It is called by the base sockethandler and in turn informs the 
    98 SendEventL. It is called by the base sockethandler and in turn informs the 
    97 @param aError - The error if any returned by the sockethandler. (KErrNone if no errors)
   100 @param aError - The error if any returned by the sockethandler. (KErrNone if no errors)
    98 @param aSource - The event buffer which had been given by the framework to send to initiator.
   101 @param aSource - The event buffer which had been given by the framework to send to initiator.
    99 */
   102 */
   100 void CPTPIPEventHandler::SendDataCompleteL(TInt aError, const MMTPType& aSource)
   103 void CPTPIPEventHandler::SendDataCompleteL(TInt aError, const MMTPType& aSource)
   101     {
   104     {
   102 	__FLOG(_L8("SendDataCompleteL - Entry"));
   105 	OstTraceFunctionEntry0( CPTPIPEVENTHANDLER_SENDDATACOMPLETEL_ENTRY );
   103     Connection().SendEventCompleteL(aError, aSource);
   106     Connection().SendEventCompleteL(aError, aSource);
   104 	__FLOG(_L8("SendDataCompleteL - Exit"));
   107     OstTraceFunctionExit0( CPTPIPEVENTHANDLER_SENDDATACOMPLETEL_EXIT );
   105     }
   108     }
   106 
   109 
   107 /**
   110 /**
   108 Initiates the receiving of the event data on the event channel. 
   111 Initiates the receiving of the event data on the event channel. 
   109 @param aEvent The buffer containing the event received from the initiator
   112 @param aEvent The buffer containing the event received from the initiator
   110 */
   113 */
   111 void CPTPIPEventHandler::ReceiveEventL(MMTPType& aEvent)
   114 void CPTPIPEventHandler::ReceiveEventL(MMTPType& aEvent)
   112     {
   115     {
   113 	__FLOG(_L8("ReceiveEventL - Entry"));
   116 	OstTraceFunctionEntry0( CPTPIPEVENTHANDLER_RECEIVEEVENTL_ENTRY );
   114     ReceiveDataL(aEvent);
   117     ReceiveDataL(aEvent);
   115 	__FLOG(_L8("ReceiveEventL - Exit"));
   118     OstTraceFunctionExit0( CPTPIPEVENTHANDLER_RECEIVEEVENTL_EXIT );
   116     }
   119     }
   117 
   120 
   118 /**
   121 /**
   119 Marks the completion of receiving data over the event channel, which was started 
   122 Marks the completion of receiving data over the event channel, which was started 
   120 by ReceiveEventL. It is called by the base sockethandler and in turn informs the
   123 by ReceiveEventL. It is called by the base sockethandler and in turn informs the
   122 @param aError - The error if any returned by the sockethandler. (KErrNone if no errors)
   125 @param aError - The error if any returned by the sockethandler. (KErrNone if no errors)
   123 @param aSink - The event buffer in which an event has been received from the initiator
   126 @param aSink - The event buffer in which an event has been received from the initiator
   124 */
   127 */
   125 void CPTPIPEventHandler::ReceiveDataCompleteL(TInt aError, MMTPType& aSink)
   128 void CPTPIPEventHandler::ReceiveDataCompleteL(TInt aError, MMTPType& aSink)
   126     {
   129     {
   127 	__FLOG(_L8("ReceiveDataCompleteL - Entry"));
   130 	OstTraceFunctionEntry0( CPTPIPEVENTHANDLER_RECEIVEDATACOMPLETEL_ENTRY );
   128     Connection().ReceiveEventCompleteL(aError, aSink); 
   131     Connection().ReceiveEventCompleteL(aError, aSink); 
   129 	__FLOG(_L8("ReceiveDataCompleteL - Exit"));
   132     OstTraceFunctionExit0( CPTPIPEVENTHANDLER_RECEIVEDATACOMPLETEL_EXIT );
   130     }
   133     }
   131 
   134 
   132 /**
   135 /**
   133 Parses the PTPIP header, gets and validates that the packet type is correct 
   136 Parses the PTPIP header, gets and validates that the packet type is correct 
   134 and sets the value of the packet length.
   137 and sets the value of the packet length.
   135 @return Type The PTPIP packet type received ie event or cancel. In case of invalid type, it returns 0
   138 @return Type The PTPIP packet type received ie event or cancel. In case of invalid type, it returns 0
   136 */   
   139 */   
   137 TInt CPTPIPEventHandler::ParsePTPIPHeaderL()
   140 TInt CPTPIPEventHandler::ParsePTPIPHeaderL()
   138 	{
   141 	{
   139 	__FLOG(_L8("ParsePTPIPHeaderL - Entry"));
   142 	OstTraceFunctionEntry0( CPTPIPEVENTHANDLER_PARSEPTPIPHEADERL_ENTRY );
   140 	
   143 	
   141 	TUint32 type = Connection().ValidateAndSetEventPayloadL();
   144 	TUint32 type = Connection().ValidateAndSetEventPayloadL();
   142 	iPTPPacketLength = Connection().EventContainer()->Uint32L(CPTPIPGenericContainer::EPacketLength);
   145 	iPTPPacketLength = Connection().EventContainer()->Uint32L(CPTPIPGenericContainer::EPacketLength);
   143 	
   146 	
   144 	__FLOG(_L8("ParsePTPIPHeaderL - Exit"));
   147 	OstTraceFunctionExit0( CPTPIPEVENTHANDLER_PARSEPTPIPHEADERL_EXIT );
   145 	return type;
   148 	return type;
   146 	}
   149 	}
   147 
   150 
   148 /**
   151 /**
   149 Called during the PTP connection establishment phase to mark the completion 
   152 Called during the PTP connection establishment phase to mark the completion 
   150 of sending the init ack to the initiator
   153 of sending the init ack to the initiator
   151 @return Flag stating that the ini has been sent successfully.
   154 @return Flag stating that the ini has been sent successfully.
   152 */
   155 */
   153 TBool CPTPIPEventHandler::HandleInitAck()
   156 TBool CPTPIPEventHandler::HandleInitAck()
   154 	{
   157 	{
   155 	__FLOG(_L8("HandleInitAck - Entry"));
   158 	OstTraceFunctionEntry0( CPTPIPEVENTHANDLER_HANDLEINITACK_ENTRY );
   156 	TBool isHandled(EFalse);
   159 	TBool isHandled(EFalse);
   157 	
   160 	
   158 	if (iState == EInitSendInProgress)
   161 	if (iState == EInitSendInProgress)
   159 		{
   162 		{
   160 		//Now signal the connection, set its state and set it to active.
   163 		//Now signal the connection, set its state and set it to active.
   161 		Connection().SetConnectionState(CPTPIPConnection::EInitialisationComplete);
   164 		Connection().SetConnectionState(CPTPIPConnection::EInitialisationComplete);
   162 		Connection().CompleteSelf(iStatus.Int());
   165 		Connection().CompleteSelf(iStatus.Int());
   163 		iState = EIdle;
   166 		iState = EIdle;
   164 		isHandled = ETrue;
   167 		isHandled = ETrue;
   165 		}
   168 		}
   166 	__FLOG(_L8("HandleInitAck - Exit"));
   169 	OstTraceFunctionExit0( CPTPIPEVENTHANDLER_HANDLEINITACK_EXIT );
   167 	return isHandled;
   170 	return isHandled;
   168 	}
   171 	}
   169 
   172 
   170 
   173 
   171 
   174