Compile function OEngine_Services(@Service, @Params)
#pragma precomp SRP_PreCompiler
/***********************************************************************************************************************

    This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
    permission from Infineon Technologies.

    Name        :   OEngine_Services

    Description :   Handler program for all module related services.

    Notes       :   The generic parameters should contain all the necessary information to process the services. Often
                    this will be information like the data Record and Key ID.

    Parameters  :
        Service         [in] -- Name of the service being requested
        Param1-10   [in/out] -- Additional request parameter holders
        Response       [out] -- Response to be sent back to the Controller (MCP) or requesting procedure

    History     :   (Date, Initials, Notes)
        10/11/23    djs     Original programmer.

***********************************************************************************************************************/
$Insert APP_INSERTS
$Insert SERVICE_SETUP
$Insert REVDOTNETEQUATES

Declare Function   Environment_Services, Logging_Services, GetCurrentProcessId, GetCommandLine
Declare Subroutine Logging_Services, Set_Property.Net

LogPath     = Environment_Services('GetApplicationRootPath') : '\LogFiles\OEngine'
LogDate     = Oconv(Date(), 'D4/')
LogTime     = Oconv(Time(), 'MTS')
Headers     = 'Logging DTM' : @FM : 'Memory - Working Set' : @FM : 'Memory - Peak Working Set'
LoggingDTM  = LogDate : ' ' : LogTime

GoToService else
    Error_Services('Set', Service : ' is not a valid service request within the ' : ServiceModule : ' services module.')
end

Return Response or ""

//-----------------------------------------------------------------------------
// SERVICES
//-----------------------------------------------------------------------------

Service LogMemoryUsage()
    
    CmdLine     = GetCommandLine()
    EngIndex    = Index(CmdLine, '/S=', 1)
    EngNo       = CmdLine[EngIndex + 3, 'F ']
    LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' ' : EngNo : ' OEngine Log.csv'
    objLog      = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ',', Headers, '', False$, False$)
    
    ErrCode       = ''
    Pid           = GetCurrentProcessId()
    If Pid NE '' then
        DotNetHandle = StartDotNet("","4.0")
        DotNetDir    = CheckDotNet('4.0'):'\'
        DirDllPath   = DotNetDir:'System.dll'
        Set_Property.Net(DotNetHandle, "AssemblyName", DirDllPath)
        If Not(Get_Status(errCode)) then
            objProc = Create_Class.Net(DotNetHandle, "System.Diagnostics.Process", False$)
            If Not(Get_status(errCode)) then
                Methods     = get_info.net(objProc, REVDOTNET_INFO_METHODS)
                objThisProc = Send_Message.Net(objProc, "GetProcessById", Pid, 'System.Int32', True$)
                If Not(Get_Status(errCode)) then
                    // Log memory values
                    PeakWorkingSet = Get_Property.Net(objThisProc, 'PeakWorkingSet64', False$) / 1024
                    WorkingSet     = Get_Property.Net(objThisProc, 'WorkingSet64', False$) / 1024
                    LogData        = LoggingDtm
                    LogData<2>     = WorkingSet:' KB'
                    LogData<3>     = PeakWorkingSet:' KB'
                    Logging_Services('AppendLog', objLog, LogData, @RM, @FM)
                    Free_Class.Net(objThisProc)
                end
                Free_Class.Net(objProc)
            end
        end
    end
    
End Service



