Elements  5.8
A C++ base framework for the Euclid Software.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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...
 
ELEMENTS_API const std::stringmoduleName ()
 Get the name of the (executable/DLL) file without file-type. More...
 
ELEMENTS_API const 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...
 
ELEMENTS_API const std::stringexeName ()
 Name of the executable file running. More...
 
ELEMENTS_API const std::vector
< std::string
linkedModules ()
 Vector of names of linked modules. More...
 
ELEMENTS_API std::vector
< boost::filesystem::path > 
linkedModulePaths ()
 
ELEMENTS_API void setModuleHandle (ImageHandle handle)
 Attach module handle. More...
 
ELEMENTS_API
boost::filesystem::path 
getExecutablePath ()
 Get the full executable path. 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...
 
ELEMENTS_API const std::string getLastErrorString ()
 Get last system error as string. More...
 
ELEMENTS_API const std::string getErrorString (unsigned long error)
 Retrieve error code as string for a given error. More...
 
ELEMENTS_API const std::string typeinfoName (const std::type_info &)
 Get platform independent information about the class type. More...
 
ELEMENTS_API const std::string typeinfoName (const char *)
 
ELEMENTS_API const std::stringhostName ()
 Host name. More...
 
ELEMENTS_API const std::stringosName ()
 OS name. More...
 
ELEMENTS_API const std::stringosVersion ()
 OS version. More...
 
ELEMENTS_API const 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::string
getEnv ()
 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)
 
ELEMENTS_API bool backTrace (std::string &btrace, const int depth, const int offset=0)
 
