Skip to content

Commit 6ffdf8e

Browse files
committed
Add JSON serialize functionality
There was only possibility to serialize topology to gstreamer format. Added JSON serialize functionality. JSON format is is compatible with VAS. Signed-off-by: Emilia Dominiak <emilia.dominiak@intel.com>
1 parent f9986c8 commit 6ffdf8e

17 files changed

Lines changed: 357 additions & 8 deletions

File tree

org.sofproject.alsa.topo/.classpath

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
4+
<accessrules>
5+
<accessrule kind="accessible" pattern="javafx/**"/>
6+
</accessrules>
7+
</classpathentry>
48
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
59
<classpathentry kind="src" path="src"/>
610
<classpathentry kind="output" path="bin"/>

org.sofproject.alsa.topo/src/org/sofproject/alsa/topo/model/AlsaTopoGraph.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.io.ByteArrayOutputStream;
3737
import java.io.IOException;
3838
import java.io.OutputStreamWriter;
39+
import java.io.StringWriter;
3940
import java.io.Writer;
4041
import java.util.ArrayList;
4142
import java.util.Arrays;
@@ -536,6 +537,11 @@ public void serialize() throws CoreException, IOException {
536537
}
537538
outputFile.getParent().refreshLocal(1, null);
538539
}
540+
541+
@Override
542+
public String getPipelinesString() {
543+
return null;
544+
}
539545

