All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
System.h
Go to the documentation of this file.
1 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/System.h,v 1.17 2008/10/28 10:40:19 marcocle Exp $
2 #ifndef GAUDIKERNEL_SYSTEM_H
3 #define GAUDIKERNEL_SYSTEM_H
4 
5 // Framework include files
6 #include "GaudiKernel/Kernel.h"
7 // STL include files
8 #include <string>
9 #include <vector>
10 #include <typeinfo>
11 
12 #include "GaudiKernel/Timing.h"
13 #include "GaudiKernel/ModuleInfo.h"
14 
15 #ifdef __linux
16 # include <pthread.h>
17 #ifndef __APPLE__
18 # include <execinfo.h>
19 #endif
20 #endif
21 
30 namespace System {
32  typedef void* ImageHandle;
34  typedef void* ProcessHandle;
36  typedef unsigned long (*EntryPoint)(const unsigned long iid, void** ppvObject);
38  typedef void* (*Creator)();
40  GAUDI_API unsigned long loadDynamicLib(const std::string& name, ImageHandle* handle);
42  GAUDI_API unsigned long unloadDynamicLib(ImageHandle handle);
44  GAUDI_API unsigned long getProcedureByName(ImageHandle handle, const std::string& name, EntryPoint* pFunction);
46  GAUDI_API unsigned long getProcedureByName(ImageHandle handle, const std::string& name, Creator* pFunction);
48  GAUDI_API unsigned long getLastError();
50  GAUDI_API const std::string getLastErrorString();
52  GAUDI_API const std::string getErrorString(unsigned long error);
54  GAUDI_API const std::string typeinfoName( const std::type_info& );
55  GAUDI_API const std::string typeinfoName( const char* );
57  GAUDI_API const std::string& hostName();
59  GAUDI_API const std::string& osName();
61  GAUDI_API const std::string& osVersion();
63  GAUDI_API const std::string& machineType();
65  GAUDI_API const std::string& accountName();
69  GAUDI_API long argc();
71  GAUDI_API const std::vector<std::string> cmdLineArgs();
73  GAUDI_API char** argv();
75  GAUDI_API std::string getEnv(const char* var);
78  GAUDI_API bool getEnv(const char* var, std::string &value);
79  inline bool getEnv(const std::string &var, std::string &value) {
80  return getEnv(var.c_str(), value);
81  }
83  GAUDI_API std::vector<std::string> getEnv();
89  GAUDI_API int setEnv(const std::string &name, const std::string &value, int overwrite = 1);
91  GAUDI_API bool isEnvSet(const char* var);
92 #ifdef __linux
93  typedef pthread_t ThreadHandle;
96  inline ThreadHandle threadSelf() { return pthread_self(); }
97 #else
98  typedef void* ThreadHandle;
101  inline ThreadHandle threadSelf() { return (void*)0; }
102 #endif
103  GAUDI_API int backTrace(void** addresses, const int depth);
104  GAUDI_API bool backTrace(std::string& btrace, const int depth, const int offset = 0);
105  GAUDI_API bool getStackLevel(void* addresses, void*& addr, std::string& fnc, std::string& lib) ;
106 
107 #if __GNUC__ >= 4
108  template <typename DESTPTR, typename SRCPTR>
121  inline DESTPTR FuncPtrCast(SRCPTR ptr) {
122  union {
123  SRCPTR src;
124  DESTPTR dst;
125  } p2p;
126  p2p.src = ptr;
127  return p2p.dst;
128  }
129 #endif
130 }
131 #endif // SYSTEM_SYSTEM_H
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:608
GAUDI_API long argc()
Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call...
Definition: System.cpp:526
GAUDI_API char ** argv()
char** command line arguments including executable name as arg[0]; You may not modify them! ...
Definition: System.cpp:593
GAUDI_API const std::string getErrorString(unsigned long error)
Retrieve error code as string for a given error.
Definition: System.cpp:259
GAUDI_API int setEnv(const std::string &name, const std::string &value, int overwrite=1)
Set an environment variables.
Definition: System.cpp:746
GAUDI_API unsigned long getLastError()
Get last system known error.
Definition: System.cpp:243
GAUDI_API unsigned long getProcedureByName(ImageHandle handle, const std::string &name, EntryPoint *pFunction)
Get a specific function defined in the DLL.
Definition: System.cpp:188
GAUDI_API bool getStackLevel(void *addresses, void *&addr, std::string &fnc, std::string &lib)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:298
void * ThreadHandle
A Thread handle.
Definition: System.h:99
GAUDI_API const std::string & accountName()
User login name.
Definition: System.cpp:502
void * ImageHandle
Definition of an image handle.
Definition: ModuleInfo.h:30
GAUDI_API int backTrace(void **addresses, const int depth)
GAUDI_API long numCmdLineArgs()
Number of arguments passed to the commandline.
Definition: System.cpp:521
GAUDI_API const std::string & osName()
OS name.
Definition: System.cpp:444
void *(* Creator)()
Definition of the "generic" DLL entry point function.
Definition: System.h:38
GAUDI_API unsigned long unloadDynamicLib(ImageHandle handle)
unload dynamic link library
Definition: System.cpp:162
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:628
GAUDI_API const std::string & hostName()
Host name.
Definition: System.cpp:427
ThreadHandle threadSelf()
thread handle "accessor"
Definition: System.h:101
GAUDI_API const std::vector< std::string > cmdLineArgs()
Command line arguments including executable name as arg[0] as vector of strings.
Definition: System.cpp:531
GAUDI_API const std::string & osVersion()
OS version.
Definition: System.cpp:461
unsigned long(* EntryPoint)(const unsigned long iid, void **ppvObject)
Definition of the "generic" DLL entry point function.
Definition: System.h:36
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:253
GAUDI_API const std::string & machineType()
Machine type.
Definition: System.cpp:482
#define GAUDI_API
Definition: Kernel.h:108
void * ProcessHandle
Definition of the process handle.
Definition: ModuleInfo.h:32
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:123