% SetProp - Holds properties passed to Generic Scheduler
% c.f. @distcomp/@setprop

% Copyright 2005-2015 The MathWorks, Inc.

classdef ( Hidden, Sealed ) SetProp < handle

    % c.f. @distcomp/@setprop/schema.m
    properties ( Hidden, SetAccess = private, GetAccess = public )
        StorageConstructor
        StorageLocation
        JobLocation
        TaskLocations
        NumberOfTasks

        % These two fields will hold the executable string and the arguments
        % for the executable. They are separated this way to allow for easier
        % quoting when being passed to third party objects.
        MatlabExecutable
        MatlabArguments
        
        % Fields related to MHLM for MDCS.  
        UseMathworksHostedLicensing = 'false';
        
        UserToken
        LicenseWebID
        LicenseNumber
    end

    methods
        % c.f. @distcomp/@setprop/schema.m iGetNumberOfTasks
        function value = get.NumberOfTasks(obj)
            value = numel(obj.TaskLocations); 
        end
    end
    
    methods ( Access = ?parallel.internal.cluster.CJSSupport )
        % c.f. @distcomp/@setprop/pSetStorageStrings.m
        function pSetStorageStrings(obj, StorageLocation, StorageConstructor, JobLocation, TaskLocations)
        % pSetStorageStrings private function to set values that need to be passed
        % to remote matlabs's started by schedulers
        
            parallel.internal.customattr.checkSimpleConstraint('string', 'StorageLocation', StorageLocation);
            parallel.internal.customattr.checkSimpleConstraint('string', 'StorageConstructor', StorageConstructor);
            parallel.internal.customattr.checkSimpleConstraint('string', 'JobLocation', JobLocation);
            parallel.internal.customattr.checkSimpleConstraint('cellstr', 'TaskLocations', TaskLocations);
            obj.StorageLocation    = StorageLocation;
            obj.StorageConstructor = StorageConstructor;
            obj.JobLocation        = JobLocation;
            obj.TaskLocations      = TaskLocations;
        end
    end

    methods ( Access = ?parallel.cluster.Generic )
        % c.f. @distcomp/@setprop/pSetExecutableStrings.m
        function pSetExecutableStrings(obj, MatlabExecutable, MatlabArguments)
        % pSetStorageStrings hidden function to set values that need to be passed
        % to remote matlabs's started by schedulers
        
            parallel.internal.customattr.checkSimpleConstraint('string', 'MatlabExecutable', MatlabExecutable);
            parallel.internal.customattr.checkSimpleConstraint('string', 'MatlabArguments', MatlabArguments);
            obj.MatlabExecutable = MatlabExecutable;
            obj.MatlabArguments  = MatlabArguments;
        end

        % c.f. @distcomp/@setprop/pSetLicensingInformation.m
        function pSetLicensingInformation(obj, usingMHLM, userToken, webLicenseID, licenseNumber)
        % pSetLicensingInformation private function to set values that need to be passed
        % to workers.
         
            parallel.internal.customattr.checkSimpleConstraint('string', 'userToken', userToken);
            parallel.internal.customattr.checkSimpleConstraint('string', 'webLicenseID', webLicenseID);
            parallel.internal.customattr.checkSimpleConstraint('string', 'licenseNumber', licenseNumber);
            if usingMHLM
                obj.UseMathworksHostedLicensing = 'true';
                obj.UserToken                   = userToken;
                obj.LicenseWebID                = webLicenseID;
                obj.LicenseNumber               = licenseNumber;
            else
                obj.UseMathworksHostedLicensing = 'false';
                obj.UserToken                   = '';
                obj.LicenseWebID                = '';
                obj.LicenseNumber               = '';
            end
        end
    end
end
