|
1 // Copyright (c) 2007-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 // IPProto demultiplexor implementation |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include <nifmbuf.h> |
|
24 #include "IPProtoDeMux.h" |
|
25 |
|
26 CIPProtoBinder::CIPProtoBinder(CIPShimSubConnectionFlow& aFlow) |
|
27 :iBinderControl(NULL), |
|
28 iLowerControl(NULL), |
|
29 iFlow(aFlow), |
|
30 iNif(NULL) |
|
31 { |
|
32 |
|
33 } |
|
34 |
|
35 |
|
36 CIPProtoBinder* CIPProtoBinder::NewL(CIPShimSubConnectionFlow& aFlow, const TDesC8& aProtocolName) |
|
37 { |
|
38 CIPProtoBinder* me = new (ELeave) CIPProtoBinder(aFlow); |
|
39 me->SetProtocolName(aProtocolName); |
|
40 return me; |
|
41 } |
|
42 |
|
43 void CIPProtoBinder::StartL() |
|
44 { |
|
45 ASSERT(iNif); |
|
46 iNif->StartL(); |
|
47 } |
|
48 |
|
49 CIPProtoBinder::~CIPProtoBinder() |
|
50 { |
|
51 ASSERT(iNif == NULL); // should have been unbound by this stage |
|
52 } |
|
53 |
|
54 void CIPProtoBinder::BindL(CIPShimIfBase* aNif) |
|
55 { |
|
56 __CFLOG_2(KIPProtoTag1, KIPProtoTag2, _L("CIPProtoBinder %08x:\tBindL(%08x)"), this, aNif); |
|
57 ASSERT(iNif == NULL); // shouldn't be binding twice |
|
58 iNif = aNif; |
|
59 } |
|
60 |
|
61 void CIPProtoBinder::Unbind() |
|
62 { |
|
63 __CFLOG_1(KIPProtoTag1, KIPProtoTag2, _L("CIPProtoBinder %08x:\tUnbind()"), this); |
|
64 ASSERT(iNif); |
|
65 iNif = NULL; |
|
66 } |
|
67 |
|
68 void CIPProtoBinder::BindToLowerFlowL(ESock::MFlowBinderControl& aLowerBinderControl) |
|
69 { |
|
70 ASSERT(iNif); |
|
71 |
|
72 __CFLOG_2(KIPProtoTag1, KIPProtoTag2, _L8("CIPProtoBinder %08x:\tBindToLowerFlowL(): protocol '%S'"), this, &iNif->ProtocolName()); |
|
73 |
|
74 iBinderControl = &aLowerBinderControl; |
|
75 iLowerControl = iBinderControl->GetControlL(iNif->ProtocolName()); |
|
76 iLowerDataSender = iBinderControl->BindL(iNif->ProtocolName(), this, this); |
|
77 } |
|
78 |
|
79 void CIPProtoBinder::UnbindFromLowerFlow() |
|
80 { |
|
81 __CFLOG_1(KIPProtoTag1, KIPProtoTag2, _L("CIPProtoBinder %08x:\tUnbindFromLowerFlow()"), this); |
|
82 |
|
83 if (!iBinderControl) |
|
84 return; |
|
85 |
|
86 iBinderControl->Unbind(this, this); |
|
87 iBinderControl = NULL; |
|
88 |
|
89 iLowerControl = NULL; |
|
90 iLowerDataSender = NULL; |
|
91 } |
|
92 |
|
93 //-========================================= |
|
94 // MUpperDataReceiver methods |
|
95 //-========================================= |
|
96 void CIPProtoBinder::Process(RMBufChain& aData) |
|
97 { |
|
98 if (iNif) |
|
99 { |
|
100 ASSERT(iNif->iUpperProtocol); |
|
101 iNif->iUpperProtocol->Process(aData, reinterpret_cast<CProtocolBase*>(iNif)); |
|
102 } |
|
103 } |
|
104 |
|
105 //-========================================= |
|
106 // MUpperControl methods |
|
107 //-========================================= |
|
108 void CIPProtoBinder::StartSending() |
|
109 { |
|
110 __CFLOG_1(KIPProtoTag1, KIPProtoTag2, _L("CIPProtoBinder %08x:\tStartSending()"), this); |
|
111 Flow().BinderReady(); |
|
112 iNif->StartSending(); |
|
113 } |
|
114 |
|
115 void CIPProtoBinder::Error(TInt aError) |
|
116 { |
|
117 __CFLOG_2(KIPProtoTag1, KIPProtoTag2, _L("CIPProtoBinder %08x:\tError(%d)"), this, aError); |
|
118 Flow().BinderError(aError, this); |
|
119 } |
|
120 //-========================================= |
|
121 // MLowerDataSender methods |
|
122 //-========================================= |
|
123 ESock::MLowerDataSender::TSendResult CIPProtoBinder::Send(RMBufChain& aData) |
|
124 { |
|
125 return iLowerDataSender->Send(aData); |
|
126 } |
|
127 |
|
128 //-========================================= |
|
129 // MLowerControl methods |
|
130 //-========================================= |
|
131 TInt CIPProtoBinder::GetName(TDes& aName) |
|
132 { |
|
133 return iLowerControl->GetName(aName); |
|
134 } |
|
135 |
|
136 TInt CIPProtoBinder::BlockFlow(TBlockOption aOption) |
|
137 { |
|
138 __CFLOG_2(KIPProtoTag1, KIPProtoTag2, _L("CIPProtoBinder %08x:\tBlockFlow(%d)"), this, aOption); |
|
139 return iLowerControl->BlockFlow(aOption); |
|
140 } |
|
141 TInt CIPProtoBinder::GetConfig(TBinderConfig& aConfig) |
|
142 { |
|
143 return iLowerControl->GetConfig(aConfig); |
|
144 } |
|
145 |
|
146 TInt CIPProtoBinder::Control(TUint aLevel, TUint aName, TDes8& aOption) |
|
147 { |
|
148 return iLowerControl->Control(aLevel, aName, aOption); |
|
149 } |
|
150 |
|
151 //-========================================= |
|
152 void CIPProtoBinder::SetProtocolName(const TDesC8& aProtocol) |
|
153 { |
|
154 iProtocolName.Copy(aProtocol); |
|
155 } |
|
156 |
|
157 |
|
158 const TDesC8& CIPProtoBinder::ProtocolName() |
|
159 { |
|
160 ASSERT(iProtocolName.Length()); |
|
161 return iProtocolName; |
|
162 } |