Logo ROOT   6.14/05
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 #include "TSystem.h"
25 
26 
27 #if !defined(__CINT__)
28  #include "Windows4Root.h"
29  #include <commctrl.h>
30 #else
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;
37 #endif
38 
39 #ifndef MAX_SID_SIZE
40 #define MAX_SID_SIZE 1024
41 #endif
42 #define MAX_NAME_STRING 1024
43 
44 #define SID_GROUP 0
45 #define SID_MEMBER 1
46 
47 struct 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
57 };
58 
59 struct 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
64 };
65 
66 
67 class TWinNTSystem : public TSystem {
68 public:
69  // pointer to message handler func
70  typedef Bool_t (*ThreadMsgFunc_t)(MSG*);
71 
72 private:
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
80 
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)
86 
87  Bool_t DispatchTimers(Bool_t mode);
88  Bool_t CheckDescriptors();
89  Bool_t CheckSignals(Bool_t sync);
90  Bool_t CountMembers(const char *lpszGroupName);
91  const char *GetLinkedLibraries();
92  Bool_t GetNbGroups();
93  Long_t LookupSID (const char *lpszAccountName, int what, int &groupIdx, int &memberIdx);
94  Bool_t CollectMembers(const char *lpszGroupName, int &groupIdx, int &memberIdx);
95  Bool_t CollectGroups();
96  Bool_t InitUsersGroups();
97  void DoBeep(Int_t freq=-1, Int_t duration=-1) const;
98 
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;
103 
104 
105 protected:
106  static int WinNTUnixConnect(int port);
107  static int WinNTUnixConnect(const char *path);
108  static int WinNTUdpConnect(const char *hostname, int port);
109 
110 public:
111  TWinNTSystem();
112  virtual ~TWinNTSystem();
113 
114  //---- non-TSystem methods ----------------------------------
115  HANDLE GetProcess();
116  Bool_t HandleConsoleEvent();
117 
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;}
125  ULong_t GetGUIThreadId() const {return fGUIThreadId;}
126  void SetGUIThreadMsgHandler(ThreadMsgFunc_t func);
127  void NotifyApplicationCreated();
128 
129 
130  //---- EventLoop --------------------------------------------
131  Bool_t ProcessEvents();
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);
136 
137  //---- Handling of system events ----------------------------
138  void DispatchSignals(ESignals sig);
139  void AddSignalHandler(TSignalHandler *sh);
140  TSignalHandler *RemoveSignalHandler(TSignalHandler *sh);
141  void ResetSignal(ESignals sig, Bool_t reset = kTRUE);
142  void ResetSignals();
143  void IgnoreSignal(ESignals sig, Bool_t ignore = kTRUE);
144  void AddFileHandler(TFileHandler *fh);
145  TFileHandler *RemoveFileHandler(TFileHandler *fh);
146  void StackTrace();
147 
148  //---- Floating Point Exceptions Control --------------------
149  Int_t GetFPEMask();
150  Int_t SetFPEMask(Int_t mask = kDefaultMask);
151 
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();
159 
160  //---- Environment manipulation -----------------------------
161  const char *Getenv(const char *name);
162  void Setenv(const char *name, const char *value);
163 
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);
179 
180  //---- Users & Groups ---------------------------------------
181  Int_t GetUid(const char *user = 0);
182  Int_t GetGid(const char *group = 0);
183  Int_t GetEffectiveUid();
184  Int_t GetEffectiveGid();
185  UserGroup_t *GetUserInfo(Int_t uid);
186  UserGroup_t *GetUserInfo(const char *user = 0);
187  UserGroup_t *GetGroupInfo(Int_t gid);
188  UserGroup_t *GetGroupInfo(const char *group = 0);
189 
190  //---- Paths & Files ----------------------------------------
191  const char DriveName(const char *pathname="/");
192  const char *PrependPathName(const char *dir, TString& name);
193  Bool_t ExpandPathName(TString &patbuf);
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;
213 
214  //---- Standard Output redirection --------------------------
215  Int_t RedirectOutput(const char *name, const char *mode = "a", RedirectHandle_t *h = 0);
216 
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);
226 
227  //---- Time & Date -------------------------------------------
228  TTime Now();
229  void AddTimer(TTimer *ti);
230  TTimer *RemoveTimer(TTimer *ti);
231  void Sleep(UInt_t milliSec);
232  Double_t GetRealTime();
233  Double_t GetCPUTime();
234 
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);
255 
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;
261 
263 };
264 
265 R__EXTERN ULong_t gConsoleWindow; // console window handle
266 
267 #endif
Bool_t fFirstFile
Definition: TWinNTSystem.h:79
int pw_quota
Definition: TWinNTSystem.h:52
int pw_uid
Definition: TWinNTSystem.h:50
void * GetGUIThreadHandle() const
Definition: TWinNTSystem.h:124
WIN32_FIND_DATA fFindFileData
Definition: TWinNTSystem.h:85
struct group * fGroups
Definition: TWinNTSystem.h:73
char * pw_shell
Definition: TWinNTSystem.h:55
int gr_gid
Definition: TWinNTSystem.h:62
const char Option_t
Definition: RtypesCore.h:62
RooCmdArg Link(const char *state, RooAbsData &data)
char * gr_name
Definition: TWinNTSystem.h:60
This class represents an Internet Protocol (IP) address.
Definition: TInetAddress.h:36
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
char * gr_passwd
Definition: TWinNTSystem.h:61
static void ThreadStub(void *Parameter)
Definition: TWinNTSystem.h:99
Basic time type with millisecond precision.
Definition: TTime.h:27
void * fGUIThreadHandle
Definition: TWinNTSystem.h:82
HANDLE fhProcess
Definition: TWinNTSystem.h:81
#define ClassDef(name, id)
Definition: Rtypes.h:320
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Definition: TClassEdit.cxx:121
R__EXTERN ULong_t gConsoleWindow
Definition: TWinNTSystem.h:265
char * pw_name
Definition: TWinNTSystem.h:48
A doubly linked list.
Definition: TList.h:44
ESignals
char * pw_gecos
Definition: TWinNTSystem.h:53
ULong_t fGUIThreadId
Definition: TWinNTSystem.h:83
char * pw_group
Definition: TWinNTSystem.h:56
unsigned int UInt_t
Definition: RtypesCore.h:42
struct passwd * fPasswords
Definition: TWinNTSystem.h:74
ULong_t GetGUIThreadId() const
Definition: TWinNTSystem.h:125
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
RooCmdArg Rename(const char *suffix)
#define h(i)
Definition: RSha256.hxx:106
const Bool_t kFALSE
Definition: RtypesCore.h:88
long Long_t
Definition: RtypesCore.h:50
double Double_t
Definition: RtypesCore.h:55
Bool_t fGroupsInitDone
Definition: TWinNTSystem.h:78
unsigned long ULong_t
Definition: RtypesCore.h:51
EAccessMode
Definition: TSystem.h:44
int pw_gid
Definition: TWinNTSystem.h:51
#define R__EXTERN
Definition: DllImport.h:27
Definition: file.py:1
char * pw_passwd
Definition: TWinNTSystem.h:49
char * pw_dir
Definition: TWinNTSystem.h:54
unsigned char UChar_t
Definition: RtypesCore.h:34
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:248
const Bool_t kTRUE
Definition: RtypesCore.h:87
char name[80]
Definition: TGX11.cxx:109
char * fDirNameBuffer
Definition: TWinNTSystem.h:84
char ** gr_mem
Definition: TWinNTSystem.h:63