Commit 780f2106 authored by Locatelli's avatar Locatelli

Merge remote-tracking branch 'origin/V4.0' into ploty2

parents afc7c43b 847744ec
......@@ -42,9 +42,9 @@ public class LoginManager {
public class ConnectionFailure extends Exception {};
public void login(String login, String password, boolean standalone, String serverId) throws LoginIncorrectException, ClientAlreadyLaunchedException, ConnectionFailure {
public void login(String login, boolean standalone, String serverId) throws LoginIncorrectException, ClientAlreadyLaunchedException, ConnectionFailure {
try {
ServerSessionManager.getInstance(serverId).login(standalone);
ServerSessionManager.getInstance(serverId).login(standalone, login);
} catch (SessionManager.ClientAlreadyLaunchedException e) {
throw new ClientAlreadyLaunchedException();
} catch (ServerSessionManager.ConnectionFailure e) {
......
......@@ -117,6 +117,13 @@ public class ServerConnection {
return true;
}
public boolean serverExists() {
serverInstance = ServerInstance.getInstance().getApplicationInstance(serverId);
return (serverInstance != null && serverInstance.exists());
}
/**
* Returns a string message for the current state
*/
......
......@@ -26,12 +26,20 @@ public class ServerInstance {
}
public void init() {
String nomadServerEndpoint = null;
// Get the server endpoint.
String nomadServerEndpoint = ConfigManager.getInstance().getNomadServerEndpoint();
if (ConfigManager.getInstance().isMainClient()) {
nomadServerEndpoint = ConfigManager.getInstance().getNomadServerEndpoint();
} else {
// nomad endpoint is build from selected instrument
//nomadServerEndpoint = return "tcp://" + SessionManager.getInstance(CommandZoneWrapper.SERVER_ID).getInstrumentName() + ":7000";
nomadServerEndpoint = "tcp://localhost:7000";
}
// Connect to the server.
server = new Server(nomadServerEndpoint);
System.out.println("in serverinstance after new Server(" + nomadServerEndpoint + ")");
}
public Application.Instance getApplicationInstance(String serverId) {
......
......@@ -83,12 +83,12 @@ public class ServerSessionManager {
return instances.get(serverId);
}
public void login(boolean standAlone) throws SessionManager.ClientAlreadyLaunchedException, ConnectionFailure, LoadFailure {
public void login(boolean standAlone, String user) throws SessionManager.ClientAlreadyLaunchedException, ConnectionFailure, LoadFailure {
init();
try {
SessionManager.getInstance(serverId).login(standAlone);
SessionManager.getInstance(serverId).login(standAlone, user);
}
catch (ClientAlreadyLaunchedException e) {
// Only rethrow the exception. The call to logoutAll is made in the main application.
......
......@@ -37,6 +37,11 @@ public class SessionManager {
private boolean allOk;
private int clientId = 0;
// If remote access
private String user;
private String password;
private String instrumentName;
private static Map<String, SessionManager> instances = new HashMap<String, SessionManager>();
public class ClientAlreadyLaunchedException extends Exception {};
......@@ -93,6 +98,10 @@ public class SessionManager {
}
public void login(boolean standAlone) throws ClientAlreadyLaunchedException {
login(standAlone, null);
}
public void login(boolean standAlone, String user) throws ClientAlreadyLaunchedException {
// Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder()
......@@ -100,9 +109,19 @@ public class SessionManager {
.build();
// Create the request.
SessionRequests.LoginRequest request = SessionRequests.LoginRequest.newBuilder()
.setStandAlone(standAlone)
.build();
SessionRequests.LoginRequest request;
if (user != null) {
request = SessionRequests.LoginRequest.newBuilder()
.setStandAlone(standAlone)
.setUser(user)
.build();
}
else {
request = SessionRequests.LoginRequest.newBuilder()
.setStandAlone(standAlone)
.build();
}
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
......@@ -123,6 +142,29 @@ public class SessionManager {
}
}
public void loginRefused(String user, String reason) {
// Create the message type.
SessionRequests.Message type = SessionRequests.Message.newBuilder()
.setType(SessionRequests.Message.Type.LoginRefused)
.build();
// Create the request.
SessionRequests.LoginRefusedRequest request = SessionRequests.LoginRefusedRequest.newBuilder()
.setUser(user)
.setReason(reason)
.build();
sessionRequester.sendTwoParts(type.toByteArray(), request.toByteArray());
try {
Common.BooleanResponse.parseFrom(sessionRequester.receive());
}
catch (InvalidProtocolBufferException e) {
System.err.println("error in parsing response of loginRefused");
}
}
public void enableRemoteControl(String clientType) {
// Create the message type.
......@@ -267,4 +309,14 @@ public class SessionManager {
public int getClientId() {
return clientId;
}
public void setRemoteAccessInformation(String user, String password, String instrumentName) {
this.user = user;
this.password = password;
this.instrumentName = instrumentName;
}
public String getInstrumentName() {
return instrumentName;
}
}
\ No newline at end of file
......@@ -104,6 +104,7 @@ public class ConfigManager {
public static final String CLIENT_TYPE_PROPERTY = "clientType";
public final static String FCU_EXTENSION = ".txt";
public static final String MAIN_USER = "main";
private Set<String> instrumentsAllowingPALFiles;
......
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