classdef ComponentArgs < handle
%ComponentArgs provides parameters related to the component under test
%
% An instance of this class is created by the target connectivity
% infrastructure and is passed as a constructor argument to a user-defined
% connectivity configuration. You can call the "get" methods of this class to
% retrieve parameter values related to the component build. See the help on these
% methods for more details: the method names are listed below.
%
% ComponentArgs methods:
% GETCOMPONENTPATH - returns a path to the component being
% built
% GETCOMPONENTCODEPATH - returns a system path to the code generation
% directory
% GETCOMPONENTCODENAME - returns the component name used for code
% generation
% GETAPPLICATIONCODEPATH - returns a system path to the application
% directory
%
% See also CODER.MYPIL.CONNECTIVITYCONFIG

% Copyright 2007-2022 The MathWorks, Inc.
%

% private properties
properties(SetAccess = 'private', GetAccess = 'private')
componentPath;
componentCodePath;
componentCodeName;
applicationCodePath;
CoderAssumptionsAnchorDir;
InternalData;
CodeInstrInfo;
TopModel;
BuildHooks;
BuildHookHandles;
AnchorFolder;
ClientInterface;
XilCompInfo;
InTheLoopType;
VerboseCommunicationOutput = false;
ComponentForDiagnostics;
end

properties (Hidden)
CoderAssumptionsEnabled = true;
CoderAssumptionsDAZCheckEnabled = true;
end

% constructor
methods
function this = ComponentArgs(componentPath, ...
componentCodePath, ...
componentCodeName, ...
applicationCodePath)
narginchk(4, 4);
% store arguments
this.componentPath = componentPath;
this.componentCodePath = componentCodePath;
this.componentCodeName = componentCodeName;
this.applicationCodePath = applicationCodePath;
end

function coderAssumptionsEnabled = get.CoderAssumptionsEnabled(this)
% Determine whether Coder Assumptions is enabled based on:
% 1) Global feature control
% 2) CoderAssumptionsEnabled property
coderAssumptionsEnabled = ...
coder.internal.connectivity.featureOn('coderassumptions') && ...
this.CoderAssumptionsEnabled;
end

function coderAssumptionsDAZCheckEnabled = get.CoderAssumptionsDAZCheckEnabled(this)
% Determine whether Coder Assumptions DAZ check is enabled
% based on:
% 1) CoderAssumptionsEnabled property
% 2) CoderAssumptionsDAZEnabled property
coderAssumptionsDAZCheckEnabled = ...
this.CoderAssumptionsEnabled && this.CoderAssumptionsDAZCheckEnabled;
end
end

% methods can't be overridden
methods (Sealed)
function componentPath = getComponentPath(this)
%GETCOMPONENTPATH returns a path to the component being built
narginchk(1, 1);
componentPath = this.componentPath;
end

function componentCodePath = getComponentCodePath(this)
% getComponentCodePath returns a path to the location
% where buildInfo.mat for the component is located; differs
% from getOriginalComponentCodePath, only if the component is
% instrumented.

componentCodePath = this.componentCodePath;
lCodeInstrInfo = getCodeInstrInfo(this);
if ~isempty(lCodeInstrInfo)
[~, topInstrObjFolder] = getInstrSrcFolder(lCodeInstrInfo);
componentCodePath = fullfile...
(componentCodePath, topInstrObjFolder);
end
end

function componentCodeName = getComponentCodeName(this)
%GETCOMPONENTCODENAME returns the component name used for code generation
narginchk(1, 1);
componentCodeName = this.componentCodeName;
end

function applicationCodePath = getApplicationCodePath(this)
%GETAPPLICATIONCODEPATH returns a system path to the application directory
narginchk(1, 1);
applicationCodePath = this.applicationCodePath;
end

function value = getParam(this, param)
validateattributes(param, {'char', 'string'}, {'scalartext'});
configInterface = this.getConfigInterface;
assert(~isempty(configInterface), ...
'Empty configInterface!');
value = configInterface.getParam(convertStringsToChars(param));
end
end

