classdef (Hidden = true) InterfaceAdaptor < rtw.connectivity.BaseAdaptor
    % InterfaceAdaptor - defines the interface for an adaptor to 
    % RTW.ComponentInterface
    %
    %   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 
        Name;
        HeaderFile;
        GraphicalPath;
        AllocationFunction;
        SetupRuntimeResourcesFunction;
        CleanupRuntimeResourcesFunction;
        Inports;
        Outports;
        Parameters;
        DataStores;
        InterRateData;
        InternalData;
        ExternalBlockOutputs;
        GlobalBlockOutputs;
        DWorks;
        InitializeFunctions;
        OutputFunctions;
        UpdateFunctions;
        TerminateFunctions;
        SystemResetFunction;
        SystemInitializeFunction;
        InitConditionsFunction;
        EnableFunction;
        DisableFunction;
        ConstructorFunction;
        DerivativeFunction;
        ServerCallPoints;
        Subsystems;
        TimingProperties;
        ClockProperties;
        Types;
        SymbolicDimensionDefinitions;
        TimingInternalIds;
        XILTargetSerializationFunctionDefinitions;
        NonSampledZeroCrossings;
        ZeroCrossingEvents;
        RuntimeEnvironment;
    end
    
    properties (Access = protected)
        Internal_Parameters;
    end
    
    methods
        function res = get.Name(this)
            % not a Sequence
            res = this.getProp('Name');
        end
        
        function res = get.HeaderFile(this)
            % not a Sequence
            res = this.getProp('HeaderFile');
        end
        
        function res = get.GraphicalPath(this)
            % not a Sequence
            res = this.getProp('GraphicalPath');
        end
        
        function res = get.Inports(this)
            res = this.getProp('Inports').toArray;
        end
        
        function res = get.Outports(this)
            res = this.getProp('Outports').toArray;
        end
        
        function res = get.Parameters(this)
            res = this.Internal_Parameters;
        end
        
        function res = get.DataStores(this)
            res = this.getProp('DataStores').toArray;
        end
        
        function res = get.InterRateData(this)
            res = this.getProp('InterRateData').toArray;
        end
        
        function res = get.InternalData(this)
            res = this.getProp('InternalData').toArray;
        end
        
        function res = get.ExternalBlockOutputs(this)
            res = this.getProp('ExternalBlockOutputs').toArray;
        end
        
        function res = get.GlobalBlockOutputs(this)
            res = this.getProp('GlobalBlockOutputs').toArray;
        end
        
        function res = get.DWorks(this)
            res = this.getProp('DWorks').toArray;
        end
        
        function res = get.ServerCallPoints(this)
            res = this.getProp('ServerCallPoints').toArray;
        end
        
        function res = get.Subsystems(this)
            res = this.getProp('Subsystems').toArray;
        end
        
        function res = get.TimingProperties(this)
            res = this.getProp('TimingProperties').toArray;
        end
        
        function res = get.ClockProperties(this)
            res = this.getProp('ClockProperties').toArray;
        end
        function res = get.Types(this)
            res = this.getProp('Types').toArray;
        end
        
        function res = get.SymbolicDimensionDefinitions(this)
            res = this.SymbolicDimensionDefinitions;
        end
        
        function res = get.TimingInternalIds(this)
            res = this.getProp('TimingInternalIds').toArray;
        end
        
        function res = get.XILTargetSerializationFunctionDefinitions(this)
            res = this.getProp('XILTargetSerializationFunctionDefinitions');
        end
        
        function res = get.NonSampledZeroCrossings(this)
            res = this.getProp('NonSampledZeroCrossings').toArray;
        end
        
        function res = get.ZeroCrossingEvents(this)
            res = this.getProp('ZeroCrossingEvents').toArray;
        end
        
        function res = get.RuntimeEnvironment(this)
            res = this.getProp('RuntimeEnvironment');
        end
    end
    
    methods(Access = protected, Abstract)
        prop = getProp(this, propName);
        populateAdaptor(this, componentInterface);
        populateInternalParameters(this);
    end
    
    methods(Access = protected)
        function populateFunctionsArray(this, category, interface)
            
            functionsArray = interface.(category).toArray;
            numInterfaces = numel(functionsArray);
            baseAdaptor = rtw.connectivity.BaseAdaptor.empty;
            adaptorsArray = repmat(baseAdaptor, 1, numInterfaces);
            for idx = 1:numInterfaces
                % create an array of adapters
                adaptorsArray(idx) = this.createFunctionInterfaceAdaptor(functionsArray(idx));
            end
            this.(category) = adaptorsArray;
        end
        
        function adaptor = createFunctionInterfaceAdaptor(~, functionInterface)
            switch class(functionInterface)
                case 'coder.descriptor.FunctionInterface'
                    adaptor = rtw.connectivity.FIAdaptor(functionInterface);
                case 'coder.descriptor.SimulinkFunctionInterface'
                    adaptor = rtw.connectivity.SlFIAdaptor(functionInterface);
                case 'coder.descriptor.AutosarClientCall'
                    adaptor = rtw.connectivity.AutosarCCAdaptor(functionInterface);
                otherwise
                    assert(false,'Unexpected class ''%s'' in createFunctionInterfaceAdaptor.', functionClass);
            end
        end
    end
    
end