540546
@Override
541547
public IRemoteOpsProvider getRemoteOpsProvider() {

org.sofproject.fw.ui/.classpath

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
4+
<accessrules>
5+
<accessrule kind="accessible" pattern="javafx/**"/>
6+
</accessrules>
7+
</classpathentry>
48
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
59
<classpathentry kind="src" path="src"/>
610
<classpathentry kind="output" path="bin"/>

org.sofproject.gst.topo/.classpath

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
4+
<accessrules>
5+
<accessrule kind="accessible" pattern="javafx/**"/>
6+
</accessrules>
7+
</classpathentry>
48
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
9+
<classpathentry exported="true" kind="lib" path="lib/jackson-annotations-2.10.1.jar"/>
10+
<classpathentry exported="true" kind="lib" path="lib/jackson-core-2.10.1.jar"/>
11+
<classpathentry exported="true" kind="lib" path="lib/jackson-databind-2.10.1.jar"/>
512
<classpathentry kind="src" path="src"/>
613
<classpathentry kind="output" path="bin"/>
714
</classpath>

org.sofproject.gst.topo/META-INF/MANIFEST.MF

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ Require-Bundle: org.sofproject.core,
1010
org.sofproject.ui,
1111
org.sofproject.topo.ui,
1212
com.jcraft.jsch
13+
Bundle-ClassPath: lib/jackson-annotations-2.10.1.jar,
14+
lib/jackson-core-2.10.1.jar,
15+
lib/jackson-databind-2.10.1.jar,
16+
.
17+
Export-Package: org.sofproject.gst.json

org.sofproject.gst.topo/build.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ source.. = src/
22
output.. = bin/
33
bin.includes = META-INF/,\
44
.,\
5-
plugin.xml
5+
plugin.xml,\
6+
lib/jackson-annotations-2.10.1.jar,\
7+
lib/jackson-core-2.10.1.jar,\
8+
lib/jackson-databind-2.10.1.jar
66.5 KB
Binary file not shown.
340 KB
Binary file not shown.
1.34 MB
Binary file not shown.
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
*/
29+
30+
package org.sofproject.gst.json;
31+
32+
import java.io.BufferedWriter;
33+
import java.io.File;
34+
import java.io.FileWriter;
35+
import java.io.IOException;
36+
37+
import org.eclipse.core.runtime.CoreException;
38+
import org.eclipse.swt.SWT;
39+
import org.eclipse.swt.events.SelectionAdapter;
40+
import org.eclipse.swt.events.SelectionEvent;
41+
import org.eclipse.swt.graphics.Rectangle;
42+
import org.eclipse.swt.layout.GridData;
43+
import org.eclipse.swt.layout.GridLayout;
44+
import org.eclipse.swt.widgets.Button;
45+
import org.eclipse.swt.widgets.Combo;
46+
import org.eclipse.swt.widgets.Display;
47+
import org.eclipse.swt.widgets.Label;
48+
import org.eclipse.swt.widgets.MessageBox;
49+
import org.eclipse.swt.widgets.Monitor;
50+
import org.eclipse.swt.widgets.Shell;
51+
import org.eclipse.swt.widgets.Text;
52+
import org.sofproject.topo.ui.graph.ITopoGraph;
53+
import org.sofproject.gst.json.JsonUtils;
54+
import com.fasterxml.jackson.databind.ObjectMapper;
55+
56+
import org.sofproject.gst.topo.model.GstTopoGraph;
57+
58+
public class JsonCustomOptionPane {
59+
60+
ITopoGraph graph;
61+
62+
private static boolean isInteger(String s) {
63+
try {
64+
Integer.parseInt(s);
65+
} catch (NumberFormatException e) {
66+
return false;
67+
} catch (NullPointerException e) {
68+
return false;
69+
}
70+
return true;
71+
}
72+
73+
public JsonCustomOptionPane(Display display, ITopoGraph graph) {
74+
this.graph = graph;
75+
Shell shell = new Shell(display, SWT.CLOSE | SWT.TITLE | SWT.MIN);
76+
77+
shell.setText("Serialize JSON");
78+
79+
GridLayout gridLayout = new GridLayout(4, false);
80+
gridLayout.verticalSpacing = 8;
81+
shell.setLayout(gridLayout);
82+
83+
new Label(shell, SWT.NULL).setText("Name:");
84+
Text nameText = new Text(shell, SWT.SINGLE | SWT.BORDER);
85+
GridData nameGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
86+
nameGridData.horizontalSpan = 3;
87+
nameText.setLayoutData(nameGridData);
88+
89+
new Label(shell, SWT.NULL).setText("Version:");
90+
Text versionText = new Text(shell, SWT.BORDER);
91+
GridData versionGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
92+
versionGridData.horizontalSpan = 3;
93+
versionText.setLayoutData(versionGridData);
94+
95+
new Label(shell, SWT.NULL).setText("Description:");
96+
Text descriptionText = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
97+
GridData descriptionGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
98+
descriptionGridData.horizontalSpan = 3;
99+
descriptionGridData.heightHint = 100;
100+
descriptionGridData.widthHint = 200;
101+
descriptionText.setLayoutData(descriptionGridData);
102+
103+
new Label(shell, SWT.NULL).setText("Type:");
104+
Combo typeCombo = new Combo(shell, SWT.READ_ONLY);
105+
typeCombo.setBounds(50, 50, 200, 65);
106+
String items[] = { "Gstreamer", "Ffmpeg" };
107+
typeCombo.setItems(items);
108+
typeCombo.setText(items[0]);
109+
GridData typeGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
110+
typeGridData.horizontalSpan = 3;
111+
typeCombo.setLayoutData(typeGridData);
112+
113+
Button okButton = new Button(shell, SWT.PUSH);
114+
okButton.setText("Ok");
115+
GridData buttonGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
116+
okButton.setLayoutData(buttonGridData);
117+
okButton.addSelectionListener(new SelectionAdapter() {
118+
119+
@Override
120+
public void widgetSelected(SelectionEvent e) {
121+
if (nameText.getText().isEmpty()) {
122+
MessageBox messageBox = new MessageBox(shell, SWT.ERROR);
123+
messageBox.setMessage("Name cannot be empty!");
124+
messageBox.open();
125+
} else if (!isInteger(versionText.getText())) {
126+
MessageBox messageBox = new MessageBox(shell, SWT.ERROR);
127+
messageBox.setMessage("Version number should be an integer!");
128+
messageBox.open();
129+
} else {
130+
try {
131+
JsonProperty jsonProperty = new JsonProperty(nameText.getText(), descriptionText.getText(),
132+
versionText.getText(), typeCombo.getItem(typeCombo.getSelectionIndex()));
133+
new JsonUtils().serializeJson(jsonProperty, graph.getPipelinesString());
134+
shell.close();
135+
} catch (CoreException | IOException error) {
136+
error.printStackTrace(); // TODO:
137+
}
138+
}
139+
}
140+
});
141+
142+
Button cancelButton = new Button(shell, SWT.PUSH);
143+
cancelButton.setText("Cancel");
144+
GridData cancelbuttonGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
145+
cancelButton.setLayoutData(cancelbuttonGridData);
146+
cancelButton.addSelectionListener(new SelectionAdapter() {
147+
148+
@Override
149+
public void widgetSelected(SelectionEvent e) {
150+
shell.close();
151+
}
152+
});
153+
154+
Monitor primary = display.getPrimaryMonitor();
155+
Rectangle bounds = primary.getBounds();
156+
Rectangle rect = shell.getBounds();
157+
int x = bounds.x + (bounds.width - rect.width) / 2;
158+
int y = bounds.y + (bounds.height - rect.height) / 2;
159+
shell.setLocation(x, y);
160+
161+
shell.pack();
162+
shell.open();
163+
while (!shell.isDisposed()) {
164+
if (!display.readAndDispatch())
165+
display.sleep();
166+
}
167+
}
168+
169+
}

0 commit comments

Comments
 (0)