classdef (Abstract) ExecutionTool < target.internal.ExecutionTool
%EXECUTIONTOOL Abstract class defining the service interface of a target 
% execution tool used to execute applications on a target platform.

%   Copyright 2020-2023 The MathWorks, Inc.
    
    properties (Dependent)
        
        % Path to application to execute
        Application string {mustBeScalarOrEmpty};
        
        % Command-line arguments to pass to the application which will be
        % executed
        ApplicationCommandLineArguments string {mustBeVector(ApplicationCommandLineArguments, 'allow-all-empties')};
    end
    
    properties

        % Target Connection info
        Connection;
    end

    methods

        % Open the application harness, if one exists. An example of an
        % application harness could be a simulator or debugger.
        function errFlag = open(this) %#ok<*MANU>
            
            this.notImplemented();            
            errFlag = false;
        end
        
        % Close the application harness, if one exists.
        function errFlag = close(this)
            
            this.notImplemented();            
            errFlag = false;
        end
        
        % Load the application into the application harness, if one exists.
        % This method does not start execution. If loading the application
        % starts execution automatically, implement this logic in 
        % startApplication without providing a loadApplication
        % implementation.
        function errFlag = loadApplication(this)
            
            this.notImplemented();            
            errFlag = false;
        end        
        
        % Unload the application from the application harness, if one
        % exists.
        function errFlag = unloadApplication(this)
            
            this.notImplemented();            
            errFlag = false;
        end
        
        % Start executing the application on the target.
        function errFlag = startApplication(this)
            
            this.notImplemented();
            errFlag = false;
        end
        
        % Stop execution of the application on the target.
        function errFlag = stopApplication(this)
            
            this.notImplemented();            
            errFlag = false;
        end
        
        % Get the status of the application running on the target.
        function [isAlive, errFlag] = getApplicationStatus(this)
            
            this.notImplemented();            
            errFlag = false;
            isAlive = target.ApplicationStatus.Unknown;
        end
        
        % Get output captured from the applications standard output stream
        function [output, errFlag] = getStandardOutput(this)
            
            this.notImplemented();
            output = '';
            errFlag = false;
        end
        
        % Get output captured from the applications standard error stream
        function [err, errFlag] = getStandardError(this)
            
            this.notImplemented();
            err = '';
            errFlag = false;
        end
    end

    methods (Hidden)        
        
        % Initialize state in the ExecutionTool instance.
        function errFlag = initialize(this)
            
            % Initialize is always optional.
            errFlag = false;
        end
        
        % Kill execution of the application on the target.
        function errFlag = terminateApplication(this)
            
            this.notImplemented();            
            errFlag = false;
        end
               
        % Wait for the application execution to end.
        function errFlag = join(this)
            
            this.notImplemented();            
            errFlag = false;
        end
        
        % Reset the application on the target.
        function errFlag = resetApplication(this)
            
            this.notImplemented();            
            errFlag = false;
        end
        
        % Attach to the executing application on the target.
        function errFlag = attach(this)
            
            this.notImplemented();
            errFlag = false;
        end
                
        % Detach to the executing application on the target.
        function errFlag = detach(this)
            
            this.notImplemented();
            errFlag = false;
        end
        
        % Get output captured from the applications standard output stream
        function [output, errFlag] = getNewStandardOutput(this)
            
            this.notImplemented();
            output = '';
            errFlag = false;
        end
        
        % Get output captured from the applications standard error stream
        function [err, errFlag] = getNewStandardError(this)
            
            this.notImplemented();
            err = '';
            errFlag = false;
        end
        
        % Get output captured from the applications standard error stream
        function errFlag = writeToStandardInput(this, textToWrite) %#ok<INUSD>
            
            this.notImplemented();
            errFlag = false;
        end
    end
    
    properties (Access=private)
        fApplication string {mustBeScalarOrEmpty};
        fApplicationCommandLineArguments string {mustBeVector(fApplicationCommandLineArguments, 'allow-all-empties')};
    end    
    
    methods (Hidden, Access=protected)        
        
        function value = getProperty_Application(this)            
            value = this.fApplication;
        end
        
        function setProperty_Application(this, value)
            this.fApplication = value;
        end
        
        function value = getProperty_ApplicationCommandLineArguments(this)
            value = this.fApplicationCommandLineArguments;
        end
        
        function setProperty_ApplicationCommandLineArguments(this, value)            
            this.fApplicationCommandLineArguments = value;
        end           
    end
    
    methods
        
        function value = get.Application(this)            
            value = this.getProperty_Application();
        end
        
        function set.Application(this, value)
            this.setProperty_Application(value);
        end
        
        function value = get.ApplicationCommandLineArguments(this)
            value = this.getProperty_ApplicationCommandLineArguments();
        end
        
        function set.ApplicationCommandLineArguments(this, value)            
            this.setProperty_ApplicationCommandLineArguments(value);
        end      
    end
end
