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