|
1 // Copyright (c) 1997-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 // Comms reader and writer mixin |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 |
|
23 #include <nifutl.h> |
|
24 #include "NI_STD.H" |
|
25 #include "Ni_Log.h" |
|
26 #include "bcacontrol.h" |
|
27 |
|
28 NONSHARABLE_CLASS(CCommReaderV2) : public CActive |
|
29 /** |
|
30 @internalComponent |
|
31 */ |
|
32 { |
|
33 friend class MCommV2; |
|
34 public: |
|
35 CCommReaderV2(MCommV2* aComm, TInt aPriority); |
|
36 virtual ~CCommReaderV2(); |
|
37 virtual void RunL(); |
|
38 virtual void DoCancel(); |
|
39 private: |
|
40 void CompleteNow(TInt aError); |
|
41 private: |
|
42 MCommV2 *iComm; |
|
43 }; |
|
44 |
|
45 NONSHARABLE_CLASS(CCommWriterV2) : public CActive |
|
46 /** |
|
47 @internalComponent |
|
48 */ |
|
49 { |
|
50 friend class MCommV2; |
|
51 public: |
|
52 CCommWriterV2(MCommV2* aComm, TInt aPriority); |
|
53 virtual ~CCommWriterV2(); |
|
54 virtual void RunL(); |
|
55 virtual void DoCancel(); |
|
56 private: |
|
57 void CompleteNow(TInt aError); |
|
58 private: |
|
59 MCommV2 *iComm; |
|
60 }; |
|
61 |
|
62 #if !defined(__EABI__) && !defined(__X86GCC__) |
|
63 EXPORT_C MCommV2::MCommV2() |
|
64 /** |
|
65 Constructor |
|
66 */ |
|
67 { |
|
68 } |
|
69 #endif |
|
70 |
|
71 EXPORT_C void MCommV2::CommDelete() |
|
72 { |
|
73 LOG( NifmanLog::Printf(_L("MCommV2 %08x:\tCommDelete()"), this); ) |
|
74 delete iCommReader; |
|
75 iCommReader = NULL; |
|
76 delete iCommWriter; |
|
77 iCommWriter = NULL; |
|
78 delete iBcaControl; |
|
79 iBcaControl = NULL; |
|
80 } |
|
81 |
|
82 |
|
83 EXPORT_C TInt MCommV2::CommOpen(const TDesC& aChannelId) |
|
84 { |
|
85 iChannelId = aChannelId; |
|
86 LOG( NifmanLog::Printf(_L("MCommV2 %08x:\tCommOpen('%S')"), this, &aChannelId); ) |
|
87 TRAPD(err, iBcaControl->StartLoadL();); |
|
88 LOG( |
|
89 if (err != KErrNone) |
|
90 { |
|
91 NifmanLog::Printf(_L("MCommV2 %08x:\tCommOpen() returned error %d"), this, err); |
|
92 } |
|
93 ) |
|
94 return err; |
|
95 } |
|
96 |
|
97 EXPORT_C void MCommV2::CommClose() |
|
98 { |
|
99 LOG( NifmanLog::Printf(_L("MCommV2 %08x:\tCommClose()"), this); ) |
|
100 iCommReader->Cancel(); |
|
101 iCommWriter->Cancel(); |
|
102 iBcaControl->Shutdown(KErrNone); |
|
103 iChannelId.Zero(); |
|
104 } |
|
105 |
|
106 EXPORT_C void MCommV2::CommConstructL(TInt aReadPriority, TInt aWritePriority) |
|
107 { |
|
108 iCommReader = new (ELeave) CCommReaderV2(this, aReadPriority); |
|
109 iCommWriter = new (ELeave) CCommWriterV2(this, aWritePriority); |
|
110 iBcaControl = new (ELeave) CScriptBcaControl (this); |
|
111 } |
|
112 |
|
113 EXPORT_C void MCommV2::CommWrite(const TDesC8& aDes) |
|
114 { |
|
115 __ASSERT_ALWAYS(iCommWriter!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
116 __ASSERT_ALWAYS(iBca!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
117 iBca->Write(iCommWriter->iStatus, aDes); |
|
118 iCommWriter->SetActive(); |
|
119 } |
|
120 |
|
121 EXPORT_C void MCommV2::CommWriteReady() |
|
122 { |
|
123 __ASSERT_ALWAYS(iCommWriter!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
124 __ASSERT_ALWAYS(iBca!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
125 iBca->Write(iCommWriter->iStatus, TPtrC8(NULL, 0)); |
|
126 iCommWriter->SetActive(); |
|
127 } |
|
128 |
|
129 EXPORT_C TBool MCommV2::CommIsWriting() const |
|
130 { |
|
131 |
|
132 return iCommWriter->IsActive(); |
|
133 } |
|
134 |
|
135 EXPORT_C void MCommV2::CommRead(TDes8& aDes) |
|
136 { |
|
137 __ASSERT_ALWAYS(iCommReader!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
138 __ASSERT_ALWAYS(iBca!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
139 iBca->Read(iCommReader->iStatus, aDes); |
|
140 iCommReader->SetActive(); |
|
141 } |
|
142 |
|
143 EXPORT_C void MCommV2::CommReadOneOrMore(TDes8& aDes) |
|
144 { |
|
145 __ASSERT_ALWAYS(iCommReader!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
146 __ASSERT_ALWAYS(iBca!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
147 iBca->Read(iCommReader->iStatus, aDes); |
|
148 iCommReader->SetActive(); |
|
149 } |
|
150 |
|
151 EXPORT_C void MCommV2::CommReadReady() |
|
152 { |
|
153 __ASSERT_ALWAYS(iCommReader!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
154 iCommReader->SetActive(); |
|
155 } |
|
156 |
|
157 EXPORT_C TBool MCommV2::CommIsReading() const |
|
158 { |
|
159 |
|
160 return iCommReader->IsActive(); |
|
161 } |
|
162 |
|
163 EXPORT_C void MCommV2::CommCancel() |
|
164 { |
|
165 if (iCommWriter) |
|
166 iCommWriter->Cancel(); |
|
167 if (iCommReader) |
|
168 iCommReader->Cancel(); |
|
169 if (iBcaControl) |
|
170 { |
|
171 iBcaControl->Cancel(); |
|
172 } |
|
173 } |
|
174 |
|
175 EXPORT_C void MCommV2::CommWriteCancel() |
|
176 { |
|
177 if (iCommWriter) |
|
178 iCommWriter->Cancel(); |
|
179 } |
|
180 |
|
181 EXPORT_C void MCommV2::CommReadCancel() |
|
182 { |
|
183 if (iCommReader) |
|
184 iCommReader->Cancel(); |
|
185 } |
|
186 |
|
187 EXPORT_C const TDesC& MCommV2::BcaName() |
|
188 { |
|
189 return BcaStack(); |
|
190 } |
|
191 |
|
192 EXPORT_C void MCommV2::SetBca(BasebandChannelAdaptation::MBca* aBca) |
|
193 { |
|
194 iBca = aBca; |
|
195 } |
|
196 EXPORT_C const TDesC& MCommV2::Port() |
|
197 { |
|
198 return iChannelId; |
|
199 } |
|
200 |
|
201 // |
|
202 |
|
203 CCommWriterV2::CCommWriterV2(MCommV2* aComm, TInt aPriority) |
|
204 : CActive(aPriority), iComm(aComm) |
|
205 { |
|
206 CActiveScheduler::Add(this); |
|
207 } |
|
208 |
|
209 CCommWriterV2::~CCommWriterV2() |
|
210 { |
|
211 Cancel(); |
|
212 } |
|
213 |
|
214 void CCommWriterV2::RunL() |
|
215 { |
|
216 iComm->CommWriteCancel(); |
|
217 iComm->CommWriteComplete(iStatus.Int()); |
|
218 } |
|
219 |
|
220 void CCommWriterV2::DoCancel() |
|
221 { |
|
222 __ASSERT_ALWAYS(iComm->iBca!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
223 iComm->iBca->CancelWrite(); |
|
224 } |
|
225 |
|
226 void CCommWriterV2::CompleteNow(TInt aError) |
|
227 { |
|
228 TRequestStatus* statusPtr=&iStatus; |
|
229 User::RequestComplete(statusPtr,aError); |
|
230 } |
|
231 |
|
232 // |
|
233 |
|
234 CCommReaderV2::CCommReaderV2(MCommV2* aComm, TInt aPriority) |
|
235 : CActive(aPriority), iComm(aComm) |
|
236 { |
|
237 CActiveScheduler::Add(this); |
|
238 } |
|
239 |
|
240 CCommReaderV2::~CCommReaderV2() |
|
241 { |
|
242 Cancel(); |
|
243 } |
|
244 |
|
245 void CCommReaderV2::RunL() |
|
246 { |
|
247 iComm->CommReadCancel(); |
|
248 iComm->CommReadComplete(iStatus.Int()); |
|
249 } |
|
250 |
|
251 void CCommReaderV2::DoCancel() |
|
252 { |
|
253 __ASSERT_ALWAYS(iComm->iBca!=NULL, NetUtilPanic(ENuPanic_NotConstructed)); |
|
254 iComm->iBca->CancelRead(); |
|
255 } |
|
256 |
|
257 void CCommReaderV2::CompleteNow(TInt aError) |
|
258 { |
|
259 TRequestStatus* statusPtr=&iStatus; |
|
260 User::RequestComplete(statusPtr,aError); |
|
261 } |
|
262 |