ROOT  6.06/09
Reference Guide
TWinNTSystem.h
Go to the documentation of this file.
1 // @(#)root/winnt:$Id$
2 // Author: Fons Rademakers 15/09/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 
13 #ifndef ROOT_TWinNTSystem
14 #define ROOT_TWinNTSystem
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TWinNTSystem //
19 // //
20 // Class providing an interface to the Windows NT Operating System. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #ifndef ROOT_TSystem
25 #include "TSystem.h"
26 #endif
27 
28 
29 #if !defined(__CINT__)
30  #include "Windows4Root.h"
31  #include <commctrl.h>
32 #else
33  typedef void* HANDLE;
34  struct WIN32_FIND_DATA;
35  typedef void* HIMAGELIST;
36  typedef void* HICON;
37  typedef UChar_t BOOL;
38  struct FILE;
39 #endif
40 
41 #ifndef MAX_SID_SIZE
42 #define MAX_SID_SIZE 1024
43 #endif
44 #define MAX_NAME_STRING 1024
45 
46 #define SID_GROUP 0
47 #define SID_MEMBER 1
48 
49 struct passwd {
50  char *pw_name; // user name
51  char *pw_passwd; // user password
52  int pw_uid; // user ID
53  int pw_gid; // user's group ID
54  int pw_quota; //
55  char *pw_gecos; // user's real (long) name
56  char *pw_dir; // user home directory
57  char *pw_shell; // shell command
58  char *pw_group; // user's group name
59 };
60 
61 struct group {
62  char *gr_name; // group name
63  char *gr_passwd; // group password
64  int gr_gid; // group id
65  char **gr_mem; // group members
66 };
67 
68 
69 class TWinNTSystem : public TSystem {
70 public:
71  // pointer to message handler func
72  typedef Bool_t (*ThreadMsgFunc_t)(MSG*);
73 
74 private:
75  struct group *fGroups; // Groups on local computer
76  struct passwd *fPasswords; // Users on local computer
77  int fNbUsers; // Number of users on local computer
78  int fNbGroups; // Number of groups on local computer
79  int fActUser; // Index of actual user in User list
80  Bool_t fGroupsInitDone; // Flag used for Users and Groups initialization
81  Bool_t fFirstFile; // Flag used by OpenDirectory/GetDirEntry
82 
83  HANDLE fhProcess; // Handle of the current process
84  void *fGUIThreadHandle; // handle of GUI server (aka command) thread
85  ULong_t fGUIThreadId; // id of GUI server (aka command) thread
86  char *fDirNameBuffer; // The string buffer to hold path name
87  WIN32_FIND_DATA fFindFileData; // Structure to look for files (aka OpenDir under UNIX)
88 
92  Bool_t CountMembers(const char *lpszGroupName);
93  const char *GetLinkedLibraries();
95  Long_t LookupSID (const char *lpszAccountName, int what, int &groupIdx, int &memberIdx);
96  Bool_t CollectMembers(const char *lpszGroupName, int &groupIdx, int &memberIdx);
99  void DoBeep(Int_t freq=-1, Int_t duration=-1) const;
100 
101  static void ThreadStub(void *Parameter) {((TWinNTSystem *)Parameter)->TimerThread();}
102  void TimerThread();
103  void FillWithHomeDirectory(const char *userName, char *mydir) const;
104  char *GetWorkingDirectory(char driveletter) const;
105 
106 
107 protected:
108  static int WinNTUnixConnect(int port);
109  static int WinNTUnixConnect(const char *path);
110  static int WinNTUdpConnect(const char *hostname, int port);
111 
112 public:
113  TWinNTSystem();
114  virtual ~TWinNTSystem();
115 
116  //---- non-TSystem methods ----------------------------------
117  HANDLE GetProcess();
119 
120  //---- Misc -------------------------------------------------
121  Bool_t Init();
122  const char *BaseName(const char *name);
123  void SetProgname(const char *name);
124  const char *GetError();
125  const char *HostName();
126  void *GetGUIThreadHandle() const {return fGUIThreadHandle;}
130 
131 
132  //---- EventLoop --------------------------------------------
134  void DispatchOneEvent(Bool_t pendingOnly = kFALSE);
135  void ExitLoop();
136  Int_t Select(TList *active, Long_t timeout);
137  Int_t Select(TFileHandler *fh, Long_t timeout);
138 
139  //---- Handling of system events ----------------------------
140  void DispatchSignals(ESignals sig);
143  void ResetSignal(ESignals sig, Bool_t reset = kTRUE);
144  void ResetSignals();
145  void IgnoreSignal(ESignals sig, Bool_t ignore = kTRUE);
146  void AddFileHandler(TFileHandler *fh);
148  void StackTrace();
149 
150  //---- Floating Point Exceptions Control --------------------
151  Int_t GetFPEMask();
153 
154  //---- Processes --------------------------------------------
155  int Exec(const char *shellcmd);
156  FILE *OpenPipe(const char *shellcmd, const char *mode);
157  int ClosePipe(FILE *pipe);
158  void Exit(int code, Bool_t mode = kTRUE);
159  void Abort(int code = 0);
160  int GetPid();
161 
162  //---- Environment manipulation -----------------------------
163  const char *Getenv(const char *name);
164  void Setenv(const char *name, const char *value);
165 
166  //---- Directories ------------------------------------------
167  int mkdir(const char *name, Bool_t recursive = kFALSE);
168  int MakeDirectory(const char *name);
169  Bool_t ChangeDirectory(const char *path);
170  const char *GetDirEntry(void *dirp);
171  const char *DirName(const char *pathname);
172  void FreeDirectory(void *dirp);
173  void *OpenDirectory(const char *name);
174  const char *WorkingDirectory(char driveletter);
175  const char *WorkingDirectory();
176  std::string GetWorkingDirectory() const;
177  const char *HomeDirectory(const char *userName=0);
178  std::string GetHomeDirectory(const char *userName=0) const;
179  const char *TempDirectory() const;
180  FILE *TempFileName(TString &base, const char *dir = 0);
181 
182  //---- Users & Groups ---------------------------------------
183  Int_t GetUid(const char *user = 0);
184  Int_t GetGid(const char *group = 0);
188  UserGroup_t *GetUserInfo(const char *user = 0);
190  UserGroup_t *GetGroupInfo(const char *group = 0);
191 
192  //---- Paths & Files ----------------------------------------
193  const char DriveName(const char *pathname="/");
194  const char *PrependPathName(const char *dir, TString& name);
195  Bool_t ExpandPathName(TString &patbuf);
196  char *ExpandPathName(const char *path);
197  Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists);
198  Bool_t IsPathLocal(const char *path);
199  Bool_t IsAbsoluteFileName(const char *dir);
200  int CopyFile(const char *from, const char *to, Bool_t overwrite = kFALSE);
201  int Rename(const char *from, const char *to);
202  int Link(const char *from, const char *to);
203  int Symlink(const char *from, const char *to);
204  int Unlink(const char *name);
205  int SetNonBlock(int fd);
206  int GetPathInfo(const char *path, FileStat_t &buf);
207  int GetFsInfo(const char *path, Long_t *id, Long_t *bsize,
208  Long_t *blocks, Long_t *bfree);
209  int Chmod(const char *file, UInt_t mode);
210  int Umask(Int_t mask);
211  int Utime(const char *file, Long_t modtime, Long_t actime);
212  const char *UnixPathName(const char *unixpathname);
213  const char *FindFile(const char *search, TString& file, EAccessMode mode = kFileExists);
214  TList *GetVolumes(Option_t *opt = "") const;
215 
216  //---- Standard Output redirection --------------------------
217  Int_t RedirectOutput(const char *name, const char *mode = "a", RedirectHandle_t *h = 0);
218 
219  //---- Dynamic Loading --------------------------------------
220  void AddDynamicPath(const char *dir);
221  const char *GetDynamicPath();
222  void SetDynamicPath(const char *path);
223  const char *FindDynamicLibrary(TString &lib, Bool_t quiet = kFALSE);
224  int Load(const char *module, const char *entry = "", Bool_t system = kFALSE);
225  const char *GetLibraries(const char *regexp = "",
226  const char *option = "",
227  Bool_t isRegexp = kTRUE);
228 
229  //---- Time & Date -------------------------------------------
230  TTime Now();
231  void AddTimer(TTimer *ti);
232  TTimer *RemoveTimer(TTimer *ti);
233  void Sleep(UInt_t milliSec);
236 
237  //---- RPC --------------------------------------------------
238  int ConnectService(const char *servername, int port, int tcpwindowsize, const char *protocol = "tcp");
239  TInetAddress GetHostByName(const char *server);
240  TInetAddress GetPeerName(int sock);
241  TInetAddress GetSockName(int sock);
242  int GetServiceByName(const char *service);
243  char *GetServiceByPort(int port);
244  int OpenConnection(const char *server, int port, int tcpwindowsize = -1, const char *protocol = "tcp");
245  int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize = -1);
246  int AnnounceUdpService(int port, int backlog);
247  int AnnounceUnixService(int port, int backlog);
248  int AnnounceUnixService(const char *sockpath, int backlog);
249  int AcceptConnection(int sock);
250  void CloseConnection(int sock, Bool_t force = kFALSE);
251  int RecvRaw(int sock, void *buffer, int length, int flag);
252  int SendRaw(int sock, const void *buffer, int length, int flag);
253  int RecvBuf(int sock, void *buffer, int length);
254  int SendBuf(int sock, const void *buffer, int length);
255  int SetSockOpt(int sock, int opt, int val);
256  int GetSockOpt(int sock, int opt, int *val);
257 
258  //---- System, CPU and Memory info
259  Int_t GetSysInfo(SysInfo_t *info) const;
260  Int_t GetCpuInfo(CpuInfo_t *info, Int_t sampleTime = 1000) const;
261  Int_t GetMemInfo(MemInfo_t *info) const;
262  Int_t GetProcInfo(ProcInfo_t *info) const;
263 
265 };
266 
267 R__EXTERN ULong_t gConsoleWindow; // console window handle
268 
269 #endif
Int_t GetGid(const char *group=0)
Returns the group's id. If group = 0, returns current user's group.
void DispatchOneEvent(Bool_t pendingOnly=kFALSE)
Dispatch a single event in TApplication::Run() loop.
const char * FindFile(const char *search, TString &file, EAccessMode mode=kFileExists)
Find location of file in a search path.
int GetSockOpt(int sock, int opt, int *val)
Get socket option.
Bool_t fFirstFile
Definition: TWinNTSystem.h:81
FILE * OpenPipe(const char *shellcmd, const char *mode)
Open a pipe.
Int_t GetEffectiveGid()
Returns the effective group id.
int pw_quota
Definition: TWinNTSystem.h:54
UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
int pw_uid
Definition: TWinNTSystem.h:52
int RecvRaw(int sock, void *buffer, int length, int flag)
Receive exactly length bytes into buffer.
const char * HostName()
Return the system's host name.
WIN32_FIND_DATA fFindFileData
Definition: TWinNTSystem.h:87
void SetDynamicPath(const char *path)
Set the dynamic path to a new value.
struct group * fGroups
Definition: TWinNTSystem.h:75
char * pw_shell
Definition: TWinNTSystem.h:57
int Link(const char *from, const char *to)
Create a link from file1 to file2.
const char * GetError()
Return system error string.
Bool_t GetNbGroups()
void * GetGUIThreadHandle() const
Definition: TWinNTSystem.h:126
const char * GetLinkedLibraries()
Get list of shared libraries loaded at the start of the executable.
int Unlink(const char *name)
Unlink, i.e. remove, a file or directory.
HANDLE GetProcess()
Get current process handle.
void DoBeep(Int_t freq=-1, Int_t duration=-1) const
Beep.
TTime Now()
Get current time in milliseconds since 0:00 Jan 1 1995.
void CloseConnection(int sock, Bool_t force=kFALSE)
Close socket.
int gr_gid
Definition: TWinNTSystem.h:64
int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
Copy a file.
const char Option_t
Definition: RtypesCore.h:62
const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
TH1 * h
Definition: legend2.C:5
void AddDynamicPath(const char *dir)
Add a new directory to the dynamic path.
char * gr_name
Definition: TWinNTSystem.h:62
TTimer * RemoveTimer(TTimer *ti)
Remove timer from list of system timers.
This class represents an Internet Protocol (IP) address.
Definition: TInetAddress.h:40
int GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
Int_t GetSysInfo(SysInfo_t *info) const
Returns static system info, like OS type, CPU type, number of CPUs RAM size, etc into the SysInfo_t s...
int Umask(Int_t mask)
Set the process file creation mode mask.
char * GetServiceByPort(int port)
Get name of internet service.
int SendRaw(int sock, const void *buffer, int length, int flag)
Send exactly length bytes from buffer.
Basic string class.
Definition: TString.h:137
Int_t GetMemInfo(MemInfo_t *info) const
Returns ram and swap memory usage info into the MemInfo_t structure.
int Int_t
Definition: RtypesCore.h:41
void IgnoreSignal(ESignals sig, Bool_t ignore=kTRUE)
If ignore is true ignore the specified signal, else restore previous behaviour.
bool Bool_t
Definition: RtypesCore.h:59
Bool_t IsAbsoluteFileName(const char *dir)
Return true if dir is an absolute pathname.
const Bool_t kFALSE
Definition: Rtypes.h:92
char * gr_passwd
Definition: TWinNTSystem.h:63
Bool_t CheckDescriptors()
Check if there is activity on some file descriptors and call their Notify() member.
const char * DirName(const char *pathname)
Return the directory name in pathname.
static void ThreadStub(void *Parameter)
Definition: TWinNTSystem.h:101
Basic time type with millisecond precision.
Definition: TTime.h:29
int ClosePipe(FILE *pipe)
Close the pipe.
Bool_t IsPathLocal(const char *path)
Returns TRUE if the url in 'path' points to the local file system.
void * fGUIThreadHandle
Definition: TWinNTSystem.h:84
Int_t GetEffectiveUid()
Returns the effective user id.
HANDLE fhProcess
Definition: TWinNTSystem.h:83
TWinNTSystem()
ctor
void NotifyApplicationCreated()
Hook to tell TSystem that the TApplication object has been created.
Bool_t DispatchTimers(Bool_t mode)
Handle and dispatch timers.
Int_t GetCpuInfo(CpuInfo_t *info, Int_t sampleTime=1000) const
Returns cpu load average and load info into the CpuInfo_t structure.
void Abort(int code=0)
Abort the application.
void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
Bool_t ChangeDirectory(const char *path)
Change directory.
static int WinNTUnixConnect(int port)
Connect to a Unix domain socket.
#define ClassDef(name, id)
Definition: Rtypes.h:254
TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
Int_t bsize[]
Definition: SparseFit4.cxx:31
Int_t GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Int_t SetFPEMask(Int_t mask=kDefaultMask)
Set which conditions trigger a floating point exception.
int AcceptConnection(int sock)
Accept a connection.
const char * FindDynamicLibrary(TString &lib, Bool_t quiet=kFALSE)
Returns and updates sLib to the path of a dynamic library (searches for library in the dynamic librar...
int GetPid()
Get process id.
void AddTimer(TTimer *ti)
Add timer to list of system timers.
const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
R__EXTERN ULong_t gConsoleWindow
Definition: TWinNTSystem.h:267
char * pw_name
Definition: TWinNTSystem.h:50
const char * WorkingDirectory()
Return the working directory for the default drive.
int GetServiceByName(const char *service)
Get port # of internet service.
int OpenConnection(const char *server, int port, int tcpwindowsize=-1, const char *protocol="tcp")
Open a connection to a service on a server.
const char * GetDynamicPath()
Return the dynamic path (used to find shared libraries).
Bool_t CollectGroups()
A doubly linked list.
Definition: TList.h:47
static const char * what
Definition: stlLoader.cc:6
Bool_t InitUsersGroups()
Collect local users and groups accounts information.
virtual ~TWinNTSystem()
dtor
int MakeDirectory(const char *name)
Make a WinNT file system directory.
const char * GetDirEntry(void *dirp)
Returns the next directory entry.
static int WinNTUdpConnect(const char *hostname, int port)
Creates a UDP socket connection Is called via the TSocket constructor.
ESignals
char * pw_gecos
Definition: TWinNTSystem.h:55
Bool_t Init()
Initialize WinNT system interface.
void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
ULong_t fGUIThreadId
Definition: TWinNTSystem.h:85
const char * BaseName(const char *name)
Base name of a file name.
Bool_t ProcessEvents()
process pending events, i.e. DispatchOneEvent(kTRUE)
Double_t length(const TVector2 &v)
Definition: CsgOps.cxx:347
Int_t GetFPEMask()
Return the bitmap of conditions that trigger a floating point exception.
char * pw_group
Definition: TWinNTSystem.h:58
int ConnectService(const char *servername, int port, int tcpwindowsize, const char *protocol="tcp")
Connect to service servicename on server servername.
void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
std::string GetWorkingDirectory() const
Return the working directory for the default drive.
unsigned int UInt_t
Definition: RtypesCore.h:42
void Exit(int code, Bool_t mode=kTRUE)
Exit the application.
int Utime(const char *file, Long_t modtime, Long_t actime)
Set a files modification and access times.
void ResetSignal(ESignals sig, Bool_t reset=kTRUE)
If reset is true reset the signal handler for the specified signal to the default handler...
struct passwd * fPasswords
Definition: TWinNTSystem.h:76
const char * UnixPathName(const char *unixpathname)
Convert a pathname to a unix pathname.
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
void ResetSignals()
Reset signals handlers to previous behaviour.
Long64_t entry
void DispatchSignals(ESignals sig)
Handle and dispatch signals.
const char * GetLibraries(const char *regexp="", const char *option="", Bool_t isRegexp=kTRUE)
Return a space separated list of loaded shared libraries.
const char DriveName(const char *pathname="/")
Return the drive letter in pathname.
void ExitLoop()
Exit from event loop.
int Exec(const char *shellcmd)
Execute a command.
UserGroup_t * GetGroupInfo(Int_t gid)
Returns all group info in the UserGroup_t structure.
long Long_t
Definition: RtypesCore.h:50
int SendBuf(int sock, const void *buffer, int length)
Send a buffer headed by a length indicator.
int AnnounceTcpService(int port, Bool_t reuse, int backlog, int tcpwindowsize=-1)
Announce TCP/IP service.
double Double_t
Definition: RtypesCore.h:55
int AnnounceUnixService(int port, int backlog)
Announce unix domain service.
int RecvBuf(int sock, void *buffer, int length)
Receive a buffer headed by a length indicator.
int Chmod(const char *file, UInt_t mode)
Set the file permission bits.
Bool_t fGroupsInitDone
Definition: TWinNTSystem.h:80
unsigned long ULong_t
Definition: RtypesCore.h:51
double func(double *x, double *p)
Definition: stressTF1.cxx:213
int AnnounceUdpService(int port, int backlog)
Announce UDP service.
void TimerThread()
Special Thread to check asynchronous timers.
Bool_t HandleConsoleEvent()
int Symlink(const char *from, const char *to)
Create a symlink from file1 to file2.
void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
EAccessMode
Definition: TSystem.h:54
int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
TInetAddress GetPeerName(int sock)
Get Internet Protocol (IP) address of remote host and port #.
#define name(a, b)
Definition: linkTestLib0.cpp:5
TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
Bool_t ExpandPathName(TString &patbuf)
Expand a pathname getting rid of special shell characaters like ~.$, etc.
int pw_gid
Definition: TWinNTSystem.h:53
void FreeDirectory(void *dirp)
Close a WinNT file system directory.
Int_t Select(TList *active, Long_t timeout)
Select on file descriptors. The timeout to is in millisec.
Double_t GetCPUTime()
int SetSockOpt(int sock, int opt, int val)
Set socket option.
TInetAddress GetSockName(int sock)
Get Internet Protocol (IP) address of host and port #.
#define R__EXTERN
Definition: DllImport.h:27
Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
Bool_t CountMembers(const char *lpszGroupName)
Bool_t(* ThreadMsgFunc_t)(MSG *)
Definition: TWinNTSystem.h:72
Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
int SetNonBlock(int fd)
Make descriptor fd non-blocking.
int GetFsInfo(const char *path, Long_t *id, Long_t *bsize, Long_t *blocks, Long_t *bfree)
Get info about a file system: id, bsize, bfree, blocks.
Double_t GetRealTime()
FILE * TempFileName(TString &base, const char *dir=0)
Create a secure temporary file by appending a unique 6 letter string to base.
Long_t LookupSID(const char *lpszAccountName, int what, int &groupIdx, int &memberIdx)
Take the name and look up a SID so that we can get full domain/user information.
char * pw_passwd
Definition: TWinNTSystem.h:51
char * pw_dir
Definition: TWinNTSystem.h:56
Bool_t CollectMembers(const char *lpszGroupName, int &groupIdx, int &memberIdx)
void SetProgname(const char *name)
Set the application name (from command line, argv[0]) and copy it in gProgName.
unsigned char UChar_t
Definition: RtypesCore.h:34
Bool_t CheckSignals(Bool_t sync)
Check if some signals were raised and call their Notify() member.
void Setenv(const char *name, const char *value)
Set environment variable.
std::string GetHomeDirectory(const char *userName=0) const
Return the user's home directory.
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:258
const Bool_t kTRUE
Definition: Rtypes.h:91
float value
Definition: math.cpp:443
void StackTrace()
Print a stack trace, if gEnv entry "Root.Stacktrace" is unset or 1, and if the image helper functions...
ULong_t GetGUIThreadId() const
Definition: TWinNTSystem.h:127
TList * GetVolumes(Option_t *opt="") const
Get list of volumes (drives) mounted on the system.
const char * Getenv(const char *name)
Get environment variable.
void FillWithHomeDirectory(const char *userName, char *mydir) const
Fill buffer with user's home directory.
void SetGUIThreadMsgHandler(ThreadMsgFunc_t func)
Set the (static part of) the event handler func for GUI messages.
Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=0)
Redirect standard output (stdout, stderr) to the specified file.
char * fDirNameBuffer
Definition: TWinNTSystem.h:86
int Rename(const char *from, const char *to)
Rename a file. Returns 0 when successful, -1 in case of failure.
char ** gr_mem
Definition: TWinNTSystem.h:65