classdef (Hidden = true) GPUHostConnectivityConfig < rtw.connectivity.Config
%GPUHOSTCONNECTIVITYCONFIG is a target connectivity configuration class for GPU Coder Host based XIL

%   This is an undocumented class. Its methods and properties are likely to
%   change without warning from one release to the next.

%   Copyright 2018-2022 The MathWorks, Inc.

    methods
        % Constructor
        function this = GPUHostConnectivityConfig(componentArgs)
            % Create an instance of rtw.connectivity.MakefileBuilder; this
            % class provides configuration data required by the build process
        
            % A target application framework specifies additional source
            % files and libraries required for building the PIL application
            targetApplicationFramework = ...
                rtw.pil.HostDemoApplicationFramework(componentArgs);
            
            % Filename extension for executable on the target system
            if ispc % Windows
                exeExtension = '.exe';
            else % Unix
                exeExtension = '';
            end
            
            builder = rtw.connectivity.MakefileBuilder(componentArgs, ...
                                                       targetApplicationFramework,...
                                                       exeExtension);
            % launcher with port 0 argument to start TCP/IP server on free port
            launcher = rtw.connectivity.GPUHostLauncher(componentArgs);
            launcher.setArgs({'-port', '0', ...
                              '-blocking', '1'});
            
            % Evaluate name of the shared library to use for rtiostream communications
            sharedLibExt=system_dependent('GetSharedLibExt');
            rtiostreamLibTcpip = ['libmwrtiostreamtcpip' sharedLibExt];

            % Configure the rtiostream via TCP/IP to operate in "blocking" mode; this avoids
            % loading the CPU when the host process is waiting for data from the
            % target.
            blockingArg = '1';
            
            % Note that the communicator dynamically determines the TCP/IP port via the
            % launcher
            rtIOStreamOpenArgs = {...
                '-hostname', 'localhost', ...
                '-client', '1', ...
                '-blocking', blockingArg, ...
                   };

            communicator = rtw.connectivity.HostTCPIPCommunicator(componentArgs, ...
                                                        launcher, ...
                                                        rtiostreamLibTcpip);
            communicator.setOpenRtIOStreamArgList(rtIOStreamOpenArgs);
            
            % call super class constructor to register components
            this@rtw.connectivity.Config(componentArgs, builder, launcher, communicator);
                                     
            % register timer 
            timer = coder.profile.crlHostTimer();
            this.setTimer(timer);
            
            % configuration for word addressable hardware
            targetApplicationFramework.configWordAddressable(this);                               
        end
    end
end

