#ifndef ROOT_TSystem
#define ROOT_TSystem
#ifndef __CINT__
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#ifndef WIN32
#include <unistd.h>
#endif
#endif
#ifndef ROOT_TNamed
#include "TNamed.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TInetAddress
#include "TInetAddress.h"
#endif
#ifndef ROOT_TTimer
#include "TTimer.h"
#endif
class TSeqCollection;
class TFdSet;
class TVirtualMutex;
enum EAccessMode {
kFileExists = 0,
kExecutePermission = 1,
kWritePermission = 2,
kReadPermission = 4
};
enum ELogOption {
kLogPid = 0x01,
kLogCons = 0x02
};
enum ELogLevel {
kLogEmerg = 0,
kLogAlert = 1,
kLogCrit = 2,
kLogErr = 3,
kLogWarning = 4,
kLogNotice = 5,
kLogInfo = 6,
kLogDebug = 7
};
enum ELogFacility {
kLogLocal0,
kLogLocal1,
kLogLocal2,
kLogLocal3,
kLogLocal4,
kLogLocal5,
kLogLocal6,
kLogLocal7
};
enum ESysConstants {
kMAXSIGNALS = 15,
kMAXPATHLEN = 8192,
kBUFFERSIZE = 8192,
kItimerResolution = 10
};
enum EFpeMask {
kNoneMask = 0x00,
kInvalid = 0x01,
kDivByZero = 0x02,
kOverflow = 0x04,
kUnderflow = 0x08,
kInexact = 0x10,
kDefaultMask = 0x07,
kAllMask = 0x1F
};
enum EFileModeMask {
kS_IFMT = 0170000,
kS_IFSOCK = 0140000,
kS_IFLNK = 0120000,
kS_IFOFF = 0110000,
kS_IFREG = 0100000,
kS_IFBLK = 0060000,
kS_IFDIR = 0040000,
kS_IFCHR = 0020000,
kS_IFIFO = 0010000,
kS_ISUID = 0004000,
kS_ISGID = 0002000,
kS_ISVTX = 0001000,
kS_IRWXU = 00700,
kS_IRUSR = 00400,
kS_IWUSR = 00200,
kS_IXUSR = 00100,
kS_IRWXG = 00070,
kS_IRGRP = 00040,
kS_IWGRP = 00020,
kS_IXGRP = 00010,
kS_IRWXO = 00007,
kS_IROTH = 00004,
kS_IWOTH = 00002,
kS_IXOTH = 00001
};
inline Bool_t R_ISDIR(Int_t mode) { return ((mode & kS_IFMT) == kS_IFDIR); }
inline Bool_t R_ISCHR(Int_t mode) { return ((mode & kS_IFMT) == kS_IFCHR); }
inline Bool_t R_ISBLK(Int_t mode) { return ((mode & kS_IFMT) == kS_IFBLK); }
inline Bool_t R_ISREG(Int_t mode) { return ((mode & kS_IFMT) == kS_IFREG); }
inline Bool_t R_ISLNK(Int_t mode) { return ((mode & kS_IFMT) == kS_IFLNK); }
inline Bool_t R_ISFIFO(Int_t mode) { return ((mode & kS_IFMT) == kS_IFIFO); }
inline Bool_t R_ISSOCK(Int_t mode) { return ((mode & kS_IFMT) == kS_IFSOCK); }
inline Bool_t R_ISOFF(Int_t mode) { return ((mode & kS_IFMT) == kS_IFOFF); }
struct FileStat_t {
Long_t fDev;
Long_t fIno;
Int_t fMode;
Int_t fUid;
Int_t fGid;
Long64_t fSize;
Long_t fMtime;
Bool_t fIsLink;
TString fUrl;
FileStat_t() : fDev(0), fIno(0), fMode(0), fUid(0), fGid(0), fSize(0),
fMtime(0), fIsLink(kFALSE), fUrl("") { }
};
struct UserGroup_t {
Int_t fUid;
Int_t fGid;
TString fUser;
TString fGroup;
TString fPasswd;
TString fRealName;
TString fShell;
UserGroup_t() : fUid(0), fGid(0), fUser(), fGroup(), fPasswd(),
fRealName (), fShell() { }
};
struct SysInfo_t {
TString fOS;
TString fModel;
TString fCpuType;
Int_t fCpus;
Int_t fCpuSpeed;
Int_t fBusSpeed;
Int_t fL2Cache;
Int_t fPhysRam;
SysInfo_t() : fOS(), fModel(), fCpuType(), fCpus(0), fCpuSpeed(0),
fBusSpeed(0), fL2Cache(0), fPhysRam(0) { }
virtual ~SysInfo_t() { }
ClassDef(SysInfo_t, 1);
};
struct CpuInfo_t {
Float_t fLoad1m;
Float_t fLoad5m;
Float_t fLoad15m;
Float_t fUser;
Float_t fSys;
Float_t fTotal;
Float_t fIdle;
CpuInfo_t() : fLoad1m(0), fLoad5m(0), fLoad15m(0),
fUser(0), fSys(0), fTotal(0), fIdle(0) { }
virtual ~CpuInfo_t() { }
ClassDef(CpuInfo_t, 1);
};
struct MemInfo_t {
Int_t fMemTotal;
Int_t fMemUsed;
Int_t fMemFree;
Int_t fSwapTotal;
Int_t fSwapUsed;
Int_t fSwapFree;
MemInfo_t() : fMemTotal(0), fMemUsed(0), fMemFree(0),
fSwapTotal(0), fSwapUsed(0), fSwapFree(0) { }
virtual ~MemInfo_t() { }
ClassDef(MemInfo_t, 1);
};
struct ProcInfo_t {
Float_t fCpuUser;
Float_t fCpuSys;
Long_t fMemResident;
Long_t fMemVirtual;
ProcInfo_t() : fCpuUser(0), fCpuSys(0), fMemResident(0),
fMemVirtual(0) { }
virtual ~ProcInfo_t() { }
ClassDef(ProcInfo_t, 1);
};
struct RedirectHandle_t {
TString fFile;
TString fStdOutTty;
TString fStdErrTty;
Int_t fStdOutDup;
Int_t fStdErrDup;
Int_t fReadOffSet;
RedirectHandle_t(const char *n = 0) : fFile(n), fStdOutTty(), fStdErrTty(), fStdOutDup(-1),
fStdErrDup(-1), fReadOffSet(-1) { }
void Reset() { fFile = ""; fStdOutTty = ""; fStdErrTty = "";
fStdOutDup = -1; fStdErrDup = -1; fReadOffSet = -1; }
};
#ifdef __CINT__
typedef void *Func_t;
#else
typedef void ((*Func_t)());
#endif
R__EXTERN const char *gRootDir;
R__EXTERN const char *gProgName;
R__EXTERN const char *gProgPath;
R__EXTERN TVirtualMutex *gSystemMutex;
class TProcessEventTimer : public TTimer {
public:
TProcessEventTimer(Long_t delay);
Bool_t Notify() { return kTRUE; }
Bool_t ProcessEvents();
ClassDef(TProcessEventTimer,0)
};
class TSystem : public TNamed {
public:
enum EAclicMode { kDefault, kDebug, kOpt };
enum EAclicProperties {
kFlatBuildDir = BIT(0)
};
protected:
TFdSet *fReadmask;
TFdSet *fWritemask;
TFdSet *fReadready;
TFdSet *fWriteready;
TFdSet *fSignals;
Int_t fNfd;
Int_t fMaxrfd;
Int_t fMaxwfd;
Int_t fSigcnt;
TString fWdpath;
TString fHostname;
Bool_t fInsideNotify;
Int_t fBeepFreq;
Int_t fBeepDuration;
Bool_t fInControl;
Bool_t fDone;
Int_t fLevel;
TString fLastErrorString;
TSeqCollection *fTimers;
TSeqCollection *fSignalHandler;
TSeqCollection *fFileHandler;
TSeqCollection *fStdExceptionHandler;
TSeqCollection *fOnExitList;
TString fListLibs;
TString fBuildArch;
TString fBuildCompiler;
TString fBuildCompilerVersion;
TString fBuildNode;
TString fBuildDir;
TString fFlagsDebug;
TString fFlagsOpt;
TString fListPaths;
TString fIncludePath;
TString fLinkedLibs;
TString fSoExt;
TString fObjExt;
EAclicMode fAclicMode;
TString fMakeSharedLib;
TString fMakeExe;
TString fLinkdefSuffix;
Int_t fAclicProperties;
TSeqCollection *fCompiled;
TSeqCollection *fHelpers;
TSystem *FindHelper(const char *path, void *dirptr = 0);
virtual Bool_t ConsistentWith(const char *path, void *dirptr = 0);
virtual const char *ExpandFileName(const char *fname);
virtual void SigAlarmInterruptsSyscalls(Bool_t) { }
virtual const char *GetLinkedLibraries();
virtual void DoBeep(Int_t =-1, Int_t =-1) const { printf("\a"); fflush(stdout); }
static const char *StripOffProto(const char *path, const char *proto) {
return !strncmp(path, proto, strlen(proto)) ? path + strlen(proto) : path;
}
private:
TSystem(const TSystem&);
TSystem& operator=(const TSystem&);
public:
TSystem(const char *name = "Generic", const char *title = "Generic System");
virtual ~TSystem();
virtual Bool_t Init();
virtual void SetProgname(const char *name);
virtual void SetDisplay();
void SetErrorStr(const char *errstr);
const char *GetErrorStr() const { return fLastErrorString; }
virtual const char *GetError();
void RemoveOnExit(TObject *obj);
virtual const char *HostName();
virtual void NotifyApplicationCreated();
static Int_t GetErrno();
static void ResetErrno();
void Beep(Int_t freq=-1, Int_t duration=-1, Bool_t setDefault=kFALSE);
void GetBeepDefaults(Int_t &freq, Int_t &duration) const { freq = fBeepFreq; duration = fBeepDuration; }
virtual void Run();
virtual Bool_t ProcessEvents();
virtual void DispatchOneEvent(Bool_t pendingOnly = kFALSE);
virtual void ExitLoop();
Bool_t InControl() const { return fInControl; }
virtual void InnerLoop();
virtual Int_t Select(TList *active, Long_t timeout);
virtual Int_t Select(TFileHandler *fh, Long_t timeout);
virtual void AddSignalHandler(TSignalHandler *sh);
virtual TSignalHandler *RemoveSignalHandler(TSignalHandler *sh);
virtual void ResetSignal(ESignals sig, Bool_t reset = kTRUE);
virtual void IgnoreSignal(ESignals sig, Bool_t ignore = kTRUE);
virtual void IgnoreInterrupt(Bool_t ignore = kTRUE);
virtual TSeqCollection *GetListOfSignalHandlers() const { return fSignalHandler; }
virtual void AddFileHandler(TFileHandler *fh);
virtual TFileHandler *RemoveFileHandler(TFileHandler *fh);
virtual TSeqCollection *GetListOfFileHandlers() const { return fFileHandler; }
virtual void AddStdExceptionHandler(TStdExceptionHandler *eh);
virtual TStdExceptionHandler *RemoveStdExceptionHandler(TStdExceptionHandler *eh);
virtual TSeqCollection *GetListOfStdExceptionHandlers() const { return fStdExceptionHandler; }
virtual Int_t GetFPEMask();
virtual Int_t SetFPEMask(Int_t mask = kDefaultMask);
virtual TTime Now();
virtual TSeqCollection *GetListOfTimers() const { return fTimers; }
virtual void AddTimer(TTimer *t);
virtual TTimer *RemoveTimer(TTimer *t);
virtual void ResetTimer(TTimer *) { }
virtual Long_t NextTimeOut(Bool_t mode);
virtual void Sleep(UInt_t milliSec);
virtual Int_t Exec(const char *shellcmd);
virtual FILE *OpenPipe(const char *command, const char *mode);
virtual int ClosePipe(FILE *pipe);
virtual TString GetFromPipe(const char *command);
virtual void Exit(int code, Bool_t mode = kTRUE);
virtual void Abort(int code = 0);
virtual int GetPid();
virtual void StackTrace();
virtual int MakeDirectory(const char *name);
virtual void *OpenDirectory(const char *name);
virtual void FreeDirectory(void *dirp);
virtual const char *GetDirEntry(void *dirp);
virtual void *GetDirPtr() const { return 0; }
virtual Bool_t ChangeDirectory(const char *path);
virtual const char *WorkingDirectory();
virtual const char *HomeDirectory(const char *userName = 0);
virtual int mkdir(const char *name, Bool_t recursive = kFALSE);
Bool_t cd(const char *path) { return ChangeDirectory(path); }
const char *pwd() { return WorkingDirectory(); }
virtual const char *TempDirectory() const;
virtual FILE *TempFileName(TString &base, const char *dir = 0);
virtual const char *BaseName(const char *pathname);
virtual const char *DirName(const char *pathname);
virtual char *ConcatFileName(const char *dir, const char *name);
virtual Bool_t IsAbsoluteFileName(const char *dir);
virtual Bool_t IsFileInIncludePath(const char *name, char **fullpath = 0);
virtual const char *PrependPathName(const char *dir, TString& name);
virtual Bool_t ExpandPathName(TString &path);
virtual char *ExpandPathName(const char *path);
virtual Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists);
virtual Bool_t IsPathLocal(const char *path);
virtual int CopyFile(const char *from, const char *to, Bool_t overwrite = kFALSE);
virtual int Rename(const char *from, const char *to);
virtual int Link(const char *from, const char *to);
virtual int Symlink(const char *from, const char *to);
virtual int Unlink(const char *name);
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime);
int GetPathInfo(const char *path, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime);
virtual int GetPathInfo(const char *path, FileStat_t &buf);
virtual int GetFsInfo(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree);
virtual int Chmod(const char *file, UInt_t mode);
virtual int Umask(Int_t mask);
virtual int Utime(const char *file, Long_t modtime, Long_t actime);
virtual const char *UnixPathName(const char *unixpathname);
virtual const char *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists);
virtual char *Which(const char *search, const char *file, EAccessMode mode = kFileExists);
virtual TList *GetVolumes(Option_t *) const { return 0; }
virtual Int_t GetUid(const char *user = 0);
virtual Int_t GetGid(const char *group = 0);
virtual Int_t GetEffectiveUid();
virtual Int_t GetEffectiveGid();
virtual UserGroup_t *GetUserInfo(Int_t uid);
virtual UserGroup_t *GetUserInfo(const char *user = 0);
virtual UserGroup_t *GetGroupInfo(Int_t gid);
virtual UserGroup_t *GetGroupInfo(const char *group = 0);
virtual void Setenv(const char *name, const char *value);
virtual void Unsetenv(const char *name);
virtual const char *Getenv(const char *env);
virtual void Openlog(const char *name, Int_t options, ELogFacility facility);
virtual void Syslog(ELogLevel level, const char *mess);
virtual void Closelog();
virtual Int_t RedirectOutput(const char *name, const char *mode = "a", RedirectHandle_t *h = 0);
virtual void ShowOutput(RedirectHandle_t *h);
virtual void AddDynamicPath(const char *pathname);
virtual const char *GetDynamicPath();
virtual void SetDynamicPath(const char *pathname);
virtual char *DynamicPathName(const char *lib, Bool_t quiet = kFALSE);
virtual Func_t DynFindSymbol(const char *module, const char *entry);
virtual int Load(const char *module, const char *entry = "", Bool_t system = kFALSE);
virtual void Unload(const char *module);
virtual void ListSymbols(const char *module, const char *re = "");
virtual void ListLibraries(const char *regexp = "");
virtual const char *GetLibraries(const char *regexp = "",
const char *option = "",
Bool_t isRegexp = kTRUE);
virtual TInetAddress GetHostByName(const char *server);
virtual TInetAddress GetPeerName(int sock);
virtual TInetAddress GetSockName(int sock);
virtual int GetServiceByName(const char *service);
virtual char *GetServiceByPort(int port);
virtual int OpenConnection(const char *server, int port, int tcpwindowsize = -1);
virtual int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize = -1);
virtual int AnnounceUnixService(int port, int backlog);
virtual int AnnounceUnixService(const char *sockpath, int backlog);
virtual int AcceptConnection(int sock);
virtual void CloseConnection(int sock, Bool_t force = kFALSE);
virtual int RecvRaw(int sock, void *buffer, int length, int flag);
virtual int SendRaw(int sock, const void *buffer, int length, int flag);
virtual int RecvBuf(int sock, void *buffer, int length);
virtual int SendBuf(int sock, const void *buffer, int length);
virtual int SetSockOpt(int sock, int kind, int val);
virtual int GetSockOpt(int sock, int kind, int *val);
virtual int GetSysInfo(SysInfo_t *info) const;
virtual int GetCpuInfo(CpuInfo_t *info, Int_t sampleTime = 1000) const;
virtual int GetMemInfo(MemInfo_t *info) const;
virtual int GetProcInfo(ProcInfo_t *info) const;
virtual void AddIncludePath(const char *includePath);
virtual void AddLinkedLibs(const char *linkedLib);
virtual int CompileMacro(const char *filename, Option_t *opt="", const char* library_name = "", const char* build_dir = "", UInt_t dirmode = 0);
virtual Int_t GetAclicProperties() const;
virtual const char *GetBuildArch() const;
virtual const char *GetBuildCompiler() const;
virtual const char *GetBuildCompilerVersion() const;
virtual const char *GetBuildNode() const;
virtual const char *GetBuildDir() const;
virtual const char *GetFlagsDebug() const;
virtual const char *GetFlagsOpt() const;
virtual const char *GetIncludePath();
virtual const char *GetLinkedLibs() const;
virtual const char *GetLinkdefSuffix() const;
virtual EAclicMode GetAclicMode() const;
virtual const char *GetMakeExe() const;
virtual const char *GetMakeSharedLib() const;
virtual const char *GetSoExt() const;
virtual const char *GetObjExt() const;
virtual void SetBuildDir(const char* build_dir, Bool_t isflat = kFALSE);
virtual void SetFlagsDebug(const char *);
virtual void SetFlagsOpt(const char *);
virtual void SetIncludePath(const char *includePath);
virtual void SetMakeExe(const char *directives);
virtual void SetAclicMode(EAclicMode mode);
virtual void SetMakeSharedLib(const char *directives);
virtual void SetLinkedLibs(const char *linkedLibs);
virtual void SetLinkdefSuffix(const char *suffix);
virtual void SetSoExt(const char *soExt);
virtual void SetObjExt(const char *objExt);
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const;
virtual void CleanCompiledMacros();
ClassDef(TSystem,0)
};
R__EXTERN TSystem *gSystem;
R__EXTERN TFileHandler *gXDisplay;
#endif