diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-05-05 19:24:45 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-05-05 19:24:45 +0300 |
| commit | 5571ab086f6288b27117e3eaae443415a162403c (patch) | |
| tree | d189224b3bca6789532516d33d12ea2f0a1327b2 /Software/Visual_Studio/Tango.Integration/ExternalBridge | |
| parent | dd81a94133e1c5117e06e84cbddf45ffec30acfc (diff) | |
| download | Tango-5571ab086f6288b27117e3eaae443415a162403c.tar.gz Tango-5571ab086f6288b27117e3eaae443415a162403c.zip | |
Require Safety Level Operations !
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/ExternalBridge')
5 files changed, 60 insertions, 20 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeClientConnectedEventArgs.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeClientConnectedEventArgs.cs index 7130845cc..e976898ef 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeClientConnectedEventArgs.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeClientConnectedEventArgs.cs @@ -9,17 +9,30 @@ namespace Tango.Integration.ExternalBridge { public class ExternalBridgeClientConnectedEventArgs : EventArgs { + private Action _confirmAction; + private Action<String> _declineAction; + public ExternalBridgeLoginRequest Request { get; set; } public String Address { get; set; } public ApplicationInformation ApplicationInformation { get; set; } - public bool Confirmed { get; set; } - - public ExternalBridgeClientConnectedEventArgs() + public ExternalBridgeClientConnectedEventArgs(Action confirmAction, Action<String> declineAction) { + _confirmAction = confirmAction; + _declineAction = declineAction; ApplicationInformation = new ApplicationInformation(); } + + public void Confirm() + { + _confirmAction?.Invoke(); + } + + public void Decline(String reason) + { + _declineAction?.Invoke(reason); + } } } diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs index 0b63f0be2..9c61f9e8b 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs @@ -53,6 +53,7 @@ namespace Tango.Integration.ExternalBridge private IMachineOperator _machineOperator; private Dictionary<MessageType, MessageHandler> _messageHandlers; + private HashSet<MessageType> _safetyOperations; #region Events @@ -65,6 +66,8 @@ namespace Tango.Integration.ExternalBridge #region Properties + public bool AllowSafetyLevelOperations { get; set; } + public bool RequiresDiagnostics { get; private set; } public bool RequiresDebugLogs { get; private set; } public bool RequiresEventsNotification { get; private set; } @@ -120,6 +123,8 @@ namespace Tango.Integration.ExternalBridge _messageHandlers.Add(MessageType.JobRequest, new MessageHandler(OnJobRequest, ExternalBridgeLoginIntent.Diagnostics)); _messageHandlers.Add(MessageType.StartPowerDownRequest, new MessageHandler(OnStartPowerDownRequest, ExternalBridgeLoginIntent.Diagnostics)); + + _safetyOperations = new HashSet<MessageType>(); } public ExternalBridgeReceiver(TcpClient tcpClient, IMachineOperator machineOperator) : this(machineOperator) @@ -142,6 +147,15 @@ namespace Tango.Integration.ExternalBridge try { + if (!AllowSafetyLevelOperations) + { + if (_safetyOperations.Contains(container.Type)) + { + SendErrorResponse(new AuthenticationException("The specified action requires safety level permission that is not granted for the current session."), container.Token); + return; + } + } + if (_messageHandlers.ContainsKey(container.Type)) { var handler = _messageHandlers[container.Type]; @@ -268,6 +282,8 @@ namespace Tango.Integration.ExternalBridge response.DeviceInformation = deviceInfo; response.ApplicationInformation = applicationInfo; + AllowSafetyLevelOperations = request.Message.RequireSafetyLevelOperations; + SendResponse<ExternalBridgeLoginResponse>(response, container.Token); UpdateMachineOperatorStatus((UpdateStatus)_machineOperator.Status); diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs index a2ad9f9c9..6cb758043 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs @@ -372,18 +372,11 @@ namespace Tango.Integration.ExternalBridge return; } - ExternalBridgeClientConnectedEventArgs args = new ExternalBridgeClientConnectedEventArgs(); - args.Request = request; - args.Address = e.Address; - ConnectionRequest?.Invoke(this, args); + ExternalBridgeClientConnectedEventArgs args = null; - var response = new ExternalBridgeLoginResponse(); - response.Authenticated = args.Confirmed; - response.SerialNumber = Machine.SerialNumber; - response.DeviceInformation = MachineOperator.DeviceInformation; - - if (args.Confirmed) + args = new ExternalBridgeClientConnectedEventArgs(() => { + //Confirmed e.Confirm(Machine, MachineOperator.DeviceInformation, args.ApplicationInformation); HasSessions = true; @@ -391,11 +384,15 @@ namespace Tango.Integration.ExternalBridge { FullControlSessionReceiver = sender as ExternalBridgeReceiver; } - } - else - { - e.Decline("Invalid password or intent."); - } + }, (reason) => + { + //Declined + e.Decline(reason); + }); + + args.Request = request; + args.Address = e.Address; + ConnectionRequest?.Invoke(this, args); } private void Receiver_ReceiverRequestReceived(object sender, ExternalBridgeReceiverRequestReceivedEventArgs e) diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeSignalRClient.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeSignalRClient.cs index 343fb302f..51dc49ed0 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeSignalRClient.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeSignalRClient.cs @@ -58,7 +58,14 @@ namespace Tango.Integration.ExternalBridge LogManager.Log("External Bridge SignalR Client Connected..."); - var response = await SendRequest<ExternalBridgeLoginRequest, ExternalBridgeLoginResponse>(login, new TransportRequestConfig() { ShouldLog = true }); + TimeSpan? timeout = null; + + if (login.RequireSafetyLevelOperations) + { + timeout = TimeSpan.FromSeconds(30); + } + + var response = await SendRequest<ExternalBridgeLoginRequest, ExternalBridgeLoginResponse>(login, new TransportRequestConfig() { ShouldLog = true, Timeout = timeout }); SessionLogger.CreateSession(); diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs index 850adff2d..d066b3be5 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs @@ -132,7 +132,14 @@ namespace Tango.Integration.ExternalBridge LogManager.Log("External Bridge TCP Client Connected..."); - var response = await SendRequest<ExternalBridgeLoginRequest, ExternalBridgeLoginResponse>(login, new TransportRequestConfig() { ShouldLog = true }); + TimeSpan? timeout = null; + + if (login.RequireSafetyLevelOperations) + { + timeout = TimeSpan.FromSeconds(30); + } + + var response = await SendRequest<ExternalBridgeLoginRequest, ExternalBridgeLoginResponse>(login, new TransportRequestConfig() { ShouldLog = true, Timeout = timeout }); ApplicationInformation = response.Message.ApplicationInformation; |
