Elements  6.2
A C++ base framework for the Euclid Software.
Classes | Typedefs | Enumerations | Functions | Variables
Elements::System Namespace Reference

Classes

class  ModuleInfo
 

Typedefs

using ImageHandle = void *
 Definition of an image handle. More...
 
using ProcessHandle = void *
 Definition of the process handle. More...
 
using EntryPoint = unsigned long(*)(const unsigned long iid, void **ppvObject)
 Definition of the "generic" DLL entry point function. More...
 
using Creator = void *(*)()
 Definition of the "generic" DLL entry point function. More...
 

Enumerations

enum  ModuleType { ModuleType::UNKNOWN, ModuleType::SHAREDLIB, ModuleType::EXECUTABLE }
 
enum  InfoType {
  InfoType::NoFetch, InfoType::RemainTime, InfoType::Times, InfoType::ProcessBasics,
  InfoType::PriorityBoost, InfoType::Memory, InfoType::Quota, InfoType::System,
  InfoType::Modules, InfoType::IO
}
 Enumeration for fetching information. More...
 

Functions

template<typename DESTPTR , typename SRCPTR >
DESTPTR FuncPtrCast (SRCPTR ptr)
 Cast from void * to function pointer. More...
 
const ELEMENTS_API std::stringmoduleName ()
 Get the name of the (executable/DLL) file without file-type. More...
 
const ELEMENTS_API std::stringmoduleNameFull ()
 Get the full name of the (executable/DLL) file. More...
 
ELEMENTS_API ModuleType moduleType ()
 Get type of the module. More...
 
ELEMENTS_API ProcessHandle processHandle ()
 Handle to running process. More...
 
ELEMENTS_API ImageHandle moduleHandle ()
 Handle to currently executed module. More...
 
ELEMENTS_API ImageHandle exeHandle ()
 Handle to the executable file running. More...
 
const ELEMENTS_API std::stringexeName ()
 Name of the executable file running. More...
 
const ELEMENTS_API std::vector< std::stringlinkedModules ()
 Vector of names of linked modules. More...
 
ELEMENTS_API std::vector< Path::Item > linkedModulePaths ()
 
ELEMENTS_API void setModuleHandle (ImageHandle handle)
 Attach module handle. More...
 
ELEMENTS_API Path::Item getExecutablePath ()
 Get the full executable path. More...
 
ELEMENTS_API Path::Item getSelfProc ()
 Get the path to the /proc directory of the process. More...
 
ELEMENTS_API unsigned long loadDynamicLib (const std::string &name, ImageHandle *handle)
 Load dynamic link library. More...
 
ELEMENTS_API unsigned long unloadDynamicLib (ImageHandle handle)
 unload dynamic link library More...
 
ELEMENTS_API unsigned long getProcedureByName (ImageHandle handle, const std::string &name, EntryPoint *pFunction)
 Get a specific function defined in the DLL. More...
 
ELEMENTS_API unsigned long getProcedureByName (ImageHandle handle, const std::string &name, Creator *pFunction)
 Get a specific function defined in the DLL. More...
 
ELEMENTS_API unsigned long getLastError ()
 Get last system known error. More...
 
const ELEMENTS_API std::string getLastErrorString ()
 Get last system error as string. More...
 
const ELEMENTS_API std::string getErrorString (unsigned long error)
 Retrieve error code as string for a given error. More...
 
const ELEMENTS_API std::string typeinfoName (const std::type_info &)
 Get platform independent information about the class type. More...
 
const ELEMENTS_API std::string typeinfoName (const char *)
 
const ELEMENTS_API std::stringhostName ()
 Host name. More...
 
const ELEMENTS_API std::stringosName ()
 OS name. More...
 
const ELEMENTS_API std::stringosVersion ()
 OS version. More...
 
const ELEMENTS_API std::stringmachineType ()
 Machine type. More...
 
ELEMENTS_API std::string getEnv (const std::string &var)
 get a particular environment variable More...
 
ELEMENTS_API bool getEnv (const string &var, string &value)
 get a particular env var, storing the value in the passed string (if set) More...
 
ELEMENTS_API std::vector< std::stringgetEnv ()
 get all environment variables More...
 
ELEMENTS_API int setEnv (const string &name, const string &value, bool overwrite)
 set an environment variables. More...
 
ELEMENTS_API int unSetEnv (const std::string &name)
 Simple wrap around unsetenv for strings. More...
 
ELEMENTS_API bool isEnvSet (const std::string &var)
 Check if an environment variable is set or not. More...
 
ELEMENTS_API int backTrace (ELEMENTS_UNUSED std::shared_ptr< void * > addresses, ELEMENTS_UNUSED const int depth)
 
const ELEMENTS_API std::vector< std::stringbackTrace (const int depth, const int offset=0)
 
