classdef (Hidden = true) SubsystemTargetInterface < rtw.pil.ModelBlockTargetInterface   
%SUBSYSTEMTARGETINTERFACE creates a subsystem target interface file
%
%   This is an undocumented class. Its methods and properties are likely to
%   change without warning from one release to the next.

%   Copyright 2019-2020 The MathWorks, Inc.

    properties(Access = 'private')
        NeedsNonFiniteSetup(1,1) logical = false;
    end

    methods
        % constructor
        function this = SubsystemTargetInterface(silPILWrapperUtils, ...
                targetInterfacePath)
            narginchk(2, 2);
            % call super class constructor
            this@rtw.pil.ModelBlockTargetInterface(silPILWrapperUtils, ...
                targetInterfacePath);  
        end                
    end
    
    methods (Access = 'protected')
        function absTimeData = getAbsoluteTimeData(this)
            % Override the superclass method with a default implementation, 
            % i.e. no ClockTicks required.
            % The ModelInterface for RLS is generated from top-level code 
            % and does not contain ClockTicks info. This is only relevant 
            % if timingBridge is required and that applies only to model 
            % reference code.
            
            modelInterface = this.SILPILWrapperUtils.getInfoStruct.modelInterface;
            
            assert(~(isfield(modelInterface, 'ClockTicksReq') || ...
                     isfield(modelInterface, 'LongClockTicksReq')), ...
                'ClockTicksReq and LongClockTicksReq are not expected in modelInterface for RLS');
            
            absTimeData.XILWrapperProvideClockTicks = false;
            
            absTimeData.ClockTicksReqVector = 0;
            absTimeData.LongClockTicksReqVector = 0;
            
            absTimeData.isClockTicksRequired = false;
            absTimeData.isLongClockTicksRequired = false;
        end  
        
        function isObj = isCPPModelObject(~, ~)
            % Subsystem code is not a class, there is no corresponding
            % ModelObject.
            isObj = false;
        end
        
        function modelObject = getCPPModelObject(~) %#ok<STOUT>
            assert(false, 'getCPPModelObject should not be called for Subsystem code');
        end
        
        function isCAPIEnabled = isCAPIEnabled(~)
            isCAPIEnabled = false;
        end
        
        function writeSectionIncludes(this)
            % call super class method
            writeSectionIncludes@rtw.pil.ModelBlockTargetInterface(this); 
            
            if this.codeInfoUtils.getCodeInfo().UsesNonFiniteUtils
               % add include to non-finites declarations
               this.writer.writeLine('#include "rt_nonfinite.h"'); 
               this.writer.newLine;
            end
        end 
        
        function writeSectionInitBody(this)            
            
            if this.codeInfoUtils.getCodeInfo().UsesNonFiniteUtils
               this.writer.wComment('initialize non-finites');
               this.writer.writeLine('rt_InitInfAndNaN(sizeof(real_T));'); 
               this.writer.newLine;
            end
            
            % call super class method
            writeSectionInitBody@rtw.pil.ModelBlockTargetInterface(this);
        end
    end
end
