1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Polytechnique Montréal - Initial API and implementation
11 * Bernd Hufmann - Productification, enhancements and fixes
13 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.service
;
16 import org
.eclipse
.linuxtools
.lttng
.core
.LttngConstants
;
17 import org
.eclipse
.tm
.tcf
.core
.Command
;
18 import org
.eclipse
.tm
.tcf
.core
.ErrorReport
;
19 import org
.eclipse
.tm
.tcf
.protocol
.IChannel
;
20 import org
.eclipse
.tm
.tcf
.protocol
.IToken
;
23 * <b><u>LttControllerServiceProxy</u></b>
25 * Provides the mplementation of the ILttControllerService interface for
26 * sending of commands to the remote system.
29 public class LttControllerServiceProxy
implements ILttControllerService
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 private static final short INVALID_ARG_LENGTH
= 2;
37 private IChannel fProxychannel
;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
42 public LttControllerServiceProxy(IChannel chan
) {
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
52 * @see org.eclipse.tm.tcf.protocol.IService#getName()
54 * Return service name, as it appears on the wire - a TCF name of the service.
57 public String
getName() {
62 * Sets the service channel.
65 public void setChannel(IChannel channel
) {
66 fProxychannel
= channel
;
71 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#getProviders(org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneGetProviders)
74 public IToken
getProviders(final DoneGetProviders done
) {
75 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_GetProviders
, new Object
[] {}) {
77 public void done(Exception error
, Object
[] args
) {
78 String
[] strArray
= new String
[0];
81 assert args
.length
== INVALID_ARG_LENGTH
;
82 error
= toDetailedError(toError(args
[0]), args
[1]);
84 strArray
= toStringArray(str
.toString());
86 done
.doneGetProviders(token
, error
, strArray
);
93 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#getTargets(java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneGetTargets)
96 public IToken
getTargets(String provider
, final DoneGetTargets done
) {
97 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_GetTargets
, new Object
[] { provider
}) {
99 public void done(Exception error
, Object
[] args
) {
100 String
[] strArray
= new String
[0];
103 assert args
.length
== INVALID_ARG_LENGTH
;
104 error
= toDetailedError(toError(args
[0]), args
[1]);
106 strArray
= toStringArray(str
.toString());
108 done
.doneGetTargets(token
, error
, strArray
);
115 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#getMarkers(java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneGetMarkers)
118 public IToken
getMarkers(String provider
, String target
, final DoneGetMarkers done
) {
119 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_GetMarkers
, new Object
[] { provider
, target
}) {
121 public void done(Exception error
, Object
[] args
) {
122 String
[] strArray
= new String
[0];
125 assert args
.length
== INVALID_ARG_LENGTH
;
126 error
= toDetailedError(toError(args
[0]), args
[1]);
128 strArray
= toStringArray(str
.toString());
130 done
.doneGetMarkers(token
, error
, strArray
);
137 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#getTraces(java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneGetTraces)
140 public IToken
getTraces(String provider
, String target
, final DoneGetTraces done
) {
141 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_GetTraces
, new Object
[] { provider
, target
}) {
143 public void done(Exception error
, Object
[] args
) {
144 String
[] strArray
= new String
[0];
147 assert args
.length
== INVALID_ARG_LENGTH
;
148 error
= toDetailedError(toError(args
[0]), args
[1]);
150 strArray
= toStringArray(str
.toString());
152 done
.doneGetTraces(token
, error
, strArray
);
159 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#getActiveTraces(java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneGetActiveTraces)
162 public IToken
getActiveTraces(String provider
, String target
, final DoneGetActiveTraces done
) {
163 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_GetActiveTraces
, new Object
[] { provider
, target
}) {
165 public void done(Exception error
, Object
[] args
) {
166 String
[] strArray
= new String
[0];
169 assert args
.length
== INVALID_ARG_LENGTH
;
170 error
= toDetailedError(toError(args
[0]), args
[1]);
172 strArray
= toStringArray(str
.toString());
174 done
.doneGetActiveTraces(token
, error
, strArray
);
181 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#getActiveTraceInfo(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneGetActiveTraceInfo)
184 public IToken
getActiveTraceInfo(String provider
, String target
, String trace
, final DoneGetActiveTraceInfo done
) {
185 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_GetActiveTraceInfo
, new Object
[] { provider
, target
, trace
}) {
187 public void done(Exception error
, Object
[] args
) {
188 String
[] strArray
= new String
[0];
191 assert args
.length
== INVALID_ARG_LENGTH
;
192 error
= toDetailedError(toError(args
[0]), args
[1]);
194 strArray
= toStringArray(str
.toString());
196 done
.doneGetActiveTraceInfo(token
, error
, strArray
);
203 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#getChannels(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneGetChannels)
206 public IToken
getChannels(String provider
, String target
, String trace
, final DoneGetChannels done
) {
208 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_GetChannels
, new Object
[] { provider
, target
, trace
}) {
210 public void done(Exception error
, Object
[] args
) {
211 String
[] strArray
= new String
[0];
214 assert args
.length
== INVALID_ARG_LENGTH
;
215 error
= toDetailedError(toError(args
[0]), args
[1]);
217 strArray
= toStringArray(str
.toString());
219 done
.doneGetChannels(token
, error
, strArray
);
226 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#setupTrace(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneSetupTrace)
229 public IToken
setupTrace(String provider
, String target
, String trace
, final DoneSetupTrace done
) {
230 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_SetupTrace
, new Object
[] { provider
, target
, trace
}) {
232 public void done(Exception error
, Object
[] args
) {
235 assert args
.length
== INVALID_ARG_LENGTH
;
236 error
= toDetailedError(toError(args
[0]), args
[1]);
239 done
.doneSetupTrace(token
, error
, str
);
246 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#setTraceTransport(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneSetTraceTransport)
249 public IToken
setTraceTransport(String provider
, String target
, String trace
, String transport
, final DoneSetTraceTransport done
) {
250 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_SetupTraceTransport
, new Object
[] { provider
, target
, trace
, transport
}) {
252 public void done(Exception error
, Object
[] args
) {
255 assert args
.length
== INVALID_ARG_LENGTH
;
256 error
= toDetailedError(toError(args
[0]), args
[1]);
259 done
.doneSetTraceTransport(token
, error
, str
);
266 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#getMarkerInfo(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneGetMarkerInfo)
269 public IToken
getMarkerInfo(String provider
, String target
, String marker
, final DoneGetMarkerInfo done
) {
270 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_GetMarkerInfo
, new Object
[] { provider
, target
, marker
}) {
272 public void done(Exception error
, Object
[] args
) {
274 String result
= ""; //$NON-NLS-1$
276 assert args
.length
== INVALID_ARG_LENGTH
;
277 error
= toDetailedError(toError(args
[0]), args
[1]);
279 result
= str
.toString();
280 if (result
.length() > 2) {
281 result
= result
.substring(1, result
.length() - 1);
284 done
.doneGetMarkerInfo(token
, error
, result
);
291 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#setMarkerEnable(java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneSetMarkerEnable)
294 public IToken
setMarkerEnable(String provider
, String target
, String marker
, Boolean enable
, final DoneSetMarkerEnable done
) {
295 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_SetMarkerEnable
, new Object
[] { provider
, target
, marker
, enable
}) {
297 public void done(Exception error
, Object
[] args
) {
300 assert args
.length
== INVALID_ARG_LENGTH
;
301 error
= toDetailedError(toError(args
[0]), args
[1]);
304 done
.doneSetMarkerEnable(token
, error
, str
);
311 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#setChannelEnable(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneSetChannelEnable)
314 public IToken
setChannelEnable(String provider
, String target
, String trace
, String channel
, Boolean enable
, final DoneSetChannelEnable done
) {
315 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_SetChannelEnable
, new Object
[] { provider
, target
, trace
, channel
, enable
}) {
317 public void done(Exception error
, Object
[] args
) {
320 assert args
.length
== INVALID_ARG_LENGTH
;
321 error
= toDetailedError(toError(args
[0]), args
[1]);
324 done
.doneSetChannelEnable(token
, error
, str
);
331 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#setChannelOverwrite(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneSetChannelOverwrite)
334 public IToken
setChannelOverwrite(String provider
, String target
, String trace
, String channel
, Boolean overwrite
, final DoneSetChannelOverwrite done
) {
335 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_SetChannelOverwrite
, new Object
[] { provider
, target
, trace
, channel
, overwrite
}) {
337 public void done(Exception error
, Object
[] args
) {
340 assert args
.length
== INVALID_ARG_LENGTH
;
341 error
= toDetailedError(toError(args
[0]), args
[1]);
344 done
.doneSetChannelOverwrite(token
, error
, str
);
351 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#setChannelTimer(java.lang.String, java.lang.String, java.lang.String, java.lang.String, long, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneSetChannelTimer)
354 public IToken
setChannelTimer(String provider
, String target
, String trace
, String channel
, long period
, final DoneSetChannelTimer done
) {
355 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_SetChannelTimer
, new Object
[] { provider
, target
, trace
, channel
, period
}) {
357 public void done(Exception error
, Object
[] args
) {
360 assert args
.length
== INVALID_ARG_LENGTH
;
361 error
= toDetailedError(toError(args
[0]), args
[1]);
364 done
.doneSetChannelTimer(token
, error
, str
);
371 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#setChannelSubbufNum(java.lang.String, java.lang.String, java.lang.String, java.lang.String, long, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneSetChannelSubbufNum)
374 public IToken
setChannelSubbufNum(String provider
, String target
, String trace
, String channel
, long subbufNum
, final DoneSetChannelSubbufNum done
) {
375 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_SetChannelSubbufNum
, new Object
[] { provider
, target
, trace
, channel
, subbufNum
}) {
377 public void done(Exception error
, Object
[] args
) {
380 assert args
.length
== INVALID_ARG_LENGTH
;
381 error
= toDetailedError(toError(args
[0]), args
[1]);
384 done
.doneSetChannelSubbufNum(token
, error
, str
);
391 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#setChannelSubbufSize(java.lang.String, java.lang.String, java.lang.String, java.lang.String, long, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneSetChannelSubbufSize)
394 public IToken
setChannelSubbufSize(String provider
, String target
, String trace
, String channel
, long subbufSize
, final DoneSetChannelSubbufSize done
) {
395 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_SetChannelSubbufSize
, new Object
[] { provider
, target
, trace
, channel
, subbufSize
}) {
397 public void done(Exception error
, Object
[] args
) {
400 assert args
.length
== INVALID_ARG_LENGTH
;
401 error
= toDetailedError(toError(args
[0]), args
[1]);
404 done
.doneSetChannelSubbufSize(token
, error
, str
);
411 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#allocTrace(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneAllocTrace)
414 public IToken
allocTrace(String provider
, String target
, String trace
, final DoneAllocTrace done
) {
415 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_AllocTrace
, new Object
[] { provider
, target
, trace
}) {
417 public void done(Exception error
, Object
[] args
) {
420 assert args
.length
== INVALID_ARG_LENGTH
;
421 error
= toDetailedError(toError(args
[0]), args
[1]);
424 done
.doneAllocTrace(token
, error
, str
);
431 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#writeTraceLocal(java.lang.String, java.lang.String, java.lang.String, java.lang.String, int, java.lang.Boolean, java.lang.Boolean, java.lang.Boolean, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneWriteTraceLocal)
434 public IToken
writeTraceLocal(String provider
, String target
, String trace
, String path
, int numChannel
, Boolean isAppend
, Boolean isFlightRecorder
, Boolean isNormalOnly
, final DoneWriteTraceLocal done
) {
435 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_WriteTraceLocal
, new Object
[] { provider
, target
, trace
, path
, numChannel
, isAppend
, isFlightRecorder
, isNormalOnly
}) {
437 public void done(Exception error
, Object
[] args
) {
440 assert args
.length
== INVALID_ARG_LENGTH
;
441 error
= toDetailedError(toError(args
[0]), args
[1]);
444 done
.doneWriteTraceLocal(token
, error
, str
);
451 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#writeTraceNetwork(java.lang.String, java.lang.String, java.lang.String, int, java.lang.Boolean, java.lang.Boolean, java.lang.Boolean, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneWriteTraceNetwork)
454 public IToken
writeTraceNetwork(String provider
, String target
, String trace
, String path
, int numChannel
, Boolean isAppend
, Boolean isFlightRecorder
, Boolean isNormalOnly
, final DoneWriteTraceNetwork done
) {
455 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_WriteTraceNetwork
, new Object
[] { provider
, target
, trace
, path
, numChannel
, isAppend
, isFlightRecorder
, isNormalOnly
}) {
457 public void done(Exception error
, Object
[] args
) {
460 assert args
.length
== INVALID_ARG_LENGTH
;
461 error
= toDetailedError(toError(args
[0]), args
[1]);
464 done
.doneWriteTraceNetwork(token
, error
, str
);
471 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#stopWriteTraceNetwork(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneWriteTraceNetwork)
474 public IToken
stopWriteTraceNetwork(String provider
, String target
, String trace
, final DoneStopWriteTraceNetwork done
) {
475 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_StopWriteTraceNetwork
, new Object
[] { provider
, target
, trace
}) {
477 public void done(Exception error
, Object
[] args
) {
480 assert args
.length
== INVALID_ARG_LENGTH
;
481 error
= toDetailedError(toError(args
[0]), args
[1]);
484 done
.doneStopWriteTraceNetwork(token
, error
, str
);
491 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#startTrace(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneStartTrace)
494 public IToken
startTrace(String provider
, String target
, String trace
, final DoneStartTrace done
) {
495 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_StartTrace
, new Object
[] { provider
, target
, trace
}) {
497 public void done(Exception error
, Object
[] args
) {
500 assert args
.length
== INVALID_ARG_LENGTH
;
501 error
= toDetailedError(toError(args
[0]), args
[1]);
504 done
.doneStartTrace(token
, error
, str
);
511 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#pauseTrace(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DonePauseTrace)
514 public IToken
pauseTrace(String provider
, String target
, String trace
, final DonePauseTrace done
) {
515 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_PauseTrace
, new Object
[] { provider
, target
, trace
}) {
517 public void done(Exception error
, Object
[] args
) {
520 assert args
.length
== INVALID_ARG_LENGTH
;
521 error
= toDetailedError(toError(args
[0]), args
[1]);
524 done
.donePauseTrace(token
, error
, str
);
531 * @see org.eclipse.linuxtools.lttng.rse.service.ILttControllerService#destroyTrace(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.rse.service.ILttControllerService.DoneDestroyTrace)
534 public IToken
destroyTrace(String provider
, String target
, String trace
, final DoneDestroyTrace done
) {
535 return new Command(fProxychannel
, this, LttngConstants
.Lttng_Control_DestroyTrace
, new Object
[] { provider
, target
, trace
}) {
537 public void done(Exception error
, Object
[] args
) {
540 assert args
.length
== INVALID_ARG_LENGTH
;
541 error
= toDetailedError(toError(args
[0]), args
[1]);
544 done
.doneDestroyTrace(token
, error
, str
);
550 * Converts comma separated string to String array.
552 private String
[] toStringArray(String list
) {
553 if (list
.length() > 2) {
554 String temp
= list
.substring(1, list
.length() - 1);
555 String
[] str
= temp
.split(LttngConstants
.Lttng_Control_Separator
);
556 for (int i
= 0; i
< str
.length
; i
++) {
557 str
[i
] = str
[i
].trim();
561 return new String
[0];
565 * Creates new error report using a given error and a detailed message.
567 private Exception
toDetailedError(Exception error
, Object detail
) {
568 if ((error
!= null) && (error
instanceof ErrorReport
) && (detail
!= null)) {
569 error
= new ErrorReport(error
.getMessage() + "\nDetail: " + detail
.toString(), ((ErrorReport
) error
).getAttributes()); //$NON-NLS-1$