classdef(Abstract) PILDataHandler
% PILDATAHANDLER provides an interface to get/set the cached
% SILPILInterface object
%
% This is an undocumented class. Its methods and properties are
% likely to change without warning from one release to the next.

% Copyright 2019-2021 The MathWorks, Inc.

methods(Abstract, Access = protected)
pilData = getPILDataImplementation(this, block);
setPILDataImplementation(this, block, data);
end

methods(Access = public)
function pilData = getPILData(this, block)
% return a copy of PILData
data = this.getPILDataImplementation(block);
if isempty(data)
pilData = data;
else
pilData = data.copy;
end
end

function setPILData(this, block, data)
% cache a copy of PILData
this.setPILDataImplementation(block, data.copy);
end

function removeCachedPILData(this, block)
% removed cached PILData by setting it to empty
this.setPILDataImplementation(block, []);
end
end

methods(Static)
function handler = createHandler(inTheLoopType)
% factory method to create the required handler
switch inTheLoopType
case {rtw.pil.InTheLoopType.ModelBlock, ...
rtw.pil.InTheLoopType.ModelBlockStandalone, ...
rtw.pil.InTheLoopType.RLSSubsystem}
handler = coder.connectivity.ModelBlockPILDataHandler;
case rtw.pil.InTheLoopType.Block
if slfeature('XilNoWrapper')
handler = coder.connectivity.MATLABPILDataHandler;
else
handler = coder.connectivity.PILBlockPILDataHandler;
end
case rtw.pil.InTheLoopType.MATLABFcn
handler = coder.connectivity.MATLABPILDataHandler;
otherwise
assert(false, 'InTheLoopType not Supported: %s', inTheLoopType);
end
end
end
end