connectivitylayer/isce/isirouter_dll/src/isilink.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 #include <kernel.h>             // For Kern
       
    20 #include "isilink.h"            // For DISILink
       
    21 #include "iscedefs.h"           // For EMuxISI...
       
    22 #include "mlinkmuxif.h"         // For MLinkMuxIf
       
    23 #include "isiroutertrace.h"     // For C_TRACE, ASSERT_RESET.. and fault codes
       
    24 #include "misilinkrouterif.h"   // For MISILinkRouterIf
       
    25 #include "isihelpers.h"         // For ISI_HEADER_OFFSET_MEDIA
       
    26 
       
    27 
       
    28 // Faults
       
    29 enum TISILinkFaults
       
    30     {
       
    31     EISILinkNullPtr = 0x01,
       
    32     EISILinkMemAllocFailed,
       
    33     EISILinkInitFailed,
       
    34     EISILinkInitFailed2,
       
    35     EISILinkRegisterFailed,
       
    36     EISILinkWrongMedia,
       
    37     EISILinkTrxPresenceSyncFailed,
       
    38     };
       
    39 
       
    40 
       
    41 MISIRouterLinkIf* MISIRouterLinkIf::CreateLinkF(
       
    42         MISILinkRouterIf* aRouter,
       
    43         const TUint8 aMediaId,
       
    44         const TUint8 aTrxId
       
    45         )
       
    46     {
       
    47     C_TRACE( ( _T( "MISIRouterLinkIf::CreateLinkF 0x%x %d %d>" ), aRouter, aMediaId, aTrxId ) );
       
    48     ASSERT_RESET_ALWAYS( aRouter, ( EISILinkNullPtr | EDISILinkTraceId << KClassIdentifierShift ) );
       
    49     DISILink* link = new DISILink( aRouter, aMediaId, aTrxId );
       
    50     ASSERT_RESET_ALWAYS( link, ( EISILinkMemAllocFailed | EDISILinkTraceId << KClassIdentifierShift ) );
       
    51     C_TRACE( ( _T( "MISIRouterLinkIf::CreateLinkF 0x%x %d %d created 0x%x<" ), aRouter, aMediaId, aTrxId, link ) );
       
    52     return link;
       
    53     }
       
    54 
       
    55 DISILink::DISILink(
       
    56         ) : iRouter( NULL ),
       
    57             iMux( NULL ),
       
    58             iTrxPresent( EFalse )
       
    59     {
       
    60     C_TRACE( ( _T( "DISILink::DISILink 0x%x>" ), this ) );
       
    61     iMediaId = 0; // TODO change to PN_MEDIA_NOT_USED when bridge supports this
       
    62     C_TRACE( ( _T( "DISILink::DISILink 0x%x<" ), this ) );
       
    63     }
       
    64 
       
    65 DISILink::DISILink(
       
    66         MISILinkRouterIf* aRouter,
       
    67         const TUint8 aMediaId,
       
    68         const TUint8 aTrxId
       
    69         ) : iRouter( aRouter ),
       
    70             iMediaId( aMediaId ),
       
    71             iTrxId( aTrxId )
       
    72     {
       
    73     C_TRACE( ( _T( "DISILink::DISILink 0x%x mediaid %d trxid %d>" ), this, aMediaId, aTrxId ) );
       
    74     // ISI Media
       
    75     iMux = MLinkMuxIf::Register( this, aTrxId, EMuxISI );
       
    76     ASSERT_RESET_ALWAYS( aRouter, ( EISILinkRegisterFailed | EDISILinkTraceId << KClassIdentifierShift ) );
       
    77     C_TRACE( ( _T( "DISILink::DISILink 0x%x mediaid %d trxid %d<" ), this, iMediaId, iTrxId ) );
       
    78     }
       
    79 
       
    80 DISILink::~DISILink()
       
    81     {
       
    82     C_TRACE( ( _T( "DISILink::~DISILink 0x%x>" ), this ) );
       
    83     iMux = NULL;
       
    84     iRouter = NULL;
       
    85     C_TRACE( ( _T( "DISILink::~DISILink 0x%x<" ), this ) );
       
    86     }
       
    87 
       
    88 // From MMuxLinkIf start
       
    89 void DISILink::Receive(
       
    90         TDes8& aMsg
       
    91         )
       
    92     {
       
    93     C_TRACE( ( _T( "DISILink::Receive 0x%x 0x%x>" ), this, &aMsg ) );
       
    94     ASSERT_RESET_ALWAYS( iMux, ( EISILinkInitFailed | EDISILinkTraceId << KClassIdentifierShift ) );
       
    95     ASSERT_RESET_ALWAYS( aMsg.Ptr()[ ISI_HEADER_OFFSET_MEDIA ] == iMediaId, ( EISILinkWrongMedia | aMsg.Ptr()[ 0 ] << KMediaIdShift | EDISILinkTraceId << KClassIdentifierShift ) );
       
    96     iRouter->RouteISIMessage( aMsg );
       
    97     C_TRACE( ( _T( "DISILink::Receive 0x%x 0x%x<" ), this, &aMsg ) );
       
    98     }
       
    99 
       
   100 /*
       
   101 * Called with FM held, no blocking no nesting of FMs and no allocation.
       
   102 */
       
   103 void DISILink::EnqueTrxPresenceChangedDfc(
       
   104         TBool aPresent
       
   105         )
       
   106     {
       
   107     // No traces allowed due to not allowed to block.
       
   108     ASSERT_RESET_ALWAYS( ( iTrxPresent != aPresent ), ( EISILinkTrxPresenceSyncFailed | EDISILinkTraceId << KClassIdentifierShift ) );
       
   109     iTrxPresent = aPresent;
       
   110     }
       
   111 // From MMuxLinkIf end
       
   112 
       
   113 // From MISIRouterLinkIf start
       
   114 void DISILink::Release(
       
   115         // None
       
   116         )
       
   117     {
       
   118     C_TRACE( ( _T( "DISILink::Release 0x%x>" ), this ) );
       
   119     delete this;
       
   120     C_TRACE( ( _T( "DISILink::Release 0x%x<" ), this ) );
       
   121     }
       
   122 
       
   123 TBool DISILink::Send(
       
   124         TDes8& aMsg
       
   125         )
       
   126     {
       
   127     C_TRACE( ( _T( "DISILink::Send 0x%x 0x%x>" ), this, &aMsg  ) );
       
   128     ASSERT_RESET_ALWAYS( iMux, ( EISILinkInitFailed2 | EDISILinkTraceId << KClassIdentifierShift ) );
       
   129     if( iTrxPresent )
       
   130         {
       
   131         TUint8* msgPtr = const_cast<TUint8*>( aMsg.Ptr() );
       
   132         msgPtr[ ISI_HEADER_OFFSET_MEDIA ] = iMediaId;
       
   133         // Send with default prio.
       
   134         iMux->Send( aMsg, EMuxISI );
       
   135         C_TRACE( ( _T( "DISILink::Send ok 0x%x %d 0x%x<" ), this, iTrxPresent, &aMsg) );
       
   136         return ETrue;
       
   137         }
       
   138     C_TRACE( ( _T( "DISILink::Send failed 0x%x %d 0x%x<" ), this, iTrxPresent, &aMsg) );
       
   139     return EFalse;
       
   140     }
       
   141 // From MISIRouterLinkIf end