ELEMENTS_API const std::vector
< std::string
backTrace (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 ()
 
ELEMENTS_API const ModuleInfogetThisExecutableInfo ()
 
path getSelfProc ()
 
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

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

Definition of the "generic" DLL entry point function.

Definition at line 124 of file System.h.

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

Definition of the "generic" DLL entry point function.

Definition at line 122 of file System.h.

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

Definition of an image handle.

Definition at line 118 of file System.h.

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

Definition of the process handle.

Definition at line 120 of file System.h.

Enumeration Type Documentation

Enumeration for fetching information.

Enumerator
NoFetch 
RemainTime 
Times 
ProcessBasics 
PriorityBoost 
Memory 
Quota 
System 
Modules 
IO 

Definition at line 28 of file SystemBase.h.

Enumerator
UNKNOWN 
SHAREDLIB 
EXECUTABLE 

Definition at line 58 of file ModuleInfo.h.

Function Documentation

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

Definition at line 396 of file System.cpp.

Referenced by backTrace(), and Elements::ProgramManager::onTerminate().

bool Elements::System::backTrace ( std::string btrace,
const int  depth,
const int  offset = 0 
)

Definition at line 408 of file System.cpp.

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

Here is the call graph for this function:

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

Definition at line 437 of file System.cpp.

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

Here is the call graph for this function:

ImageHandle Elements::System::exeHandle ( )

Handle to the executable file running.

Definition at line 166 of file ModuleInfo.cpp.

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

Name of the executable file running.

Definition at line 186 of file ModuleInfo.cpp.

References getExecutablePath(), and std::string::length().

Here is the call graph for this function:

template<typename DESTPTR , typename SRCPTR >
DESTPTR Elements::System::FuncPtrCast ( SRCPTR  ptr)
inline

Cast from void * to function pointer.

Small helper function that allows the cast from void * to function pointer
and vice versa without the message
*   warning: ISO C++ forbids casting between pointer-to-function and pointer-to-object
*   

It is an ugly trick but works. See:

Definition at line 55 of file FuncPtrCast.h.

string Elements::System::getEnv ( const std::string var)
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 341 of file System.cpp.

References std::string::c_str().

Here is the call graph for this function:

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

get all environment variables

get all defined environment vars

Definition at line 365 of file System.cpp.

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

Here is the call graph for this function:

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

Retrieve error code as string for a given error.

Definition at line 169 of file System.cpp.

References std::strerror().

Referenced by getLastErrorString().

Here is the call graph for this function:

path Elements::System::getExecutablePath ( )

Get the full executable path.

Definition at line 248 of file ModuleInfo.cpp.

References getSelfProc().

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

Here is the call graph for this function:

unsigned long Elements::System::getLastError ( )

Get last system known error.

Retrieve last error code.

Definition at line 157 of file System.cpp.

Referenced by getLastErrorString(), and unloadDynamicLib().

const string Elements::System::getLastErrorString ( )

Get last system error as string.

Retrieve last error code as string.

Definition at line 163 of file System.cpp.

References getErrorString(), and getLastError().

Referenced by getProcedureByName().

Here is the call graph for this function:

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

Get a specific function defined in the DLL.

Definition at line 125 of file System.cpp.

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

Referenced by getProcedureByName().

Here is the call graph for this function:

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

Get a specific function defined in the DLL.

Definition at line 151 of file System.cpp.

References getProcedureByName().

Here is the call graph for this function:

path Elements::System::getSelfProc ( )

Definition at line 194 of file ModuleInfo.cpp.

Referenced by getExecutablePath(), and linkedModulePaths().

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().

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

Definition at line 465 of file System.cpp.

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

Here is the call graph for this function:

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

Definition at line 34 of file ThisModule.cpp.

References Elements::System::ModuleInfo::isEmpty().

Here is the call graph for this function:

static const ModuleInfo& Elements::System::getThisModuleInfo ( )
inlinestatic

Definition at line 35 of file ThisModule.h.

References Elements::System::ModuleInfo::isEmpty().

Here is the call graph for this function:

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

Host name.

Definition at line 285 of file System.cpp.

References std::unique_ptr< T >::get(), and HOST_NAME_MAX.

Here is the call graph for this function:

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

Check if an environment variable is set or not.

Definition at line 355 of file System.cpp.

References getEnv().

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

Here is the call graph for this function:

vector< path > Elements::System::linkedModulePaths ( )

Definition at line 210 of file ModuleInfo.cpp.

References std::getline(), getSelfProc(), and std::vector< T >::push_back().

Referenced by linkedModules().

Here is the call graph for this function:

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

Vector of names of linked modules.

Definition at line 236 of file ModuleInfo.cpp.

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

Here is the call graph for this function:

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

Load dynamic link library.

Definition at line 89 of file System.cpp.

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

Here is the call graph for this function:

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

Machine type.

Definition at line 320 of file System.cpp.

ImageHandle Elements::System::moduleHandle ( )

Handle to currently executed module.

Definition at line 154 of file ModuleInfo.cpp.

References processHandle().

Referenced by moduleName(), and moduleNameFull().

Here is the call graph for this function:

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

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

Retrieve base name of module.

Definition at line 96 of file ModuleInfo.cpp.

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

Here is the call graph for this function:

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

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

Retrieve full name of module.

Definition at line 108 of file ModuleInfo.cpp.

References moduleHandle(), and processHandle().

Referenced by moduleType().

Here is the call graph for this function:

ModuleType Elements::System::moduleType ( )

Get type of the module.

Definition at line 125 of file ModuleInfo.cpp.

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

Here is the call graph for this function:

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

OS name.

Definition at line 296 of file System.cpp.

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

OS version.

Definition at line 308 of file System.cpp.

void * Elements::System::processHandle ( )

Handle to running process.

Retrieve process handle.

Definition at line 144 of file ModuleInfo.cpp.

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

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 377 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:

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

Attach module handle.

Definition at line 150 of file ModuleInfo.cpp.

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

Get platform independent information about the class type.

Definition at line 191 of file System.cpp.

References std::type_info::name().

Here is the call graph for this function:

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

substitute ', ' with ','

substitute ', ' with ','

Definition at line 195 of file System.cpp.

References std::string::find(), and std::string::replace().

Here is the call graph for this function:

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

unload dynamic link library

Definition at line 116 of file System.cpp.

References getLastError().

Here is the call graph for this function:

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

Simple wrap around unsetenv for strings.

Definition at line 388 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

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

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

Definition at line 90 of file System.h.

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

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.

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.

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.

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

alias for LIB_SUFFIX

Definition at line 84 of file System.h.

Referenced by loadDynamicLib().

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.

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

Definition at line 98 of file System.h.

Referenced by backTrace().