Commit 2bbdfa5b authored by yannick legoc's avatar yannick legoc
Browse files

Reimplemented for loop accessor.

parent 6663f899
......@@ -198,16 +198,6 @@
<arg line="${idlFlags} ${idlCoreDir}/commandzone/CommandZoneAccessor.idl" />
</exec>
<echo message="Generating ScanCommandBoxAccessor.java" />
<exec executable="idl">
<arg line="${idlFlags} ${idlCoreDir}/commandzone/ScanCommandBoxAccessor.idl" />
</exec>
<echo message="Generating ForLoopCommandBoxAccessor.java" />
<exec executable="idl">
<arg line="${idlFlags} ${idlCoreDir}/commandzone/ForLoopCommandBoxAccessor.idl" />
</exec>
<echo message="Generating CommandBoxDescriptor.java" />
<exec executable="idl">
<arg line="${idlFlags} ${idlCoreDir}/commandzone/CommandBoxDescriptor.idl" />
......
......@@ -20,7 +20,7 @@ package fr.ill.ics.bridge.command;
import fr.ill.ics.bridge.events.ServerForLoopChangeEvent;
import fr.ill.ics.bridge.listeners.ServerForLoopChangeListener;
import fr.ill.ics.nscclient.command.ForLoopCommandBoxAccessorProxy;
import fr.ill.ics.nscclient.command.CommandZoneAccessor;
import fr.ill.ics.nscclient.command.ServerForLoopCommandBox;
import fr.ill.ics.nscclient.dataprovider.CommandDatabase;
import fr.ill.ics.nscclient.dataprovider.ServantDatabase;
......@@ -94,14 +94,14 @@ public class ForLoopCommandWrapper extends CommandWrapper implements IForLoopEve
public void setForLoopType(int index, LoopType type) {
if (type == LoopType.RANGE) {
serverForLoopCommandBox.setForLoopType(index, ForLoopCommandBoxAccessorProxy.Type.RANGE);
serverForLoopCommandBox.setForLoopType(index, CommandZoneAccessor.ForLoopType.RANGE);
} else {
serverForLoopCommandBox.setForLoopType(index, ForLoopCommandBoxAccessorProxy.Type.VALUES);
serverForLoopCommandBox.setForLoopType(index, CommandZoneAccessor.ForLoopType.VALUES);
}
}
public LoopType getForLoopType(int index) {
if (serverForLoopCommandBox.getForLoopType(index) == ForLoopCommandBoxAccessorProxy.Type.VALUES) {
if (serverForLoopCommandBox.getForLoopType(index) == CommandZoneAccessor.ForLoopType.VALUES) {
return LoopType.VALUES;
}
return LoopType.RANGE;
......
......@@ -34,8 +34,6 @@ import fr.ill.ics.cameo.RequesterCreationException;
import fr.ill.ics.nomadserver.commandzone.CommandZoneRequests;
import fr.ill.ics.nomadserver.common.Common;
import fr.ill.ics.nomadserver.common.Common.Error.Type;
import fr.ill.ics.nomadserver.core.commandzone.ScanCommandBoxAccessorPackage.BadCommandBoxTypeException;
import fr.ill.ics.nomadserver.core.commandzone.ScanCommandBoxAccessorPackage.CommandBoxNotFoundException;
import fr.ill.ics.nscclient.serverconnection.ServerInstance;
public class CommandZoneAccessor {
......@@ -46,8 +44,8 @@ public class CommandZoneAccessor {
private Application.Requester commandBoxRequester;
public enum ExecutionPhaseState {CONSTRUCTION, RUNNING, FINISHED, PAUSED};
public enum ContainerType {COMMANDZONE, IFTHEN, IFELSE, FORLOOP, SCAN};
public enum ForLoopType {RANGE, VALUES};
private static Map<String, CommandZoneAccessor> instances = new HashMap<String, CommandZoneAccessor>();
......@@ -1266,7 +1264,6 @@ public class CommandZoneAccessor {
processError(response.getError(), commandBoxID);
}
else {
System.out.println("addNewAtomicCommandBoxAtEnd " + commandBoxID);
return new ServerAtomicCommandBox(serverId, response.getValue());
}
}
......@@ -1732,4 +1729,515 @@ public class CommandZoneAccessor {
return null;
}
public void setVariableName(int commandBoxID, int lineIndex, String variableName) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.SetVariableName)
.build();
// Create the request.
CommandZoneRequests.SetForLoopStringValueRequest request = CommandZoneRequests.SetForLoopStringValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.setValue(variableName)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "setVariableName", "error in parsing response");
}
}
public String getVariableName(int commandBoxID, int lineIndex) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetVariableName)
.build();
// Create the request.
CommandZoneRequests.GetForLoopValueRequest request = CommandZoneRequests.GetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.StringResponse response = Common.StringResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
else {
return response.getValue();
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getVariableName", "error in parsing response for command box " + commandBoxID);
}
return null;
}
public void setStartValue(int commandBoxID, int lineIndex, double startValue) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.SetStartValue)
.build();
// Create the request.
CommandZoneRequests.SetForLoopValueRequest request = CommandZoneRequests.SetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.setValue(startValue)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "setStartValue", "error in parsing response");
}
}
public void setEndValue(int commandBoxID, int lineIndex, double endValue) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.SetEndValue)
.build();
// Create the request.
CommandZoneRequests.SetForLoopValueRequest request = CommandZoneRequests.SetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.setValue(endValue)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "setEndValue", "error in parsing response");
}
}
public void setStepSize(int commandBoxID, int lineIndex, double stepSize) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.SetStepSize)
.build();
// Create the request.
CommandZoneRequests.SetForLoopValueRequest request = CommandZoneRequests.SetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.setValue(stepSize)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "setStepSize", "error in parsing response");
}
}
public double getStartValue(int commandBoxID, int lineIndex) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetStartValue)
.build();
// Create the request.
CommandZoneRequests.GetForLoopValueRequest request = CommandZoneRequests.GetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.Float64Response response = Common.Float64Response.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
else {
return response.getValue();
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getStartValue", "error in parsing response for command box " + commandBoxID);
}
return 0;
}
public double getEndValue(int commandBoxID, int lineIndex) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetEndValue)
.build();
// Create the request.
CommandZoneRequests.GetForLoopValueRequest request = CommandZoneRequests.GetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.Float64Response response = Common.Float64Response.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
else {
return response.getValue();
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getEndValue", "error in parsing response for command box " + commandBoxID);
}
return 0;
}
public double getStepSize(int commandBoxID, int lineIndex) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetStepSize)
.build();
// Create the request.
CommandZoneRequests.GetForLoopValueRequest request = CommandZoneRequests.GetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.Float64Response response = Common.Float64Response.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
else {
return response.getValue();
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getStepSize", "error in parsing response for command box " + commandBoxID);
}
return 0;
}
public double getCurrentValue(int commandBoxID, int lineIndex) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetCurrentValue)
.build();
// Create the request.
CommandZoneRequests.GetForLoopValueRequest request = CommandZoneRequests.GetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.Float64Response response = Common.Float64Response.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
else {
return response.getValue();
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getCurrentValue", "error in parsing response for command box " + commandBoxID);
}
return 0;
}
public void setForLoopType(int commandBoxID, int lineIndex, ForLoopType forLoopType) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.SetType)
.build();
// Create the request.
CommandZoneRequests.SetForLoopTypeRequest request = CommandZoneRequests.SetForLoopTypeRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.setType((forLoopType == ForLoopType.VALUES ? CommandZoneRequests.ForLoopType.Type.VALUES : CommandZoneRequests.ForLoopType.Type.RANGE))
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "setForLoopType", "error in parsing response");
}
}
public ForLoopType getForLoopType(int commandBoxID, int lineIndex) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetCurrentValue)
.build();
// Create the request.
CommandZoneRequests.GetForLoopValueRequest request = CommandZoneRequests.GetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
CommandZoneRequests.ForLoopTypeResponse response = CommandZoneRequests.ForLoopTypeResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
else {
CommandZoneRequests.ForLoopType.Type forLoopType = response.getValue();
if (forLoopType == CommandZoneRequests.ForLoopType.Type.VALUES) {
return ForLoopType.VALUES;
}
return ForLoopType.RANGE;
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getForLoopType", "error in parsing response for command box " + commandBoxID);
}
return ForLoopType.RANGE;
}
public boolean setValues(int commandBoxID, int lineIndex, String values) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.SetValues)
.build();
// Create the request.
CommandZoneRequests.SetForLoopStringValueRequest request = CommandZoneRequests.SetForLoopStringValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.setValue(values)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
return false;
}
return true;
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "setValues", "error in parsing response");
}
return false;
}
public String getValues(int commandBoxID, int lineIndex) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetValues)
.build();
// Create the request.
CommandZoneRequests.GetForLoopValueRequest request = CommandZoneRequests.GetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.StringResponse response = Common.StringResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
else {
return response.getValue();
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "getValues", "error in parsing response for command box " + commandBoxID);
}
return null;
}
public boolean addForLoopLine(int commandBoxID, int lineIndex) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.AddForLoopLine)
.build();
// Create the request.
CommandZoneRequests.GetForLoopValueRequest request = CommandZoneRequests.GetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
return false;
}
return response.getValue();
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "addForLoopLine", "error in parsing response");
}
return false;
}
public void removeForLoopLine(int commandBoxID, int lineIndex) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.RemoveForLoopLine)
.build();
// Create the request.
CommandZoneRequests.GetForLoopValueRequest request = CommandZoneRequests.GetForLoopValueRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.setLineIndex(lineIndex)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse response = Common.BooleanResponse.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
}
catch (InvalidProtocolBufferException e) {
LOGGER.logp(Level.WARNING, this.getClass().getName(), "removeForLoopLine", "error in parsing response");
}
}
public int getNumberOfLines(int commandBoxID) {
// Create the message type.
CommandZoneRequests.Message type = CommandZoneRequests.Message.newBuilder()
.setType(CommandZoneRequests.Message.Type.GetNumberOfLines)
.build();
// Create the request.
CommandZoneRequests.CommandBoxRequest request = CommandZoneRequests.CommandBoxRequest.newBuilder()
.setCommandBoxID(commandBoxID)
.build();
commandBoxRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.Int32Response response = Common.Int32Response.parseFrom(commandBoxRequester.receive());
// Test the error.
if (response.hasError()) {
processError(response.getError(), commandBoxID);
}
else {
return response.getValue();
}
}