function oldHandler = dctSchedulerMessageHandler(input, levelNum)
%DCTSCHEDULERMESSAGEHANDLER 
%
%  dctSchedulerMessageHandler(input, levelNum)
%

%  Copyright 2005-2020 The MathWorks, Inc.


mlock;
persistent theHandler;
persistent handlerNargIn;

% Always return the previous handler
oldHandler = theHandler;
if nargin == 0
    % Simply query for handler
elseif ischar(input)
    % Do nothing if no handler has been registered
    if isempty(theHandler)
        return
    end
    % This function should NEVER error
    try
        if handlerNargIn == 1
            theHandler(input);
        elseif handlerNargIn > 1
            theHandler(input, levelNum);
        end
    catch err
        warning(err.identifier, '%s', err.message);
    end
elseif isempty(input)
    % Reset the handler. (Note that we check ISEMPTY after ISCHAR to defend
    % against input being '').
    theHandler = [];
elseif isa(input, 'function_handle')
    % Set the handler, and extract NARGIN from it. 
    theHandler = input;
    handlerNargIn = nargin(theHandler);
end
