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
.ui
.tracecontrol
.utility
;
16 import java
.io
.FileNotFoundException
;
17 import java
.io
.FileOutputStream
;
18 import java
.io
.IOException
;
20 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.model
.TraceResource
;
21 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.model
.config
.TraceConfig
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.subsystems
.TraceSubSystem
;
23 import org
.eclipse
.rse
.ui
.SystemBasePlugin
;
24 import org
.eclipse
.tm
.tcf
.protocol
.JSON
;
27 * <b><u>DownloadProxy</u></b>
29 * Proxy implementation for storing trace data locally on host where client is running. (writeTraceNetwork)
32 public class DownloadProxy
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 TraceSubSystem fSubSystem
;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
47 * @param subSystem The trace SubSystem
49 public DownloadProxy(TraceSubSystem subSystem
) {
50 fSubSystem
= subSystem
;
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 * Writes trace data to traces files.
60 * @param data binary data
62 public void writeDownloadedTrace(byte[] data
) {
65 args
= JSON
.parseSequence(data
);
66 } catch (IOException e
) {
67 SystemBasePlugin
.logError("DownloadProxy", e
); //$NON-NLS-1$
70 byte[] traceData
= JSON
.toByteArray(args
[4]);
71 TraceResource trace
= fSubSystem
.findTrace(args
[0].toString(), args
[1].toString(), args
[2].toString());
73 TraceConfig conf
= trace
.getTraceConfig();
74 FileOutputStream fos
= null;
75 if (!TraceConfig
.InvalidTracePath
.equals(conf
.getTracePath())) {
76 String fileName
= conf
.getTracePath() + "/" + args
[3].toString(); //$NON-NLS-1$
78 fos
= new FileOutputStream(fileName
, true);
81 // ((TraceResource) args[2]).setSize(sizeFile.length());
82 } catch (FileNotFoundException e
) {
83 SystemBasePlugin
.logError("DownloadProxy", e
); //$NON-NLS-1$
84 } catch (IOException e
) {
85 SystemBasePlugin
.logError("DownloadProxy", e
); //$NON-NLS-1$
97 public void handleUnwriteTraceDataEvent(byte [] data
) {
100 args
= JSON
.parseSequence(data
);
101 // Check if it is an ust trace
102 TraceResource trace
= fSubSystem
.findTrace(args
[0].toString(), args
[1].toString(), args
[2].toString());
103 if ((trace
!= null) && trace
.isUst()) {
107 } catch (IOException e
) {
108 SystemBasePlugin
.logError("DownloadProxy", e
); //$NON-NLS-1$
114 * Method that handles trace done event which is sent at the end of the trace session.
116 * @param data Binary data
118 public void handleTraceDoneEvent(byte [] data
) {