|
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 "dummytraceserver.h" |
|
19 |
|
20 _LIT8(KTRACEMSG, "Test trace server message: %d\n"); |
|
21 |
|
22 // |
|
23 // |
|
24 // CDummyTraceServer implementation |
|
25 // |
|
26 // |
|
27 |
|
28 CDummyTraceServer* CDummyTraceServer::NewLC(CConsoleIO* aConsoleIO) |
|
29 { |
|
30 CDummyTraceServer* self = new(ELeave) CDummyTraceServer(aConsoleIO); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 |
|
34 return self; |
|
35 } |
|
36 |
|
37 CDummyTraceServer::CDummyTraceServer(CConsoleIO* aConsoleIO) |
|
38 : CActive(EPriorityLow), |
|
39 iConsoleIO(aConsoleIO), |
|
40 iMessageId(0) |
|
41 |
|
42 { |
|
43 CActiveScheduler::Add(this); |
|
44 } |
|
45 |
|
46 void CDummyTraceServer::ConstructL() |
|
47 { |
|
48 User::LeaveIfError(iTimer.CreateLocal()); |
|
49 } |
|
50 |
|
51 CDummyTraceServer::~CDummyTraceServer() |
|
52 { |
|
53 |
|
54 } |
|
55 |
|
56 void CDummyTraceServer::Start() |
|
57 { |
|
58 |
|
59 TInt err = iAcmPort.Connect(); |
|
60 if (err != KErrNone) |
|
61 { |
|
62 iConsoleIO->PrintToScreen(_L("Connect failed: %d"), err); |
|
63 return; |
|
64 } |
|
65 iConsoleIO->PrintToScreen(_L("Successfully the DbgTrc Comms server\n")); |
|
66 |
|
67 |
|
68 err = iAcmPort.Open(); |
|
69 if (err != KErrNone) |
|
70 { |
|
71 iConsoleIO->PrintToScreen(_L("Opening port failed: %d\n"), err); |
|
72 return; |
|
73 } |
|
74 iConsoleIO->PrintToScreen(_L("Successfully opened the DbgTrc Comm Port\n")); |
|
75 |
|
76 |
|
77 TAcmConfig config; |
|
78 err = iAcmPort.GetAcmConfig(config); |
|
79 if (err != KErrNone) |
|
80 { |
|
81 iConsoleIO->PrintToScreen(_L("Unable to get port configuration: %d\n"), err); |
|
82 return; |
|
83 } |
|
84 iConsoleIO->PrintToScreen(_L("Current ACM port number: %d\n"), config().iPortNumber); |
|
85 |
|
86 err = iAcmPort.RegisterProtocolID(EOstProtTraceCore, EFalse); |
|
87 if (err != KErrNone) |
|
88 { |
|
89 iConsoleIO->PrintToScreen(_L("Unable to register protocol: %d\n"), err); |
|
90 return; |
|
91 } |
|
92 iConsoleIO->PrintToScreen(_L("Registered the protocol id: %d\n"), EOstProtTraceCore); |
|
93 |
|
94 Activate(); |
|
95 |
|
96 iConsoleIO->PrintToScreen(_L("Started sending dummy traces\n")); |
|
97 } |
|
98 |
|
99 void CDummyTraceServer::SendMessage() |
|
100 { |
|
101 TBuf8<100> msg; |
|
102 TRequestStatus status; |
|
103 |
|
104 msg.Format(KTRACEMSG, iMessageId++); |
|
105 iAcmPort.WriteMessage(status, msg, EFalse); |
|
106 User::WaitForRequest(status); |
|
107 } |
|
108 |
|
109 void CDummyTraceServer::Activate() |
|
110 { |
|
111 iTimer.After(iStatus, KPeriod); |
|
112 SetActive(); |
|
113 } |
|
114 |
|
115 |
|
116 |
|
117 void CDummyTraceServer::RunL() |
|
118 { |
|
119 // now send the message |
|
120 SendMessage(); |
|
121 // reactivate the timer |
|
122 Activate(); |
|
123 } |
|
124 |
|
125 void CDummyTraceServer::DoCancel() |
|
126 { |
|
127 iTimer.Cancel(); |
|
128 |
|
129 Cancel(); |
|
130 iTimer.Close(); |
|
131 Deque(); |
|
132 |
|
133 TInt err = iAcmPort.UnRegisterProtocolID(EOstProtTraceCore); |
|
134 if (err != KErrNone) |
|
135 { |
|
136 iConsoleIO->PrintToScreen(_L("Unable to unregister protocol: %d\n"), err); |
|
137 return; |
|
138 } |
|
139 iConsoleIO->PrintToScreen(_L("Successfuly unregistered the protocol id: %d\n"), EOstProtTraceCore); |
|
140 |
|
141 |
|
142 err = iAcmPort.Close(); |
|
143 if (err != KErrNone) |
|
144 { |
|
145 iConsoleIO->PrintToScreen(_L("Unable to close the port: %d\n"), err); |
|
146 return; |
|
147 } |
|
148 iConsoleIO->PrintToScreen(_L("Successfuly closed the port\n")); |
|
149 |
|
150 } |
|
151 |