classdef ComponentArgs < coder.connectivity.ComponentArgs
%ComponentArgs provides parameters related to the model build 
%
%   An instance of this class is created by the target connectivity
%   infrastructure and is passed as a constructor argument to a user-defined
%   connectivity configuration. You can call the "get" methods of this class to
%   retrieve parameter values related to the model build. See the help on these
%   methods for more details: the method names are listed below.
%
%   ComponentArgs methods:
%       GETCOMPONENTPATH       - returns a path to the model component being 
%                                built
%       GETCOMPONENTCODEPATH   - returns a system path to the code generation 
%                                directory
%       GETCOMPONENTCODENAME   - returns the component name used for code
%                                generation
%       GETAPPLICATIONCODEPATH - returns a system path to the application 
%                                directory
%
%   See also CODER.MYPIL.CONNECTIVITYCONFIG

%   Copyright 2007-2018 The MathWorks, Inc.
%   

    % private properties
    properties(SetAccess = 'private', GetAccess = 'private')                
        ModelName;
    end

    % constructor
    methods
        function this = ComponentArgs(componentPath, ...
                                      componentCodePath, ...
                                      componentCodeName, ...
                                      applicationCodePath)
            narginchk(4, 4);    
            validateattributes(componentPath, {'char', 'string'}, {'scalartext'});
            validateattributes(componentCodePath, {'char', 'string'}, {'scalartext'});
            validateattributes(componentCodeName, {'char', 'string'}, {'scalartext'});
            validateattributes(applicationCodePath, {'char', 'string'}, {'scalartext'});

            this@coder.connectivity.ComponentArgs(convertStringsToChars(componentPath), ...
                                                  convertStringsToChars(componentCodePath), ...
                                                  convertStringsToChars(componentCodeName), ...
                                                  convertStringsToChars(applicationCodePath));                        
        end
    end   
    
    methods (Sealed, Hidden)                          
        function modelName = getModelName(this)
            if isempty(this.ModelName)
                this.ModelName = strtok(this.getComponentPath,'/');
            end
            modelName = this.ModelName;
        end        
    end
    
    methods (Hidden)        
        function clientInterface = getClientInterface(this)
            clientInterface = getClientInterface@coder.connectivity.ComponentArgs(this);
            if isempty(clientInterface)
                % create default Simulink interface
                clientInterface = coder.connectivity.SimulinkInterface;
                % cache for future calls
                this.setClientInterface(clientInterface);
            end
        end
        
        function configInterface = getConfigInterface(this)           
            configInterface = getConfigInterface@coder.connectivity.ComponentArgs(this);
            if isempty(configInterface)
                clientInterface = this.getClientInterface;                
                configInterface = clientInterface.createConfigInterface( ...
                    getActiveConfigSet(this.getModelName), this.getModelName);
            end
        end                        
    end
end
