|
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 "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 #include <e32cons.h> |
|
19 #include <e32base.h> |
|
20 |
|
21 #include "logging.h" |
|
22 #include "portreader.h" |
|
23 |
|
24 |
|
25 |
|
26 CPortReader* CPortReader::NewL(RComm& aPort) |
|
27 { |
|
28 LOG_MSG("CPortReader::NewL"); |
|
29 |
|
30 CPortReader* self = new(ELeave) CPortReader(aPort); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CPortReader::CPortReader(RComm& aPort) |
|
38 : CActive(CActive::EPriorityStandard), |
|
39 iPort(aPort), |
|
40 iAlreadyReading(EFalse) |
|
41 { |
|
42 LOG_MSG("CPortReader::CPortReader"); |
|
43 |
|
44 } |
|
45 |
|
46 CPortReader::~CPortReader() |
|
47 { |
|
48 LOG_MSG("CPortReader::~CPortReader"); |
|
49 |
|
50 Cancel(); |
|
51 |
|
52 } |
|
53 |
|
54 void CPortReader::ConstructL() |
|
55 { |
|
56 LOG_MSG("CPortReader::ConstructL"); |
|
57 |
|
58 CActiveScheduler::Add(this); |
|
59 } |
|
60 |
|
61 void CPortReader::StartRead(MDataListener* aListener) |
|
62 { |
|
63 LOG_MSG("CPortReader::StartRead"); |
|
64 |
|
65 if (iAlreadyReading) |
|
66 return; |
|
67 |
|
68 iListener = aListener; |
|
69 |
|
70 IssueReadRequest(); |
|
71 iAlreadyReading = ETrue; |
|
72 } |
|
73 |
|
74 void CPortReader::IssueReadRequest() |
|
75 { |
|
76 LOG_MSG("CPortReader::IssueReadRequest"); |
|
77 |
|
78 iNextReadChar = 0; |
|
79 iReceivedChars.Zero(); |
|
80 iPort.ReadOneOrMore(iStatus, iReceivedChars); |
|
81 |
|
82 SetActive(); |
|
83 } |
|
84 |
|
85 void CPortReader::RunL() |
|
86 { |
|
87 LOG_MSG("CPortReader::RunL"); |
|
88 |
|
89 // pass the data onto listener |
|
90 if (iStatus.Int() == KErrNone && iListener) |
|
91 iListener->DataAvailable(iReceivedChars, iReceivedChars.Length()); |
|
92 |
|
93 // continue waiting for data |
|
94 IssueReadRequest(); |
|
95 } |
|
96 |
|
97 void CPortReader::DoCancel() |
|
98 { |
|
99 LOG_MSG("CPortReader::DoCancel"); |
|
100 |
|
101 iPort.ReadCancel(); |
|
102 |
|
103 iAlreadyReading = EFalse; |
|
104 } |
|
105 |