Commit aee0810d authored by ics's avatar ics

ForLoop synchronisation

parent f2c67df7
......@@ -27,6 +27,7 @@ import fr.ill.ics.bridge.listeners.ServerExpressionChangeListener;
import fr.ill.ics.bridge.listeners.ServerProgressChangeListener;
import fr.ill.ics.bridge.listeners.ServerPropertyChangeListener;
import fr.ill.ics.bridge.listeners.ServerResetCommandListener;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopType;
import fr.ill.ics.nscclient.command.ServerCommandBox;
import fr.ill.ics.nscclient.notification.commandzone.CommandZoneEventClient;
......@@ -84,6 +85,7 @@ public abstract class CommandWrapper implements IServerCommand, ICommandBoxEvent
public void removeServerCommandBoxSyncListener(ServerCommandBoxSyncListener listener) {
this.commandBoxSyncListener = null;
CommandZoneEventClient.getInstance().removeCommandBoxListener(this);
}
public void addServerExpressionChangeListener(ServerExpressionChangeListener listener) {
......@@ -239,6 +241,11 @@ public abstract class CommandWrapper implements IServerCommand, ICommandBoxEvent
commandBoxSyncListener.onSetForLoopType(type, lineIndex);
}
@Override
public void onSetForLoopStepType(ForLoopStepType type, int lineIndex) {
commandBoxSyncListener.onSetForLoopStepType(type, lineIndex);
}
@Override
public void onSetForLoopValues(int lineIndex, String value) {
commandBoxSyncListener.onSetForLoopValues(lineIndex, value);
......
......@@ -123,7 +123,7 @@ public class ForLoopCommandWrapper extends CommandWrapper implements IForLoopEve
return StepType.NBPOINTS;
}
public boolean addForLoopLine(int index) {
public final boolean addForLoopLine(int index) {
return serverForLoopCommandBox.addForLoopLine(index);
}
......
......@@ -18,6 +18,7 @@
package fr.ill.ics.bridge.command;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopType;
public interface ICommandBoxSyncEventListener {
......@@ -42,4 +43,5 @@ public interface ICommandBoxSyncEventListener {
void onAddForLoopLine(int lineIndex);
void onRemoveForLoopLine(int lineIndex);
void onSetForLoopStepType(ForLoopStepType forLoopStepType, int lineIndex);
}
\ No newline at end of file
......@@ -18,6 +18,7 @@
package fr.ill.ics.bridge.listeners;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopType;
public interface ServerCommandBoxSyncListener {
......@@ -37,4 +38,5 @@ public interface ServerCommandBoxSyncListener {
void onSetForLoopStepSize(int lineIndex, double value);
void onAddForLoopLine(int lineIndex);
void onRemoveForLoopLine(int lineIndex);
void onSetForLoopStepType(ForLoopStepType type, int lineIndex);
}
\ No newline at end of file
......@@ -61,7 +61,7 @@ public class CommandZoneSyncEventClient {
}
}
public void removeCommandZoneListener(ICommandBoxSyncEventListener listener) {
public void removeCommandBoxListener(ICommandBoxSyncEventListener listener) {
synchronized (commandBoxListeners) {
if (commandBoxListeners.containsKey(listener.getCommandBoxID())) {
HashSet<ICommandBoxSyncEventListener> listeners = commandBoxListeners.get(listener.getCommandBoxID());
......@@ -157,6 +157,20 @@ public class CommandZoneSyncEventClient {
}
}
private void notifySetForLoopStepType(SetForLoopStepType event) {
synchronized (commandBoxListeners) {
if (commandBoxListeners.containsKey(event.getCommandBoxId())) {
HashSet<ICommandBoxSyncEventListener> listeners = commandBoxListeners.get(event.getCommandBoxId());
Iterator<ICommandBoxSyncEventListener> it = listeners.iterator();
while (it.hasNext()) {
it.next().onSetForLoopStepType(event.getForLoopStepType(), event.getLineIndex());
}
}
}
}
private void notifySetForLoopValues(SetForLoopValues event) {
synchronized (commandBoxListeners) {
......@@ -338,7 +352,6 @@ public class CommandZoneSyncEventClient {
}
private void notifyAddNewForLoopCommandBox(AddNewForLoopCommandBox event) {
synchronized (commandZoneListeners) {
Iterator<ICommandZoneSyncEventListener> it = commandZoneListeners.iterator();
while (it.hasNext()) {
......@@ -348,7 +361,6 @@ public class CommandZoneSyncEventClient {
}
private void notifyAddNewForLoopCommandBoxAtEnd(AddNewForLoopCommandBoxAtEnd event) {
synchronized (commandZoneListeners) {
Iterator<ICommandZoneSyncEventListener> it = commandZoneListeners.iterator();
while (it.hasNext()) {
......@@ -457,6 +469,9 @@ public class CommandZoneSyncEventClient {
else if (event instanceof SetForLoopType) {
notifySetForLoopType((SetForLoopType)event);
}
else if (event instanceof SetForLoopStepType) {
notifySetForLoopStepType((SetForLoopStepType)event);
}
else if (event instanceof SetForLoopValues) {
notifySetForLoopValues((SetForLoopValues)event);
}
......
......@@ -6,6 +6,7 @@ import fr.ill.ics.nomadserver.commandzone.CommandZoneRequests;
import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nomadserver.notification.NotificationMessage;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ContainerType;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopType;
import fr.ill.ics.nscclient.sessionmanagement.SessionManager;
......@@ -296,6 +297,15 @@ public class CommandZoneSyncEventNotifier {
return new SetForLoopType(request.getCommandBoxID(), request.getLineIndex(), (forLoopType == CommandZoneRequests.ForLoopType.Type.VALUES ? ForLoopType.VALUES : ForLoopType.RANGE));
}
}
else if (type == CommandZoneRequests.Message.Type.SetStepType) {
CommandZoneRequests.SetForLoopStepTypeRequest request = CommandZoneRequests.SetForLoopStepTypeRequest.parseFrom(message.getSerializedContent());
// Notify only if it is the same client that was the originator of the request.
if (request.getClientID() != getClientID()) {
CommandZoneRequests.ForLoopStepType.Type forLoopStepType = request.getType();
return new SetForLoopStepType(request.getCommandBoxID(), request.getLineIndex(), (forLoopStepType == CommandZoneRequests.ForLoopStepType.Type.DELTA ? ForLoopStepType.DELTA : ForLoopStepType.NBPOINTS));
}
}
else if (type == CommandZoneRequests.Message.Type.SetVariableName) {
CommandZoneRequests.SetForLoopStringValueRequest request = CommandZoneRequests.SetForLoopStringValueRequest.parseFrom(message.getSerializedContent());
......
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
package fr.ill.ics.nscclient.notification.commandzone.sync;
import fr.ill.ics.nscclient.command.CommandZoneAccessor.ForLoopStepType;
public class SetForLoopStepType extends CommandBoxSyncEvent {
private ForLoopStepType forLoopStepType;
private int lineIndex;
public SetForLoopStepType(int commandBoxId, int lineIndex, ForLoopStepType forLoopStepType) {
super(commandBoxId);
this.forLoopStepType = forLoopStepType;
this.lineIndex = lineIndex;
}
public ForLoopStepType getForLoopStepType() {
return forLoopStepType;
}
public int getLineIndex() {
return lineIndex;
}
}
\ No newline at end of file
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