connectivitylayer/isce/p2papi_dll/src/p2pif.cpp
changeset 0 63b37f68c1ce
child 9 8486d82aef45
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 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <p2pif.h>                  // For RP2PIf
       
    22 #include "p2puserapitrace.h"        // For C_TRACE...
       
    23 #include "p2pinternaldefs.h"        // For KP2PDriverName..
       
    24 
       
    25 // CONSTANTS
       
    26 const TInt KConnectionLostArraySize( 1 );
       
    27 const TInt KOpenArraySize( 1 );
       
    28 const TInt KReceiveArraySize( 2 );
       
    29 const TInt KSendArraySize( 1 );
       
    30 const TInt KFirstParam( 0 );
       
    31 const TInt KSecondParam( 1 );
       
    32 
       
    33 enum TP2PApiFaults
       
    34     {
       
    35     EP2PApiDriverLoadFailed = 0x00,
       
    36     EP2PApiCloseFailed,
       
    37     };
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 const TInt KInfoLength( sizeof(TUint8) );
       
    41 
       
    42 EXPORT_C RP2PIf::RP2PIf()
       
    43     {
       
    44 
       
    45     C_TRACE( ( _T( "RP2PIf::RP2PIf<>" ) ) );
       
    46 
       
    47     }
       
    48 
       
    49 
       
    50 EXPORT_C RP2PIf::~RP2PIf()
       
    51     {
       
    52 
       
    53     C_TRACE( ( _T( "RP2PIf::~RP2PIf 0x%x>" ), this ) );
       
    54     Close();
       
    55     C_TRACE( ( _T( "RP2PIf::~RP2PIf 0x%x<" ), this ) );
       
    56 
       
    57     }
       
    58 
       
    59 EXPORT_C void RP2PIf::Close(
       
    60         // None
       
    61         )
       
    62     {
       
    63 
       
    64     C_TRACE( ( _T( "RP2PIf::Close 0x%x>" ), this ) );
       
    65     RHandleBase::Close();
       
    66     C_TRACE( ( _T( "RP2PIf::Close 0x%x<" ), this ) );
       
    67 
       
    68     }
       
    69 
       
    70 EXPORT_C void RP2PIf::ConnectionLost(
       
    71         TRequestStatus& aStatus
       
    72         )
       
    73     {
       
    74 
       
    75     C_TRACE( ( _T( "RP2PIf::ConnectionLost 0x%x>" ), this ) );
       
    76     TAny* params[ KConnectionLostArraySize ];
       
    77     // Set status pending, just in case client haven't done it.
       
    78     aStatus = KRequestPending;
       
    79     params[ KFirstParam ] = reinterpret_cast<TAny*>( &aStatus );
       
    80     DoControl( EP2PAsyncConnectionLost, params );
       
    81     C_TRACE( ( _T( "RP2PIf::ConnectionLost 0x%x<" ), this ) );
       
    82 
       
    83     }
       
    84 
       
    85 EXPORT_C void RP2PIf::ConnectionLostCancel(
       
    86         // None
       
    87         )
       
    88     {
       
    89 
       
    90     C_TRACE( ( _T( "RP2PIf::ConnectionLostCancel 0x%x>" ), this ) );
       
    91     DoCancel( EP2PAsyncConnectionLost );
       
    92     C_TRACE( ( _T( "RP2PIf::ConnectionLostCancel 0x%x<" ), this ) );
       
    93 
       
    94     }
       
    95 
       
    96 EXPORT_C void RP2PIf::Open(
       
    97         const TP2PProtocol aP2PProtocolId,
       
    98         TRequestStatus& aStatus,
       
    99         TOwnerType aType
       
   100         )
       
   101     {
       
   102 
       
   103     C_TRACE( ( _T( "RP2PIf::Open 0x%x 0x%x 0x%x 0x%x>" ), this, aP2PProtocolId, &aStatus, aType ) );
       
   104     // Same driver is used for all P2P protocols, it might be already loaded (KErrAlreadyExists), that is ok.
       
   105     TInt loadStatus( User::LoadLogicalDevice( KP2PDriverLddBinaryName ) );
       
   106     C_TRACE( ( _T( "RP2PIf::Open devicedriver loaded %d" ), loadStatus ) );
       
   107     ASSERT_PANIC_ALWAYS( ( KErrNone == loadStatus || KErrAlreadyExists == loadStatus), EP2PApiDriverLoadFailed );
       
   108     TInt error( KErrInUse );
       
   109     C_TRACE( ( _T( "RP2PIf::Open ldd" ) ) );
       
   110     TBuf8<KInfoLength> info;
       
   111     info.Append( aP2PProtocolId );
       
   112     // TODO: check wrong usage of driver load differently than from here
       
   113     // KErrPermissionDenied( no capabilities) ,  KErrNotSupported (Wrong protocol id), KErrGeneral (DThread::Open), 
       
   114     // KErrAlreadyExists same object had opened the interface with some other protocolid
       
   115     error = DoCreate( KP2PDriverName, 
       
   116                       TVersion(), 
       
   117                       KNullUnit, 
       
   118                       NULL, 
       
   119                       &info, 
       
   120                       aType );
       
   121     if( KErrNone != error )
       
   122         {
       
   123         C_TRACE( ( _T( "RP2PIf::Open 0x%x failed 0x%x error %d" ), this, aP2PProtocolId, error ) );
       
   124         TRequestStatus* ptrStatus = &aStatus;
       
   125         User::RequestComplete( ptrStatus, error );
       
   126         }
       
   127     else
       
   128         {
       
   129         C_TRACE( ( _T( "RP2PIf::Open 0x%x aP2PProtocolId 0x%x" ), this, aP2PProtocolId ) );
       
   130         aStatus = KRequestPending;
       
   131         TAny* params[ KOpenArraySize ];
       
   132         params[ KFirstParam ] = reinterpret_cast< TAny* >( &aStatus );
       
   133         // KErrInUse (protocol id already used)
       
   134         error = DoControl( EP2PAsyncOpen, params );
       
   135         TRACE_ASSERT_ALWAYS_COND( KErrNone == error );
       
   136         }
       
   137     C_TRACE( ( _T( "RP2PIf::Open 0x%x 0x%x 0x%x 0x%x<" ), this, aP2PProtocolId, &aStatus, aType ) );
       
   138 
       
   139     }
       
   140 
       
   141 EXPORT_C void RP2PIf::OpenCancel(
       
   142         // None
       
   143         )
       
   144     {
       
   145 
       
   146     C_TRACE( ( _T( "RP2PIf::OpenCancel 0x%x>" ), this ) );
       
   147     DoCancel( EP2PAsyncOpen );
       
   148     Close();
       
   149     C_TRACE( ( _T( "RP2PIf::OpenCancel 0x%x<" ), this ) );
       
   150 
       
   151     }
       
   152 
       
   153 EXPORT_C void RP2PIf::Receive(
       
   154         TRequestStatus& aStatus,
       
   155         TDes8& aReceiveBuffer
       
   156         )
       
   157     {
       
   158 
       
   159     C_TRACE( ( _T( "RP2PIf::Receive 0x%x 0x%x 0x%x>" ), this, &aStatus, &aReceiveBuffer ) );
       
   160     TAny* params[ KReceiveArraySize ];
       
   161     // Set status pending, just in case client haven't done it.
       
   162     aStatus = KRequestPending;
       
   163     params[ KFirstParam ] = reinterpret_cast<TAny*>( &aStatus );
       
   164     params[ KSecondParam ] = reinterpret_cast<TAny*>( &aReceiveBuffer );
       
   165     DoControl( EP2PAsyncReceive, params );
       
   166     C_TRACE( ( _T( "RP2PIf::Receive 0x%x 0x%x 0x%x<" ), this, &aStatus, &aReceiveBuffer ) );
       
   167 
       
   168     }
       
   169 
       
   170 EXPORT_C void RP2PIf::ReceiveCancel(
       
   171         // None
       
   172         )
       
   173     {
       
   174 
       
   175     C_TRACE( ( _T( "RP2PIf::ReceiveCancel 0x%x>"), this ) );
       
   176     DoCancel( EP2PAsyncReceive );
       
   177     C_TRACE( ( _T( "RP2PIf::ReceiveCancel 0x%x<"), this ) );
       
   178 
       
   179     }
       
   180 
       
   181 EXPORT_C TInt RP2PIf::Send(
       
   182         const TDesC8& aSendBuffer
       
   183         )
       
   184     {
       
   185 
       
   186     C_TRACE( ( _T( "RP2PIf::Send 0x%x 0x%x>" ), this, &aSendBuffer ) );
       
   187     TAny* params[ KSendArraySize ];
       
   188     params[ KFirstParam ] = reinterpret_cast<TAny*>( const_cast<TDesC8*>( &aSendBuffer ));
       
   189     TInt sendResult = DoControl( EP2PSend, params );
       
   190     C_TRACE( ( _T( "RP2PIf::Send 0x%x %d<" ), this, sendResult ) );
       
   191     return sendResult;
       
   192 
       
   193     }
       
   194 
       
   195 //  End of File
       
   196