0
|
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 "dbgtrccomm.h"
|
|
19 |
#include "dbgtrcclidefs.h"
|
|
20 |
|
|
21 |
// System includes
|
|
22 |
|
|
23 |
// User includes
|
|
24 |
#include "dbgtrccmdcodes.h"
|
|
25 |
#include "dbgtrccliutils.h"
|
|
26 |
// Type definitions
|
|
27 |
|
|
28 |
// Constants
|
|
29 |
const TInt KNumberOfServerStartupAttempts = 2;
|
|
30 |
|
|
31 |
// Enumerations
|
|
32 |
|
|
33 |
//
|
|
34 |
// RDbgTrcComm (source)
|
|
35 |
//
|
|
36 |
|
|
37 |
//
|
|
38 |
// RDbgTrcComm::RDbgTrcComm
|
|
39 |
//
|
|
40 |
// Constructor
|
|
41 |
//
|
|
42 |
EXPORT_C RDbgTrcComm::RDbgTrcComm()
|
|
43 |
{
|
|
44 |
}
|
|
45 |
|
|
46 |
//
|
|
47 |
// RDbgTrcComm::Connect()
|
|
48 |
//
|
|
49 |
// Connects the client process to the DbgTrc server, starting the server
|
|
50 |
// if it is not already running.
|
|
51 |
// return KErrNone if successful, otherwise one of the system-wide errors.
|
|
52 |
//
|
|
53 |
EXPORT_C TInt RDbgTrcComm::Connect()
|
|
54 |
{
|
|
55 |
TInt startupAttempts = KNumberOfServerStartupAttempts;
|
|
56 |
for(;;)
|
|
57 |
{
|
|
58 |
TInt ret = CreateSession(DbgTrcCliDefs::ServerAndThreadName(), DbgTrcCliDefs::Version(), KDbgTrcServerAsynchronousSlotCount);
|
|
59 |
if (ret != KErrNotFound && ret != KErrServerTerminated)
|
|
60 |
{
|
|
61 |
return ret;
|
|
62 |
}
|
|
63 |
|
|
64 |
if (startupAttempts-- == 0)
|
|
65 |
{
|
|
66 |
return ret;
|
|
67 |
}
|
|
68 |
|
|
69 |
ret = DbgTrcCliUtils::StartDbgTrcServer();
|
|
70 |
if (ret != KErrNone && ret != KErrAlreadyExists)
|
|
71 |
{
|
|
72 |
return ret;
|
|
73 |
}
|
|
74 |
}
|
|
75 |
}
|
|
76 |
|
|
77 |
|
|
78 |
//
|
|
79 |
//RDbgTrcComm::Disconnect()
|
|
80 |
//
|
|
81 |
// Connects the client process to the DbgTrc server, starting the server
|
|
82 |
// if it is not already running.
|
|
83 |
// return KErrNone if successful, otherwise one of the system-wide errors.
|
|
84 |
//
|
|
85 |
EXPORT_C TInt RDbgTrcComm::Disconnect()
|
|
86 |
{
|
|
87 |
// let the session object that we are disconnecting.
|
|
88 |
TInt error = SendReceive(EDbgTrcCmdDisconnect);
|
|
89 |
|
|
90 |
// needs to close the session somehow, there is no close session right now in RSessionBase.
|
|
91 |
// Either we need to switch to RSubSessionBase or use HandleBase close to see if it closes the session.
|
|
92 |
return error;
|
|
93 |
}
|
|
94 |
|
|
95 |
|
|
96 |
//
|
|
97 |
// RDbgTrcComm::Version()
|
|
98 |
//
|
|
99 |
// Provides the version number of the DbgTrc server.
|
|
100 |
// @return The version number.
|
|
101 |
//
|
|
102 |
EXPORT_C TVersion RDbgTrcComm::Version() const
|
|
103 |
{
|
|
104 |
return DbgTrcCliDefs::Version();
|
|
105 |
}
|
|
106 |
|
|
107 |
//
|
|
108 |
// RDbgTrcComm::GetAcmConfig(TDes8& aConfig)
|
|
109 |
//
|
|
110 |
// Get the current configuration for the ACM port.
|
|
111 |
// This would be either the default ACM port settings or
|
|
112 |
// port settings set by another client if the port is already opened.
|
|
113 |
// @return KErrNone - if succesful
|
|
114 |
// Negative - if failed.
|
|
115 |
//
|
|
116 |
EXPORT_C TInt RDbgTrcComm::GetAcmConfig(TDes8& aConfig)
|
|
117 |
{
|
|
118 |
TIpcArgs args(aConfig.Length(), &aConfig);
|
|
119 |
|
|
120 |
return SendReceive(EDbgTrcCmdCodeGetAcmConfig, args);
|
|
121 |
}
|
|
122 |
|
|
123 |
//
|
|
124 |
// RDbgTrcComm::SetAcmConfig(TDes8& aConfig)
|
|
125 |
//
|
|
126 |
// Set the current configuration for the ACM port.
|
|
127 |
// If the port is already configured by another client,
|
|
128 |
// then the function would return KErrInUse, meaning its already set.
|
|
129 |
//
|
|
130 |
// @return KErrNone - if succesful
|
|
131 |
// Negative - if failed.
|
|
132 |
//
|
|
133 |
EXPORT_C TInt RDbgTrcComm::SetAcmConfig(TDesC8& aConfig)
|
|
134 |
{
|
|
135 |
TIpcArgs args(aConfig.Length(), &aConfig);
|
|
136 |
|
|
137 |
return SendReceive(EDbgTrcCmdCodeSetAcmConfig, args);
|
|
138 |
}
|
|
139 |
|
|
140 |
|
|
141 |
//
|
|
142 |
// RDbgTrcComm::Open()
|
|
143 |
//
|
|
144 |
// Reads data from the already opened file.
|
|
145 |
// @return KErrNone - if succesful
|
|
146 |
// Negative - if failed.
|
|
147 |
//
|
|
148 |
EXPORT_C TInt RDbgTrcComm::Open()
|
|
149 |
{
|
|
150 |
return SendReceive(EDbgTrcCmdCodeOpen);
|
|
151 |
}
|
|
152 |
|
|
153 |
//
|
|
154 |
// RDbgTrcComm::WriteFile()
|
|
155 |
//
|
|
156 |
// Writes data into the already opened file.
|
|
157 |
// @return KErrNone - if succesful
|
|
158 |
// Negative - if failed.
|
|
159 |
//
|
|
160 |
EXPORT_C TInt RDbgTrcComm::Close()
|
|
161 |
{
|
|
162 |
TInt err = SendReceive(EDbgTrcCmdCodeClose);
|
|
163 |
|
|
164 |
RHandleBase::Close();
|
|
165 |
return err;
|
|
166 |
}
|
|
167 |
|
|
168 |
//
|
|
169 |
// RDbgTrcComm::RegisterProtocolID()
|
|
170 |
//
|
|
171 |
// Registers the protocol id with the dbgtrc server.
|
|
172 |
// Only protocol id per session.
|
|
173 |
// @return KErrNone - if succesful
|
|
174 |
// Negative - if failed.
|
|
175 |
//
|
|
176 |
EXPORT_C TInt RDbgTrcComm::RegisterProtocolID(const TOstProtIds aId, TBool aNeedHeader)
|
|
177 |
{
|
|
178 |
TIpcArgs args(aId, aNeedHeader);
|
|
179 |
|
|
180 |
return SendReceive(EDbgTrcCmdCodeRegisterId, args);
|
|
181 |
}
|
|
182 |
|
|
183 |
//
|
|
184 |
// RDbgTrcComm::RegisterProtocolIDs()
|
|
185 |
//
|
|
186 |
// Registers the protocol ids with the dbgtrc server.
|
|
187 |
// Only protocol id per session.
|
|
188 |
// @return KErrNone - if succesful
|
|
189 |
// Negative - if failed.
|
|
190 |
//
|
|
191 |
EXPORT_C TInt RDbgTrcComm::RegisterProtocolIDs(const TOstProtIds* aIds, const TUint aNumberofIds, TBool aNeedHeader)
|
|
192 |
{
|
|
193 |
if (!aIds || aNumberofIds <= 0)
|
|
194 |
return KErrArgument;
|
|
195 |
|
|
196 |
TPtr8 ids((TUint8*)aIds, aNumberofIds);
|
|
197 |
|
|
198 |
TIpcArgs args(aNeedHeader, ids.Length(), &ids);
|
|
199 |
|
|
200 |
return SendReceive(EDbgTrcCmdCodeRegisterIds, args);
|
|
201 |
}
|
|
202 |
|
|
203 |
//
|
|
204 |
// RDbgTrcComm::UnRegisterProtocolID()
|
|
205 |
//
|
|
206 |
// Unregisters the protocol id with the dbgtrc server.
|
|
207 |
// This is probably not necessary, the only case
|
|
208 |
// where it might be necessary is when one client wants to recieve two types of messages.
|
|
209 |
// @return KErrNone - if succesful
|
|
210 |
// Negative - if failed.
|
|
211 |
//
|
|
212 |
EXPORT_C TInt RDbgTrcComm::UnRegisterProtocolID(const TOstProtIds aId)
|
|
213 |
{
|
|
214 |
TIpcArgs args(aId);
|
|
215 |
|
|
216 |
return SendReceive(EDbgTrcCmdCodeUnRegisterId, args);
|
|
217 |
}
|
|
218 |
|
|
219 |
//
|
|
220 |
// RDbgTrcComm::UnRegisterProtocolIDs()
|
|
221 |
//
|
|
222 |
// Unregisters the protocol ids with the dbgtrc server.
|
|
223 |
// This is probably not necessary, the only case
|
|
224 |
// where it might be necessary is when one client wants to recieve two types of messages.
|
|
225 |
// @return KErrNone - if succesful
|
|
226 |
// Negative - if failed.
|
|
227 |
//
|
|
228 |
EXPORT_C TInt RDbgTrcComm::UnRegisterProtocolIDs(const TOstProtIds* aIds, const TUint aNumberofIds)
|
|
229 |
{
|
|
230 |
if (!aIds || aNumberofIds <= 0)
|
|
231 |
return KErrArgument;
|
|
232 |
|
|
233 |
TPtr8 ids((TUint8*)aIds, aNumberofIds);
|
|
234 |
|
|
235 |
TIpcArgs args(ids.Length(), &ids);
|
|
236 |
|
|
237 |
return SendReceive(EDbgTrcCmdCodeUnRegisterIds, args);
|
|
238 |
}
|
|
239 |
|
|
240 |
//
|
|
241 |
// RDbgTrcComm::ReadMessage(TRequestStatus& aStatus, TDes8& aDes)
|
|
242 |
//
|
|
243 |
// Reads the message from the message queue for this session if there is one.
|
|
244 |
// Otherwise queues up the request.
|
|
245 |
//
|
|
246 |
// @return KErrNone - if succesful
|
|
247 |
// Negative - if failed.
|
|
248 |
//
|
|
249 |
EXPORT_C void RDbgTrcComm::ReadMessage(TRequestStatus& aStatus, TDes8& aDes)
|
|
250 |
{
|
|
251 |
TIpcArgs args(aDes.MaxLength(), &aDes);
|
|
252 |
|
|
253 |
SendReceive(EDbgTrcCmdCodeReadMsg, args, aStatus);
|
|
254 |
}
|
|
255 |
|
|
256 |
//
|
|
257 |
// RDbgTrcComm::ReadCancel()
|
|
258 |
//
|
|
259 |
// Reads the message from the message queue for this session if there is one.
|
|
260 |
// Otherwise queues up the request.
|
|
261 |
//
|
|
262 |
// @return KErrNone - if succesful
|
|
263 |
// Negative - if failed.
|
|
264 |
//
|
|
265 |
EXPORT_C TInt RDbgTrcComm::ReadCancel()
|
|
266 |
{
|
|
267 |
return SendReceive(EDbgTrcCmdCodeReadCancel);
|
|
268 |
}
|
|
269 |
|
|
270 |
|
|
271 |
//
|
|
272 |
// RDbgTrcComm::WriteMessage(TRequestStatus& aStatus, TDes8& aDes, TBool aHasHeader)
|
|
273 |
//
|
|
274 |
//
|
|
275 |
// @return KErrNone - if succesful
|
|
276 |
// Negative - if failed.
|
|
277 |
//
|
|
278 |
EXPORT_C void RDbgTrcComm::WriteMessage(TRequestStatus& aStatus, const TDesC8& aDes, TBool aHasHeader)
|
|
279 |
{
|
|
280 |
TIpcArgs args(aHasHeader, aDes.Length(), &aDes);
|
|
281 |
|
|
282 |
SendReceive(EDbgTrcCmdCodeWriteMsg, args, aStatus);
|
|
283 |
}
|
|
284 |
|
|
285 |
//
|
|
286 |
// RDbgTrcComm::WriteCancel()
|
|
287 |
//
|
|
288 |
//
|
|
289 |
// @return KErrNone - if succesful
|
|
290 |
// Negative - if failed.
|
|
291 |
//
|
|
292 |
EXPORT_C TInt RDbgTrcComm::WriteCancel()
|
|
293 |
{
|
|
294 |
return SendReceive(EDbgTrcCmdCodeWriteCancel);
|
|
295 |
}
|