connectivitylayer/usbphonetlink/usbpnserver_exe/src/cusbpnalt.cpp
changeset 0 63b37f68c1ce
child 5 8ccc39f9d787
equal deleted inserted replaced
-1:000000000000 0:63b37f68c1ce
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "cusbpnalt.h"
       
    20 #include "usbpndefinitions.h"       // For constants
       
    21 #include "usbpntrace.h"
       
    22 #include "musbpnaltobserver.h"
       
    23 
       
    24 #include "osttracedefinitions.h"
       
    25 #ifdef OST_TRACE_COMPILER_IN_USE
       
    26 #include "cusbpnaltTraces.h"
       
    27 #endif
       
    28 
       
    29 #include <d32usbc.h>                // For RDevUsbcClient
       
    30 #include <iscapi.h>                 // For RIscApi
       
    31 #ifndef NCP_COMMON_BRIDGE_FAMILY
       
    32 #include <sos_usbisi.h>             // For SOS USB Media Module Message constants
       
    33 #include <tisi.h>                   // For TIsiSend
       
    34 #include <phonetisi.h>              // For PhoNet definitions
       
    35 #include <pn_const.h>               // For resources
       
    36 #include <mediaisi.h>               // For media control
       
    37 #endif /* NCP_COMMON_BRIDGE_FAMILY */
       
    38 
       
    39 // EXTERNAL DATA STRUCTURES
       
    40 // EXTERNAL FUNCTION PROTOTYPES
       
    41 // CONSTANTS
       
    42 // MACROS
       
    43 // LOCAL CONSTANTS AND MACROS
       
    44 // MODULE DATA STRUCTURES
       
    45 // LOCAL FUNCTION PROTOTYPES
       
    46 // FORWARD DECLARATIONS
       
    47 
       
    48 // ============================= LOCAL FUNCTIONS ===============================
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CUsbPnAlt::CUsbPnAlt
       
    53 // C++ default constructor can NOT contain any code, that
       
    54 // might leave.
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CUsbPnAlt::CUsbPnAlt( MUsbPnAltObserver& aAltObserver, RDevUsbcClient& aLdd, RIscApi& aIscApi )
       
    58     :CActive( CActive::EPriorityStandard )
       
    59     ,iAltObserver( aAltObserver )
       
    60     ,iLdd( aLdd )
       
    61     ,iIscApi( aIscApi )
       
    62     {
       
    63     OstTrace1( TRACE_NORMAL, CUSBPNALT_CUSBPNALT_ENTRY, "CUsbPnAlt::CUsbPnAlt;aAltObserver=%x", ( TUint )&( aAltObserver ) );
       
    64     C_TRACE( ( _T( "CUsbPnAlt::CUsbPnAlt( aAltObserver 0x%x )" ), &aAltObserver ) );
       
    65 
       
    66     CActiveScheduler::Add(this);
       
    67 
       
    68     OstTrace0( TRACE_NORMAL, CUSBPNALT_CUSBPNALT_EXIT, "CUsbPnAlt::CUsbPnAlt - return" );
       
    69     C_TRACE( ( _T( "CUsbPnAlt::CUsbPnAlt() - return" ) ) );
       
    70     }
       
    71 
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CUsbPnAlt::NewL
       
    75 // Two-phased constructor.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CUsbPnAlt* CUsbPnAlt::NewL( MUsbPnAltObserver& aAltObserver, RDevUsbcClient& aLdd, RIscApi& aIscApi )
       
    79     {
       
    80     OstTrace1( TRACE_NORMAL, CUSBPNALT_NEWL_ENTRY, "CUsbPnAlt::NewL;aAltObserver=%x", ( TUint )&( aAltObserver ) );
       
    81     C_TRACE( ( _T( "CUsbPnAlt::NewL( aAltObserver 0x%x )" ), &aAltObserver ) );
       
    82 
       
    83     CUsbPnAlt* self = new( ELeave ) CUsbPnAlt( aAltObserver, aLdd, aIscApi );
       
    84 
       
    85     OstTrace1( TRACE_NORMAL, CUSBPNALT_NEWL_EXIT, "CUsbPnAlt::NewL - return;self=%x", self );
       
    86     C_TRACE( ( _T( "CUsbPnAlt::NewL() - return 0x%x" ), self ) );
       
    87     return self;
       
    88     }
       
    89 
       
    90 
       
    91 // Destructor
       
    92 CUsbPnAlt::~CUsbPnAlt()
       
    93     {
       
    94     OstTrace0( TRACE_NORMAL, CUSBPNALT_CUSBPNALT_DESTRUCTOR_ENTRY, "CUsbPnAlt::~CUsbPnAlt" );
       
    95     C_TRACE( ( _T( "CUsbPnAlt::~CUsbPnAlt()" ) ) );
       
    96 
       
    97     Cancel();
       
    98 
       
    99     OstTrace0( TRACE_NORMAL, CUSBPNALT_CUSBPNALT_DESTRUCTOR_EXIT, "CUsbPnAlt::~CUsbPnAlt - return" );
       
   100     C_TRACE( ( _T( "CUsbPnAlt::~CUsbPnAlt() - return" ) ) );
       
   101     }
       
   102 
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CUsbPnAlt::ListenStateChange
       
   106 // ?implementation_description
       
   107 // (other items were commented in a header).
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CUsbPnAlt::ListenStateChange( )
       
   111     {
       
   112     OstTrace0( TRACE_NORMAL, CUSBPNALT_LISTENSTATECHANGE_ENTRY, "CUsbPnAlt::ListenStateChange" );
       
   113     C_TRACE( ( _T( "CUsbPnAlt::ListenStateChange()" ) ) );
       
   114 
       
   115     iLdd.AlternateDeviceStatusNotify( iStatus, iState );
       
   116     SetActive();
       
   117 
       
   118     OstTrace0( TRACE_NORMAL, CUSBPNALT_LISTENSTATECHANGE_EXIT, "CUsbPnAlt::ListenStateChange - return void" );
       
   119     C_TRACE( ( _T( "CUsbPnAlt::ListenStateChange() - return void" ) ) );
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CUsbPnAlt::DoCancel
       
   124 // ?implementation_description
       
   125 // (other items were commented in a header).
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 void CUsbPnAlt::DoCancel( )
       
   129     {
       
   130     OstTrace0( TRACE_NORMAL, CUSBPNALT_DOCANCEL_ENTRY, "CUsbPnAlt::DoCancel" );
       
   131     C_TRACE( ( _T( "CUsbPnAlt::DoCancel()" ) ) );
       
   132 
       
   133     iLdd.AlternateDeviceStatusNotifyCancel();
       
   134 
       
   135     OstTrace0( TRACE_NORMAL, CUSBPNALT_DOCANCEL_EXIT, "CUsbPnAlt::DoCancel - return void" );
       
   136     C_TRACE( ( _T( "CUsbPnAlt::DoCancel() - return void" ) ) );
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CUsbPnAlt::RunL
       
   141 // ?implementation_description
       
   142 // (other items were commented in a header).
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CUsbPnAlt::RunL( )
       
   146     {
       
   147     OstTrace1( TRACE_API, CUSBPNALT_RUNL_ENTRY, "CUsbPnAlt::RunL;iStatus=%d", iStatus.Int() );
       
   148     A_TRACE( ( _T( "CUsbPnAlt::RunL() iStatus:%d" ), iStatus.Int() ) );
       
   149 
       
   150     User::LeaveIfError( iStatus.Int() );
       
   151 #ifndef NCP_COMMON_BRIDGE_FAMILY
       
   152     // Check and send control messages.
       
   153     if( !( iState & KUsbAlternateSetting ) ) // KUsbAlternateSetting bit is not set.
       
   154         {
       
   155         switch( iState )
       
   156             {
       
   157             case EUsbcDeviceStateAddress:
       
   158                 {
       
   159                 OstTrace0( TRACE_API, CUSBPNALT_RUNL_DUP1, "CUsbPnAlt::RunL - EUsbcDeviceStateAddress" );
       
   160                 A_TRACE( ( _T( "CUsbPnAlt::RunL - EUsbcDeviceStateAddress")));
       
   161                 SendControlMessage( PNS_USB_CABLE_PLUGGED );
       
   162                 break;
       
   163                 }
       
   164             case EUsbcDeviceStateConfigured:
       
   165                 {
       
   166                 OstTrace0( TRACE_API, CUSBPNALT_RUNL_DUP2, "CUsbPnAlt::RunL - EUsbcDeviceStateConfigured" );
       
   167                 A_TRACE( ( _T( "CUsbPnAlt::RunL - EUsbcDeviceStateConfigured")));
       
   168                 SendControlMessage( PNS_USB_CONNECTED );
       
   169                 break;
       
   170                 }
       
   171             case EUsbcDeviceStateUndefined:
       
   172                 {
       
   173                 OstTrace0( TRACE_API, CUSBPNALT_RUNL_DUP3, "CUsbPnAlt::RunL - EUsbcDeviceStateUndefined" );
       
   174                 A_TRACE( ( _T( "CUsbPnAlt::RunL - EUsbcDeviceStateUndefined")));
       
   175                 SendControlMessage( PNS_USB_CABLE_UNPLUGGED );
       
   176                 break;
       
   177                 }
       
   178             }
       
   179         }
       
   180 #endif /* NCP_COMMON_BRIDGE_FAMILY */
       
   181     iAltObserver.HandleDeviceStateChange( iState );
       
   182 
       
   183     iLdd.AlternateDeviceStatusNotify( iStatus, iState );
       
   184     SetActive();
       
   185 
       
   186     OstTrace0( TRACE_API, CUSBPNALT_RUNL_EXIT, "CUsbPnAlt::RunL - return void");
       
   187     A_TRACE( ( _T( "CUsbPnAlt::RunL() - return void" ) ) );
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CUsbPnAlt::RunError
       
   192 // ?implementation_description
       
   193 // (other items were commented in a header).
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 TInt CUsbPnAlt::RunError( TInt aError )
       
   197     {
       
   198     OstTrace1( TRACE_NORMAL, CUSBPNALT_RUNERROR_ENTRY, "CUsbPnAlt::RunError;aError=%d", aError );
       
   199     C_TRACE( ( _T( "CUsbPnAlt::RunError( aError:%d )" ), aError ) );
       
   200     TRACE_ASSERT_ALWAYS;
       
   201     User::Panic( KUsbPnPanicCat, aError );
       
   202     OstTrace1( TRACE_NORMAL, CUSBPNALT_RUNERROR_EXIT, "CUsbPnAlt::RunError - return;aError=%d", aError );
       
   203     C_TRACE( ( _T( "CUsbPnAlt::RunError() return - aError:%d )" ), aError ) );
       
   204     return aError;
       
   205     }
       
   206 
       
   207 #ifndef NCP_COMMON_BRIDGE_FAMILY
       
   208 // -----------------------------------------------------------------------------
       
   209 // CUsbPnAlt::SendControlMessage
       
   210 // ?implementation_description
       
   211 // (other items were commented in a header).
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CUsbPnAlt::SendControlMessage( const TUint8 aId ) const
       
   215     {
       
   216     C_TRACE( ( _T( "CUsbPnAlt::SendControlMessage( aId:%d )" ), aId ) );
       
   217     OstTrace0( TRACE_API, CUSBPNALT_SENDCONTROLMESSAGE_DUP1, "CUsbPnAlt::SendControlMessage( aId )" );
       
   218 
       
   219     TBuf8< SIZE_PNS_MEDIA_SPECIFIC_REQ > buf;
       
   220     TIsiSend ctrlMsg(buf, 12 );
       
   221     ctrlMsg.Set8bit( ISI_HEADER_OFFSET_SENDERDEVICE, PN_DEV_PC );
       
   222     ctrlMsg.Set8bit( ISI_HEADER_OFFSET_RESOURCEID, PN_MEDIA_CONTROL );
       
   223     ctrlMsg.Set8bit( ISI_HEADER_OFFSET_RECEIVEROBJECT, PN_OBJ_ROUTER );
       
   224     ctrlMsg.Set8bit( ISI_HEADER_OFFSET_TRANSID, 0x00 );
       
   225     ctrlMsg.Set8bit( ISI_HEADER_OFFSET_MESSAGEID, PNS_MEDIA_SPECIFIC_REQ );
       
   226     ctrlMsg.Set8bit( ISI_HEADER_OFFSET_SUBMESSAGEID, PN_MEDIA_USB );
       
   227     ctrlMsg.Set8bit( ISI_HEADER_OFFSET_SUBMESSAGEID + 1, aId );
       
   228     ctrlMsg.Complete();
       
   229 
       
   230     C_TRACE( ( _T( "CUsbPnAlt::SendControlMessage() - Sending...") ) );
       
   231     OstTrace0( TRACE_API, CUSBPNALT_SENDCONTROLMESSAGE_DUP2, "CUsbPnAlt::SendControlMessage() - Sending..." );
       
   232     iIscApi.Send( buf );
       
   233 
       
   234     C_TRACE( ( _T( "CUsbPnAlt::SendControlMessage() - return void") ) );
       
   235     OstTrace0( TRACE_API, CUSBPNALT_SENDCONTROLMESSAGE_DUP3, "CUsbPnAlt::SendControlMessage() - return void" );
       
   236     }
       
   237 
       
   238 #endif /* NCP_COMMON_BRIDGE_FAMILY */
       
   239 
       
   240 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   241 
       
   242 //  End of File