function update(hSrc, event)
%UPDATE - receive Simulink configset events
%   Author(s): J. Sun

%   Copyright 2006-2015 The MathWorks, Inc.

if strcmp(event, 'attach')
    if hdlcoderui.isslhdlcinstalled
        hSrc.hdlinstalled = true;
    else
        hSrc.hdlinstalled = false;
        return;
    end
elseif ~hSrc.hdlinstalled
    return;
elseif strcmp(event, 'activate')
    % 'activate' - simulink post load event
    set(hSrc, 'ReadOnly', 'On');
    
    mdlHandle = hSrc.getModel;
    if isempty(mdlHandle)
        % Do not create HDL Component for configset that is not attached to
        % a model.
        return;
    end
    mdlName = get_param(mdlHandle,'Name');

    if isempty(hSrc.HDLCoder)
        hSrc.createHDLCoder(mdlName);
    else
        cli = hSrc.getCLI;
        snn = cli.HDLSubsystem;
        snnMdlName = strtok(snn, '/');
        if ~isempty(snnMdlName) && ~strcmp(mdlName, snnMdlName)
            hSrc.createHDLCoder(snnMdlName);
        end
    end
    
    if isempty(hSrc.HDLListener)
        hSrc.registerEventsAtPostLoad(get_param(mdlHandle,'DistinctName'));
    end
end
end
