| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# System Namespace Reference

Note: OS specific details for environment resolution. More...

## Classes
class | PathResolver
struct | PROCESS_BASIC_INFORMATION
struct | QUOTA_LIMITS
| Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using ProcessPooledQuotaLimits NtSetInformationProcess using ProcessQuotaLimits. More...
struct | IO_COUNTERS
| Process I/O Counters NtQueryInformationProcess using ProcessIoCounters. More...
struct | VM_COUNTERS
| Process Virtual Memory Counters NtQueryInformationProcess using ProcessVmCounters. More...
struct | POOLED_USAGE_AND_LIMITS
| Process Pooled Quota Usage and Limits NtQueryInformationProcess using ProcessPooledUsageAndLimits. More...
struct | KERNEL_USER_TIMES
| Process/Thread System and User Time NtQueryInformationProcess using ProcessTimes NtQueryInformationThread using ThreadTimes. More...
class | ProcessDescriptor
| Provides access to process information. More...
## Typedefs
typedef void * | ImageHandle
| Definition of an image handle.
typedef void * | ProcessHandle
| Definition of the process handle.
typedef unsigned long(* | EntryPoint )(const unsigned long iid, void **ppvObject)
| Definition of the "generic" DLL entry point function.
typedef void *(* | Creator )()
| Definition of the "generic" DLL entry point function.
typedef void * | ThreadHandle
| A Thread handle.
typedef struct _PEB * | PPEB
| Basic Process Information NtQueryInformationProcess using ProcessBasicInfo.
## Enumerations
enum | MemoryUnit { Byte, kByte, MByte, GByte, TByte, PByte, EByte }
| Unit of memory. More...
enum | ModuleType { UNKNOWN, SHAREDLIB, EXECUTABLE }
enum | InfoType { NoFetch, RemainTime, Times, ProcessBasics, PriorityBoost, Memory, Quota, System, Modules, IO }
| Enumeration for fetching information. More...
enum | TimeType { Year, Month, Day, Hour, Min, Sec, milliSec, microSec, nanoSec }
| Time type for conversion. More...
enum | PR_file_type { PR_regular_file, PR_directory }
enum | PR_search_type { PR_local, PR_recursive }
enum | ProcessInfoCommand { ProcessBasicInformation, ProcessQuotaLimits, ProcessIoCounters, ProcessVmCounters, ProcessTimes, ProcessBasePriority, ProcessRaisePriority, ProcessDebugPort, ProcessExceptionPort, ProcessAccessToken, ProcessLdtInformation, ProcessLdtSize, ProcessDefaultHardErrorMode, ProcessIoPortHandlers, ProcessPooledUsageAndLimits, ProcessWorkingSetWatch, ProcessUserModeIOPL, ProcessEnableAlignmentFaultFixup, ProcessPriorityClass, ProcessWx86Information, ProcessHandleCount, ProcessAffinityMask, ProcessPriorityBoost, MaxProcessInfoClass, ProcessEllapsedTime }
## Functions
GAUDI_API long | breakExecution ()
| Break the execution of the application and invoke the debugger.
GAUDI_API long | breakExecution (long pid)
| Break the execution of the application and invoke the debugger in a remote process.
GAUDI_API std::string | homeDirectory ()
GAUDI_API std::string | tempDirectory ()
GAUDI_API StatusCode | resolveEnv (const std::string &var, std::string &res, int recusions=124)
GAUDI_API long | adjustMemory (MemoryUnit typ, long value)
| Convert time from kByte to requested representation (Experts only).
GAUDI_API long | procID ()
| Basic Process Information: Process ID.
GAUDI_API long | parentID (InfoType fetch=ProcessBasics, long pid=-1)
| Basic Process Information: Parent's process ID.
GAUDI_API long | affinityMask (InfoType fetch=ProcessBasics, long pid=-1)
| Basic Process Information: Affinity mask.
GAUDI_API long | exitStatus (InfoType fetch=ProcessBasics, long pid=-1)
| Basic Process Information: Exit status (does not really make sense for the running process, but for others!).
GAUDI_API long | basePriority (InfoType fetch=ProcessBasics, long pid=-1)
| Basic Process Information: Base priority.
GAUDI_API long | priorityBoost (InfoType fetch=PriorityBoost, long pid=-1)
| Basic Process Information: priority boost.
GAUDI_API long | numPageFault (InfoType fetch=Memory, long pid=-1)
| Basic Process Information: Number of page faults.
GAUDI_API long | pagefileUsage (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
| Basic Process Information: Current page file usage.
GAUDI_API long | pagefileUsagePeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
| Basic Process Information: Peak usage of page file.
GAUDI_API long | pagefileUsageLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
| Basic Process Information: Peak usage of page file.
GAUDI_API long | nonPagedMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
| Basic Process Information: Current usage of non paged memory.
GAUDI_API long | nonPagedMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
| Basic Process Information: Peak usage of non paged memory.
GAUDI_API long | nonPagedMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
| System Process Limits: Maximum amount of non-paged memory this process is allowed to use.
GAUDI_API long | pagedMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
| Basic Process Information: Amount of paged memory currently occupied by the process 'pid'.
GAUDI_API long | pagedMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
| Basic Process Information: Maximum of paged memory occupied by the process 'pid'.
GAUDI_API long | pagedMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
| Basic Process Information: Amount of paged memory that can be occupied by the process 'pid'.
GAUDI_API long | minMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
| System Process Limits: Minimum amount of virtual memory this process may use.
GAUDI_API long | maxMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
| System Process Limits: Maximum amount of virtual memory this process is allowed to use.
GAUDI_API long | mappedMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
| Basic Process Information: priority boost.
GAUDI_API long | mappedMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
| Basic Process Information: priority boost.
GAUDI_API long | virtualMemory (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
| Basic Process Information: priority boost.
GAUDI_API long | virtualMemoryPeak (MemoryUnit unit=kByte, InfoType fetch=Memory, long pid=-1)
| Basic Process Information: priority boost.
GAUDI_API long | virtualMemoryLimit (MemoryUnit unit=kByte, InfoType fetch=Quota, long pid=-1)
| System Process Limits: Maximum amount of the page file this process is allowed to use.
GAUDI_API const std::string & | moduleName ()
| Get the name of the (executable/DLL) file without file-type.
GAUDI_API const std::string & | moduleNameFull ()
| Get the full name of the (executable/DLL) file.
GAUDI_API ModuleType | moduleType ()
| Get type of the module.
GAUDI_API ProcessHandle | processHandle ()
| Handle to running process.
GAUDI_API ImageHandle | moduleHandle ()
| Handle to currently executed module.
GAUDI_API ImageHandle | exeHandle ()
| Handle to the executable file running.
GAUDI_API const std::string & | exeName ()
| Name of the executable file running.
GAUDI_API const std::vector < std::string > | linkedModules ()
| Vector of names of linked modules.
GAUDI_API void | setModuleHandle (ImageHandle handle)
| Attach module handle.
GAUDI_API PathResolver::SearchPathStatus | PathResolverCheckSearchPath (const std::string &search_path)
GAUDI_API std::string | PathResolverFindDirectory (const std::string &logical_file_name, const std::string &search_path)
GAUDI_API std::string | PathResolverFindDirectoryFromList (const std::string &logical_file_name, const std::string &search_list)
GAUDI_API std::string | PathResolverFindFile (const std::string &logical_file_name, const std::string &search_path)
GAUDI_API std::string | PathResolverFindFileFromList (const std::string &logical_file_name, const std::string &search_list)
GAUDI_API std::string | PathResolverFindXMLFile (const std::string &logical_file_name)
GAUDI_API std::string | PathResolverFindDataFile (const std::string &logical_file_name)
GAUDI_API unsigned long | loadDynamicLib (const std::string &name, ImageHandle *handle)
| Load dynamic link library.
GAUDI_API unsigned long | unloadDynamicLib (ImageHandle handle)
| unload dynamic link library
GAUDI_API unsigned long | getProcedureByName (ImageHandle handle, const std::string &name, EntryPoint *pFunction)
| Get a specific function defined in the DLL.
GAUDI_API unsigned long | getProcedureByName (ImageHandle handle, const std::string &name, Creator *pFunction)
| Get a specific function defined in the DLL.
GAUDI_API unsigned long | getLastError ()
| Get last system known error.
GAUDI_API const std::string | getLastErrorString ()
| Get last system error as string.
GAUDI_API const std::string | getErrorString (unsigned long error)
| Retrieve error code as string for a given error.
GAUDI_API const std::string | typeinfoName (const std::type_info &)
| Get platform independent information about the class type.
GAUDI_API const std::string | typeinfoName (const char *)
GAUDI_API const std::string & | hostName ()
| Host name.
GAUDI_API const std::string & | osName ()
| OS name.
GAUDI_API const std::string & | osVersion ()
| OS version.
GAUDI_API const std::string & | machineType ()
| Machine type.
GAUDI_API const std::string & | accountName ()
| User login name.
GAUDI_API long | numCmdLineArgs ()
| Number of arguments passed to the commandline.
GAUDI_API long | argc ()
| Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call...
GAUDI_API const std::vector < std::string > | cmdLineArgs ()
| Command line arguments including executable name as arg[0] as vector of strings.
GAUDI_API char ** | argv ()
| char** command line arguments including executable name as arg[0]; You may not modify them!
GAUDI_API const std::string | getEnv (const char *var)
| get a particular environment variable
GAUDI_API const std::vector < std::string > | getEnv ()
| get all environment variables
GAUDI_API int | setEnv (const std::string &name, const std::string &value, int overwrite=1)
| Set an environment variables.
ThreadHandle | threadSelf ()
| thread handle "accessor"
GAUDI_API int | backTrace (void **addresses, const int depth)
GAUDI_API bool | backTrace (std::string &btrace, const int depth, const int offset=0)
GAUDI_API bool | getStackLevel (void *addresses, void *&addr, std::string &fnc, std::string &lib)
GAUDI_API longlong | adjustTime (TimeType typ, longlong timevalue)
| Convert time from OS native time to requested representation (Experts only).
GAUDI_API longlong | ellapsedTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
| Ellapsed time since start of process in milli seconds.
GAUDI_API longlong | kernelTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
| CPU kernel mode time of process in milli seconds.
GAUDI_API longlong | userTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
| CPU user mode time of process in milli seconds.
GAUDI_API longlong | cpuTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
| Consumed CPU time of process in milli seconds.
GAUDI_API longlong | remainingTime (TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
| Maximum processing time left for this process.
GAUDI_API longlong | creationTime (TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
| Process Creation time.
GAUDI_API longlong | systemStart (TimeType typ=Sec)
| Maximum processing time left for this process.
GAUDI_API longlong | upTime (TimeType typ=Hour)
| Maximum processing time left for this process.
GAUDI_API longlong | currentTime (TimeType typ=milliSec)
| Retrieve absolute system time.
GAUDI_API longlong | tickCount ()
| Retrieve the number of ticks since system startup.
static void | PR_compress_path (std::string &dir)
static void | PR_dirname (const std::string &file_name, std::string &result)
static bool | PR_absolute_path (const std::string &name)
static void | PR_basename (const std::string &file_name, std::string &result)
static bool | PR_test_exist (const std::string &name, std::string &real_name, PR_file_type file_type)
static void | PR_scan_dir (const std::string &dir_name, std::vector< std::string > &list)
static bool | PR_find (const std::string &search_base, const std::string &logical_file_prefix, const std::string &logical_file_name, PR_file_type file_type, PathResolver::SearchType search_type, std::string &result)
static bool | PR_find_from_list (const std::string &logical_file_name, const std::string &search_list, PR_file_type file_type, PathResolver::SearchType search_type, std::string &result)
System::ProcessDescriptor * | getProcess ()
| Retrieve Process structure.
int | backTrace (void **addresses __attribute__((unused)), const int depth __attribute__((unused)))
bool | getStackLevel (void *addresses __attribute__((unused)), void *&addr __attribute__((unused)), std::string &fnc __attribute__((unused)), std::string &lib __attribute__((unused)))

## Detailed Description

Note: OS specific details for environment resolution.

Note: OS specific details for process timing.

Note: OS specific details as well as Gaudi details may not occur in this definition file, because this header is the used by both, the OS specific implementations and the gaudi specific implementation.

ModuleInfo: OS specific details to access at run-time the module configuration of the process.

Note: OS specific details for memory usage.

Entrypoints:

Author:
  : M.Frank

Version:
  : 1.0

Entrypoints:

- basePriority Base priority
- procID Process ID
- parentID Parent's process ID
- affinityMask Affinity mask
- exitStatus Exit status
- priorityBoost Priority boost
- numPageFault Number of page faults
- pagefileUsage Current page file usage
- pagefileUsagePeak Peak usage of page file
- nonPagedMemory Current usage of non paged memory
- nonPagedMemoryPeak Peak usage of non paged memory
- nonPagedMemoryLimit Maximum amount of non-paged memory this process is allowed to use
- pagedMemory Amount of paged memory currently occupied
- pagedMemoryPeak Maximum of paged memory occupied by the process
- pagedMemoryLimit paged memory that can be occupied by the process
- memorySize Size of currently occupied memory
- memorySizePeak Maximum memory occupied by the process
- memoryLimit Amount of memory that can be occupied by the process
- virtualMemorySize Virtual memory size currenly occupied
- peakVirtualMemorySize Maximum amount of virtual memory occupied
- virtualMemoryLimit Amount of virtual memory that can be occupied by the process
- minMemoryLimit Minimum amount of virtual memory this process may use
- maxMemoryLimit Maximum amount of virtual memory this process is allowed to use
- mappedMemorySize Currenly mapped virtual memory size
- mappedMemorySizePeak Peak mapped virtual memory size

Author:
  : M.Frank

Version:
  : 1.0

M.Frank

Since e.g. IID is defined in both, this would lead automatically to complete comilation failures.....

Author:
  M.Frank

Entrypoints:

- remainingTime returns the time the process could still execute
- ellapsedTime: returns ellapsed time since program start
- kernelTime: returns the amount of time the process has spent in kernel mode
- userTime: returns the amount of time the process has spent in user mode
- cpuTime: returns kernel+user time

On Windows NT Time is expressed as the amount of time that has elapsed since midnight on January 1, 1601 at Greenwich, England.

On Unix time is expressed as the amount of time that has elapsed since midnight on January 1, 1970 at Greenwich, England.

History :

        +---------+----------------------------------------------+--------+
        |    Date |                 Comment                      | Who    |
        +---------+----------------------------------------------+--------+
        | 11/11/00| Initial version.                             | MF     |
        +---------+----------------------------------------------+--------+

Author:
  : M.Frank

Version:
  : 1.0

## Typedef Documentation

typedef void*(* System::Creator)()

Definition of the "generic" DLL entry point function.

Definition at line 38 of file System.h.

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

Definition of the "generic" DLL entry point function.

Definition at line 36 of file System.h.

typedef void * System::ImageHandle

Definition of an image handle.

Definition at line 30 of file ModuleInfo.h.

typedef struct _PEB* System::PPEB

Basic Process Information NtQueryInformationProcess using ProcessBasicInfo.

Definition at line 18 of file ProcessDescriptor.h.

typedef void * System::ProcessHandle

Definition of the process handle.

Definition at line 32 of file ModuleInfo.h.

typedef void* System::ThreadHandle

A Thread handle.

Definition at line 91 of file System.h.

## Enumeration Type Documentation

enum System::InfoType

Enumeration for fetching information.

Enumerator:

  NoFetch |
  RemainTime |
  Times |
  ProcessBasics |
  PriorityBoost |
  Memory |
  Quota |
  System |
  Modules |
  IO |

Definition at line 18 of file SystemBase.h.

    00018                   {   NoFetch,
    00019                       RemainTime,
    00020                       Times,
    00021                       ProcessBasics,
    00022                       PriorityBoost,
    00023                       Memory,
    00024                       Quota,
    00025                       System,
    00026                       Modules,
    00027                       IO };

enum System::MemoryUnit

Unit of memory.

Enumerator:

  Byte |
  kByte |
  MByte |
  GByte |
  TByte |
  PByte |
  EByte |

Definition at line 57 of file Memory.h.

    00057 { Byte, kByte, MByte, GByte, TByte, PByte, EByte };

enum System::ModuleType

Enumerator:

  UNKNOWN |
  SHAREDLIB |
  EXECUTABLE |

Definition at line 28 of file ModuleInfo.h.

    00028 { UNKNOWN, SHAREDLIB, EXECUTABLE };

enum System::PR_file_type

Enumerator:

  PR_regular_file |
  PR_directory |

Definition at line 24 of file PathResolver.cpp.

    00025   {
    00026     PR_regular_file,
    00027     PR_directory
    00028   } PR_file_type;

enum System::PR_search_type

Enumerator:

  PR_local |
  PR_recursive |

Definition at line 30 of file PathResolver.cpp.

    00030              {
    00031   PR_local,
    00032   PR_recursive } PR_search_type;

enum System::ProcessInfoCommand

Enumerator:

  ProcessBasicInformation |
  ProcessQuotaLimits |
  ProcessIoCounters |
  ProcessVmCounters |
  ProcessTimes |
  ProcessBasePriority |
  ProcessRaisePriority |
  ProcessDebugPort |
  ProcessExceptionPort |
  ProcessAccessToken |
  ProcessLdtInformation |
  ProcessLdtSize |
  ProcessDefaultHardErrorMode |
  ProcessIoPortHandlers |
  ProcessPooledUsageAndLimits |
  ProcessWorkingSetWatch |
  ProcessUserModeIOPL |
  ProcessEnableAlignmentFaultFixup |
  ProcessPriorityClass |
  ProcessWx86Information |
  ProcessHandleCount |
  ProcessAffinityMask |
  ProcessPriorityBoost |
  MaxProcessInfoClass |
  ProcessEllapsedTime |

Definition at line 21 of file ProcessDescriptor.cpp.

    00021                           {
    00022       ProcessBasicInformation,
    00023       ProcessQuotaLimits,
    00024       ProcessIoCounters,
    00025       ProcessVmCounters,
    00026       ProcessTimes,
    00027       ProcessBasePriority,
    00028       ProcessRaisePriority,
    00029       ProcessDebugPort,
    00030       ProcessExceptionPort,
    00031       ProcessAccessToken,
    00032       ProcessLdtInformation,
    00033       ProcessLdtSize,
    00034       ProcessDefaultHardErrorMode,
    00035       ProcessIoPortHandlers,          // Note: this is kernel mode only
    00036       ProcessPooledUsageAndLimits,
    00037       ProcessWorkingSetWatch,
    00038       ProcessUserModeIOPL,
    00039       ProcessEnableAlignmentFaultFixup,
    00040       ProcessPriorityClass,
    00041       ProcessWx86Information,
    00042       ProcessHandleCount,
    00043       ProcessAffinityMask,
    00044       ProcessPriorityBoost,
    00045       MaxProcessInfoClass,  //
    00046       ProcessEllapsedTime
    00047   };

enum System::TimeType

Time type for conversion.

Enumerator:

  Year |
  Month |
  Day |
  Hour |
  Min |
  Sec |
  milliSec |
  microSec |
  nanoSec |

Definition at line 53 of file Timing.h.

    00053 { Year, Month, Day, Hour, Min, Sec, milliSec, microSec, nanoSec };

## Function Documentation

const std::string & System::accountName | ( |  | ) |

User login name.

Definition at line 564 of file System.cpp.

    00564                                      {
    00565   static std::string account = "";
    00566   if ( account == "" ) {
    00567 #ifdef _WIN32
    00568     char buffer[512];
    00569     unsigned long buflen = sizeof(buffer);
    00570     ::GetUserName(buffer, &buflen);
    00571     account = buffer;
    00572 #else
    00573     const char* acct = ::getlogin();
    00574     if ( 0 == acct ) acct = ::getenv("LOGNAME");
    00575     if ( 0 == acct ) acct = ::getenv("USER");
    00576     account = (acct) ? acct : "Unknown";
    00577 #endif
    00578   }
    00579   return account;
    00580 }

long System::adjustMemory | ( | MemoryUnit | typ,
|  | long | value |
| ) |  |  |

Convert time from kByte to requested representation (Experts only).

Convert requested memory value from kByte to requested value.

Definition at line 35 of file Memory.cpp.

    00035                                                           {
    00036   if ( value != -1 )    {
    00037     switch ( unit )   {
    00038     case Byte:      value =       value;    break;
    00039     case kByte:     value =       value/1024;    break;
    00040     case MByte:     value =      (value/1024)/1024;    break;
    00041     case GByte:     value =     ((value/1024)/1024)/1024;    break;
    00042     case TByte:     value =    (((value/1024)/1024)/1024)/1024;    break;
    00043     case PByte:     value =   ((((value/1024)/1024)/1024)/1024)/1024;    break;
    00044     case EByte:     value =  (((((value/1024)/1024)/1024)/1024)/1024)/1024;    break;
    00045     default:        value =  -1;    break;
    00046     }
    00047   }
    00048   return value;
    00049 }

longlong System::adjustTime | ( | TimeType | typ,
|  | longlong | timevalue |
| ) |  |  |

Convert time from OS native time to requested representation (Experts only).

unfortunately "-ansi" flag turn off teh correct definition of CLK_TCK and forces it to be equal CLOCKS_PER_SEC, it is wrong!

t /= CLOCKS_PER_SEC; // needs division by clock tick unit

Definition at line 38 of file Timing.cpp.

    00038                                                       {
    00039   if ( t != -1 )   {
    00040 #ifndef _WIN32
    00042     //  t /= CLK_TCK ;     // needs division by clock tick unit
    00046
    00048 #endif
    00049     switch( typ )   {
    00050     case Year:      t /= 365;
    00051     case Day:       t /= 24;
    00052     case Hour:      t /= 60;
    00053     case Min:       t /= 60;
    00054     case Sec:       t /= 1000;
    00055     case milliSec:  t /= 1000;
    00056     case microSec:  t /= 10;                    break;
    00057     case nanoSec:   t *= 100;                   break;
    00058     case Month:     t /= (12*24*3600);
    00059                     t /= 10000000;              break;
    00060     default:                                    break;
    00061     }
    00062   }
    00063   return t;
    00064 }

long System::affinityMask | ( | InfoType | fetch = `ProcessBasics`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Affinity mask.

Definition at line 74 of file Memory.cpp.

    00074                                                     {
    00075   PROCESS_BASIC_INFORMATION info;
    00076   if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
    00077     return info.AffinityMask;
    00078   return 0;
    00079 }

long System::argc | ( |  | ) |

Number of arguments passed to the commandline (==numCmdLineArgs()); just to match argv call...

Number of arguments passed to the commandline.

Definition at line 588 of file System.cpp.

    00588                      {
    00589   return cmdLineArgs().size();
    00590 }

char ** System::argv | ( |  | ) |

char** command line arguments including executable name as arg[0]; You may not modify them!

Const char** command line arguments including executable name as arg[0].

added by I.B.

Definition at line 650 of file System.cpp.

    00650                        {
    00652   if( s_argvChars.empty() ) { cmdLineArgs(); }
    00653
    00654   // We rely here on the fact that a vector's allocation table is contiguous
    00655   return (char**)&s_argvChars[0];
    00656 }

int System::backTrace | ( | void **addresses | __attribute__(unused),
|  | const int depth | __attribute__(unused) |
| ) |  |  |

Definition at line 693 of file System.cpp.

    00695 {
    00696
    00697 #ifdef __linux
    00698
    00699   int count = backtrace( addresses, depth );
    00700   if ( count > 0 ) {
    00701     return count;
    00702   } else {
    00703     return 0;
    00704   }
    00705
    00706 #else // windows and osx parts not implemented
    00707   return 0;
    00708 #endif
    00709
    00710 }

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

Definition at line 712 of file System.cpp.

    00713 {
    00714   // Always hide the first two levels of the stack trace (that's us)
    00715   const int totalOffset = offset + 2;
    00716   const int totalDepth = depth + totalOffset;
    00717
    00718   std::string fnc, lib;
    00719
    00720   void** addresses = (void**) malloc(totalDepth*sizeof(void *));
    00721   if ( addresses != 0 ){
    00722     int count = System::backTrace(addresses,totalDepth);
    00723     for (int i = totalOffset; i < count; ++i) {
    00724       void *addr = 0;
    00725
    00726       if (System::getStackLevel(addresses[i],addr,fnc,lib)) {
    00727         std::ostringstream ost;
    00728         ost << "#" << std::setw(3) << std::setiosflags( std::ios::left ) << i-totalOffset+1;
    00729         ost << std::hex << addr << std::dec << " " << fnc << "  [" << lib << "]" << std::endl;
    00730         btrace += ost.str();
    00731       }
    00732     }
    00733     free(addresses);
    00734   }
    00735   else {
    00736     free(addresses);
    00737     return false;
    00738   }
    00739
    00740   return true;
    00741 }

GAUDI_API int System::backTrace | ( | void ** | addresses,
|  | const int | depth |
| ) |  |  |

long System::basePriority | ( | InfoType | fetch = `ProcessBasics`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Base priority.

Definition at line 52 of file Memory.cpp.

    00052                                                     {
    00053   PROCESS_BASIC_INFORMATION info;
    00054   if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
    00055     return info.BasePriority;
    00056   return 0;
    00057 }

long System::breakExecution | ( | long | pid | ) |

Break the execution of the application and invoke the debugger in a remote process.

Break the execution of the application and invoke the debugger on a possibly remote process.

Definition at line 47 of file Debugger.cpp.

    00047                                       {
    00048 #ifdef _WIN32
    00049   long result = 0;
    00050   if ( pid == Win::_getpid() )    {
    00051     _asm int 3
    00052     return 1;
    00053   }
    00054   else    {
    00055     Win::LPTHREAD_START_ROUTINE fun;
    00056     Win::HANDLE th, ph;
    00057     Win::HINSTANCE mh;
    00058     Win::DWORD id;
    00059     mh = Win::LoadLibrary( "Kernel32" );
    00060     if ( 0 != mh )    {
    00061       fun = (Win::LPTHREAD_START_ROUTINE)Win::GetProcAddress(mh, "DebugBreak");
    00062       if ( 0 != fun )   {
    00063         ph = Win::OpenProcess (PROCESS_ALL_ACCESS, TRUE, pid);
    00064         if ( 0 != ph )      {
    00065           th = Win::CreateRemoteThread(ph,NULL,0,fun,0,0,&id);
    00066           if ( 0 != th )   {
    00067             Win::CloseHandle(th);
    00068             result = 1;
    00069           }
    00070           Win::CloseHandle(ph);
    00071         }
    00072       }
    00073       Win::FreeLibrary(mh);
    00074     }
    00075   }
    00076   if ( result != 1 ) result = Win::GetLastError();
    00077   return result;
    00078 #else
    00079   // I have no clu how to do this in linux
    00080   return pid;
    00081 #endif
    00082 }

long System::breakExecution | ( |  | ) |

Break the execution of the application and invoke the debugger.

Definition at line 36 of file Debugger.cpp.

    00036                               {
    00037 #ifdef _WIN32
    00038   _asm int 3
    00039   return 1;
    00040 #else
    00041   // I have no clu how to do this in linux
    00042   return 0;
    00043 #endif
    00044 }

const std::vector< std::string > System::cmdLineArgs | ( |  | ) |

Command line arguments including executable name as arg[0] as vector of strings.

Const char** command line arguments including executable name as arg[0].

Definition at line 593 of file System.cpp.

    00593                                                   {
    00594   if ( s_argvChars.size() == 0 )    {
    00595     char exe[1024];
    00596 #ifdef _WIN32
    00597     // For compatibility with UNIX we CANNOT use strtok!
    00598     // If we would use strtok, options like -g="My world" at
    00599     // the command line level would result on NT in TWO options
    00600     // instead in one as in UNIX.
    00601     char *next, *tmp1, *tmp2;
    00602     for(LPTSTR cmd = ::GetCommandLine(); *cmd; cmd=next)   {
    00603       memset(exe,0,sizeof(exe));
    00604       while ( *cmd == ' ' ) cmd++;
    00605       next=::strchr(cmd,' ');
    00606       if ( !next ) next = cmd + strlen(cmd);
    00607       if ( (tmp1=::strchr(cmd,'\"')) > 0 && tmp1 < next )  {
    00608         tmp2 = ::strchr(++tmp1,'\"');
    00609         if ( tmp2 > 0 )   {
    00610           next = ++tmp2;
    00611           if ( cmd < tmp1 ) strncpy(exe, cmd, tmp1-cmd-1);
    00612           strncpy(&exe[strlen(exe)], tmp1, tmp2-tmp1-1);
    00613         }
    00614         else    {
    00615           std::cout << "Mismatched \" in command line arguments" << std::endl;
    00616           s_argvChars.erase(s_argvChars.begin(), s_argvChars.end());
    00617           s_argvStrings.erase(s_argvStrings.begin(), s_argvStrings.end());
    00618           return s_argvStrings;
    00619         }
    00620       }
    00621       else    {
    00622         strncpy(exe, cmd, next-cmd);
    00623       }
    00624       s_argvStrings.push_back(exe);
    00625       s_argvChars.push_back( s_argvStrings.back().c_str());
    00626     }
    00627 #elif defined(linux) || defined(__APPLE__)
    00628     sprintf(exe, "/proc/%d/cmdline", ::getpid());
    00629     FILE *cmdLine = ::fopen(exe,"r");
    00630     char cmd[1024];
    00631     if ( cmdLine )   {
    00632       long len = fread(cmd, sizeof(char), sizeof(cmd), cmdLine);
    00633       if ( len > 0 )   {
    00634         cmd[len] = 0;
    00635         for ( char* token = cmd; token-cmd < len; token += strlen(token)+1 )  {
    00636           s_argvStrings.push_back(token);
    00637           s_argvChars.push_back( s_argvStrings.back().c_str());
    00638         }
    00639         s_argvStrings[0] = exeName();
    00640         s_argvChars[0]   = s_argvStrings[0].c_str();
    00641       }
    00642     }
    00643     ::fclose(cmdLine);
    00644 #endif
    00645   }
    00646   return s_argvStrings;
    00647 }

longlong System::cpuTime | ( | TimeType | typ = `milliSec`,
|  | InfoType | fetch = `Times`,
|  | long | pid = `-1` |
| ) |  |  |

Consumed CPU time of process in milli seconds.

CPU kernel time of process in milli seconds.

Parameters:

  | typ | Indicator or the unit the time will be returned.
  | fetch | Indicator of the information to be fetched. If Fetch_None, the information will not be updated.
  | pid | Process ID of which the information will be returned

Returns:
  Requested value in the indicated units.

Definition at line 170 of file Timing.cpp.

    00170                                                                {
    00171   longlong cputime = 0;
    00172   KERNEL_USER_TIMES info;
    00173   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )   {
    00174     cputime = adjustTime(typ, info.KernelTime+info.UserTime );
    00175   }
    00176   return cputime;
    00177 }

longlong System::creationTime | ( | TimeType | typ = `milliSec`,
|  | InfoType | fetch = `Times`,
|  | long | pid = `-1` |
| ) |  |  |

Process Creation time.

Units of time between process creation and begin of epoche.

Parameters:

  | typ | Indicator or the unit the time will be returned.
  | fetch | Indicator of the information to be fetched. If Fetch_None, the information will not be updated.
  | pid | Process ID of which the information will be returned

Returns:
  Requested value in the indicated units.

Definition at line 116 of file Timing.cpp.

    00116                                                                       {
    00117   longlong created = 0;
    00118   KERNEL_USER_TIMES info;
    00119   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )   {
    00120     created = adjustTime(typ, info.CreateTime-UNIX_BASE_TIME);
    00121   }
    00122   return created;
    00123 }

longlong System::currentTime | ( | TimeType | typ = `milliSec` | ) |

Retrieve absolute system time.

Retrieve current system time.

Parameters:

  | typ | Indicator or the unit the time will be returned.

Returns:
  Requested value in the indicated units.

Definition at line 81 of file Timing.cpp.

    00081                                             {
    00082   longlong current = 0;
    00083 #ifdef _WIN32
    00084   ::GetSystemTimeAsFileTime((FILETIME*)&current);
    00085   current -= UNIX_BASE_TIME;
    00086 #else
    00087   struct timeval tv;
    00088   struct timezone tz;
    00089   ::gettimeofday(&tv, &tz);
    00090   current  = tv.tv_sec;
    00091   current *= 1000000;
    00092   current += tv.tv_usec;
    00093   current *= 10;
    00094 #endif
    00095   return adjustTime(typ, current);
    00096 }

longlong System::ellapsedTime | ( | TimeType | typ = `milliSec`,
|  | InfoType | fetch = `Times`,
|  | long | pid = `-1` |
| ) |  |  |

Ellapsed time since start of process in milli seconds.

Parameters:

  | typ | Indicator or the unit the time will be returned.
  | timevalue | Time value to be converted.

Returns:
  Requested value in the indicated units.

Definition at line 141 of file Timing.cpp.

    00141                                                                     {
    00142   KERNEL_USER_TIMES info;
    00143   longlong ellapsed = currentTime(microSec)*10;
    00144   getProcess()->query(pid, fetch, &info);
    00145   ellapsed = adjustTime(typ, ellapsed+UNIX_BASE_TIME-info.CreateTime);
    00146   return ellapsed;
    00147 }

System::ImageHandle System::exeHandle | ( |  | ) |

Handle to the executable file running.

Definition at line 167 of file ModuleInfo.cpp.

    00167                                        {
    00168 #ifdef _WIN32
    00169   if ( processHandle() )    {
    00170     static HINSTANCE handle = 0;
    00171     DWORD   cbNeeded;
    00172     if ( 0 == handle && _psApi.isValid() )    {
    00173       if ( _psApi.EnumProcessModules( processHandle(), &handle, sizeof(ModuleHandle), &cbNeeded) )   {
    00174       }
    00175     }
    00176     return handle;
    00177   }
    00178   return 0;
    00179 #elif defined(linux) || defined(__APPLE__)
    00180   // This does NOT work!
    00181   static Dl_info infoBuf, *info = &infoBuf;
    00182   if ( 0 == info ) {
    00183     void* handle = ::dlopen(0, RTLD_LAZY);
    00184     //printf("Exe handle:%X\n", handle);
    00185     if ( 0 != handle ) {
    00186       void* func = ::dlsym(handle, "main");
    00187       //printf("Exe:Func handle:%X\n", func);
    00188       if ( 0 != func ) {
    00189         if ( 0 != ::dladdr(func, &infoBuf) ) {
    00190                 //std::cout << "All OK" << std::endl;
    00191           info = &infoBuf;
    00192         }
    00193       }
    00194     }
    00195   }
    00196   return info;
    00197 #elif __hpux
    00198   // Don't know how to solve this .....
    00199   return 0;
    00200 #endif
    00201 }

const std::string & System::exeName | ( |  | ) |

Name of the executable file running.

Definition at line 203 of file ModuleInfo.cpp.

    00203                                     {
    00204   static std::string module("");
    00205   if ( module.length() == 0 )    {
    00206     char name[PATH_MAX] = {"Unknown.module"};
    00207     name[0] = 0;
    00208 #ifdef _WIN32
    00209     if ( _psApi.isValid() && processHandle() )   {
    00210       _psApi.GetModuleFileNameExA( processHandle(), (HINSTANCE)exeHandle(), name,sizeof(name) );
    00211     }
    00212 #elif defined(linux) || defined(__APPLE__)
    00213     char cmd[512];
    00214     ::sprintf(cmd, "/proc/%d/exe", ::getpid());
    00215     module = "Unknown";
    00216     ::readlink(cmd, name, sizeof(name));
    00217 #elif __hpux
    00218     ::realpath(((HMODULE*)exeHandle())->dsc.filename, name);
    00219 #endif
    00220     module = name;
    00221   }
    00222   return module;
    00223 }

long System::exitStatus | ( | InfoType | fetch = `ProcessBasics`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Exit status (does not really make sense for the running process, but for others!).

Definition at line 82 of file Memory.cpp.

    00082                                                   {
    00083   PROCESS_BASIC_INFORMATION info;
    00084   if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
    00085     return info.ExitStatus;
    00086   return -2;
    00087 }

const std::vector< std::string > System::getEnv | ( |  | ) |

get all environment variables

get all defined environment vars

Definition at line 673 of file System.cpp.

    00673                                           {
    00674 #if defined(_WIN32)
    00675 #  define environ _environ
    00676 #elif defined(__APPLE__)
    00677   static char **environ = *_NSGetEnviron();
    00678 #endif
    00679   std::vector<std::string> vars;
    00680   for (int i=0; environ[i] != 0; ++i) {
    00681     vars.push_back(environ[i]);
    00682   }
    00683   return vars;
    00684 }

const std::string System::getEnv | ( | const char * | var | ) |

get a particular environment variable

get a particular env var, return "UNKNOWN" if not defined

Definition at line 659 of file System.cpp.

    00659                                               {
    00660   char* env;
    00661   if  ( (env = getenv(var)) != 0 ) {
    00662     return env;
    00663   } else {
    00664     return "UNKNOWN";
    00665   }
    00666 }

const std::string System::getErrorString | ( | unsigned long | error | ) |

Retrieve error code as string for a given error.

Definition at line 253 of file System.cpp.

    00253                                                              {
    00254   std::string errString =  "";
    00255 #ifdef _WIN32
    00256   LPVOID lpMessageBuffer;
    00257   ::FormatMessage(
    00258     FORMAT_MESSAGE_ALLOCATE_BUFFER |  FORMAT_MESSAGE_FROM_SYSTEM,
    00259     NULL,
    00260     error,
    00261     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //The user default language
    00262     (LPTSTR) &lpMessageBuffer,
    00263     0,
    00264     NULL );
    00265   errString = (const char*)lpMessageBuffer;
    00266   // Free the buffer allocated by the system
    00267   ::LocalFree( lpMessageBuffer );
    00268 #else
    00269   char *cerrString(0);
    00270   // Remember: for linux dl* routines must be handled differently!
    00271   if ( error == 0xAFFEDEAD ) {
    00272     cerrString = (char*)::dlerror();
    00273     if ( 0 == cerrString ) {
    00274       cerrString = ::strerror(error);
    00275     }
    00276     if ( 0 == cerrString ) {
    00277       cerrString = (char *)"Unknown error. No information found in strerror()!";
    00278     }
    00279     else {
    00280       errString = std::string(cerrString);
    00281     }
    00282     errno = 0;
    00283   }
    00284   else    {
    00285     cerrString = ::strerror(error);
    00286     errString = std::string(cerrString);
    00287   }
    00288 #endif
    00289   return errString;
    00290 }

unsigned long System::getLastError | ( |  | ) |

Get last system known error.

Retrieve last error code.

Definition at line 237 of file System.cpp.

    00237                                       {
    00238 #ifdef _WIN32
    00239   return ::GetLastError();
    00240 #else
    00241   // convert errno (int) to unsigned long
    00242   return static_cast<unsigned long>(static_cast<unsigned int>(errno));
    00243 #endif
    00244 }

const std::string System::getLastErrorString | ( |  | ) |

Get last system error as string.

Retrieve last error code as string.

Definition at line 247 of file System.cpp.

    00247                                               {
    00248   const std::string errString = getErrorString(getLastError());
    00249   return errString;
    00250 }

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

Get a specific function defined in the DLL.

Definition at line 232 of file System.cpp.

    00232                                                                                                          {
    00233   return getProcedureByName(handle, name, (EntryPoint*)pFunction);
    00234 }

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

Get a specific function defined in the DLL.

Definition at line 182 of file System.cpp.

    00182                                                                                                             {
    00183 #ifdef _WIN32
    00184   *pFunction = (EntryPoint)::GetProcAddress((HINSTANCE)handle, name.data());
    00185   if ( 0 == *pFunction )    {
    00186     return System::getLastError();
    00187   }
    00188   return 1;
    00189 #elif defined(linux)
    00190 #if __GNUC__ < 4
    00191   *pFunction = (EntryPoint)::dlsym(handle, name.c_str());
    00192 #else
    00193   *pFunction = FuncPtrCast<EntryPoint>(::dlsym(handle, name.c_str()));
    00194 #endif
    00195   if ( 0 == *pFunction )    {
    00196     errno = 0xAFFEDEAD;
    00197    // std::cout << "System::getProcedureByName>" << getLastErrorString() << std::endl;
    00198     return 0;
    00199   }
    00200   return 1;
    00201 #elif defined(__APPLE__)
    00202   *pFunction = (EntryPoint)::dlsym(handle, name.c_str());
    00203   if(!(*pFunction)) {
    00204     // Try with an underscore :
    00205     std::string sname = "_" + name;
    00206     *pFunction = (EntryPoint)::dlsym(handle, sname.c_str());
    00207   }
    00208   if ( 0 == *pFunction )    {
    00209     errno = 0xAFFEDEAD;
    00210     std::cout << "System::getProcedureByName>" << getLastErrorString() << std::endl;
    00211     //std::cout << "System::getProcedureByName> failure" << std::endl;
    00212     return 0;
    00213   }
    00214   return 1;
    00215 #elif __hpux
    00216   HMODULE* mod = (HMODULE*)handle;
    00217   if ( 0 != mod ) {
    00218     long ll1 = name.length();
    00219     for ( int i = 0; i < mod->numSym; i++ ) {
    00220       long ll2 = strlen(mod->sym[i].name);
    00221       if ( 0 != ::strncmp(mod->sym[i].name, name.c_str(), (ll1>ll2) ? ll1 : ll2)==0 ) {
    00222               *pFunction = (EntryPoint) mod->sym[i].value;
    00223               return 1;
    00224       }
    00225     }
    00226   }
    00227   return 0;
    00228 #endif
    00229 }

ProcessDescriptor * System::getProcess | ( |  | ) |

Retrieve Process structure.

Definition at line 213 of file ProcessDescriptor.cpp.

    00213                                               {
    00214   static ProcessDescriptor p;
    00215 #ifdef _WIN32
    00216   static bool first = true;
    00217   if ( first )    {
    00218     first = false;
    00219     void* mh = ::LoadLibrary("NTDll.dll");
    00220     if ( mh )  {
    00221       NtApi::NtQueryInformationProcess = (NtApi::__NtQueryInformationProcess)
    00222         ::GetProcAddress((HINSTANCE)mh, "NtQueryInformationProcess");
    00223     }
    00224   }
    00225 #endif
    00226   return &p;
    00227 }

bool System::getStackLevel | ( | void *addresses | __attribute__(unused),
|  | void *&addr | __attribute__(unused),
|  | std::string &fnc | __attribute__(unused),
|  | std::string &lib | __attribute__(unused) |
| ) |  |  |

Definition at line 743 of file System.cpp.

    00747 {
    00748
    00749 #ifdef __linux
    00750
    00751   Dl_info info;
    00752
    00753   if ( dladdr( addresses, &info ) && info.dli_fname
    00754       && info.dli_fname[0] != '\0' ) {
    00755     const char* symbol = info.dli_sname
    00756     && info.dli_sname[0] != '\0' ? info.dli_sname : 0;
    00757
    00758     lib = info.dli_fname;
    00759     addr = info.dli_saddr;
    00760     const char* dmg(0);
    00761
    00762     if (symbol != 0) {
    00763       int stat;
    00764       dmg = abi::__cxa_demangle(symbol,0,0,&stat);
    00765       fnc = (stat == 0) ? dmg : symbol;
    00766     } else {
    00767       fnc = "local";
    00768     }
    00769     free((void*)dmg);
    00770     return true ;
    00771   } else {
    00772     return false ;
    00773   }
    00774
    00775 #else // not implemented for windows and osx
    00776   return false ;
    00777 #endif
    00778
    00779 }

GAUDI_API bool System::getStackLevel | ( | void * | addresses,
|  | void *& | addr,
|  | std::string & | fnc,
|  | std::string & | lib |
| ) |  |  |

std::string System::homeDirectory | ( |  | ) |

Definition at line 58 of file Environment.cpp.

    00058                                  {
    00059    // Return the user's home directory.
    00060   std::string home_dir = "./";
    00061   const char *h = 0;
    00062   if ( 0 == (h = ::getenv("home")))  {
    00063     h = ::getenv("HOME");
    00064   }
    00065   if ( h ) {
    00066     home_dir = h;
    00067   }
    00068   else {
    00069     // for Windows NT HOME might be defined as either $(HOMESHARE)/$(HOMEPATH)
    00070     //                                         or     $(HOMEDRIVE)/$(HOMEPATH)
    00071     h = ::getenv("HOMESHARE");
    00072     if ( 0 == h )  {
    00073       h = ::getenv("HOMEDRIVE");
    00074     }
    00075     if (h) {
    00076       home_dir = h;
    00077       h = ::getenv("HOMEPATH");
    00078       if( h )  {
    00079         home_dir += h;
    00080       }
    00081     }
    00082   }
    00083   return home_dir;
    00084 }

const std::string & System::hostName | ( |  | ) |

Host name.

Definition at line 489 of file System.cpp.

    00489                                   {
    00490   static std::string host = "";
    00491   if ( host == "" ) {
    00492     char buffer[512];
    00493     memset(buffer,0,sizeof(buffer));
    00494 #ifdef _WIN32
    00495     unsigned long len = sizeof(buffer);
    00496     ::GetComputerName(buffer, &len);
    00497 #else
    00498     ::gethostname(buffer, sizeof(buffer));
    00499 #endif
    00500     host = buffer;
    00501   }
    00502   return host;
    00503 }

longlong System::kernelTime | ( | TimeType | typ = `milliSec`,
|  | InfoType | fetch = `Times`,
|  | long | pid = `-1` |
| ) |  |  |

CPU kernel mode time of process in milli seconds.

CPU kernel time of process in milli seconds.

Parameters:

  | typ | Indicator or the unit the time will be returned.
  | fetch | Indicator of the information to be fetched. If Fetch_None, the information will not be updated.
  | pid | Process ID of which the information will be returned

Returns:
  Requested value in the indicated units.

Definition at line 150 of file Timing.cpp.

    00150                                                                   {
    00151   KERNEL_USER_TIMES info;
    00152   longlong kerneltime = 0;
    00153   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )   {
    00154     kerneltime = adjustTime(typ, info.KernelTime );
    00155   }
    00156   return kerneltime;
    00157 }

const std::vector< std::string > System::linkedModules | ( |  | ) |

Vector of names of linked modules.

Definition at line 225 of file ModuleInfo.cpp.

    00225                                                     {
    00226   if ( s_linkedModules.size() == 0 )    {
    00227 #ifdef _WIN32
    00228     char   name[255];  // Maximum file name length on NT 4.0
    00229     DWORD  cbNeeded;
    00230     HINSTANCE handle[1024];
    00231     if ( _psApi.isValid() )    {
    00232       if ( _psApi.EnumProcessModules(processHandle(),handle,sizeof(handle),&cbNeeded) )   {
    00233         for (size_t i = 0; i < cbNeeded/sizeof(HANDLE); i++ )    {
    00234           if ( 0 < _psApi.GetModuleFileNameExA( processHandle(), handle[i], name, sizeof(name)) )   {
    00235             s_linkedModules.push_back(name);
    00236           }
    00237         }
    00238       }
    00239     }
    00240 #elif defined(linux) || defined(__APPLE__)
    00241     char ff[512], cmd[1024], fname[1024], buf1[64], buf2[64], buf3[64], buf4[64];
    00242     ::sprintf(ff, "/proc/%d/maps", ::getpid());
    00243     FILE* maps = ::fopen(ff, "r");
    00244     while( ::fgets(cmd, sizeof(cmd), maps) ) {
    00245       int len;
    00246       sscanf(cmd, "%s %s %s %s %d %s", buf1, buf2, buf3, buf4, &len, fname);
    00247       if ( len > 0 && strncmp(buf2,"r-xp",strlen("r-xp")) == 0 ) {
    00248         s_linkedModules.push_back(fname);
    00249       }
    00250     }
    00251     ::fclose(maps);
    00252 #endif
    00253   }
    00254   return s_linkedModules;
    00255 }

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

Load dynamic link library.

Definition at line 123 of file System.cpp.

    00123                                                                                {
    00124   unsigned long res;
    00125   // if name is empty, just load it
    00126   if (name.length() == 0) {
    00127     res = loadWithoutEnvironment(name, handle);
    00128   } else {
    00129     // If the name is a logical name (environment variable), the try
    00130     // to load the corresponding library from there.
    00131     std::string env = name;
    00132     if ( 0 != ::getenv(env.c_str()) )    {
    00133       std::string imgName = ::getenv(env.c_str());
    00134       res = loadWithoutEnvironment(imgName, handle);
    00135     } else {
    00136       // build the dll name
    00137       std::string dllName = name;
    00138 #if defined(linux) || defined(__APPLE__)
    00139       dllName = "lib" + dllName;
    00140 #endif
    00141       dllName += SHLIB_SUFFIX;
    00142       // try to locate the dll using the standard PATH
    00143       res = loadWithoutEnvironment(dllName, handle);
    00144     }
    00145     if ( res != 1 ) {
    00146 #if defined(linux) || defined(__APPLE__)
    00147       errno = 0xAFFEDEAD;
    00148 #endif
    00149      // std::cout << "System::loadDynamicLib>" << getLastErrorString() << std::endl;
    00150     }
    00151   }
    00152   return res;
    00153 }

const std::string & System::machineType | ( |  | ) |

Machine type.

Definition at line 544 of file System.cpp.

    00544                                      {
    00545   static std::string mach = "";
    00546 #ifdef _WIN32
    00547   SYSTEM_INFO ut;
    00548   ::GetSystemInfo(&ut);
    00549   char arch[64];
    00550   sprintf(arch,"%d",ut.wProcessorArchitecture);
    00551   mach =  arch;
    00552 #else
    00553   struct utsname ut;
    00554   if (uname(&ut) == 0) {
    00555     mach = ut.machine;
    00556   } else {
    00557     mach = "UNKNOWN";
    00558   }
    00559 #endif
    00560   return mach;
    00561 }

long System::mappedMemory | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: priority boost.

Definition at line 181 of file Memory.cpp.

    00181                                                                      {
    00182   VM_COUNTERS info;
    00183   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00184     return adjustMemory(unit, info.WorkingSetSize);
    00185   return -2;
    00186 }

long System::mappedMemoryPeak | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: priority boost.

Definition at line 189 of file Memory.cpp.

    00189                                                                          {
    00190   VM_COUNTERS info;
    00191   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00192     return adjustMemory(unit, info.PeakWorkingSetSize);
    00193   return -2;
    00194 }

long System::maxMemoryLimit | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Quota`,
|  | long | pid = `-1` |
| ) |  |  |

System Process Limits: Maximum amount of virtual memory this process is allowed to use.

Definition at line 205 of file Memory.cpp.

    00205                                                                        {
    00206   QUOTA_LIMITS quota;
    00207   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
    00208     return adjustMemory(unit, quota.MaximumWorkingSetSize);
    00209   return 0;
    00210 }

long System::minMemoryLimit | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Quota`,
|  | long | pid = `-1` |
| ) |  |  |

System Process Limits: Minimum amount of virtual memory this process may use.

Definition at line 197 of file Memory.cpp.

    00197                                                                        {
    00198   QUOTA_LIMITS quota;
    00199   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
    00200     return adjustMemory(unit, quota.MinimumWorkingSetSize);
    00201   return 0;
    00202 }

System::ImageHandle System::moduleHandle | ( |  | ) |

Handle to currently executed module.

Definition at line 136 of file ModuleInfo.cpp.

    00136                                           {
    00137   if ( 0 == ModuleHandle )    {
    00138     if ( processHandle() )    {
    00139 #ifdef _WIN32
    00140       static HINSTANCE handle = 0;
    00141       DWORD   cbNeeded;
    00142       if ( 0 == handle && _psApi.isValid() )    {
    00143         if ( _psApi.EnumProcessModules( processHandle(), &handle, sizeof(ModuleHandle), &cbNeeded) )   {
    00144         }
    00145       }
    00146       return handle;
    00147 #elif defined(linux) || defined(__APPLE__)
    00148       static Dl_info info;
    00149       if ( 0 !=
    00150            ::dladdr(
    00151 #if __GNUC__ < 4
    00152                (void*)System::moduleHandle
    00153 #else
    00154                FuncPtrCast<void*>(System::moduleHandle)
    00155 #endif
    00156                , &info) ) {
    00157         return &info;
    00158       }
    00159 #elif __hpux
    00160       return 0;  // Don't know how to solve this .....
    00161 #endif
    00162     }
    00163   }
    00164   return ModuleHandle;
    00165 }

const std::string & System::moduleName | ( |  | ) |

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

Retrieve base name of module.

Definition at line 55 of file ModuleInfo.cpp.

    00055                                       {
    00056   static std::string module("");
    00057   if ( module == "" )   {
    00058     if ( processHandle() && moduleHandle() )    {
    00059 #ifdef _WIN32
    00060       char moduleName[256] = {"Unknown.module"};
    00061       moduleName[0] = 0;
    00062       if ( _psApi.isValid() )   {
    00063         _psApi.GetModuleBaseNameA( processHandle(), (HINSTANCE)moduleHandle(), moduleName, sizeof(moduleName) );
    00064       }
    00065       std::string mod = moduleName;
    00066 #elif defined(linux) || defined(__APPLE__)
    00067       std::string mod = ::basename((char*)((Dl_info*)moduleHandle())->dli_fname);
    00068 #elif __hpux
    00069       std::string mod = ::basename(((HMODULE*)moduleHandle())->dsc.filename);
    00070 #endif
    00071       module = mod.substr(0, mod.rfind('.'));
    00072     }
    00073   }
    00074   return module;
    00075 }

const std::string & System::moduleNameFull | ( |  | ) |

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

Retrieve full name of module.

Definition at line 78 of file ModuleInfo.cpp.

    00078                                           {
    00079   static std::string module("");
    00080   if ( module == "" )   {
    00081     if ( processHandle() && moduleHandle() )    {
    00082       char name[PATH_MAX] = {"Unknown.module"};
    00083       name[0] = 0;
    00084 #ifdef _WIN32
    00085       if ( _psApi.isValid() )   {
    00086         _psApi.GetModuleFileNameExA( processHandle(), (HINSTANCE)moduleHandle(), name,sizeof(name) );
    00087       }
    00088 #elif defined(linux) || defined(__APPLE__)
    00089       ::realpath(((Dl_info*)moduleHandle())->dli_fname, name);
    00090 #elif __hpux
    00091       ::realpath(((HMODULE*)moduleHandle())->dsc.filename, name);
    00092 #endif
    00093       module = name;
    00094     }
    00095   }
    00096   return module;
    00097 }

System::ModuleType System::moduleType | ( |  | ) |

Get type of the module.

Definition at line 100 of file ModuleInfo.cpp.

    00100                                       {
    00101   static ModuleType type = UNKNOWN;
    00102   if ( type == UNKNOWN )    {
    00103     const std::string& module = moduleNameFull();
    00104     int loc = module.rfind('.')+1;
    00105     if ( loc == 0 )
    00106       type = EXECUTABLE;
    00107     else if ( module[loc] == 'e' || module[loc] == 'E' )
    00108       type = EXECUTABLE;
    00109 #ifdef _WIN32
    00110     else if ( module[loc] == 'd' || module[loc] == 'D' )
    00111 #else
    00112     else if ( module[loc] == 's' && module[loc+1] == 'o' )
    00113 #endif
    00114       type = SHAREDLIB;
    00115     else
    00116       type = UNKNOWN;
    00117   }
    00118   return type;
    00119 }

long System::nonPagedMemory | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Current usage of non paged memory.

Basic Process Information: priority boost.

Definition at line 106 of file Memory.cpp.

    00106                                                                        {
    00107   VM_COUNTERS info;
    00108   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00109     return adjustMemory(unit, info.QuotaNonPagedPoolUsage);
    00110   return -2;
    00111 }

long System::nonPagedMemoryLimit | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Quota`,
|  | long | pid = `-1` |
| ) |  |  |

System Process Limits: Maximum amount of non-paged memory this process is allowed to use.

Definition at line 114 of file Memory.cpp.

    00114                                                                             {
    00115   POOLED_USAGE_AND_LIMITS quota;
    00116   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
    00117     return adjustMemory(unit, quota.NonPagedPoolLimit);
    00118   return 0;
    00119 }

long System::nonPagedMemoryPeak | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Peak usage of non paged memory.

Basic Process Information: priority boost.

Definition at line 98 of file Memory.cpp.

    00098                                                                            {
    00099   VM_COUNTERS info;
    00100   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00101     return adjustMemory(unit, info.QuotaPeakNonPagedPoolUsage);
    00102   return -2;
    00103 }

long System::numCmdLineArgs | ( |  | ) |

Number of arguments passed to the commandline.

Definition at line 583 of file System.cpp.

    00583                               {
    00584   return cmdLineArgs().size();
    00585 }

long System::numPageFault | ( | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Number of page faults.

Basic Process Information: priority boost.

Definition at line 146 of file Memory.cpp.

    00146                                                     {
    00147   VM_COUNTERS info;
    00148   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00149     return info.PageFaultCount;
    00150   return -2;
    00151 }

const std::string & System::osName | ( |  | ) |

OS name.

Definition at line 506 of file System.cpp.

    00506                                 {
    00507   static std::string osname = "";
    00508 #ifdef _WIN32
    00509   osname = "Windows";
    00510 #else
    00511   struct utsname ut;
    00512   if (uname(&ut) == 0) {
    00513     osname = ut.sysname;
    00514   } else {
    00515     osname = "UNKNOWN";
    00516   }
    00517 #endif
    00518   return osname;
    00519 }

const std::string & System::osVersion | ( |  | ) |

OS version.

Definition at line 523 of file System.cpp.

    00523                                    {
    00524   static std::string osver = "";
    00525 #ifdef _WIN32
    00526   OSVERSIONINFO ut;
    00527   ut.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    00528   ::GetVersionEx(&ut);
    00529   char ver[64];
    00530   sprintf(ver,"%d.%d",ut.dwMajorVersion,ut.dwMinorVersion);
    00531   osver = ver;
    00532 #else
    00533   struct utsname ut;
    00534   if (uname(&ut) == 0) {
    00535     osver = ut.release;
    00536   } else {
    00537     osver = "UNKNOWN";
    00538   }
    00539 #endif
    00540   return osver;
    00541 }

long System::pagedMemory | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Amount of paged memory currently occupied by the process 'pid'.

Definition at line 122 of file Memory.cpp.

    00122                                                                     {
    00123   VM_COUNTERS info;
    00124   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00125     return adjustMemory(unit, info.QuotaPagedPoolUsage);
    00126   return -2;
    00127 }

long System::pagedMemoryLimit | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Quota`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Amount of paged memory that can be occupied by the process 'pid'.

Definition at line 138 of file Memory.cpp.

    00138                                                                          {
    00139   POOLED_USAGE_AND_LIMITS quota;
    00140   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )
    00141     return adjustMemory(unit, quota.PagedPoolLimit);
    00142   return 0;
    00143 }

long System::pagedMemoryPeak | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Maximum of paged memory occupied by the process 'pid'.

Definition at line 130 of file Memory.cpp.

    00130                                                                         {
    00131   VM_COUNTERS info;
    00132   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00133     return adjustMemory(unit, info.QuotaPeakPagedPoolUsage);
    00134   return -2;
    00135 }

long System::pagefileUsage | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Current page file usage.

Basic Process Information: priority boost.

Definition at line 154 of file Memory.cpp.

    00154                                                                       {
    00155   VM_COUNTERS info;
    00156   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00157     return adjustMemory(unit, info.PagefileUsage);
    00158   return -2;
    00159 }

long System::pagefileUsageLimit | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Quota`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Peak usage of page file.

Basic Process Information: priority boost.

Definition at line 170 of file Memory.cpp.

    00170                                                                            {
    00171   POOLED_USAGE_AND_LIMITS quota;
    00172   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )    {
    00173     if ( long(quota.PagefileLimit) < 0 )
    00174       return -1;//LONG_MAX;
    00175     return adjustMemory(unit, quota.PagefileLimit);
    00176   }
    00177   return -2;
    00178 }

long System::pagefileUsagePeak | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Peak usage of page file.

Basic Process Information: priority boost.

Definition at line 162 of file Memory.cpp.

    00162                                                                           {
    00163   VM_COUNTERS info;
    00164   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00165     return adjustMemory(unit, info.PeakPagefileUsage);
    00166   return -2;
    00167 }

long System::parentID | ( | InfoType | fetch = `ProcessBasics`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: Parent's process ID.

Definition at line 66 of file Memory.cpp.

    00066                                                 {
    00067   PROCESS_BASIC_INFORMATION info;
    00068   if ( fetch != NoFetch && getProcess()->query(pid, ProcessBasics, &info) )
    00069     return info.InheritedFromUniqueProcessId;
    00070   return 0;
    00071 }

PathResolver::SearchPathStatus System::PathResolverCheckSearchPath | ( | const std::string & | search_path | ) |

Definition at line 597 of file PathResolver.cpp.

    00598 {
    00599   return PathResolver::check_search_path (search_path);
    00600 }

std::string System::PathResolverFindDataFile | ( | const std::string & | logical_file_name | ) |

Definition at line 631 of file PathResolver.cpp.

    00632 {
    00633   return PathResolver::find_file (logical_file_name, "DATAPATH");
    00634 }

std::string System::PathResolverFindDirectory | ( | const std::string & | logical_file_name,
|  | const std::string & | search_path |
| ) |  |  |

Definition at line 602 of file PathResolver.cpp.

    00604 {
    00605   return PathResolver::find_directory (logical_file_name, search_path);
    00606 }

std::string System::PathResolverFindDirectoryFromList | ( | const std::string & | logical_file_name,
|  | const std::string & | search_list |
| ) |  |  |

Definition at line 608 of file PathResolver.cpp.

    00610 {
    00611   return PathResolver::find_directory_from_list (logical_file_name, search_list);
    00612 }

std::string System::PathResolverFindFile | ( | const std::string & | logical_file_name,
|  | const std::string & | search_path |
| ) |  |  |

Definition at line 614 of file PathResolver.cpp.

    00616 {
    00617   return PathResolver::find_file (logical_file_name, search_path);
    00618 }

std::string System::PathResolverFindFileFromList | ( | const std::string & | logical_file_name,
|  | const std::string & | search_list |
| ) |  |  |

Definition at line 620 of file PathResolver.cpp.

    00622 {
    00623   return PathResolver::find_file_from_list (logical_file_name, search_list);
    00624 }

std::string System::PathResolverFindXMLFile | ( | const std::string & | logical_file_name | ) |

Definition at line 626 of file PathResolver.cpp.

    00627 {
    00628   return PathResolver::find_file (logical_file_name, "XMLPATH");
    00629 }

static bool System::PR_absolute_path | ( | const std::string & | name | ) | `[static]`

Definition at line 116 of file PathResolver.cpp.

    00117 {
    00118   if (name.size () == 0) return (false);
    00119
    00120   if ((name[0] == '/') ||
    00121       (name[0] == '\\')) return (true);
    00122
    00123   if (name.size () >= 2)
    00124     {
    00125       if (name[1] == ':')
    00126         {
    00127           return (true);
    00128         }
    00129     }
    00130   return (false);
    00131 }

static void System::PR_basename | ( | const std::string & | file_name,
|  | std::string & | result |
| ) |  |  | `[static]`

Definition at line 133 of file PathResolver.cpp.

    00134 {
    00135   std::string::size_type pos = file_name.find_last_of ('/');
    00136
    00137   if (pos == std::string::npos)
    00138     {
    00139       pos = file_name.find_last_of ('\\');
    00140     }
    00141
    00142   if (pos == std::string::npos)
    00143     {
    00144       result = file_name;
    00145     }
    00146   else
    00147     {
    00148       result = file_name.substr (pos + 1);
    00149     }
    00150 }

static void System::PR_compress_path | ( | std::string & | dir | ) | `[static]`

Definition at line 34 of file PathResolver.cpp.

    00035 {
    00036 #ifdef _WIN32
    00037   static const char pattern[] = "\\..\\";
    00038 #else
    00039   static const char pattern[] = "/../";
    00040 #endif
    00041
    00042 #ifdef _WIN32
    00043   static const char file_separator = '\\';
    00044   static const char double_file_separator[] = "\\\\";
    00045 #else
    00046   static const char file_separator = '/';
    00047   static const char double_file_separator[] = "//";
    00048 #endif
    00049
    00050   if (dir.size () == 0) return;
    00051
    00052     //
    00053     // We first synchronize to using file_separator() in any case.
    00054     //
    00055
    00056   for (;;)
    00057     {
    00058       std::string::size_type pos;
    00059       pos = dir.find (double_file_separator);
    00060       if (pos == std::string::npos) break;
    00061       dir.erase (pos, 1);
    00062     }
    00063
    00064   for (;;)
    00065     {
    00066       std::string::size_type pos1;
    00067       std::string::size_type pos2;
    00068
    00069       pos1 = dir.find (pattern);
    00070       if (pos1 == std::string::npos) break;
    00071
    00072         //
    00073         // extract "aaaa/xxxx" from "aaaa/xxxx/../bbbb"
    00074         //
    00075       std::string p = dir.substr (0, pos1);
    00076
    00077         //
    00078         // Is "aaaa/xxxx" only made of "xxxx" ?
    00079         //
    00080       pos2 = p.find_last_of (file_separator);
    00081
    00082       if (pos2 == std::string::npos) break;
    00083
    00084         //    01234567890123456
    00085         //    aaaa/xxxx/../bbbb
    00086         //        2    1   3
    00087         //
    00088         // erase the "/xxxx/../" pattern
    00089         // result will be "aaaa/bbbb"
    00090         //
    00091       dir.erase (pos2, pos1 + 4 - pos2 - 1);
    00092     }
    00093
    00094     //if (dir[dir.size () - 1] == file_separator ()) dir.erase (dir.size () - 1);
    00095 }

static void System::PR_dirname | ( | const std::string & | file_name,
|  | std::string & | result |
| ) |  |  | `[static]`

Definition at line 97 of file PathResolver.cpp.

    00098 {
    00099   std::string::size_type pos = file_name.find_last_of ('/');
    00100   if (pos == std::string::npos)
    00101     {
    00102       pos = file_name.find_last_of ('\\');
    00103     }
    00104
    00105   if (pos == std::string::npos)
    00106     {
    00107       result = "";
    00108     }
    00109   else
    00110     {
    00111       result = file_name;
    00112       result.erase (pos);
    00113     }
    00114 }

static bool System::PR_find | ( | const std::string & | search_base,
|  | const std::string & | logical_file_prefix,
|  | const std::string & | logical_file_name,
|  | PR_file_type | file_type,
|  | PathResolver::SearchType | search_type,
|  | std::string & | result |
| ) |  |  | `[static]`

Definition at line 321 of file PathResolver.cpp.

    00327 {
    00328   static int level = 0;
    00329
    00330 #ifdef _WIN32
    00331   static const char file_separator = '\\';
    00332 #else
    00333   static const char file_separator = '/';
    00334 #endif
    00335
    00336   std::string file_path = "";
    00337   std::string real_name = "";
    00338
    00339   //PR_indent (level); std::cout << "PR_find> sb=" << search_base << " lfp=" << logical_file_prefix << " lfn=" << logical_file_name << std::endl;
    00340
    00341   if (search_base != "")
    00342     {
    00343       file_path = search_base;
    00344       file_path += file_separator;
    00345     }
    00346   else
    00347     {
    00348       file_path = "";
    00349     }
    00350
    00351   file_path += logical_file_name;
    00352
    00353   //PR_indent (level); std::cout << "PR_find> test1 file_path=" << file_path << std::endl;
    00354
    00355   result = file_path;
    00356   bool found = PR_test_exist (file_path, result, file_type);
    00357
    00358   if (!found && (logical_file_prefix != ""))
    00359     {
    00360       if (search_base != "")
    00361         {
    00362           file_path = search_base;
    00363           file_path += file_separator;
    00364         }
    00365       else
    00366         {
    00367           file_path = "";
    00368         }
    00369
    00370       file_path += logical_file_prefix;
    00371       file_path += file_separator;
    00372       file_path += logical_file_name;
    00373
    00374       //PR_indent (level); std::cout << "PR_find> test2 file_path=" << file_path << std::endl;
    00375
    00376       result = file_path;
    00377       found = PR_test_exist (file_path, result, file_type);
    00378     }
    00379
    00380   //PR_indent (level); std::cout << "PR_find> test3 found=" << found << " search_type=" << search_type << std::endl;
    00381
    00382   if (!found && (search_type == PathResolver::RecursiveSearch))
    00383     {
    00384       std::string dir_name = "";
    00385       std::string file_name = "";
    00386       std::vector<std::string> list;
    00387
    00388       PR_scan_dir (search_base, list);
    00389
    00390       std::vector<std::string>::iterator it;
    00391
    00392       for (it = list.begin (); it != list.end (); ++it)
    00393         {
    00394           const std::string& d = *it;
    00395
    00396           if (PR_test_exist (d, file_path, PR_directory))
    00397             {
    00398               //PR_indent (level); std::cout << "d=" << d << std::endl;
    00399
    00400               level++;
    00401               bool s = PR_find (d, logical_file_prefix, logical_file_name, file_type, search_type, result);
    00402               level--;
    00403
    00404               if (s)
    00405                 {
    00406                   //PR_indent (level); std::cout << "PR_find> result=" << result << std::endl;
    00407                   found = true;
    00408                   break;
    00409                 }
    00410             }
    00411         }
    00412     }
    00413
    00414   return (found);
    00415 }

static bool System::PR_find_from_list | ( | const std::string & | logical_file_name,
|  | const std::string & | search_list,
|  | PR_file_type | file_type,
|  | PathResolver::SearchType | search_type,
|  | std::string & | result |
| ) |  |  | `[static]`

Definition at line 417 of file PathResolver.cpp.

    00422 {
    00423 #ifdef _WIN32
    00424   static const char path_separator = ';';
    00425 #else
    00426   static const char path_separator = ':';
    00427 #endif
    00428
    00429   std::string::size_type pos = 0;
    00430
    00431   std::string file_name = "";
    00432   std::string file_prefix = "";
    00433
    00434   PR_basename (logical_file_name, file_name);
    00435   PR_dirname (logical_file_name, file_prefix);
    00436
    00437   //consider relative paths to be part of file_name
    00438   if (!file_prefix.empty() && file_prefix[0]!='/') {
    00439     file_name = file_prefix + '/' + file_name;
    00440     file_prefix="";
    00441   }
    00442
    00443   std::string real_name = "";
    00444
    00445   bool found = false;
    00446
    00447   if (PR_find ("", file_prefix, file_name, file_type, search_type, result))
    00448     {
    00449       found = true;
    00450     }
    00451
    00452   if (!found)
    00453     {
    00454       for (int i = 0;;i++)
    00455         {
    00456           bool ending = false;
    00457
    00458           std::string::size_type next = search_list.find (path_separator, pos);
    00459
    00460           std::string path = search_list.substr (pos, next - pos);
    00461
    00462           if (next == std::string::npos)
    00463             {
    00464               path = search_list.substr (pos);
    00465               ending = true;
    00466             }
    00467           else
    00468             {
    00469               path = search_list.substr (pos, next - pos);
    00470               pos = next + 1;
    00471             }
    00472
    00473           //std::cout << "path[" << i << "]=" << path << std::endl;
    00474
    00475           if (PR_find (path, file_prefix, file_name, file_type, search_type, result))
    00476             {
    00477               found = true;
    00478               break;
    00479             }
    00480
    00481           if (ending) break;
    00482         }
    00483     }
    00484
    00485   return (found);
    00486 }

static void System::PR_scan_dir | ( | const std::string & | dir_name,
|  | std::vector< std::string > & | list |
| ) |  |  | `[static]`

Definition at line 213 of file PathResolver.cpp.

    00215 {
    00216 #ifdef _WIN32
    00217   static const char file_separator = '\\';
    00218 #else
    00219   static const char file_separator = '/';
    00220 #endif
    00221
    00222   static std::string dir_prefix;
    00223   static std::string name_prefix;
    00224   static std::string real_name;
    00225
    00226   dir_prefix = dir_name;
    00227   if (dir_name == "") dir_prefix = ".";
    00228
    00229   //std::cout << "PR_scan_dir1> dir_name=" << dir_name << " dir_prefix=" << dir_prefix << std::endl;
    00230
    00231   if (!PR_test_exist (dir_prefix, real_name, PR_directory)) {
    00232     PR_dirname (dir_prefix, dir_prefix);
    00233     PR_basename (dir_name, name_prefix);
    00234   }
    00235
    00236   bool need_filter = false;
    00237
    00238   std::string::size_type wild_card;
    00239
    00240   wild_card = name_prefix.find ('*');
    00241   if (wild_card != std::string::npos) {
    00242     name_prefix.erase (wild_card);
    00243
    00244     if (name_prefix.size () > 0) {
    00245       need_filter = true;
    00246     }
    00247   }
    00248
    00249   list.clear();
    00250
    00251 #ifdef _WIN32
    00252
    00253   long dir;
    00254   struct _finddata_t entry;
    00255
    00256   static std::string search;
    00257
    00258   search = dir_prefix;
    00259   search += file_separator;
    00260   search += "*";
    00261
    00262   dir = _findfirst (search.c_str (), &entry);
    00263   if (dir > 0) {
    00264     for (;;)   {
    00265       if ((strcmp ((char*) entry.name, ".") != 0) &&
    00266           (strcmp ((char*) entry.name, "..") != 0) &&
    00267           (strncmp ((char*) entry.name, ".nfs", 4) != 0)) {
    00268         const char* name = entry.name;
    00269
    00270         if (need_filter &&
    00271           (strncmp (name, name_prefix.c_str (), name_prefix.size ()) == 0)) continue;
    00272         std::string name_entry;
    00273         name_entry = dir_prefix;
    00274         name_entry += file_separator;
    00275         name_entry += name;
    00276
    00277         list.push_back (name_entry);
    00278       }
    00279
    00280       int status = _findnext (dir, &entry);
    00281       if (status != 0) {
    00282         break;
    00283       }
    00284     }
    00285     _findclose (dir);
    00286   }
    00287 #else
    00288
    00289   DIR* dir = opendir (dir_prefix.c_str ());
    00290
    00291   struct dirent* entry;
    00292
    00293   if (dir != 0) {
    00294     while ((entry = readdir (dir)) != 0) {
    00295       //if (entry->d_name[0] == '.') continue;
    00296       if (!strcmp ((char*) entry->d_name, ".")) continue;
    00297       if (!strcmp ((char*) entry->d_name, "..")) continue;
    00298       if (!strncmp ((char*) entry->d_name, ".nfs", 4)) continue;
    00299
    00300       const char* name = entry->d_name;
    00301
    00302       //std::cout << "scan_dir4> name=" << name << std::endl;
    00303
    00304       if (need_filter &&
    00305           (strncmp (name, name_prefix.c_str (), name_prefix.size ()) != 0)) continue;
    00306
    00307       std::string name_entry;
    00308
    00309       name_entry = dir_prefix;
    00310       name_entry += file_separator;
    00311       name_entry += name;
    00312
    00313       list.push_back (name_entry);
    00314     }
    00315     closedir (dir);
    00316   }
    00317 #endif
    00318 }

static bool System::PR_test_exist | ( | const std::string & | name,
|  | std::string & | real_name,
|  | PR_file_type | file_type |
| ) |  |  | `[static]`

Definition at line 152 of file PathResolver.cpp.

    00153 {
    00154   struct stat file_stat;
    00155   int status;
    00156
    00157   char buf[1024];
    00158   strcpy (buf, name.c_str ());
    00159
    00160 #ifdef _WIN32
    00161   static const char file_separator = '\\';
    00162 #else
    00163   static const char file_separator = '/';
    00164 #endif
    00165
    00166   real_name = name;
    00167 #ifndef _WIN32
    00168   for (;;) {
    00169     status = lstat (buf, &file_stat);
    00170     if (status == 0) {
    00171           if (S_ISLNK (file_stat.st_mode) != 0) {
    00172             //std::cout << "#1 " << buf << " stat=" << std::oct << file_stat.st_mode << std::dec << std::endl;
    00173             int n = readlink (buf, buf, sizeof (buf));
    00174             if (n >= 0) buf[n] = 0;
    00175             //std::cout << "test_exist> buf=" << buf << std::endl;
    00176             if (PR_absolute_path (buf)) {
    00177           real_name = buf;
    00178         }
    00179             else {
    00180           PR_dirname (real_name, real_name);
    00181           real_name += file_separator;
    00182           real_name += buf;
    00183           PR_compress_path (real_name);
    00184           strcpy (buf, real_name.c_str ());
    00185         }
    00186             //std::cout << "#2 " << real_name << std::endl;
    00187             //break;
    00188       }
    00189       else {
    00190         break;
    00191       }
    00192     }
    00193     else {
    00194       break;
    00195     }
    00196   }
    00197 #endif
    00198   status = stat (name.c_str (), &file_stat);
    00199
    00200   if (status == 0) {
    00201     if ((file_stat.st_mode & S_IFDIR) == 0) {
    00202       return (file_type == PR_regular_file);
    00203     }
    00204     else {
    00205       return (file_type == PR_directory);
    00206     }
    00207   }
    00208   else {
    00209     return (false);
    00210   }
    00211 }

long System::priorityBoost | ( | InfoType | fetch = `PriorityBoost`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: priority boost.

Definition at line 90 of file Memory.cpp.

    00090                                                      {
    00091   long info;
    00092   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00093     return info;
    00094   return -2;
    00095 }

void * System::processHandle | ( |  | ) |

Handle to running process.

Retrieve processhandle.

Definition at line 122 of file ModuleInfo.cpp.

    00122                               {
    00123   static long pid = ::getpid();
    00124 #ifdef _WIN32
    00125   static HANDLE hP = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pid);
    00126 #else
    00127   static void* hP = (void*)pid;
    00128 #endif
    00129   return hP;
    00130 }

long System::procID | ( |  | ) |

Basic Process Information: Process ID.

Definition at line 60 of file Memory.cpp.

    00060                       {
    00061   static long s_pid = ::getpid();
    00062   return s_pid;
    00063 }

longlong System::remainingTime | ( | TimeType | typ = `milliSec`,
|  | InfoType | fetch = `Quota`,
|  | long | pid = `-1` |
| ) |  |  |

Maximum processing time left for this process.

System Process Limits: Maximum processing time left for this process.

Parameters:

  | typ | Indicator or the unit the time will be returned.
  | fetch | Indicator of the information to be fetched. If Fetch_None, the information will not be updated.
  | pid | Process ID of which the information will be returned

Returns:
  Requested value in the indicated units.

Definition at line 126 of file Timing.cpp.

    00126                                                                        {
    00127   longlong left = 0;
    00128   QUOTA_LIMITS quota;
    00129   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )   {
    00130     if ( left == -1 )     {
    00131       //left = _I64_MAX;
    00132     }
    00133     else  {
    00134       left = adjustTime(typ, quota.TimeLimit);
    00135     }
    00136   }
    00137   return left;
    00138 }

StatusCode System::resolveEnv | ( | const std::string & | var,
|  | std::string & | res,
|  | int | recusions = `124` |
| ) |  |  |

Definition at line 49 of file Environment.cpp.

    00049                                                                                    {
    00050   std::string source = var;
    00051   res = i_resolve(source, recursions);
    00052   if ( res.find("${") == std::string::npos ) {
    00053     return StatusCode::SUCCESS;
    00054   }
    00055   return StatusCode::FAILURE;
    00056 }

int System::setEnv | ( | const std::string & | name,
|  | const std::string & | value,
|  | int | overwrite = `1` |
| ) |  |  |

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 782 of file System.cpp.

    00783 {
    00784 #ifndef WIN32
    00785   // UNIX version
    00786   return value.empty() ?
    00787     // remove if set to nothing (and return success)
    00788     ::unsetenv(name.c_str()) , 0 :
    00789     // set the value
    00790     ::setenv(name.c_str(),value.c_str(), overwrite);
    00791 #else
    00792   // Windows version
    00793   if ( value.empty() ) {
    00794     // equivalent to unsetenv
    00795     return ::_putenv((name+"=").c_str());
    00796   }
    00797   else {
    00798     if ( !getenv(name.c_str()) || overwrite ) {
    00799       // set if not yet present or overwrite is set (force)
    00800       return ::_putenv((name+"="+value).c_str());
    00801     }
    00802   }
    00803   return 0; // if we get here, we are trying to set a variable already set, but
    00804             // not to overwrite.
    00805             // It is considered a success on Linux (man P setenv)
    00806 #endif
    00807
    00808 }

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

Attach module handle.

Definition at line 132 of file ModuleInfo.cpp.

    00132                                                         {
    00133   ModuleHandle = handle;
    00134 }

longlong System::systemStart | ( | TimeType | typ = `Sec` | ) |

Maximum processing time left for this process.

Units of time since system startup and begin of epoche.

Parameters:

  | typ | Indicator or the unit the time will be returned.

Returns:
  Requested value in the indicated units.

Definition at line 99 of file Timing.cpp.

    00099                                             {
    00100   static longlong sys_start = 0;
    00101   if ( 0 == sys_start )   {
    00102     longlong c = currentTime(microSec);
    00103     longlong t = tickCount();
    00104     sys_start = 10*c - t;
    00105   }
    00106   return adjustTime(typ, sys_start);
    00107 }

std::string System::tempDirectory | ( |  | ) |

Definition at line 86 of file Environment.cpp.

    00086                                   {
    00087    // Return a user configured or systemwide directory to create
    00088    // temporary files in.
    00089    const char *dir = ::getenv("TEMP");
    00090    if (!dir)   dir = ::getenv("TEMPDIR");
    00091    if (!dir)   dir = ::getenv("TEMP_DIR");
    00092    if (!dir)   dir = ::getenv("TMP");
    00093    if (!dir)   dir = ::getenv("TMPDIR");
    00094    if (!dir)   dir = ::getenv("TMP_DIR");
    00095    if (!dir) return homeDirectory();
    00096    return dir;
    00097 }

ThreadHandle System::threadSelf | ( |  | ) | `[inline]`

thread handle "accessor"

Definition at line 93 of file System.h.

    00093 { return (void*)0; }

longlong System::tickCount | ( |  | ) |

Retrieve the number of ticks since system startup.

Returns:
  Requested value in the indicated units.

Definition at line 67 of file Timing.cpp.

    00067                               {
    00068   longlong count = 10000;
    00069 #ifdef _WIN32
    00070   count *= ::GetTickCount(); // Number of milliSec since system startup
    00071 #else
    00072   struct tms buf;
    00073   count *= 10*times(&buf);
    00074 #endif
    00075   return count;
    00076 }

const std::string System::typeinfoName | ( | const char * | class_name | ) |

Definition at line 364 of file System.cpp.

    00364                                                             {
    00365   std::string result;
    00366 #ifdef _WIN32
    00367   long off = 0;
    00368   if ( ::strncmp(class_name, "class ", 6) == 0 )   {
    00369     // The returned name is prefixed with "class "
    00370     off = 6;
    00371   }
    00372   if ( ::strncmp(class_name, "struct ", 7) == 0 )   {
    00373     // The returned name is prefixed with "struct "
    00374     off = 7;
    00375   }
    00376   if ( off > 0 )    {
    00377     std::string tmp = class_name + off;
    00378     long loc = 0;
    00379     while( (loc = tmp.find("class ")) > 0 )  {
    00380       tmp.erase(loc, 6);
    00381     }
    00382     loc = 0;
    00383     while( (loc = tmp.find("struct ")) > 0 )  {
    00384       tmp.erase(loc, 7);
    00385     }
    00386     result = tmp;
    00387   }
    00388   else  {
    00389     result = class_name;
    00390   }
    00391   // Change any " *" to "*"
    00392   while ( (off=result.find(" *")) != std::string::npos ) {
    00393     result.replace(off, 2, "*");
    00394   }
    00395   // Change any " &" to "&"
    00396   while ( (off=result.find(" &")) != std::string::npos ) {
    00397     result.replace(off, 2, "&");
    00398   }
    00399
    00400 #elif defined(__linux) || defined(__APPLE__)
    00401     if ( ::strlen(class_name) == 1 ) {
    00402       // See http://www.realitydiluted.com/mirrors/reality.sgi.com/dehnert_engr/cxx/abi.pdf
    00403       // for details
    00404       switch(class_name[0]) {
    00405       case 'v':
    00406         result = "void";
    00407         break;
    00408       case 'w':
    00409         result = "wchar_t";
    00410         break;
    00411       case 'b':
    00412         result = "bool";
    00413         break;
    00414       case 'c':
    00415         result = "char";
    00416         break;
    00417       case 'a':
    00418         result = "signed char";
    00419         break;
    00420       case 'h':
    00421         result = "unsigned char";
    00422         break;
    00423       case 's':
    00424         result = "short";
    00425         break;
    00426       case 't':
    00427         result = "unsigned short";
    00428         break;
    00429       case 'i':
    00430         result = "int";
    00431         break;
    00432       case 'j':
    00433         result = "unsigned int";
    00434         break;
    00435       case 'l':
    00436         result = "long";
    00437         break;
    00438       case 'm':
    00439         result = "unsigned long";
    00440         break;
    00441       case 'x':
    00442         result = "long long";
    00443         break;
    00444       case 'y':
    00445         result = "unsigned long long";
    00446         break;
    00447       case 'n':
    00448         result = "__int128";
    00449         break;
    00450       case 'o':
    00451         result = "unsigned __int128";
    00452         break;
    00453       case 'f':
    00454         result = "float";
    00455         break;
    00456       case 'd':
    00457         result = "double";
    00458         break;
    00459       case 'e':
    00460         result = "long double";
    00461         break;
    00462       case 'g':
    00463         result = "__float128";
    00464         break;
    00465       case 'z':
    00466         result = "ellipsis";
    00467         break;
    00468       }
    00469     }
    00470     else  {
    00471       int   status;
    00472       char* realname;
    00473       realname = abi::__cxa_demangle(class_name, 0, 0, &status);
    00474       if (realname == 0) return class_name;
    00475       result = realname;
    00476       free(realname);
    00478       std::string::size_type pos = result.find(", ");
    00479       while( std::string::npos != pos ) {
    00480         result.replace( pos , 2 , "," ) ;
    00481         pos = result.find(", ");
    00482       }
    00483     }
    00484 #endif
    00485   return result;
    00486 }

const std::string System::typeinfoName | ( | const std::type_info & | tinfo | ) |

Get platform independent information about the class type.

Definition at line 361 of file System.cpp.

    00361                                                                {
    00362   return typeinfoName(tinfo.name());
    00363 }

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

unload dynamic link library

Definition at line 156 of file System.cpp.

    00156                                                             {
    00157 #ifdef _WIN32
    00158   if ( !::FreeLibrary((HINSTANCE)handle) ) {
    00159 #elif defined(linux) || defined(__APPLE__)
    00160   ::dlclose( handle );
    00161   if ( 0 ) {
    00162 #elif __hpux
    00163   // On HP we have to run finalization ourselves.....
    00164   Creator pFinalize = 0;
    00165   if ( getProcedureByName(handle, "_fini", &pFinalize) ) {
    00166     pFinalize();
    00167   }
    00168   HMODULE* mod = (HMODULE*)handle;
    00169   if ( 0 == ::shl_unload( mod->dsc.handle ) ) {
    00170     delete mod;
    00171   }
    00172   else {
    00173 #else
    00174   if (false){
    00175 #endif
    00176     return getLastError();
    00177   }
    00178   return 1;
    00179 }

longlong System::upTime | ( | TimeType | typ = `Hour` | ) |

Maximum processing time left for this process.

Units of time since system startup in requested units.

Parameters:

  | typ | Indicator or the unit the time will be returned.

Returns:
  Requested value in the indicated units.

Definition at line 110 of file Timing.cpp.

    00110                                        {
    00111   static longlong sys_start = 10*systemStart(microSec);
    00112   return adjustTime(typ, 10*currentTime(microSec)-sys_start);
    00113 }

longlong System::userTime | ( | TimeType | typ = `milliSec`,
|  | InfoType | fetch = `Times`,
|  | long | pid = `-1` |
| ) |  |  |

CPU user mode time of process in milli seconds.

CPU kernel time of process in milli seconds.

Parameters:

  | typ | Indicator or the unit the time will be returned.
  | fetch | Indicator of the information to be fetched. If Fetch_None, the information will not be updated.
  | pid | Process ID of which the information will be returned

Returns:
  Requested value in the indicated units.

Definition at line 160 of file Timing.cpp.

    00160                                                                 {
    00161   longlong usertime = 0;
    00162   KERNEL_USER_TIMES info;
    00163   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )   {
    00164     usertime = adjustTime(typ, info.UserTime );
    00165   }
    00166   return usertime;
    00167 }

long System::virtualMemory | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: priority boost.

Definition at line 213 of file Memory.cpp.

    00213                                                                       {
    00214   VM_COUNTERS info;
    00215   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00216     return adjustMemory(unit, info.VirtualSize);
    00217   return -2;
    00218 }

long System::virtualMemoryLimit | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Quota`,
|  | long | pid = `-1` |
| ) |  |  |

System Process Limits: Maximum amount of the page file this process is allowed to use.

Definition at line 229 of file Memory.cpp.

    00229                                                                            {
    00230   QUOTA_LIMITS quota;
    00231   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) )    {
    00232     if ( long(quota.PagefileLimit) == -1 )
    00233       return -1;//LONG_MAX;
    00234     return adjustMemory(unit, quota.PagefileLimit);
    00235   }
    00236   return 0;
    00237 }

long System::virtualMemoryPeak | ( | MemoryUnit | unit = `kByte`,
|  | InfoType | fetch = `Memory`,
|  | long | pid = `-1` |
| ) |  |  |

Basic Process Information: priority boost.

Definition at line 221 of file Memory.cpp.

    00221                                                                           {
    00222   VM_COUNTERS info;
    00223   if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) )
    00224     return adjustMemory(unit, info.PeakVirtualSize);
    00225   return -2;
    00226 }