Commit 97bc54b9 authored by Piotr Różański's avatar Piotr Różański Committed by Marian Dovgialo

#45485 Sending online tags to OBCI instead of saving it by Svarog

parent 74136f8b
......@@ -138,4 +138,8 @@ public final void saveDocument() throws SignalMLException, IOException {
*/
protected abstract void writeDocument(OutputStream os) throws SignalMLException, IOException;
@Override
public boolean isSaveable() {
return true;
}
}
......@@ -56,21 +56,6 @@
*/
private EventListenerList listenerList = new EventListenerList();
@Override
public boolean isAllSaved() {
synchronized (this) {
for (Document document : documents) {
if (document instanceof MutableDocument) {
MutableDocument md = (MutableDocument) document;
if (!md.isSaved()) {
return false;
}
}
}
}
return true;
}
@Override
public int getDocumentCount() {
synchronized (this) {
......
......@@ -418,7 +418,7 @@ public void closeAllDocuments() throws IOException, SignalMLException {
*/
public boolean saveDocument(Document document, boolean saveAsOnly) throws IOException, SignalMLException {
if (!(document instanceof MutableDocument)) {
if (!document.isSaveable()) {
return true;
}
......@@ -1508,7 +1508,7 @@ private boolean assertDocumentIsSaved(Document document, boolean saveAsOnly, boo
boolean ok;
if (document instanceof MutableDocument) {
if (document.isSaveable()) {
MutableDocument md = (MutableDocument) document;
if (!md.isSaved()) {
......
......@@ -27,14 +27,6 @@
*/
public interface DocumentManager {
/**
* Checks if all documents {@link MutableDocument that can be saved} are
* saved.
* @return {@code true} if all documents are saved, {@code false} if at
* least one is not saved
*/
boolean isAllSaved();
/**
* Returns the number of all {@link Document documents} in this manager.
* @return the number of all documents in this manager
......
......@@ -408,4 +408,9 @@ public void updateSignalSpaceConstraints(SignalSpaceConstraints constraints) {
return exportedStyles;
}
@Override
public boolean isSaveable() {
boolean isOnline = parent instanceof MonitorSignalDocument;
return !isOnline; // online tags are saved by OBCI
}
}
......@@ -39,6 +39,7 @@
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.UUID;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
......@@ -2350,7 +2351,8 @@ private void changeSelectedTagType() {
private void createUserTagInMonitorMode() {
MonitorSignalDocument monitor = (MonitorSignalDocument) document;
if (tagStyle.getType() == SignalSelectionType.CHANNEL) {
final MonitorTag tag = new MonitorTag(tagStyle, MonitorTag.getCurrentTimestamp(), 1.0, -1, null);
String tagID = UUID.randomUUID().toString();
final MonitorTag tag = new MonitorTag(tagStyle, MonitorTag.getCurrentTimestamp(), 1.0, -1, tagID);
monitor.getMonitorWorker().acceptUserTag(tag);
}
}
......
......@@ -33,6 +33,7 @@
import org.signalml.app.worker.monitor.messages.MessageType;
import org.signalml.app.worker.monitor.messages.SignalMsg;
import org.signalml.app.worker.monitor.messages.IncompleteTagMsg;
import org.signalml.app.worker.monitor.messages.TagMsg;
import org.signalml.peer.Peer;
import org.signalml.psychopy.PsychopyStatusListener;
......@@ -81,7 +82,14 @@ public MonitorWorker(ExperimentDescriptor experimentDescriptor, RoundBufferMulti
}
public void acceptUserTag(MonitorTag tag) {
process(Collections.singletonList(tag));
TagMsg tagMessage = new TagMsg(
tag.getID(),
tag.getStyle().getName(),
Integer.toString(tag.getChannel()),
tag.getTimestamp(),
tag.getTimestamp() + tag.getLength()
);
peer.publish(tagMessage);
}
@Override
......
package org.signalml.app.worker.monitor.messages;
import java.util.LinkedHashMap;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
/**
......@@ -23,6 +24,24 @@
@JsonProperty("desc")
private LinkedHashMap<String, Object> desc;
public IncompleteTagMsg() {
super();
}
public IncompleteTagMsg(String id, String name, String channels, double start_timestamp) {
this(MessageType.INCOMPLETE_TAG_MSG, id, name, channels, start_timestamp);
}
protected IncompleteTagMsg(MessageType type, String id, String name, String channels, double start_timestamp) {
super(type);
this.id = id;
this.name = name;
this.channels = channels;
this.start_timestamp = start_timestamp;
this.desc = new LinkedHashMap<>();
}
@JsonIgnore
public double getStartTimestamp()
{
return start_timestamp;
......@@ -31,6 +50,7 @@ public double getStartTimestamp()
/**
* @return tag duration in seconds (∞ for incomplete tags)
*/
@JsonIgnore
public double getDuration()
{
// special value to mark unfinished tags
......
package org.signalml.app.worker.monitor.messages;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
/**
......@@ -10,15 +11,26 @@
@JsonProperty("end_timestamp")
private double end_timestamp;
public TagMsg() {
super();
}
public TagMsg(String id, String name, String channels, double start_timestamp, double end_timestamp) {
super(MessageType.TAG_MSG, id, name, channels, start_timestamp);
this.end_timestamp = end_timestamp;
}
/**
* @return tag duration in seconds
*/
@JsonIgnore
@Override
public double getDuration()
{
return getEndTimestamp() - getStartTimestamp();
}
@JsonIgnore
public double getEndTimestamp()
{
return end_timestamp;
......
......@@ -191,7 +191,7 @@ public BaseMessage receive(int timoutMillis) throws OpenbciCommunicationExceptio
return receiveFromSocket(sub, timoutMillis);
}
public void publish(BaseMessage message) {
public synchronized void publish(BaseMessage message) {
if (this.closed){
throw new ZMQException(_("sockets are closed"), 5);
}
......
......@@ -132,4 +132,9 @@ public void setActive(boolean active) {
//if anything should be done after this state change
//this method should be overriden.
}
@Override
public boolean isSaveable() {
return false;
}
}
......@@ -125,4 +125,19 @@
*/
public void setActive(boolean active);
/**
* Return whether the document can be saved to a file by Svarog.
*
* @internal This is a replacement for checking "X instanceof MutableDocument"
* as a fast fix before a release, so that TagDocument in online mode would
* not be treated as mutable, i.e. saveable. Rather, it should be implemented
* by refactoring the class hierarchy and introducing a new class
* MonitorTagDocument which would NOT be a MutableDocument. Also,
* AbstractMutableFileDocument could be removed in the process, as its only
* subclass is TagDocument.
*
* @return true if document is saveable, false otherwise
*/
public boolean isSaveable();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment