
%

%   Copyright 2017-2023 The MathWorks, Inc.

classdef ModelblockLogger < Sldv.SubsystemLogger
    properties
        refMdlToMdlBlk = []; %Mapping between ref model and model block.
        globalRefSig = []; %All global data store signals referenced in the hierarchy.
    end
    methods (Access = public)
        function obj = ModelblockLogger(varargin)
            obj = obj@Sldv.SubsystemLogger(varargin{:});
        end
        function data = logInputSignals(obj,modelBlockH, varargin)
            data = logInputSignals@Sldv.SignalLogger(obj,modelBlockH,[],varargin{:});
        end
        function setSlicerContextInfo(obj,refMdlToMdlBlk,globalRefSig)
            obj.refMdlToMdlBlk = refMdlToMdlBlk;
            obj.globalRefSig = globalRefSig;
        end
    end
    methods (Access = protected)
        function restoreLoggers(obj,varargin)
            restoreLoggers@Sldv.SubsystemLogger(obj,varargin{:});
            if isfield(obj.subsystemIO,'globalVarInfo')
                numGlobals = length(obj.subsystemIO.globalVarInfo);
                for i = 1:numGlobals
                    sigName = obj.subsystemIO.globalVarInfo{i}.SignalName;
                    % Fetch signal object from global context, turn off DataLogging
                    % and write back.
                    signal = getVarFromGlobalScope(obj.TopLevelModelH, sigName);
                    signal.LoggingInfo.DataLogging = false;
                    assigninGlobalScope(obj.TopLevelModelH, sigName, signal);
                end
            end
        end
        runTests(obj);
        setModelLoggingInfo(obj);
        deriveRefMdlPortInfo(obj);
        [sldvData, sampleTimeInformation] = generateDataForLogging(obj)
    end
    methods(Static = true)
        globalDsmData = deriveDSWExecPriorToMdlBlk(mdlBlkH,rootMdlH,refMdlToMdlBlk,globalRefSig);
    end
end

