classdef (Hidden = true) SubsystemSILPILWrapperUtils < rtw.pil.ModelRefSILPILWrapperUtils
%SUBSYSTEMSILPILWRAPPERUTILS SIL/PIL subsystem wrapper utilities
%
% 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.

methods
% constructor
function this = SubsystemSILPILWrapperUtils(silPILInterface, ...
infoStruct, ...
clientInterface,...
topModelOriginalParams, ...
lXilCompInfo)

% call super class constructor
this@rtw.pil.ModelRefSILPILWrapperUtils(silPILInterface, ...
infoStruct, ...
clientInterface, ...
topModelOriginalParams, ...
lXilCompInfo);

unsupportedConfigSetParams = repmat(struct('Name', '', 'Value', ''), 1, 2);
unsupportedConfigSetParams(1).Name = 'GroupInternalDataByFunction';
unsupportedConfigSetParams(1).Value = 'on';
unsupportedConfigSetParams(2).Name = 'PassReuseOutputArgsAs';
unsupportedConfigSetParams(2).Value = 'Structure reference';
if strcmp(this.getParam(unsupportedConfigSetParams(1).Name), unsupportedConfigSetParams(1).Value) && ...
strcmp(this.getParam(unsupportedConfigSetParams(2).Name), unsupportedConfigSetParams(2).Value)

functionInterface = this.getSILPILInterface.getRootModel();
subsystem = this.getComponentForDiagnostics();
e = MSLException(message('PIL:pil_subsystem:UnsupportedDataLayout', ...
functionInterface, ...
subsystem, ...
unsupportedConfigSetParams(1).Name, ...
unsupportedConfigSetParams(2).Name, ...
unsupportedConfigSetParams(1).Value, ...
unsupportedConfigSetParams(2).Value));
e.throw;
end
end

function rootModel = getLoadableRootComponent(this)
% rootModel of Simulink component path that can be loaded
rootModel = rtw.pil.RLSUtils.getUniqueContextName(...
this.getSILPILInterface.getRootModel);
end

function name = getComponentForSfuncName(this)
% return the name of the component after which the Sfunction is
% going to be named
name = rtw.pil.RLSUtils.getUniqueContextName(...
this.getCodeInfoUtils.GraphicalPath);
end

function name = getComponentForDiagnostics(this)
% return the name of the Root Component for reporting in
% diagnostic messages
name = this.getSILPILInterface.RLSSubsystemName;
end

function isReadOnly = isComponentReadOnly(~)
% RLS simulation are always ReadOnly because the code is
% generated in advance and FunctionInterface models are not
% directly accessible to users
isReadOnly = true;
end
end

methods(Access = 'protected')
function validateExportedParameters(this)
% error out for exported parameters, at the moment the only
% exported storage class supported by RLS is 'ExportToFile'.
params = this.getCodeInfo.Parameters;
exportedParams = false(size(params));
for idx=1:length(params)
storageImpl = this.getBaseStorageImplementation(params(idx).Implementation);
owner = rtw.pil.OwnerAccessor.getOwner(storageImpl);
if ~isempty(owner)
exportedParams(idx) = true;
end
end

if any(exportedParams)
exportedParamNames = {params(exportedParams).GraphicalName};
e = MSLException(message('PIL:pil_subsystem:UnsupportedParameter', ...
strjoin(exportedParamNames, ', ')));
e.throw;
end
end
end
end