|
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 <kernel.h> // For Kern |
|
21 |
|
22 #include "p2plink.h" // For DP2PLink |
|
23 #include "p2proutertrace.h" // For C_TRACE.. |
|
24 #include "mlinkmuxif.h" // For MLinkMuxIf |
|
25 #include "iscedefs.h" // For EMuxAmountOfProtocols |
|
26 #include "p2pdefs.h" // For EP2PAmountOfProtocols |
|
27 #include "trxdefs.h" // For EAmountOfTrxs |
|
28 |
|
29 // Faults |
|
30 enum TP2PLinkFaults |
|
31 { |
|
32 EP2PLinkNullPtr = 0x00, |
|
33 EP2PMemAllocFailed, |
|
34 EP2PInitFailed, |
|
35 EP2PInitFailed2, |
|
36 EP2PRegisterFailed, |
|
37 }; |
|
38 |
|
39 // Macros |
|
40 // Because P2P ids are different than multiplexing ids they had to be mapped. |
|
41 // There is other than P2P protocols multiplexed and they shall not be visible |
|
42 // in P2P routing nor API. |
|
43 #define MAP_P2P_TO_MUX( aP2PId )( aP2PId + ( EMuxAmountOfProtocols - EP2PAmountOfProtocols ) ) |
|
44 #define MAP_MUX_TO_P2P( aMuxId )( aMuxId - ( EMuxAmountOfProtocols - EP2PAmountOfProtocols ) ) |
|
45 |
|
46 MP2PRouterLinkIf* MP2PRouterLinkIf::CreateLinkF( |
|
47 MP2PLinkRouterIf* aRouter, |
|
48 const TUint8 aProtocolId, |
|
49 const TUint8 aTrxId |
|
50 ) |
|
51 { |
|
52 |
|
53 C_TRACE( ( _T( "MP2PRouterLinkIf::CreateLinkF 0x%x %d %d>" ), aRouter, aProtocolId, aTrxId ) ); |
|
54 ASSERT_RESET_ALWAYS( aRouter, ( EP2PLinkNullPtr | EDP2PLinkTraceId << KClassIdentifierShift ) ); |
|
55 DP2PLink* link = new DP2PLink( aRouter, aProtocolId, aTrxId ); |
|
56 ASSERT_RESET_ALWAYS( aRouter, ( EP2PMemAllocFailed | EDP2PLinkTraceId << KClassIdentifierShift ) ); |
|
57 C_TRACE( ( _T( "MP2PRouterLinkIf::CreateLinkF 0x%x %d %d created 0x%x<" ), aRouter, aProtocolId, aTrxId, link ) ); |
|
58 return link; |
|
59 |
|
60 } |
|
61 |
|
62 DP2PLink::DP2PLink( |
|
63 ) : iRouter( NULL ) |
|
64 { |
|
65 |
|
66 C_TRACE( ( _T( "DP2PLink::DP2PLink 0x%x>" ), this ) ); |
|
67 iProtocolId = 0x00; |
|
68 iShTrxId = 0x00; |
|
69 iMux = NULL; |
|
70 C_TRACE( ( _T( "DP2PLink::DP2PLink 0x%x<" ), this ) ); |
|
71 |
|
72 } |
|
73 |
|
74 DP2PLink::DP2PLink( |
|
75 MP2PLinkRouterIf* aRouter, |
|
76 const TUint8 aProtocolId, |
|
77 const TUint8 aTrxId |
|
78 ) : iRouter( aRouter ) |
|
79 { |
|
80 |
|
81 C_TRACE( ( _T( "DP2PLink::DP2PLink 0x%x protid %d map %d trxid %d>" ), this, aProtocolId, iProtocolId, aTrxId ) ); |
|
82 // Map from Point-to-point protocol to multiplexing protocol. |
|
83 iProtocolId = MAP_P2P_TO_MUX( aProtocolId ); |
|
84 iShTrxId = ~aTrxId; |
|
85 iMux = MLinkMuxIf::Register( this, aTrxId, iProtocolId ); |
|
86 ASSERT_RESET_ALWAYS( aRouter, ( EP2PRegisterFailed | EDP2PLinkTraceId << KClassIdentifierShift ) ); |
|
87 C_TRACE( ( _T( "DP2PLink::DP2PLink 0x%x protid %d map %d trxid %d<" ), this, aProtocolId, iProtocolId, aTrxId ) ); |
|
88 |
|
89 } |
|
90 |
|
91 DP2PLink::~DP2PLink() |
|
92 { |
|
93 |
|
94 C_TRACE( ( _T( "DP2PLink::~DP2PLink 0x%x>" ), this ) ); |
|
95 C_TRACE( ( _T( "DP2PLink::~DP2PLink 0x%x<" ), this ) ); |
|
96 |
|
97 } |
|
98 |
|
99 |
|
100 // From MMuxLinkIf start |
|
101 void DP2PLink::Receive( |
|
102 TDes8& aMsg |
|
103 ) |
|
104 { |
|
105 |
|
106 C_TRACE( ( _T( "DP2PLink::Receive 0x%x 0x%x id %d>" ), this, &aMsg, iProtocolId ) ); |
|
107 ASSERT_RESET_ALWAYS( iMux, ( EP2PInitFailed | EDP2PLinkTraceId << KClassIdentifierShift ) ); |
|
108 iRouter->Receive( aMsg, MAP_MUX_TO_P2P( iProtocolId ) ); |
|
109 C_TRACE( ( _T( "DP2PLink::Receive 0x%x 0x%x id %d<" ), this, &aMsg, iProtocolId ) ); |
|
110 |
|
111 } |
|
112 |
|
113 /* |
|
114 * Called with FM held, no blocking no nesting of FMs and no allocation. |
|
115 */ |
|
116 void DP2PLink::EnqueTrxPresenceChangedDfc( |
|
117 TBool aPresent |
|
118 ) |
|
119 { |
|
120 |
|
121 // No traces allowed due to not allowed to block. |
|
122 // Negation sets variable to be over EAmountOfTrxs if it is not present. |
|
123 iShTrxId = ~iShTrxId;// TODO: check this atomicity and synch if needed |
|
124 iRouter->NotifyTrxPresenceEnqueDfc( aPresent ); |
|
125 |
|
126 } |
|
127 // From MMuxLinkIf end |
|
128 |
|
129 // From MP2PRouterLinkIf start |
|
130 TBool DP2PLink::TrxPresent() |
|
131 { |
|
132 |
|
133 C_TRACE( ( _T( "DP2PLink::TrxPresent 0x%x>" ), this ) ); |
|
134 // Amount of trx shall always be less than the negative |
|
135 TBool value( iShTrxId < EAmountOfTrxs ? ETrue : EFalse ); |
|
136 C_TRACE( ( _T( "DP2PLink::TrxPresent 0x%x %d<" ), this, value ) ); |
|
137 return value; |
|
138 |
|
139 } |
|
140 |
|
141 void DP2PLink::Release( |
|
142 // None |
|
143 ) |
|
144 { |
|
145 |
|
146 C_TRACE( ( _T( "DP2PLink::Release 0x%x>" ), this ) ); |
|
147 delete this; |
|
148 C_TRACE( ( _T( "DP2PLink::Release 0x%x<" ), this ) ); |
|
149 |
|
150 } |
|
151 |
|
152 void DP2PLink::Send( |
|
153 TDes8& aMsg |
|
154 ) |
|
155 { |
|
156 |
|
157 C_TRACE( ( _T( "DP2PLink::Send 0x%x 0x%x map %d <>" ), this, &aMsg, iProtocolId ) ); |
|
158 ASSERT_RESET_ALWAYS( iMux, ( EP2PInitFailed2 | EDP2PLinkTraceId << KClassIdentifierShift ) ); |
|
159 // Send with default prio. |
|
160 iMux->Send( aMsg, iProtocolId ); // TODO: send priorities |
|
161 |
|
162 } |
|
163 |
|
164 // From MP2PRouterLinkIf end |
|
165 |