methods (Sealed, Hidden)

function componentCodePath = getOriginalComponentCodePath(this)
% getOriginalComponentCodePath returns a path to the location
% where buildInfo.mat for the original component is located
componentCodePath = this.componentCodePath;
end

function isLCC = usingLcc(this)
isLCC = strcmp(this.XilCompInfo.XilMexCompilerKey, 'LCC-x');
end

function setXilCompInfo(this, lXilCompInfo)
this.XilCompInfo = lXilCompInfo;
end

function lXilCompInfo = getXilCompInfo(this)
narginchk(1, 1);
lXilCompInfo = this.XilCompInfo;
end

function setInternalData(this, internalData)
narginchk(2, 2);
this.InternalData = internalData;
end

function internalData = getInternalData(this)
narginchk(1, 1);
internalData = this.InternalData;
end

function setBuildHookHandles(this, lBuildHookHandles)
this.BuildHookHandles = lBuildHookHandles;
end

function lBuildHookHandles = getBuildHookHandles(this)
lBuildHookHandles = this.BuildHookHandles;
end

function setBuildHooks(this, lBuildHooks)
this.BuildHooks = lBuildHooks;
end

function setInTheLoopType(this, val)
this.InTheLoopType = val;
end

function val = getInTheLoopType(this)
val = this.InTheLoopType;
end

function lBuildHooks = getBuildHooks(this)
lBuildHooks = this.BuildHooks;
end

function setTopModel(this, lTopModel)
this.TopModel = lTopModel;
end

function lTopModel = getTopModel(this)
lTopModel = this.TopModel;
end

function lAnchorFolder = getAnchorFolder(this)
lAnchorFolder = this.AnchorFolder;
end

function setAnchorFolder(this, lAnchorFolder)
this.AnchorFolder = lAnchorFolder;
end

function setCodeInstrInfo(this, lCodeInstrInfo)
this.CodeInstrInfo = lCodeInstrInfo;
end

function lCodeInstrInfo = getCodeInstrInfo(this)
lCodeInstrInfo = this.CodeInstrInfo;
end

function isSIL = isSIL(this)
internalData = this.getInternalData;
if isempty(internalData) || ~isfield(internalData, 'IsSIL')
% support command line testing by e.g. end user
isSIL = false;
else
isSIL = internalData.IsSIL;
end
end

function isSILAndPWS = isSILAndPWS(this)
isSILAndPWS = this.isSIL &&...
strcmp(this.getParam('PortableWordSizes'),'on');
end

function componentCodePath = getComponentCodePathForReport(this)
narginchk(1, 1);

componentCodePath = this.componentCodePath;
end

function setVerboseCommunicationOutput(this, value)
this.VerboseCommunicationOutput = value;
end

function value = getVerboseCommunicationOutput(this)
value = this.VerboseCommunicationOutput;
end

function setCoderAssumptionsAnchorDir(this, folder)
this.CoderAssumptionsAnchorDir = folder;
end

function folder = getCoderAssumptionsAnchorDir(this)
folder = this.CoderAssumptionsAnchorDir;
end

function setComponentForDiagnostics(this, component)
this.ComponentForDiagnostics = component;
end

function component = getComponentForDiagnostics(this)
component = this.ComponentForDiagnostics;
end
end

methods (Hidden)
function clientInterface = getClientInterface(this)
clientInterface = this.ClientInterface;
end

function setClientInterface(this, clientInterface)
assert(isa(clientInterface, 'coder.connectivity.ClientInterface'), ...
'clientInterface invalid data type.');
this.ClientInterface = clientInterface;
end

function configInterface = getConfigInterface(this)
internalData = this.getInternalData;
if ~isempty(internalData)
configInterface = internalData.configInterface;
else
configInterface = [];
end
end
end
end