ELEMENTS_API bool getStackLevel (ELEMENTS_UNUSED void *addresses, ELEMENTS_UNUSED void *&addr, ELEMENTS_UNUSED std::string &fnc, ELEMENTS_UNUSED std::string &lib)
 
static const ModuleInfogetThisModuleInfo ()
 function to retrieve the current module More...
 
const ELEMENTS_API ModuleInfogetThisExecutableInfo ()
 
 __attribute__ ((noinline)) int backTrace(ELEMENTS_UNUSED std
 
bool getStackLevel (void *addresses ELEMENTS_UNUSED, void *&addr ELEMENTS_UNUSED, string &fnc ELEMENTS_UNUSED, string &lib ELEMENTS_UNUSED)
 

Variables

const std::string SHLIB_VAR_NAME {"LD_LIBRARY_PATH"}
 name of the shared dynamic library path More...
 
const std::string LIB_PREFIX {"lib"}
 constant that represent the common prefix of the libraries More...
 
const std::string LIB_EXTENSION {"so"}
 constant that represent the common extension of the libraries More...
 
const std::string LIB_SUFFIX {"." + LIB_EXTENSION}
 constant that represents the standard suffix of the libraries: usually "."+LIB_EXTENSION More...
 
const std::string SHLIB_SUFFIX {LIB_SUFFIX}
 alias for LIB_SUFFIX More...
 
const std::string DEFAULT_INSTALL_PREFIX {"/usr"}
 constant for the canonical installation prefix (on Linux and MacOSX at least) More...
 
const int STACK_OFFSET {2}
 

Typedef Documentation

◆ Creator

using Elements::System::Creator = typedef void* (*)()

Definition of the "generic" DLL entry point function.

Definition at line 115 of file System.h.

◆ EntryPoint

using Elements::System::EntryPoint = typedef unsigned long (*)(const unsigned long iid, void** ppvObject)

Definition of the "generic" DLL entry point function.

Definition at line 113 of file System.h.

◆ ImageHandle

using Elements::System::ImageHandle = typedef void*

Definition of an image handle.

Definition at line 109 of file System.h.

◆ ProcessHandle

using Elements::System::ProcessHandle = typedef void*

Definition of the process handle.

Definition at line 111 of file System.h.

Enumeration Type Documentation

◆ InfoType

Enumeration for fetching information.

Enumerator
NoFetch 
RemainTime 
Times 
ProcessBasics 
PriorityBoost 
Memory 
Quota 
System 
Modules 
IO 

Definition at line 28 of file SystemBase.h.

◆ ModuleType

Enumerator
UNKNOWN 
SHAREDLIB 
EXECUTABLE 

Definition at line 58 of file ModuleInfo.h.

Function Documentation

◆ __attribute__()

Elements::System::__attribute__ ( (noinline)  )

Definition at line 386 of file System.cpp.

◆ backTrace() [1/2]

const vector< string > Elements::System::backTrace ( const int  depth,
const int  offset = 0 
)

Definition at line 397 of file System.cpp.

References backTrace(), std::dec(), getStackLevel(), std::hex(), std::setiosflags(), std::setw(), STACK_OFFSET, and std::ostringstream::str().

Here is the call graph for this function:

◆ backTrace() [2/2]

ELEMENTS_API int Elements::System::backTrace ( ELEMENTS_UNUSED std::shared_ptr< void * >  addresses,
ELEMENTS_UNUSED const int  depth 
)

◆ exeHandle()

ImageHandle Elements::System::exeHandle ( )

Handle to the executable file running.

Definition at line 164 of file ModuleInfo.cpp.

◆ exeName()

const string & Elements::System::exeName ( )

Name of the executable file running.

Definition at line 183 of file ModuleInfo.cpp.

References getExecutablePath().

Here is the call graph for this function:

◆ getEnv() [1/3]

vector< string > Elements::System::getEnv ( )

get all environment variables

get all defined environment vars

Definition at line 357 of file System.cpp.

References std::vector< T >::emplace_back().

Here is the call graph for this function:

◆ getEnv() [2/3]

string Elements::System::getEnv ( const std::string var)

get a particular environment variable

Definition at line 324 of file System.cpp.

Referenced by Elements::Environment::get(), isEnvSet(), loadDynamicLib(), Elements::Environment::set(), and Elements::Environment::unSet().

◆ getEnv() [3/3]

bool Elements::System::getEnv ( const std::string var,
std::string value 
)

get a particular env var, storing the value in the passed string (if set)

get a particular environment variable, storing the value in the passed string if the variable is set. Returns true if the variable is set, false otherwise.

Definition at line 334 of file System.cpp.

References std::string::c_str().

Here is the call graph for this function:

◆ getErrorString()

const string Elements::System::getErrorString ( unsigned long  error)

Retrieve error code as string for a given error.

Definition at line 165 of file System.cpp.

References std::strerror().

Referenced by getLastErrorString().

Here is the call graph for this function:

◆ getExecutablePath()

Path::Item Elements::System::getExecutablePath ( )

Get the full executable path.

Definition at line 246 of file ModuleInfo.cpp.

References getSelfProc().

Referenced by exeName(), Elements::ProgramManager::setProgramName(), and Elements::ProgramManager::setProgramPath().

Here is the call graph for this function:

◆ getLastError()

unsigned long Elements::System::getLastError ( )

Get last system known error.

Retrieve last error code.

Definition at line 153 of file System.cpp.

Referenced by getLastErrorString(), and unloadDynamicLib().

◆ getLastErrorString()

const string Elements::System::getLastErrorString ( )

Get last system error as string.

Retrieve last error code as string.

Definition at line 159 of file System.cpp.

References getErrorString(), and getLastError().

Referenced by getProcedureByName().

Here is the call graph for this function:

◆ getProcedureByName() [1/2]

unsigned long Elements::System::getProcedureByName ( ImageHandle  handle,
const std::string name,
Creator pFunction 
)

Get a specific function defined in the DLL.

Definition at line 148 of file System.cpp.

References getProcedureByName().

Here is the call graph for this function:

◆ getProcedureByName() [2/2]

unsigned long Elements::System::getProcedureByName ( ImageHandle  handle,
const std::string name,
EntryPoint pFunction 
)

Get a specific function defined in the DLL.

Definition at line 124 of file System.cpp.

References std::string::c_str(), std::endl(), and getLastErrorString().

Referenced by getProcedureByName().

Here is the call graph for this function:

◆ getSelfProc()

Path::Item Elements::System::getSelfProc ( )

Get the path to the /proc directory of the process.

Definition at line 191 of file ModuleInfo.cpp.

Referenced by getExecutablePath(), and linkedModulePaths().

◆ getStackLevel() [1/2]

ELEMENTS_API bool Elements::System::getStackLevel ( ELEMENTS_UNUSED void *  addresses,
ELEMENTS_UNUSED void *&  addr,
ELEMENTS_UNUSED std::string fnc,
ELEMENTS_UNUSED std::string lib 
)

Referenced by backTrace().

◆ getStackLevel() [2/2]

bool Elements::System::getStackLevel ( void *addresses  ELEMENTS_UNUSED,
void *&addr  ELEMENTS_UNUSED,
string &fnc  ELEMENTS_UNUSED,
string &lib  ELEMENTS_UNUSED 
)

Definition at line 427 of file System.cpp.

References std::unique_ptr< T >::get().

Here is the call graph for this function:

◆ getThisExecutableInfo()

const ModuleInfo & Elements::System::getThisExecutableInfo ( )

◆ hostName()

const string & Elements::System::hostName ( )

Host name.

Definition at line 278 of file System.cpp.

References std::array< T >::data(), and HOST_NAME_MAX.

Here is the call graph for this function:

◆ isEnvSet()

bool Elements::System::isEnvSet ( const std::string var)

Check if an environment variable is set or not.

Definition at line 347 of file System.cpp.

References getEnv().

Referenced by Elements::Environment::hasKey().

Here is the call graph for this function:

◆ linkedModulePaths()

vector< Path::Item > Elements::System::linkedModulePaths ( )

Definition at line 206 of file ModuleInfo.cpp.

References std::ifstream::close(), std::vector< T >::emplace_back(), std::getline(), and getSelfProc().

Referenced by linkedModules().

Here is the call graph for this function:

◆ linkedModules()

const vector< string > Elements::System::linkedModules ( )

Vector of names of linked modules.

Definition at line 235 of file ModuleInfo.cpp.

References std::vector< T >::emplace_back(), linkedModulePaths(), and Elements::Kernel::Units::m.

Here is the call graph for this function:

◆ loadDynamicLib()

unsigned long Elements::System::loadDynamicLib ( const std::string name,
ImageHandle handle 
)

Load dynamic link library.

Definition at line 88 of file System.cpp.

References getEnv(), std::string::length(), and SHLIB_SUFFIX.

Here is the call graph for this function:

◆ machineType()

const string & Elements::System::machineType ( )

Machine type.

Definition at line 313 of file System.cpp.

◆ moduleHandle()

ImageHandle Elements::System::moduleHandle ( )

Handle to currently executed module.

Definition at line 152 of file ModuleInfo.cpp.

References processHandle().

Referenced by moduleName(), and moduleNameFull().

Here is the call graph for this function:

◆ moduleName()

const string & Elements::System::moduleName ( )

Get the name of the (executable/DLL) file without file-type.

Retrieve base name of module.

Definition at line 95 of file ModuleInfo.cpp.

References std::string::find(), moduleHandle(), processHandle(), and std::string::substr().

Here is the call graph for this function:

◆ moduleNameFull()

const string & Elements::System::moduleNameFull ( )

Get the full name of the (executable/DLL) file.

Retrieve full name of module.

Definition at line 107 of file ModuleInfo.cpp.

References moduleHandle(), and processHandle().

Referenced by moduleType().

Here is the call graph for this function:

◆ moduleType()

ModuleType Elements::System::moduleType ( )

Get type of the module.

Definition at line 123 of file ModuleInfo.cpp.

References EXECUTABLE, moduleNameFull(), std::string::rfind(), SHAREDLIB, and UNKNOWN.

Here is the call graph for this function:

◆ osName()

const string & Elements::System::osName ( )

OS name.

Definition at line 289 of file System.cpp.

◆ osVersion()

const string & Elements::System::osVersion ( )

OS version.

Definition at line 301 of file System.cpp.

◆ processHandle()

void * Elements::System::processHandle ( )

Handle to running process.

Retrieve process handle.

Definition at line 142 of file ModuleInfo.cpp.

Referenced by moduleHandle(), moduleName(), and moduleNameFull().

◆ setEnv()

int Elements::System::setEnv ( const std::string name,
const std::string value,
bool  overwrite = true 
)

set an environment variables.

Set an environment variables. If value is empty, the variable is removed from the environment. When overwrite is 0, the variable is not set if already present. Returns 0 on success, -1 on failure. See man 3 setenv.

Returns
0 if successful, -1 if not

Definition at line 369 of file System.cpp.

References std::string::c_str().

Referenced by Elements::Environment::restore(), and Elements::Environment::set().

Here is the call graph for this function:

◆ setModuleHandle()

void Elements::System::setModuleHandle ( ImageHandle  handle)

Attach module handle.

Definition at line 148 of file ModuleInfo.cpp.

◆ typeinfoName() [1/2]

const string Elements::System::typeinfoName ( const char *  class_name)

substitute ', ' with ','

substitute ', ' with ','

Definition at line 190 of file System.cpp.

References std::string::find(), std::unique_ptr< T >::get(), and std::string::replace().

Here is the call graph for this function:

◆ typeinfoName() [2/2]

const string Elements::System::typeinfoName ( const std::type_info tinfo)

Get platform independent information about the class type.

Definition at line 186 of file System.cpp.

References std::type_info::name().

Here is the call graph for this function:

◆ unloadDynamicLib()

unsigned long Elements::System::unloadDynamicLib ( ImageHandle  handle)

unload dynamic link library

Definition at line 115 of file System.cpp.

References getLastError().

Here is the call graph for this function:

◆ unSetEnv()

int Elements::System::unSetEnv ( const std::string name)

Simple wrap around unsetenv for strings.

Definition at line 379 of file System.cpp.

References std::string::c_str().

Referenced by Elements::Environment::restore(), and Elements::Environment::unSet().

Here is the call graph for this function:

Variable Documentation

◆ DEFAULT_INSTALL_PREFIX

const std::string Elements::System::DEFAULT_INSTALL_PREFIX {"/usr"}

constant for the canonical installation prefix (on Linux and MacOSX at least)

Examples
ElementsKernel/tests/src/Configuration_test.cpp.

Definition at line 90 of file System.h.

Referenced by Elements::Kernel::getAuxiliaryLocations(), and Elements::Kernel::getConfigurationLocations().

◆ LIB_EXTENSION

const std::string Elements::System::LIB_EXTENSION {"so"}

constant that represent the common extension of the libraries

Definition at line 72 of file System.h.

◆ LIB_PREFIX

const std::string Elements::System::LIB_PREFIX {"lib"}

constant that represent the common prefix of the libraries

Definition at line 64 of file System.h.

◆ LIB_SUFFIX

const std::string Elements::System::LIB_SUFFIX {"." + LIB_EXTENSION}

constant that represents the standard suffix of the libraries: usually "."+LIB_EXTENSION

Definition at line 79 of file System.h.

◆ SHLIB_SUFFIX

const std::string Elements::System::SHLIB_SUFFIX {LIB_SUFFIX}

alias for LIB_SUFFIX

Definition at line 84 of file System.h.

Referenced by loadDynamicLib().

◆ SHLIB_VAR_NAME

const std::string Elements::System::SHLIB_VAR_NAME {"LD_LIBRARY_PATH"}

name of the shared dynamic library path

Definition at line 58 of file System.h.

◆ STACK_OFFSET

const int Elements::System::STACK_OFFSET {2}

Definition at line 92 of file System.h.

Referenced by backTrace().