classdef (Hidden = true) HostSILDebugger < rtw.connectivity.XILDebugger
    %HOSTSILDEBUGGER provides a handle to a debugger for use with SIL on the host. 
    %
    %   This is an undocumented class. Its methods and properties are likely to
    %   change without warning from one release to the next.
    %
    %   HostSILDebugger is an abstract class which is implemented by
    %   platform-specific subclasses.
    
    %   Copyright 2014-2020 The MathWorks, Inc.
    
    methods
        % constructor
        function this = HostSILDebugger(componentArgs, topContext, silDebuggingInfo)
            narginchk(3,3);
            this@rtw.connectivity.XILDebugger(componentArgs, topContext, silDebuggingInfo);
        end
        
        function delete(this)
            delete@rtw.connectivity.XILDebugger(this);
        end
    end
    
    methods (Abstract)
        
        launchProcess(this)
        %LAUNCHPROCESS - called to launch the debug utility with the
        %SIL/PIL process
    
    end
    
    methods (Static = true) % static methods

        function result = commandExists(theCommand)
            % Create a script to test if a command is present in the user's
            % distribution
            scriptFile = [tempname '.sh'];
            rtw.connectivity.Utils.cleanTempFile(scriptFile);
                       
            fid = fopen(scriptFile, 'w');
            % use POSIX command -v to determine if ddd exists 
            fprintf(fid, 'command -v %s >/dev/null 2>&1 || exit 1',theCommand);
            fclose(fid);
            %Pass script to shell. See g1944828
            result = system(['/bin/sh "' scriptFile '" < /dev/null']) == 0;
            
            % Cleanup the script file
            rtw.connectivity.Utils.cleanTempFile(scriptFile);
        end

    end
end
