classdef (Hidden = true) TargetInterfaceHeaderWriter < handle
%TARGETINTERFACEHEADERWRITER Write out the target interface header file.
%
%   This is an undocumented class. Its methods and properties are likely to
%   change without warning from one release to the next.

%   Copyright 2016 The MathWorks, Inc.

    % properties
    properties (SetAccess = 'private', GetAccess = 'private')
       HeaderFilePath;
       % writer
       Writer;
       IncludeGuard;
    end
        
    methods
        % constructor
        function this = TargetInterfaceHeaderWriter(outputPath, headerName)
            narginchk(2, 2);            
            
            % model specific files
            this.HeaderFilePath = fullfile(outputPath, headerName);
        end  
        
        function writeOutput(this, append, callCBeautifier, obfuscateCode)            
            narginchk(4, 4);
            
            args = {'append', append,...
                'callCBeautifier', callCBeautifier,...
                'obfuscateCode', obfuscateCode};
            
            % header file     
            [~, fname] = fileparts(this.HeaderFilePath);
            this.IncludeGuard = sprintf('%s_H', upper(fname));            
            this.Writer = rtw.connectivity.CodeWriter.create('fileName', this.HeaderFilePath, args{:});
            this.writeHeaderFile;
            this.Writer.close;
            
        end
    end
    
    methods (Access = 'private')
               
        function writeHeaderFile(this)
            [~, fname, fext] = fileparts(this.HeaderFilePath);
            this.Writer.wLine('/*');
            this.Writer.wLine(' * File: %s%s', fname, fext);
            this.Writer.wLine(' *');
            this.Writer.wLine(' * Abstract: Target interface definitions.');
            this.Writer.wLine(' */');
            this.Writer.newLine;     
            this.writeSectionIncludeGuardHeader;
            this.Writer.wLine('#include "rtwtypes.h"');
            this.Writer.wLine('#include "xil_interface_common.h"');
            this.Writer.wLine('#include "xil_interface_lib_private.h"');          
            this.Writer.wLine('#include "xil_data_stream.h"');
            this.Writer.newLine;            
            this.Writer.wLine('void xilPreEntryPoint(uint32_T entryPointID);');
            this.Writer.wLine('XIL_INTERFACE_ERROR_CODE xilPostEntryPoint(uint32_T entryPointID);');
            this.Writer.wLine('XIL_INTERFACE_ERROR_CODE xilPostTerminatePoint(uint32_T entryPointID);');           
            this.Writer.newLine;     
            this.writeSectionIncludeGuardTrailer;
        end
        
        
        function writeSectionIncludeGuardHeader(this)           
           this.Writer.wLine('#ifndef %s', this.IncludeGuard);
           this.Writer.wLine('#define %s', this.IncludeGuard);  
           this.Writer.newLine;
        end
        
        function writeSectionIncludeGuardTrailer(this)
           this.Writer.wLine('#endif /* %s */', this.IncludeGuard);
        end           
    end
end

% LocalWords:  CBeautifier
