mtptransports/mtpptpiptransport/ptpipplugin/src/cptpipeventhandler.cpp
changeset 0 d0791faffa3f
child 47 63cf70d3ecd8
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2008-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 // ceventhandler.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @internalComponent
       
    20 */
       
    21 
       
    22 #include "cptpipeventhandler.h"
       
    23 #include "tptpipinitevtack.h"
       
    24 #include "ptpippanic.h"
       
    25 
       
    26 __FLOG_STMT(_LIT8(KComponent,"CEventHandler");) 
       
    27 
       
    28 /**
       
    29 Creates the channel for commands. The base class constructl is called. 
       
    30 */
       
    31 CPTPIPEventHandler* CPTPIPEventHandler::NewL(CPTPIPConnection& aConnection)
       
    32 	{
       
    33 	
       
    34 	CPTPIPEventHandler* self = new(ELeave) CPTPIPEventHandler(aConnection);
       
    35 	CleanupStack::PushL(self);
       
    36 #ifdef __FLOG_ACTIVE    
       
    37     self->ConstructL(KComponent);
       
    38 #else
       
    39     self->ConstructL();
       
    40 #endif
       
    41 	CleanupStack::Pop();
       
    42 	return self;
       
    43 	}
       
    44 
       
    45 /**
       
    46 Destructor
       
    47 */
       
    48 CPTPIPEventHandler::~CPTPIPEventHandler()
       
    49 	{
       
    50 	__FLOG(_L8("Destructor - Entry"));
       
    51 	__FLOG(_L8("Destructor - Exit"));
       
    52 	}
       
    53 
       
    54 /**
       
    55 Constructor
       
    56 */
       
    57 CPTPIPEventHandler::CPTPIPEventHandler(CPTPIPConnection& aConnection): 
       
    58 	CPTPIPSocketHandlerBase(aConnection, CActive::EPriorityUserInput )
       
    59 	{
       
    60 	}
       
    61 
       
    62 /**
       
    63 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.
       
    65 */
       
    66 void CPTPIPEventHandler::SendInitAck(CPTPIPGenericContainer* aEvtAck)
       
    67 	{
       
    68 	__FLOG(_L8("SendInitAck - Entry"));
       
    69 	iChunkStatus = aEvtAck->FirstReadChunk(iSendChunkData);
       
    70 	iSendData.Set(iSendChunkData);
       
    71 	iSocket.Send(iSendData,0,iStatus);
       
    72 	SetState(EInitSendInProgress);
       
    73 	SetActive();
       
    74 	__FLOG(_L8("SendInitAck - Exit"));
       
    75 	}
       
    76 
       
    77 /**
       
    78 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. 
       
    80 @param aData The buffer containing the event which is created by the framework to send to the initiator
       
    81 */
       
    82 void CPTPIPEventHandler::SendEventL(const MMTPType& aEvent)
       
    83     {
       
    84 	__FLOG(_L8("SendEventL - Entry"));
       
    85 	
       
    86 	// We need to stop listening, and send the event. 
       
    87 	Cancel();
       
    88 	
       
    89     SendDataL(aEvent, 0);
       
    90 	__FLOG(_L8("SendEventL - Exit"));
       
    91     }
       
    92 
       
    93 /**
       
    94 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 
       
    96 connection.
       
    97 @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.
       
    99 */
       
   100 void CPTPIPEventHandler::SendDataCompleteL(TInt aError, const MMTPType& aSource)
       
   101     {
       
   102 	__FLOG(_L8("SendDataCompleteL - Entry"));
       
   103     Connection().SendEventCompleteL(aError, aSource);
       
   104 	__FLOG(_L8("SendDataCompleteL - Exit"));
       
   105     }
       
   106 
       
   107 /**
       
   108 Initiates the receiving of the event data on the event channel. 
       
   109 @param aEvent The buffer containing the event received from the initiator
       
   110 */
       
   111 void CPTPIPEventHandler::ReceiveEventL(MMTPType& aEvent)
       
   112     {
       
   113 	__FLOG(_L8("ReceiveEventL - Entry"));
       
   114     ReceiveDataL(aEvent);
       
   115 	__FLOG(_L8("ReceiveEventL - Exit"));
       
   116     }
       
   117 
       
   118 /**
       
   119 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
       
   121 connection.
       
   122 @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
       
   124 */
       
   125 void CPTPIPEventHandler::ReceiveDataCompleteL(TInt aError, MMTPType& aSink)
       
   126     {
       
   127 	__FLOG(_L8("ReceiveDataCompleteL - Entry"));
       
   128     Connection().ReceiveEventCompleteL(aError, aSink); 
       
   129 	__FLOG(_L8("ReceiveDataCompleteL - Exit"));
       
   130     }
       
   131 
       
   132 /**
       
   133 Parses the PTPIP header, gets and validates that the packet type is correct 
       
   134 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
       
   136 */   
       
   137 TInt CPTPIPEventHandler::ParsePTPIPHeaderL()
       
   138 	{
       
   139 	__FLOG(_L8("ParsePTPIPHeaderL - Entry"));
       
   140 	
       
   141 	TUint32 type = Connection().ValidateAndSetEventPayloadL();
       
   142 	iPTPPacketLength = Connection().EventContainer()->Uint32L(CPTPIPGenericContainer::EPacketLength);
       
   143 	
       
   144 	__FLOG(_L8("ParsePTPIPHeaderL - Exit"));
       
   145 	return type;
       
   146 	}
       
   147 
       
   148 /**
       
   149 Called during the PTP connection establishment phase to mark the completion 
       
   150 of sending the init ack to the initiator
       
   151 @return Flag stating that the ini has been sent successfully.
       
   152 */
       
   153 TBool CPTPIPEventHandler::HandleInitAck()
       
   154 	{
       
   155 	__FLOG(_L8("HandleInitAck - Entry"));
       
   156 	TBool isHandled(EFalse);
       
   157 	
       
   158 	if (iState == EInitSendInProgress)
       
   159 		{
       
   160 		//Now signal the connection, set its state and set it to active.
       
   161 		Connection().SetConnectionState(CPTPIPConnection::EInitialisationComplete);
       
   162 		Connection().CompleteSelf(iStatus.Int());
       
   163 		iState = EIdle;
       
   164 		isHandled = ETrue;
       
   165 		}
       
   166 	__FLOG(_L8("HandleInitAck - Exit"));
       
   167 	return isHandled;
       
   168 	}
       
   169 
       
   170 
       
   171 
       
   172 	
       
   173 	
       
   174