[beast: 15/57] SFI: platform: add program_cwd, program_alias and application_name



commit e0b4ff460db4316f273a3a848d1beb7f76ae4049
Author: Tim Janik <timj gnu org>
Date:   Mon Jul 17 11:00:02 2017 +0200

    SFI: platform: add program_cwd, program_alias and application_name
    
    Signed-off-by: Tim Janik <timj gnu org>

 sfi/platform.cc |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 sfi/platform.hh |   12 +++++++++---
 2 files changed, 56 insertions(+), 3 deletions(-)
---
diff --git a/sfi/platform.cc b/sfi/platform.cc
index 841e479..260a976 100644
--- a/sfi/platform.cc
+++ b/sfi/platform.cc
@@ -1,5 +1,6 @@
 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
 #include "platform.hh"
+#include "path.hh"
 #include <unistd.h>
 #if defined __APPLE__
 #include <mach-o/dyld.h>        // _NSGetExecutablePath
@@ -66,4 +67,50 @@ executable_name()
   return cached_executable_name;
 }
 
+static String cached_program_alias;
+
+String
+program_alias ()
+{
+  return cached_program_alias.empty() ? executable_name() : cached_program_alias;
+}
+
+void
+program_alias_init (String customname)
+{
+  assert_return (cached_program_alias.empty() == true);
+  cached_program_alias = customname;
+}
+
+static String cached_application_name;
+
+String
+application_name ()
+{
+  return cached_application_name.empty() ? program_alias() : cached_application_name;
+}
+
+void
+application_name_init (String desktopname)
+{
+  assert_return (cached_application_name.empty() == true);
+  cached_application_name = desktopname;
+}
+
+String
+program_cwd ()
+{
+  static String cached_program_cwd = Path::cwd();
+  return cached_program_cwd;
+}
+
+struct EarlyStartup102 {
+  EarlyStartup102()
+  {
+    program_cwd(); // initialize early, i.e. before main() changes cwd
+  }
+};
+
+static EarlyStartup102 _early_startup_102 __attribute__ ((init_priority (102)));
+
 } // Bse
diff --git a/sfi/platform.hh b/sfi/platform.hh
index 4616534..50e7fe0 100644
--- a/sfi/platform.hh
+++ b/sfi/platform.hh
@@ -2,12 +2,18 @@
 #ifndef __BSE_PLATFORM_HH__
 #define __BSE_PLATFORM_HH__
 
-#include <sfi/glib-extra.hh>
+#include <sfi/cxxaux.hh>
 
 namespace Bse {
 
-std::string     executable_path();
-std::string     executable_name();
+// == process info ==
+String      program_alias         ();                   ///< Retrieve the program name as used for logging 
or debug messages.
+void        program_alias_init    (String customname);  ///< Set program_alias to a non-localized alias 
other than program_argv0 if desired.
+String      application_name      ();                   ///< Retrieve the localized program name intended 
for user display.
+void        application_name_init (String desktopname); ///< Set the application_name to a name other than 
program_alias if desired.
+String      program_cwd           ();                   ///< The current working directory during startup.
+std::string executable_name       ();                   ///< Retrieve the name part of executable_path().
+std::string executable_path       ();                   ///< Retrieve the path to the currently running 
executable.
 
 } // Bse
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]