classdef (Hidden = true) HostInterfaceHeaderWriter < handle
%HOSTINTERFACEHEADERWRITER Write out the host 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-2022 The MathWorks, Inc.

% properties
properties (SetAccess = 'private', GetAccess = 'private')
HeaderFilePath;
% writer
Writer;
IncludeGuard;
end

methods
% constructor
function this = HostInterfaceHeaderWriter(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: Host interface definitions.');
this.Writer.wLine(' */');
this.Writer.newLine;
this.writeSectionIncludeGuardHeader;
this.Writer.wLine('#include "tmwtypes.h"');
this.Writer.wLine('#include "coder/connectivity/memunit/MemUnitTransformerType.h"');
this.Writer.newLine;
this.Writer.wLine('#ifdef __cplusplus');
this.Writer.wLine('extern "C" {');
this.Writer.wLine('#endif');
this.Writer.newLine;
this.Writer.wLine('boolean_T xilReadData(uint8_T *dst, size_t numElements, mem_unit_type_T dataTypeId);');
this.Writer.wLine('boolean_T xilWriteData(uint8_T *src, size_t numElements, mem_unit_type_T dataTypeId);');
this.Writer.wLine('void xilPreEntryPointHost(uint32_T taskID);');
this.Writer.wLine('void xilEntryPointHost(uint32_T taskID);');
this.Writer.wLine('void xilPostEntryPointHost(uint32_T taskID);');
this.Writer.wLine('void xilInitializeHost(void (*cleanUp)(void));');
this.Writer.newLine;
this.Writer.wLine('#ifdef __cplusplus');
this.Writer.wLine('}');
this.Writer.wLine('#endif');
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