TWinNTSystem.h

Go to the documentation of this file.
00001 // @(#)root/winnt:$Id: TWinNTSystem.h 37109 2010-11-30 16:30:58Z pcanal $
00002 // Author: Fons Rademakers   15/09/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 
00013 #ifndef ROOT_TWinNTSystem
00014 #define ROOT_TWinNTSystem
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TWinNTSystem                                                         //
00019 //                                                                      //
00020 // Class providing an interface to the Windows NT Operating System.     //
00021 //                                                                      //
00022 //////////////////////////////////////////////////////////////////////////
00023 
00024 #ifndef ROOT_TSystem
00025 #include "TSystem.h"
00026 #endif
00027 
00028 
00029 #if !defined(__CINT__)
00030  #include "Windows4Root.h"
00031  #include <commctrl.h>
00032 #else
00033  typedef void* HANDLE;
00034  struct WIN32_FIND_DATA;
00035  typedef void* HIMAGELIST;
00036  typedef void* HICON;
00037  typedef UChar_t BOOL;
00038  struct FILE;
00039 #endif
00040 
00041 #ifndef MAX_SID_SIZE
00042 #define MAX_SID_SIZE   1024
00043 #endif
00044 #define MAX_NAME_STRING   1024
00045 
00046 #define SID_GROUP         0
00047 #define SID_MEMBER        1
00048 
00049 struct passwd {
00050    char *pw_name;       // user name
00051    char *pw_passwd;     // user password
00052    int   pw_uid;        // user ID
00053    int   pw_gid;        // user's group ID
00054    int   pw_quota;      //
00055    char *pw_gecos;      // user's real (long) name
00056    char *pw_dir;        // user home directory
00057    char *pw_shell;      // shell command
00058    char *pw_group;      // user's group name
00059 };
00060 
00061 struct group {
00062    char   *gr_name;     // group name
00063    char   *gr_passwd;   // group password
00064    int    gr_gid;       // group id
00065    char   **gr_mem;     // group members
00066 };
00067 
00068 
00069 class TWinNTSystem : public TSystem {
00070 public:
00071    // pointer to message handler func
00072    typedef Bool_t (*ThreadMsgFunc_t)(MSG*);
00073 
00074 private:
00075    struct group     *fGroups;           // Groups on local computer
00076    struct passwd    *fPasswords;        // Users on local computer
00077    int               fNbUsers;          // Number of users on local computer
00078    int               fNbGroups;         // Number of groups on local computer
00079    int               fActUser;          // Index of actual user in User list
00080    Bool_t            fGroupsInitDone;   // Flag used for Users and Groups initialization
00081    Bool_t            fFirstFile;        // Flag used by OpenDirectory/GetDirEntry
00082 
00083    HANDLE            fhProcess;         // Handle of the current process
00084    void             *fGUIThreadHandle;  // handle of GUI server (aka command) thread
00085    ULong_t           fGUIThreadId;      // id of GUI server (aka command) thread
00086    char             *fDirNameBuffer;    // The string buffer to hold path name
00087    WIN32_FIND_DATA   fFindFileData;     // Structure to look for files (aka OpenDir under UNIX)
00088 
00089    Bool_t            DispatchTimers(Bool_t mode);
00090    Bool_t            CheckDescriptors();
00091    Bool_t            CheckSignals(Bool_t sync);
00092    Bool_t            CountMembers(const char *lpszGroupName);
00093    const char       *GetLinkedLibraries();
00094    Bool_t            GetNbGroups();
00095    Long_t            LookupSID (const char *lpszAccountName, int what, int &groupIdx, int &memberIdx);
00096    Bool_t            CollectMembers(const char *lpszGroupName, int &groupIdx, int &memberIdx);
00097    Bool_t            CollectGroups();
00098    Bool_t            InitUsersGroups();
00099    void              DoBeep(Int_t freq=-1, Int_t duration=-1) const;
00100 
00101    static void       ThreadStub(void *Parameter) {((TWinNTSystem *)Parameter)->TimerThread();}
00102    void              TimerThread();
00103 
00104 public:
00105    TWinNTSystem();
00106    virtual ~TWinNTSystem();
00107 
00108    //---- non-TSystem methods ----------------------------------
00109    HANDLE            GetProcess();
00110    Bool_t            HandleConsoleEvent();
00111 
00112    //---- Misc -------------------------------------------------
00113    Bool_t            Init();
00114    const char       *BaseName(const char *name);
00115    void              SetProgname(const char *name);
00116    const char       *GetError();
00117    const char       *HostName();
00118    void             *GetGUIThreadHandle() const {return fGUIThreadHandle;}
00119    ULong_t           GetGUIThreadId() const {return fGUIThreadId;}
00120    void              SetGUIThreadMsgHandler(ThreadMsgFunc_t func);
00121    void              NotifyApplicationCreated();
00122 
00123 
00124    //---- EventLoop --------------------------------------------
00125    Bool_t            ProcessEvents();
00126    void              DispatchOneEvent(Bool_t pendingOnly = kFALSE);
00127    void              ExitLoop();
00128    Int_t             Select(TList *active, Long_t timeout);
00129    Int_t             Select(TFileHandler *fh, Long_t timeout);
00130 
00131    //---- Handling of system events ----------------------------
00132    void              AddSignalHandler(TSignalHandler *sh);
00133    TSignalHandler   *RemoveSignalHandler(TSignalHandler *sh);
00134    void              ResetSignal(ESignals sig, Bool_t reset = kTRUE);
00135    void              IgnoreSignal(ESignals sig, Bool_t ignore = kTRUE);
00136    void              AddFileHandler(TFileHandler *fh);
00137    TFileHandler     *RemoveFileHandler(TFileHandler *fh);
00138    void              StackTrace();
00139 
00140    //---- Floating Point Exceptions Control --------------------
00141    Int_t             GetFPEMask();
00142    Int_t             SetFPEMask(Int_t mask = kDefaultMask);
00143 
00144    //---- Processes --------------------------------------------
00145    int               Exec(const char *shellcmd);
00146    FILE             *OpenPipe(const char *shellcmd, const char *mode);
00147    int               ClosePipe(FILE *pipe);
00148    void              Exit(int code, Bool_t mode = kTRUE);
00149    void              Abort(int code = 0);
00150    int               GetPid();
00151 
00152    //---- Environment manipulation -----------------------------
00153    const char       *Getenv(const char *name);
00154    void              Setenv(const char *name, const char *value);
00155 
00156    //---- Directories ------------------------------------------
00157    int               mkdir(const char *name, Bool_t recursive = kFALSE);
00158    int               MakeDirectory(const char *name);
00159    Bool_t            ChangeDirectory(const char *path);
00160    const char       *GetDirEntry(void *dirp);
00161    const char       *DirName(const char *pathname);
00162    void              FreeDirectory(void *dirp);
00163    void             *OpenDirectory(const char *name);
00164    const char       *WorkingDirectory(char driveletter);
00165    const char       *WorkingDirectory();
00166    const char       *HomeDirectory(const char *userName=0);
00167    const char       *TempDirectory() const;
00168    FILE             *TempFileName(TString &base, const char *dir = 0);
00169 
00170    //---- Users & Groups ---------------------------------------
00171    Int_t             GetUid(const char *user = 0);
00172    Int_t             GetGid(const char *group = 0);
00173    Int_t             GetEffectiveUid();
00174    Int_t             GetEffectiveGid();
00175    UserGroup_t      *GetUserInfo(Int_t uid);
00176    UserGroup_t      *GetUserInfo(const char *user = 0);
00177    UserGroup_t      *GetGroupInfo(Int_t gid);
00178    UserGroup_t      *GetGroupInfo(const char *group = 0);
00179 
00180    //---- Paths & Files ----------------------------------------
00181    const char        DriveName(const char *pathname="/");
00182    const char       *PrependPathName(const char *dir, TString& name);
00183    Bool_t            ExpandPathName(TString &patbuf);
00184    char             *ExpandPathName(const char *path);
00185    Bool_t            AccessPathName(const char *path, EAccessMode mode = kFileExists);
00186    Bool_t            IsPathLocal(const char *path);
00187    Bool_t            IsAbsoluteFileName(const char *dir);
00188    int               CopyFile(const char *from, const char *to, Bool_t overwrite = kFALSE);
00189    int               Rename(const char *from, const char *to);
00190    int               Link(const char *from, const char *to);
00191    int               Symlink(const char *from, const char *to);
00192    int               Unlink(const char *name);
00193    int               SetNonBlock(int fd);
00194    int               GetPathInfo(const char *path, FileStat_t &buf);
00195    int               GetFsInfo(const char *path, Long_t *id, Long_t *bsize,
00196                                  Long_t *blocks, Long_t *bfree);
00197    int               Chmod(const char *file, UInt_t mode);
00198    int               Umask(Int_t mask);
00199    int               Utime(const char *file, Long_t modtime, Long_t actime);
00200    const char       *UnixPathName(const char *unixpathname);
00201    const char       *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists);
00202    TList            *GetVolumes(Option_t *opt = "") const;
00203 
00204    //---- Standard Output redirection --------------------------
00205    Int_t             RedirectOutput(const char *name, const char *mode = "a", RedirectHandle_t *h = 0);
00206 
00207    //---- Dynamic Loading --------------------------------------
00208    void              AddDynamicPath(const char *dir);
00209    const char       *GetDynamicPath();
00210    void              SetDynamicPath(const char *path);
00211    char             *DynamicPathName(const char *lib, Bool_t quiet = kFALSE);
00212    int               Load(const char *module, const char *entry = "", Bool_t system = kFALSE);
00213    const char       *GetLibraries(const char *regexp = "",
00214                                   const char *option = "",
00215                                   Bool_t isRegexp = kTRUE);
00216 
00217    //---- Time & Date -------------------------------------------
00218    TTime             Now();
00219    void              AddTimer(TTimer *ti);
00220    TTimer           *RemoveTimer(TTimer *ti);
00221    void              Sleep(UInt_t milliSec);
00222    Double_t          GetRealTime();
00223    Double_t          GetCPUTime();
00224 
00225    //---- RPC --------------------------------------------------
00226    int               ConnectService(const char *servername, int port, int tcpwindowsize);
00227    TInetAddress      GetHostByName(const char *server);
00228    TInetAddress      GetPeerName(int sock);
00229    TInetAddress      GetSockName(int sock);
00230    int               GetServiceByName(const char *service);
00231    char              *GetServiceByPort(int port);
00232    int               OpenConnection(const char *server, int port, int tcpwindowsize = -1);
00233    int               AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize = -1);
00234    int               AnnounceUnixService(int port, int backlog);
00235    int               AnnounceUnixService(const char *sockpath, int backlog);
00236    int               AcceptConnection(int sock);
00237    void              CloseConnection(int sock, Bool_t force = kFALSE);
00238    int               RecvRaw(int sock, void *buffer, int length, int flag);
00239    int               SendRaw(int sock, const void *buffer, int length, int flag);
00240    int               RecvBuf(int sock, void *buffer, int length);
00241    int               SendBuf(int sock, const void *buffer, int length);
00242    int               SetSockOpt(int sock, int opt, int val);
00243    int               GetSockOpt(int sock, int opt, int *val);
00244 
00245    static int        WinNTUnixConnect(int port);
00246    static int        WinNTUnixConnect(const char *path);
00247 
00248    //---- System, CPU and Memory info
00249    Int_t             GetSysInfo(SysInfo_t *info) const;
00250    Int_t             GetCpuInfo(CpuInfo_t *info, Int_t sampleTime = 1000) const;
00251    Int_t             GetMemInfo(MemInfo_t *info) const;
00252    Int_t             GetProcInfo(ProcInfo_t *info) const;
00253 
00254    ClassDef(TWinNTSystem, 0)
00255 };
00256 
00257 R__EXTERN ULong_t gConsoleWindow;   // console window handle
00258 
00259 #endif

Generated on Tue Jul 5 14:12:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1