ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TApplicationServer.h
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: G. Ganis 10/5/2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, 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 #ifndef ROOT_TApplicationServer
13 #define ROOT_TApplicationServer
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TApplicationServer //
18 // //
19 // TApplicationServer is the remote application run by the roots main //
20 // program. The input is taken from the socket connection to the client.//
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #ifndef ROOT_TApplication
25 #include "TApplication.h"
26 #endif
27 #ifndef ROOT_TString
28 #include "TString.h"
29 #endif
30 #ifndef ROOT_TSysEvtHandler
31 #include "TSysEvtHandler.h"
32 #endif
33 #ifndef ROOT_TUrl
34 #include "TUrl.h"
35 #endif
36 
37 class TList;
38 class TMessage;
39 class TSocket;
40 class TRemoteObject;
41 
43 
44 private:
45  Int_t fProtocol; //user protocol version number
46  TUrl fUrl; //user's url
47  TSocket *fSocket; //socket connection to user
48  Bool_t fIsValid; //flag validity
49  Bool_t fInterrupt; //flag interrupt state
50 
51  TString fLogFilePath; //Path to log file
52  FILE *fLogFile; //log file
53  Int_t fLogFileDes; //log file descriptor
54  Bool_t fRealTimeLog; //TRUE if log messages should be send back in real-time
55 
56  TString fSessId; // Identifier for this session
57 
58  TString fWorkDir; // Working dir
59 
60  TList *fSentCanvases; // List of canvases already sent
61  TRemoteObject *fWorkingDir; // Working (remote) directory
62 
63  void ExecLogon();
64  Int_t Setup();
65  Int_t SendCanvases(); // Send back to client any created canvas
66 
67 protected:
68  void HandleCheckFile(TMessage *mess);
69 
70  static void ErrorHandler(Int_t level, Bool_t abort, const char *location,
71  const char *msg);
72 
73 public:
74  TApplicationServer(Int_t *argc, char **argv, FILE *flog, const char *logfile);
75  virtual ~TApplicationServer();
76 
77  void GetOptions(Int_t *argc, char **argv);
78  Int_t GetProtocol() const { return fProtocol; }
79  Int_t GetPort() const { return fUrl.GetPort(); }
80  const char *GetUser() const { return fUrl.GetUser(); }
81  const char *GetHost() const { return fUrl.GetHost(); }
82  TSocket *GetSocket() const { return fSocket; }
83 
84  void HandleSocketInput();
85  void HandleUrgentData();
86  void HandleSigPipe();
87  void Interrupt() { fInterrupt = kTRUE; }
88  Bool_t IsValid() const { return fIsValid; }
89 
90  Long_t ProcessLine(const char *line, Bool_t = kFALSE, Int_t *err = 0);
91 
92  void Reset(const char *dir);
93  Int_t ReceiveFile(const char *file, Bool_t bin, Long64_t size);
94  void Run(Bool_t retrn = kFALSE);
95  void SendLogFile(Int_t status = 0, Int_t start = -1, Int_t end = -1);
96  Int_t BrowseDirectory(const char *dirname);
97  Int_t BrowseFile(const char *fname);
98  Int_t BrowseKey(const char *keyname);
99 
100  void Terminate(Int_t status);
101 
102  ClassDef(TApplicationServer,0) //Remote Application Interface
103 };
104 
105 
106 //----- Handles output from commands executed externally via a pipe. ---------//
107 //----- The output is redirected one level up (i.e., to master or client). ---//
108 //______________________________________________________________________________
109 class TASLogHandler : public TFileHandler {
110 private:
111  TSocket *fSocket; // Socket where to redirect the message
112  FILE *fFile; // File connected with the open pipe
113  TString fPfx; // Prefix to be prepended to messages
114 
115  static TString fgPfx; // Default prefix to be prepended to messages
116 public:
117  enum EStatusBits { kFileIsPipe = BIT(23) };
118  TASLogHandler(const char *cmd, TSocket *s, const char *pfx = "");
119  TASLogHandler(FILE *f, TSocket *s, const char *pfx = "");
120  virtual ~TASLogHandler();
121 
122  Bool_t IsValid() { return ((fFile && fSocket) ? kTRUE : kFALSE); }
123 
124  Bool_t Notify();
125  Bool_t ReadNotify() { return Notify(); }
126 
127  static void SetDefaultPrefix(const char *pfx);
128 };
129 
130 //--- Guard class: close pipe, deactivatethe related descriptor --------------//
131 //______________________________________________________________________________
133 
134 private:
136 
137 public:
138  TASLogHandlerGuard(const char *cmd, TSocket *s,
139  const char *pfx = "", Bool_t on = kTRUE);
140  TASLogHandlerGuard(FILE *f, TSocket *s,
141  const char *pfx = "", Bool_t on = kTRUE);
142  virtual ~TASLogHandlerGuard();
143 };
144 
145 #endif
const char * GetHost() const
Definition: TUrl.h:76
Int_t GetProtocol() const
TASLogHandler * fExecHandler
long long Long64_t
Definition: RtypesCore.h:69
TRemoteObject * fWorkingDir
static TString fgPfx
TLine * line
void HandleUrgentData()
Handle Out-Of-Band data sent by the master or client.
Int_t GetPort() const
void GetOptions(Int_t *argc, char **argv)
Get and handle command line options.
static void ErrorHandler(Int_t level, Bool_t abort, const char *location, const char *msg)
The error handler function.
This class represents a WWW compatible URL.
Definition: TUrl.h:41
#define BIT(n)
Definition: Rtypes.h:120
const char * GetUser() const
void Terminate(Int_t status)
Terminate the proof server.
Basic string class.
Definition: TString.h:137
TAlienJobStatus * status
Definition: TAlienJob.cxx:51
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Int_t SendCanvases()
Send any created canvas to client.
TFile * f
const char * GetHost() const
static void SetDefaultPrefix(const char *pfx)
Static method to set the default prefix.
virtual ~TApplicationServer()
Cleanup.
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session...
Definition: TRemoteObject.h:42
#define ClassDef(name, id)
Definition: Rtypes.h:254
Int_t BrowseKey(const char *keyname)
Read key object and send it back to client.
void Run(Bool_t retrn=kFALSE)
Main server eventloop.
Long_t ProcessLine(const char *line, Bool_t=kFALSE, Int_t *err=0)
Parse a command line received from the client, making sure that the files needed for the execution...
TString flog
Definition: pq2main.cxx:37
void SendLogFile(Int_t status=0, Int_t start=-1, Int_t end=-1)
Send log file to master.
TSocket * GetSocket() const
A doubly linked list.
Definition: TList.h:47
Int_t GetPort() const
Definition: TUrl.h:87
Int_t BrowseFile(const char *fname)
Browse root file and send back its content; if fname is null, send the full list of files...
Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
TASLogHandler(const char *cmd, TSocket *s, const char *pfx="")
Execute 'cmd' in a pipe and handle output messages from the related file.
void HandleCheckFile(TMessage *mess)
Handle file checking request.
void HandleSigPipe()
Called when the client is not alive anymore (i.e.
long Long_t
Definition: RtypesCore.h:50
Int_t Setup()
Print the Remote Server logo on standard output.
void HandleSocketInput()
Handle input coming from the client or from the master server.
tuple file
Definition: fildir.py:20
EStatusBits
Definition: TObject.h:76
TApplicationServer(Int_t *argc, char **argv, FILE *flog, const char *logfile)
void dir(char *path=0)
Definition: rootalias.C:30
Int_t BrowseDirectory(const char *dirname)
Browse directory and send back its content to client.
Bool_t Notify()
Handle available message in the open file.
void Reset(const char *dir)
Reset environment to be ready for execution of next command.
virtual ~TASLogHandlerGuard()
Close a guard for executing a command in a pipe.
void ExecLogon()
Execute logon macro's.
Bool_t IsValid() const
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:45
Int_t ReceiveFile(const char *file, Bool_t bin, Long64_t size)
Receive a file, either sent by a client or a master server.
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual ~TASLogHandler()
Handle available message in the open file.
const char * GetUser() const
Definition: TUrl.h:74
TASLogHandlerGuard(const char *cmd, TSocket *s, const char *pfx="", Bool_t on=kTRUE)
Init a guard for executing a command in a pipe.