Logo ROOT   6.10/09
Reference Guide
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 #include "TApplication.h"
25 #include "TString.h"
26 #include "TSysEvtHandler.h"
27 #include "TUrl.h"
28 
29 class TList;
30 class TMessage;
31 class TSocket;
32 class TRemoteObject;
33 
35 
36 private:
37  Int_t fProtocol; //user protocol version number
38  TUrl fUrl; //user's url
39  TSocket *fSocket; //socket connection to user
40  Bool_t fIsValid; //flag validity
41  Bool_t fInterrupt; //flag interrupt state
42 
43  TString fLogFilePath; //Path to log file
44  FILE *fLogFile; //log file
45  Int_t fLogFileDes; //log file descriptor
46  Bool_t fRealTimeLog; //TRUE if log messages should be send back in real-time
47 
48  TString fSessId; // Identifier for this session
49 
50  TString fWorkDir; // Working dir
51 
52  TList *fSentCanvases; // List of canvases already sent
53  TRemoteObject *fWorkingDir; // Working (remote) directory
54 
55  void ExecLogon();
56  Int_t Setup();
57  Int_t SendCanvases(); // Send back to client any created canvas
58 
59 protected:
60  void HandleCheckFile(TMessage *mess);
61 
62  static void ErrorHandler(Int_t level, Bool_t abort, const char *location,
63  const char *msg);
64 
65 public:
66  TApplicationServer(Int_t *argc, char **argv, FILE *flog, const char *logfile);
67  virtual ~TApplicationServer();
68 
69  void GetOptions(Int_t *argc, char **argv);
70  Int_t GetProtocol() const { return fProtocol; }
71  Int_t GetPort() const { return fUrl.GetPort(); }
72  const char *GetUser() const { return fUrl.GetUser(); }
73  const char *GetHost() const { return fUrl.GetHost(); }
74  TSocket *GetSocket() const { return fSocket; }
75 
76  void HandleSocketInput();
77  void HandleUrgentData();
78  void HandleSigPipe();
79  void Interrupt() { fInterrupt = kTRUE; }
80  Bool_t IsValid() const { return fIsValid; }
81 
82  Long_t ProcessLine(const char *line, Bool_t = kFALSE, Int_t *err = 0);
83 
84  void Reset(const char *dir);
85  Int_t ReceiveFile(const char *file, Bool_t bin, Long64_t size);
86  void Run(Bool_t retrn = kFALSE);
87  void SendLogFile(Int_t status = 0, Int_t start = -1, Int_t end = -1);
88  Int_t BrowseDirectory(const char *dirname);
89  Int_t BrowseFile(const char *fname);
90  Int_t BrowseKey(const char *keyname);
91 
92  void Terminate(Int_t status);
93 
94  ClassDef(TApplicationServer,0) //Remote Application Interface
95 };
96 
97 
98 //----- Handles output from commands executed externally via a pipe. ---------//
99 //----- The output is redirected one level up (i.e., to master or client). ---//
100 //______________________________________________________________________________
101 class TASLogHandler : public TFileHandler {
102 private:
103  TSocket *fSocket; // Socket where to redirect the message
104  FILE *fFile; // File connected with the open pipe
105  TString fPfx; // Prefix to be prepended to messages
106 
107  static TString fgPfx; // Default prefix to be prepended to messages
108 public:
109  enum EStatusBits { kFileIsPipe = BIT(23) };
110  TASLogHandler(const char *cmd, TSocket *s, const char *pfx = "");
111  TASLogHandler(FILE *f, TSocket *s, const char *pfx = "");
112  virtual ~TASLogHandler();
113 
114  Bool_t IsValid() { return ((fFile && fSocket) ? kTRUE : kFALSE); }
115 
116  Bool_t Notify();
117  Bool_t ReadNotify() { return Notify(); }
118 
119  static void SetDefaultPrefix(const char *pfx);
120 };
121 
122 //--- Guard class: close pipe, deactivatethe related descriptor --------------//
123 //______________________________________________________________________________
125 
126 private:
128 
129 public:
130  TASLogHandlerGuard(const char *cmd, TSocket *s,
131  const char *pfx = "", Bool_t on = kTRUE);
132  TASLogHandlerGuard(FILE *f, TSocket *s,
133  const char *pfx = "", Bool_t on = kTRUE);
134  virtual ~TASLogHandlerGuard();
135 };
136 
137 #endif
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.
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.
const char * GetUser() const
This class represents a WWW compatible URL.
Definition: TUrl.h:35
#define BIT(n)
Definition: Rtypes.h:75
Int_t GetProtocol() const
void Terminate(Int_t status)
Terminate the proof server.
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t SendCanvases()
Send any created canvas to client.
const char * GetHost() const
Definition: TUrl.h:70
virtual ~TApplicationServer()
Cleanup.
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session...
Definition: TRemoteObject.h:36
#define ClassDef(name, id)
Definition: Rtypes.h:297
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition: TObject.cxx:499
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.
A doubly linked list.
Definition: TList.h:43
const char * GetUser() const
Definition: TUrl.h:68
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.
void HandleCheckFile(TMessage *mess)
Handle file checking request.
const Bool_t kFALSE
Definition: RtypesCore.h:92
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.
double f(double x)
EStatusBits
Definition: TObject.h:57
TApplicationServer(Int_t *argc, char **argv, FILE *flog, const char *logfile)
Main constructor.
TSocket * GetSocket() const
Int_t GetPort() const
Definition: TUrl.h:81
Int_t BrowseDirectory(const char *dirname)
Browse directory and send back its content to client.
Bool_t IsValid() const
Definition: file.py:1
void Reset(const char *dir)
Reset environment to be ready for execution of next command.
void ExecLogon()
Execute logon macro's.
const char * GetHost() const
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:39
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: RtypesCore.h:91