TApplicationServer.h

Go to the documentation of this file.
00001 // @(#)root/net:$Id: TApplicationServer.h 23091 2008-04-09 15:04:27Z rdm $
00002 // Author: G. Ganis  10/5/2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TApplicationServer
00013 #define ROOT_TApplicationServer
00014 
00015 //////////////////////////////////////////////////////////////////////////
00016 //                                                                      //
00017 // TApplicationServer                                                   //
00018 //                                                                      //
00019 // TApplicationServer is the remote application run by the roots main   //
00020 // program. The input is taken from the socket connection to the client.//
00021 //                                                                      //
00022 //////////////////////////////////////////////////////////////////////////
00023 
00024 #ifndef ROOT_TApplication
00025 #include "TApplication.h"
00026 #endif
00027 #ifndef ROOT_TString
00028 #include "TString.h"
00029 #endif
00030 #ifndef ROOT_TSysEvtHandler
00031 #include "TSysEvtHandler.h"
00032 #endif
00033 #ifndef ROOT_TUrl
00034 #include "TUrl.h"
00035 #endif
00036 
00037 class TList;
00038 class TMessage;
00039 class TSocket;
00040 class TRemoteObject;
00041 
00042 class TApplicationServer : public TApplication {
00043 
00044 private:
00045    Int_t         fProtocol;         //user protocol version number
00046    TUrl          fUrl;              //user's url
00047    TSocket      *fSocket;           //socket connection to user
00048    Bool_t        fIsValid;          //flag validity
00049    Bool_t        fInterrupt;        //flag interrupt state
00050 
00051    TString       fLogFilePath;      //Path to log file
00052    FILE         *fLogFile;          //log file
00053    Int_t         fLogFileDes;       //log file descriptor
00054    Bool_t        fRealTimeLog;      //TRUE if log messages should be send back in real-time
00055 
00056    TString       fSessId;           // Identifier for this session
00057 
00058    TString       fWorkDir;          // Working dir
00059 
00060    TList        *fSentCanvases;     // List of canvases already sent
00061    TRemoteObject *fWorkingDir;      // Working (remote) directory
00062 
00063    void          ExecLogon();
00064    Int_t         Setup();
00065    Int_t         SendCanvases();    // Send back to client any created canvas
00066 
00067 protected:
00068    void          HandleCheckFile(TMessage *mess);
00069 
00070    static void   ErrorHandler(Int_t level, Bool_t abort, const char *location,
00071                               const char *msg);
00072 
00073 public:
00074    TApplicationServer(Int_t *argc, char **argv, FILE *flog, const char *logfile);
00075    virtual ~TApplicationServer();
00076 
00077    void           GetOptions(Int_t *argc, char **argv);
00078    Int_t          GetProtocol() const   { return fProtocol; }
00079    Int_t          GetPort() const       { return fUrl.GetPort(); }
00080    const char    *GetUser() const       { return fUrl.GetUser(); }
00081    const char    *GetHost() const       { return fUrl.GetHost(); }
00082    TSocket       *GetSocket() const     { return fSocket; }
00083 
00084    void           HandleSocketInput();
00085    void           HandleUrgentData();
00086    void           HandleSigPipe();
00087    void           Interrupt() { fInterrupt = kTRUE; }
00088    Bool_t         IsValid() const { return fIsValid; }
00089 
00090    Long_t         ProcessLine(const char *line, Bool_t = kFALSE, Int_t *err = 0);
00091 
00092    void           Reset(const char *dir);
00093    Int_t          ReceiveFile(const char *file, Bool_t bin, Long64_t size);
00094    void           Run(Bool_t retrn = kFALSE);
00095    void           SendLogFile(Int_t status = 0, Int_t start = -1, Int_t end = -1);
00096    Int_t          BrowseDirectory(const char *dirname);
00097    Int_t          BrowseFile(const char *fname);
00098    Int_t          BrowseKey(const char *keyname);
00099 
00100    void           Terminate(Int_t status);
00101 
00102    ClassDef(TApplicationServer,0)  //Remote Application Interface
00103 };
00104 
00105 
00106 //----- Handles output from commands executed externally via a pipe. ---------//
00107 //----- The output is redirected one level up (i.e., to master or client). ---//
00108 //______________________________________________________________________________
00109 class TASLogHandler : public TFileHandler {
00110 private:
00111    TSocket     *fSocket; // Socket where to redirect the message
00112    FILE        *fFile;   // File connected with the open pipe
00113    TString      fPfx;    // Prefix to be prepended to messages
00114 
00115    static TString fgPfx; // Default prefix to be prepended to messages
00116 public:
00117    enum EStatusBits { kFileIsPipe = BIT(23) };
00118    TASLogHandler(const char *cmd, TSocket *s, const char *pfx = "");
00119    TASLogHandler(FILE *f, TSocket *s, const char *pfx = "");
00120    virtual ~TASLogHandler();
00121 
00122    Bool_t IsValid() { return ((fFile && fSocket) ? kTRUE : kFALSE); }
00123 
00124    Bool_t Notify();
00125    Bool_t ReadNotify() { return Notify(); }
00126 
00127    static void SetDefaultPrefix(const char *pfx);
00128 };
00129 
00130 //--- Guard class: close pipe, deactivatethe related descriptor --------------//
00131 //______________________________________________________________________________
00132 class TASLogHandlerGuard {
00133 
00134 private:
00135    TASLogHandler   *fExecHandler;
00136 
00137 public:
00138    TASLogHandlerGuard(const char *cmd, TSocket *s,
00139                       const char *pfx = "", Bool_t on = kTRUE);
00140    TASLogHandlerGuard(FILE *f, TSocket *s,
00141                       const char *pfx = "", Bool_t on = kTRUE);
00142    virtual ~TASLogHandlerGuard();
00143 };
00144 
00145 #endif

Generated on Tue Jul 5 14:26:30 2011 for ROOT_528-00b_version by  doxygen 1.5.1