• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // system_utils.h: declaration of OS-specific utility functions
8 
9 #ifndef COMMON_SYSTEM_UTILS_H_
10 #define COMMON_SYSTEM_UTILS_H_
11 
12 #include "common/Optional.h"
13 #include "common/angleutils.h"
14 
15 #include <string>
16 
17 namespace angle
18 {
19 std::string GetExecutableName();
20 std::string GetExecutablePath();
21 std::string GetExecutableDirectory();
22 std::string GetModuleDirectory();
23 const char *GetSharedLibraryExtension();
24 const char *GetExecutableExtension();
25 char GetPathSeparator();
26 Optional<std::string> GetCWD();
27 bool SetCWD(const char *dirName);
28 bool SetEnvironmentVar(const char *variableName, const char *value);
29 bool UnsetEnvironmentVar(const char *variableName);
30 bool GetBoolEnvironmentVar(const char *variableName);
31 std::string GetEnvironmentVar(const char *variableName);
32 std::string GetEnvironmentVarOrUnCachedAndroidProperty(const char *variableName,
33                                                        const char *propertyName);
34 std::string GetEnvironmentVarOrAndroidProperty(const char *variableName, const char *propertyName);
35 const char *GetPathSeparatorForEnvironmentVar();
36 bool PrependPathToEnvironmentVar(const char *variableName, const char *path);
37 bool IsDirectory(const char *filename);
38 bool IsFullPath(std::string dirName);
39 std::string GetRootDirectory();
40 std::string ConcatenatePath(std::string first, std::string second);
41 
42 // Get absolute time in seconds.  Use this function to get an absolute time with an unknown origin.
43 double GetCurrentTime();
44 
45 // Run an application and get the output.  Gets a nullptr-terminated set of args to execute the
46 // application with, and returns the stdout and stderr outputs as well as the exit code.
47 //
48 // Pass nullptr for stdoutOut/stderrOut if you don't need to capture. exitCodeOut is required.
49 //
50 // Returns false if it fails to actually execute the application.
51 bool RunApp(const std::vector<const char *> &args,
52             std::string *stdoutOut,
53             std::string *stderrOut,
54             int *exitCodeOut);
55 
56 class Library : angle::NonCopyable
57 {
58   public:
~Library()59     virtual ~Library() {}
60     virtual void *getSymbol(const char *symbolName) = 0;
61     virtual void *getNative() const                 = 0;
62     virtual std::string getPath() const             = 0;
63 
64     template <typename FuncT>
getAs(const char * symbolName,FuncT * funcOut)65     void getAs(const char *symbolName, FuncT *funcOut)
66     {
67         *funcOut = reinterpret_cast<FuncT>(getSymbol(symbolName));
68     }
69 };
70 
71 // Use SYSTEM_DIR to bypass loading ANGLE libraries with the same name as system DLLS
72 // (e.g. opengl32.dll)
73 enum class SearchType
74 {
75     // Try to find the library in the same directory as the current module
76     ModuleDir,
77     // Load the library from the system directories
78     SystemDir,
79     // Get a reference to an already loaded shared library.
80     AlreadyLoaded,
81 };
82 
83 Library *OpenSharedLibrary(const char *libraryName, SearchType searchType);
84 Library *OpenSharedLibraryWithExtension(const char *libraryName, SearchType searchType);
85 
86 // Returns true if the process is currently being debugged.
87 bool IsDebuggerAttached();
88 
89 // Calls system APIs to break into the debugger.
90 void BreakDebugger();
91 }  // namespace angle
92 
93 #endif  // COMMON_SYSTEM_UTILS_H_
94