mtpfws/mtpfw/inc/cmtpconnection.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  @internalComponent
       
    19 */
       
    20 
       
    21 #ifndef CMTPCONNECTION_H
       
    22 #define CMTPCONNECTION_H
       
    23 
       
    24 #include <e32property.h>
       
    25 #include <e32base.h>
       
    26 #include <mtp/mmtpconnection.h>
       
    27 #include <mtp/mtpdataproviderapitypes.h>
       
    28 #include <mtp/tmtptypeevent.h>
       
    29 #include <mtp/tmtptyperesponse.h>
       
    30 #include <mtp/rmtpclient.h>
       
    31 
       
    32 #include "mmtpconnectionprotocol.h"
       
    33 #include "rmtpframework.h"
       
    34 #include "mtpdebug.h"
       
    35 #include "mtpbuildoptions.hrh"
       
    36 #include "mtpdebug.h"
       
    37 
       
    38 class CMTPSession;
       
    39 class MMTPTransportConnection;
       
    40 class TRequestStatus;
       
    41 class TMTPTypeRequest;
       
    42 class TMTPTypeFlatBase;
       
    43 
       
    44 #ifdef MTP_CAPTURE_TEST_DATA
       
    45 class CMTPRequestLogger;
       
    46 #endif
       
    47 
       
    48 /** 
       
    49 Implements the connection level portion of the MTP communication model and 
       
    50 associated transport layer protocol binding. This class Implements the API 
       
    51 portion (@see MMTPConnectionProtocol) of the transport layer API/SPI interface 
       
    52 pair by which MTP framework and transport protocol connections 
       
    53 (@see MMTPTransportConnection) interact. A unique @see CMTPConnection instance 
       
    54 is created and bound to each @see MMTPTransportConnection instance that is 
       
    55 loaded. 
       
    56 
       
    57 It also implements the data provider layer MTP connection interface 
       
    58 (@see MMTPConnection) which represents the virtual circuit between data provider 
       
    59 and the transport layer.
       
    60 @internalComponent
       
    61  
       
    62 */
       
    63 class CMTPConnection : 
       
    64     public CBase,
       
    65     public MMTPConnection, 
       
    66     public MMTPConnectionProtocol
       
    67     {
       
    68 private:
       
    69 
       
    70 	class CMTPEventLink :
       
    71 		public CBase
       
    72 		{
       
    73 	public:
       
    74 		CMTPEventLink(const TMTPTypeEvent& aEvent);
       
    75 		
       
    76 	public:
       
    77 		TSglQueLink		iLink;
       
    78 		TMTPTypeEvent	iEvent;		
       
    79 		};
       
    80     
       
    81 public:
       
    82 
       
    83     static CMTPConnection* NewLC(TUint aConnectionId, MMTPTransportConnection& aTransportConnection);
       
    84     ~CMTPConnection();
       
    85 
       
    86     void ReceiveDataL(MMTPType& aData, const TMTPTypeRequest& aRequest, TRequestStatus& aStatus);
       
    87     void SendDataL(const MMTPType& aData, const TMTPTypeRequest& aRequest, TRequestStatus& aStatus);
       
    88     void SendEventL(const TMTPTypeEvent& aEvent);
       
    89     void SendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, TRequestStatus& aStatus);
       
    90     IMPORT_C void SessionClosedL(TUint32 aSessionMTPId);
       
    91     IMPORT_C void SessionOpenedL(TUint32 aSessionMTPId);
       
    92     IMPORT_C TInt GetDataReceiveResult() const;
       
    93     void ConnectionSuspended();
       
    94     void ConnectionResumedL(MMTPTransportConnection& aTransportConnection);
       
    95     void TransactionCompleteL(const TMTPTypeRequest& aRequest);
       
    96     
       
    97 public: // From MMTPConnection & MMTPConnectionProtocol
       
    98 
       
    99     TUint ConnectionId() const;
       
   100     
       
   101 public: // From MMTPConnection
       
   102 
       
   103     TUint SessionCount() const;
       
   104     TBool SessionWithMTPIdExists(TUint32 aMTPId) const;
       
   105     MMTPSession& SessionWithMTPIdL(TUint32 aMTPId) const;
       
   106     TBool SessionWithUniqueIdExists(TUint32 aUniqueId) const;
       
   107     MMTPSession& SessionWithUniqueIdL(TUint32 aUniqueId) const;
       
   108     TMTPTransactionPhase TransactionPhaseL(TUint32 aMTPSessionId) const;
       
   109 	void DisconnectionNotifyL();
       
   110 
       
   111 private: // From MMTPConnectionProtocol
       
   112 
       
   113     void ReceivedEventL(const TMTPTypeEvent& aEvent);
       
   114     void ReceivedRequestL(const TMTPTypeRequest& aRequest);
       
   115     void ReceiveDataCompleteL(TInt aErr, const MMTPType& aData, const TMTPTypeRequest& aRequest);
       
   116     void SendDataCompleteL(TInt aErr, const MMTPType& aData, const TMTPTypeRequest& aRequest);
       
   117     void SendEventCompleteL(TInt aErr, const TMTPTypeEvent& aEvent);
       
   118     void SendResponseCompleteL(TInt aErr, const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest);
       
   119 	void Unbind(MMTPTransportConnection& aConnection);
       
   120 
       
   121 private:
       
   122 
       
   123     CMTPConnection(TUint aConnectionId, MMTPTransportConnection& aTransportConnection);
       
   124     void ConstructL();
       
   125   
       
   126     void InitiateMTPErrorRecoveryL(const TMTPTypeRequest& aRequest, TUint16 aResponseCode);
       
   127     void MTPErrorRecoveryComplete();
       
   128     void UnrecoverableMTPError();
       
   129     
       
   130     void InitiateTransactionCancelL(TInt aSessionIdx);
       
   131     
       
   132     TUint ActiveSessions() const;
       
   133     void CloseAllSessions();
       
   134     void CloseSession(TUint aIdx);
       
   135     CMTPSession& SessionL(const TMTPTypeFlatBase& aDataset, TInt aSessionIdElementNo) const;
       
   136     
       
   137     static TInt SessionOrder(const TUint32* aL, const CMTPSession& aR);
       
   138     static TInt SessionOrder(const CMTPSession& aL, const CMTPSession& aR);
       
   139     
       
   140     void SetState(TUint aState);
       
   141     TUint State() const;
       
   142     
       
   143     TBool ValidFrameworkRequest(CMTPSession* aSession, TUint aValidStates, TRequestStatus* aStatus);
       
   144     
       
   145     void RemoveEventsForSession(TUint32 aMTPId);
       
   146     
       
   147     void EnqueueEvent(CMTPEventLink* aLink);
       
   148     void DequeueEvent(CMTPEventLink* aLink);
       
   149 
       
   150 /**
       
   151   * This method define and attach the property for publishing connection state 
       
   152   *  events.
       
   153   */
       
   154     void DefineConnStatePropertyL(); 
       
   155 
       
   156 /**
       
   157   * This method is to publish various connection state.
       
   158   */
       
   159     void PublishConnState(TMTPConnStateType aConnState);	
       
   160 
       
   161     void ValidateAndPublishConnState(CMTPSession& aSession, TInt aState);
       
   162 	
       
   163     
       
   164 private: // Owned
       
   165   
       
   166     enum TStates
       
   167         {
       
   168         EStateUnknown,
       
   169         EStateOpen,
       
   170         EStateErrorRecovery,
       
   171         EStateErrorShutdown,
       
   172         EStateShutdown
       
   173         };
       
   174 
       
   175     TUint                       iConnectionId;
       
   176     RPointerArray<CMTPSession>  iSessions;
       
   177     TUint                       iState;
       
   178     RMTPFramework               iSingletons;
       
   179     TAny*                       iExtendedInterface;
       
   180     TMTPTypeResponse 			iResponse;
       
   181     TSglQue<CMTPEventLink>		iEventQ;
       
   182     TInt 						iPendingEventCount;   
       
   183     TInt 						iDataReceiveResult;
       
   184     /**
       
   185     FLOGGER debug trace member variable.
       
   186     */
       
   187     __FLOG_DECLARATION_MEMBER_MUTABLE;
       
   188     
       
   189 private: // Not owned
       
   190 
       
   191     MMTPTransportConnection*    iTransportConnection;
       
   192 
       
   193     //For publishing the connection state.
       
   194     RProperty iProperty; 
       
   195 	
       
   196     /**
       
   197     Special build, capture request, data phase and responses to disk.
       
   198     */
       
   199 #ifdef MTP_CAPTURE_TEST_DATA 
       
   200     CMTPRequestLogger*          iRequestLogger;
       
   201 #endif
       
   202     };
       
   203     
       
   204 #endif // CMTPCONNECTION_H