From 8c898b68e2efdfcfa0ccd76f7944addeedd27aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 28 Sep 2024 14:26:37 -0300 Subject: [PATCH] Try fix new Sys functions in Haiku. --- include/eepp/system/sys.hpp | 2 +- src/eepp/system/sys.cpp | 55 ++++++++++++++----- .../autocomplete/autocompleteplugin.hpp | 2 +- .../plugins/formatter/formatterplugin.hpp | 2 +- src/tools/ecode/plugins/git/gitplugin.hpp | 2 +- .../ecode/plugins/linter/linterplugin.hpp | 2 +- .../ecode/plugins/lsp/lspclientplugin.hpp | 2 +- .../ecode/plugins/xmltools/xmltoolsplugin.hpp | 2 +- 8 files changed, 48 insertions(+), 21 deletions(-) diff --git a/include/eepp/system/sys.hpp b/include/eepp/system/sys.hpp index b94d24fda..c0dc2c540 100644 --- a/include/eepp/system/sys.hpp +++ b/include/eepp/system/sys.hpp @@ -129,7 +129,7 @@ class EE_API Sys { static std::vector pidof( const std::string& processName ); /** @returns The unix timestamp of the process creation time */ - static Uint64 getProcessCreationTime( Uint64 pid ); + static Int64 getProcessCreationTime( Uint64 pid ); }; }} // namespace EE::System diff --git a/src/eepp/system/sys.cpp b/src/eepp/system/sys.cpp index cac0b54ff..84d886496 100644 --- a/src/eepp/system/sys.cpp +++ b/src/eepp/system/sys.cpp @@ -1322,8 +1322,8 @@ std::string Sys::getProcessFilePath() { #endif } -Uint64 Sys::getProcessCreationTime( Uint64 pid ) { - Uint64 creationTime = 0; +Int64 Sys::getProcessCreationTime( Uint64 pid ) { + Int64 creationTime = -1; #if EE_PLATFORM == EE_PLATFORM_WIN int rpid = static_cast( pid ); @@ -1397,16 +1397,29 @@ Uint64 Sys::getProcessCreationTime( Uint64 pid ) { creationTime = proc.ki_start.tv_sec; #elif EE_PLATFORM == EE_PLATFORM_HAIKU - thread_info threadInfo; int rpid = static_cast( pid ); - status_t result = get_thread_info( rpid, &threadInfo ); // Get thread info for the PID passed - if ( result == B_OK ) { - // Approximate creation time by subtracting CPU time (user_time + kernel_time) from current - // time - creationTime = time( NULL ) - ( threadInfo.user_time + threadInfo.kernel_time ) / - 1000000; // Convert microseconds to seconds - } else { - return -1; + int32 cookie = 0; + team_info teamInfo; + + while ( get_next_team_info( &cookie, &teamInfo ) == B_OK ) { + if ( teamInfo.team != rpid ) + continue; + + KMessage extendedInfo; + status_t status = get_extended_team_info( teamInfo.team, B_TEAM_INFO_BASIC, extendedInfo ); + + if ( status == B_BAD_TEAM_ID ) { + // The team might have simply ended between the last function calls. + continue; + } else if ( status != B_OK ) { + break; + } + + bigtime_t startTime = 0; + if ( extendedInfo.FindInt64( "start_time", &startTime ) != B_OK ) + continue; + + return startTime; } #endif @@ -1544,12 +1557,26 @@ std::vector Sys::pidof( const std::string& processName ) { return pids; #elif EE_PLATFORM == EE_PLATFORM_HAIKU std::vector pids; - team_info teamInfo; int32 cookie = 0; - std::string lProcessName = String::toLower( processName ); + team_info teamInfo; + const char* cprocessName = processName.c_str(); while ( get_next_team_info( &cookie, &teamInfo ) == B_OK ) { - if ( lProcessName == String::toLower( FileSystem::fileNameFromPath( teamInfo.args ) ) ) { + KMessage extendedInfo; + status_t status = get_extended_team_info( teamInfo.team, B_TEAM_INFO_BASIC, extendedInfo ); + + if ( status == B_BAD_TEAM_ID ) { + // The team might have simply ended between the last function calls. + continue; + } else if ( status != B_OK ) { + return {}; + } + + const char* teamName = NULL; + if ( extendedInfo.FindString( "name", &teamName ) != B_OK ) + continue; + + if ( strcmp( teamName, cprocessName ) == 0 ) { pids.push_back( teamInfo.team ); } } diff --git a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.hpp b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.hpp index c8828894c..6bbc86e4c 100644 --- a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.hpp +++ b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.hpp @@ -63,7 +63,7 @@ class AutoCompletePlugin : public Plugin { "Auto complete shows the completion popup as you type, so you can fill " "in long words by typing only a few characters.", AutoCompletePlugin::New, - { 0, 2, 5 }, + { 0, 2, 6 }, AutoCompletePlugin::NewSync }; } diff --git a/src/tools/ecode/plugins/formatter/formatterplugin.hpp b/src/tools/ecode/plugins/formatter/formatterplugin.hpp index e6f22c253..68fb8bb84 100644 --- a/src/tools/ecode/plugins/formatter/formatterplugin.hpp +++ b/src/tools/ecode/plugins/formatter/formatterplugin.hpp @@ -34,7 +34,7 @@ class FormatterPlugin : public Plugin { static PluginDefinition Definition() { return { "autoformatter", "Auto Formatter", "Enables the code formatter/prettifier plugin.", - FormatterPlugin::New, { 0, 2, 4 }, FormatterPlugin::NewSync }; + FormatterPlugin::New, { 0, 2, 5 }, FormatterPlugin::NewSync }; } static Plugin* New( PluginManager* pluginManager ); diff --git a/src/tools/ecode/plugins/git/gitplugin.hpp b/src/tools/ecode/plugins/git/gitplugin.hpp index 736a9c7e8..1490510cb 100644 --- a/src/tools/ecode/plugins/git/gitplugin.hpp +++ b/src/tools/ecode/plugins/git/gitplugin.hpp @@ -36,7 +36,7 @@ static constexpr const char* GIT_STASH = "git-stash"; class GitPlugin : public PluginBase { public: static PluginDefinition Definition() { - return { "git", "Git", "Git integration", GitPlugin::New, { 0, 1, 0 }, GitPlugin::NewSync }; + return { "git", "Git", "Git integration", GitPlugin::New, { 0, 1, 1 }, GitPlugin::NewSync }; } static Plugin* New( PluginManager* pluginManager ); diff --git a/src/tools/ecode/plugins/linter/linterplugin.hpp b/src/tools/ecode/plugins/linter/linterplugin.hpp index abbfed21a..da42fb1a6 100644 --- a/src/tools/ecode/plugins/linter/linterplugin.hpp +++ b/src/tools/ecode/plugins/linter/linterplugin.hpp @@ -59,7 +59,7 @@ class LinterPlugin : public Plugin { "Use static code analysis tool used to flag programming errors, bugs, " "stylistic errors, and suspicious constructs.", LinterPlugin::New, - { 0, 2, 5 }, + { 0, 2, 6 }, LinterPlugin::NewSync }; } diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.hpp b/src/tools/ecode/plugins/lsp/lspclientplugin.hpp index b417b9842..ac529c6a1 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.hpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.hpp @@ -27,7 +27,7 @@ class LSPClientPlugin : public Plugin { public: static PluginDefinition Definition() { return { "lspclient", "LSP Client", "Language Server Protocol Client.", - LSPClientPlugin::New, { 0, 2, 6 }, LSPClientPlugin::NewSync }; + LSPClientPlugin::New, { 0, 2, 7 }, LSPClientPlugin::NewSync }; } static Plugin* New( PluginManager* pluginManager ); diff --git a/src/tools/ecode/plugins/xmltools/xmltoolsplugin.hpp b/src/tools/ecode/plugins/xmltools/xmltoolsplugin.hpp index 399d818be..11977ba37 100644 --- a/src/tools/ecode/plugins/xmltools/xmltoolsplugin.hpp +++ b/src/tools/ecode/plugins/xmltools/xmltoolsplugin.hpp @@ -20,7 +20,7 @@ class XMLToolsPlugin : public PluginBase { "XML Tools", "Simple tools to improve your XML editing experience.", XMLToolsPlugin::New, - { 0, 0, 3 }, + { 0, 0, 4 }, XMLToolsPlugin::NewSync }; }