|
1 // Copyright (c) 2001-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 // |
|
15 |
|
16 #include "serial.h" |
|
17 #include "TestMgr.h" |
|
18 // |
|
19 // Serial Listener Active Object - receive commands on the serial port |
|
20 // |
|
21 |
|
22 CSerialListener::CSerialListener(RComm* aCommPort, CTestMgr* aController) |
|
23 : CActive(CActive::EPriorityStandard), iCommPort(aCommPort), iController(aController) |
|
24 { |
|
25 } |
|
26 |
|
27 CSerialListener* CSerialListener::NewL(RComm* aCommPort, CTestMgr* aController) |
|
28 { |
|
29 CSerialListener* self = new (ELeave) CSerialListener(aCommPort, aController); |
|
30 CleanupStack::PushL(self); |
|
31 self->ConstructL(); |
|
32 CleanupStack::Pop(); // self |
|
33 CActiveScheduler::Add(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 void CSerialListener::ConstructL() |
|
38 { |
|
39 } |
|
40 |
|
41 CSerialListener::~CSerialListener() |
|
42 { |
|
43 Cancel(); |
|
44 } |
|
45 |
|
46 void CSerialListener::Recv() |
|
47 { |
|
48 // read data from Comm port |
|
49 iCommPort->Read(iStatus, iDataBuffer); |
|
50 SetActive(); |
|
51 } |
|
52 |
|
53 void CSerialListener::RunL() |
|
54 { |
|
55 iLastBuffer = iDataBuffer; |
|
56 // notify controller we have read something |
|
57 iController->Notify(CTestMgr::EReadComplete); |
|
58 // start the listener again |
|
59 Recv(); |
|
60 } |
|
61 |
|
62 void CSerialListener::DoCancel() |
|
63 { |
|
64 iCommPort->ReadCancel(); |
|
65 } |
|
66 // |
|
67 // Serial Sender Active Object - send commands on the serial port |
|
68 // |
|
69 |
|
70 CSerialSender* CSerialSender::NewL(RComm* aCommPort, CTestMgr* aController) |
|
71 { |
|
72 CSerialSender* self = new (ELeave) CSerialSender(aCommPort, aController); |
|
73 CleanupStack::PushL(self); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop(); // self |
|
76 CActiveScheduler::Add(self); |
|
77 return self; |
|
78 } |
|
79 |
|
80 void CSerialSender::ConstructL() |
|
81 { |
|
82 } |
|
83 |
|
84 CSerialSender::~CSerialSender() |
|
85 { |
|
86 Cancel(); |
|
87 } |
|
88 |
|
89 void CSerialSender::Send(TBuffer& aBuff) |
|
90 { |
|
91 if (!IsActive()) |
|
92 { |
|
93 // take a local copy of data to send |
|
94 iDataBuffer = aBuff; |
|
95 // send the data |
|
96 iCommPort->Write(iStatus, iDataBuffer); |
|
97 SetActive(); |
|
98 } |
|
99 } |
|
100 |
|
101 CSerialSender::CSerialSender(RComm* aCommPort, CTestMgr* aController) |
|
102 : CActive(CActive::EPriorityStandard), iCommPort(aCommPort), iController(aController) |
|
103 { |
|
104 } |
|
105 |
|
106 void CSerialSender::RunL() |
|
107 { |
|
108 // notify controller that send has finished |
|
109 iController->Notify(CTestMgr::EWriteComplete); |
|
110 } |
|
111 |
|
112 void CSerialSender::DoCancel() |
|
113 { |
|
114 iCommPort->WriteCancel(); |
|
115 } |
|
116 |