|
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 |
|
19 |
|
20 |
|
21 #include <e32cons.h> |
|
22 |
|
23 #include "logging.h" |
|
24 #include "portwriter.h" |
|
25 |
|
26 |
|
27 |
|
28 CPortWriter* CPortWriter::NewL(RComm& aPort) |
|
29 { |
|
30 LOG_MSG("CPortWriter::NewL"); |
|
31 |
|
32 CPortWriter* self = new(ELeave) CPortWriter(aPort); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 CPortWriter::CPortWriter(RComm& aPort) |
|
40 : CActive(CActive::EPriorityStandard), |
|
41 iPort(aPort), |
|
42 iListener(NULL), |
|
43 iAlreadyWriting(EFalse) |
|
44 { |
|
45 LOG_MSG("CPortWriter::CPortWriter"); |
|
46 |
|
47 |
|
48 } |
|
49 |
|
50 CPortWriter::~CPortWriter() |
|
51 { |
|
52 LOG_MSG("CPortWriter::~CPortWriter"); |
|
53 Cancel(); |
|
54 } |
|
55 |
|
56 void CPortWriter::ConstructL() |
|
57 { |
|
58 LOG_MSG("CPortWriter::ConstructL"); |
|
59 |
|
60 CActiveScheduler::Add(this); |
|
61 } |
|
62 |
|
63 void CPortWriter::StartWrite(TDesC8& aMsg, MDataListener* aListener) |
|
64 { |
|
65 LOG_MSG("CPortWriter::StartWrite"); |
|
66 iAlreadyWriting = ETrue; |
|
67 iListener = aListener; |
|
68 |
|
69 iPort.Write(iStatus, aMsg); |
|
70 |
|
71 SetActive(); |
|
72 } |
|
73 |
|
74 void CPortWriter::RunL() |
|
75 { |
|
76 LOG_MSG("CPortWriter::RunL"); |
|
77 |
|
78 iAlreadyWriting = EFalse; |
|
79 |
|
80 if (iListener) |
|
81 iListener->DataWriteComplete(iStatus.Int()); |
|
82 else |
|
83 LOG_MSG("Invalid listener, something wrong"); |
|
84 } |
|
85 |
|
86 void CPortWriter::DoCancel() |
|
87 { |
|
88 LOG_MSG("CPortWriter::DoCancel"); |
|
89 |
|
90 iPort.WriteCancel(); |
|
91 } |
|
92 |
|
93 |