ROOT logo
// @(#)root/net:$Id: TApplicationServer.h 23091 2008-04-09 15:04:27Z rdm $
// Author: G. Ganis  10/5/2007

/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TApplicationServer
#define ROOT_TApplicationServer

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TApplicationServer                                                   //
//                                                                      //
// TApplicationServer is the remote application run by the roots main   //
// program. The input is taken from the socket connection to the client.//
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TApplication
#include "TApplication.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TSysEvtHandler
#include "TSysEvtHandler.h"
#endif
#ifndef ROOT_TUrl
#include "TUrl.h"
#endif

class TList;
class TMessage;
class TSocket;
class TRemoteObject;

class TApplicationServer : public TApplication {

private:
   Int_t         fProtocol;         //user protocol version number
   TUrl          fUrl;              //user's url
   TSocket      *fSocket;           //socket connection to user
   Bool_t        fIsValid;          //flag validity
   Bool_t        fInterrupt;        //flag interrupt state

   TString       fLogFilePath;      //Path to log file
   FILE         *fLogFile;          //log file
   Int_t         fLogFileDes;       //log file descriptor
   Bool_t        fRealTimeLog;      //TRUE if log messages should be send back in real-time

   TString       fSessId;           // Identifier for this session

   TString       fWorkDir;          // Working dir

   TList        *fSentCanvases;     // List of canvases already sent
   TRemoteObject *fWorkingDir;      // Working (remote) directory

   void          ExecLogon();
   Int_t         Setup();
   Int_t         SendCanvases();    // Send back to client any created canvas

protected:
   void          HandleCheckFile(TMessage *mess);

   static void   ErrorHandler(Int_t level, Bool_t abort, const char *location,
                              const char *msg);

public:
   TApplicationServer(Int_t *argc, char **argv, FILE *flog, const char *logfile);
   virtual ~TApplicationServer();

   void           GetOptions(Int_t *argc, char **argv);
   Int_t          GetProtocol() const   { return fProtocol; }
   Int_t          GetPort() const       { return fUrl.GetPort(); }
   const char    *GetUser() const       { return fUrl.GetUser(); }
   const char    *GetHost() const       { return fUrl.GetHost(); }
   TSocket       *GetSocket() const     { return fSocket; }

   void           HandleSocketInput();
   void           HandleUrgentData();
   void           HandleSigPipe();
   void           Interrupt() { fInterrupt = kTRUE; }
   Bool_t         IsValid() const { return fIsValid; }

   Long_t         ProcessLine(const char *line, Bool_t = kFALSE, Int_t *err = 0);

   void           Reset(const char *dir);
   Int_t          ReceiveFile(const char *file, Bool_t bin, Long64_t size);
   void           Run(Bool_t retrn = kFALSE);
   void           SendLogFile(Int_t status = 0, Int_t start = -1, Int_t end = -1);
   Int_t          BrowseDirectory(const char *dirname);
   Int_t          BrowseFile(const char *fname);
   Int_t          BrowseKey(const char *keyname);

   void           Terminate(Int_t status);

   ClassDef(TApplicationServer,0)  //Remote Application Interface
};


//----- Handles output from commands executed externally via a pipe. ---------//
//----- The output is redirected one level up (i.e., to master or client). ---//
//______________________________________________________________________________
class TASLogHandler : public TFileHandler {
private:
   TSocket     *fSocket; // Socket where to redirect the message
   FILE        *fFile;   // File connected with the open pipe
   TString      fPfx;    // Prefix to be prepended to messages

   static TString fgPfx; // Default prefix to be prepended to messages
public:
   enum EStatusBits { kFileIsPipe = BIT(23) };
   TASLogHandler(const char *cmd, TSocket *s, const char *pfx = "");
   TASLogHandler(FILE *f, TSocket *s, const char *pfx = "");
   virtual ~TASLogHandler();

   Bool_t IsValid() { return ((fFile && fSocket) ? kTRUE : kFALSE); }

   Bool_t Notify();
   Bool_t ReadNotify() { return Notify(); }

   static void SetDefaultPrefix(const char *pfx);
};

//--- Guard class: close pipe, deactivatethe related descriptor --------------//
//______________________________________________________________________________
class TASLogHandlerGuard {

private:
   TASLogHandler   *fExecHandler;

public:
   TASLogHandlerGuard(const char *cmd, TSocket *s,
                      const char *pfx = "", Bool_t on = kTRUE);
   TASLogHandlerGuard(FILE *f, TSocket *s,
                      const char *pfx = "", Bool_t on = kTRUE);
   virtual ~TASLogHandlerGuard();
};

#endif
 TApplicationServer.h:1
 TApplicationServer.h:2
 TApplicationServer.h:3
 TApplicationServer.h:4
 TApplicationServer.h:5
 TApplicationServer.h:6
 TApplicationServer.h:7
 TApplicationServer.h:8
 TApplicationServer.h:9
 TApplicationServer.h:10
 TApplicationServer.h:11
 TApplicationServer.h:12
 TApplicationServer.h:13
 TApplicationServer.h:14
 TApplicationServer.h:15
 TApplicationServer.h:16
 TApplicationServer.h:17
 TApplicationServer.h:18
 TApplicationServer.h:19
 TApplicationServer.h:20
 TApplicationServer.h:21
 TApplicationServer.h:22
 TApplicationServer.h:23
 TApplicationServer.h:24
 TApplicationServer.h:25
 TApplicationServer.h:26
 TApplicationServer.h:27
 TApplicationServer.h:28
 TApplicationServer.h:29
 TApplicationServer.h:30
 TApplicationServer.h:31
 TApplicationServer.h:32
 TApplicationServer.h:33
 TApplicationServer.h:34
 TApplicationServer.h:35
 TApplicationServer.h:36
 TApplicationServer.h:37
 TApplicationServer.h:38
 TApplicationServer.h:39
 TApplicationServer.h:40
 TApplicationServer.h:41
 TApplicationServer.h:42
 TApplicationServer.h:43
 TApplicationServer.h:44
 TApplicationServer.h:45
 TApplicationServer.h:46
 TApplicationServer.h:47
 TApplicationServer.h:48
 TApplicationServer.h:49
 TApplicationServer.h:50
 TApplicationServer.h:51
 TApplicationServer.h:52
 TApplicationServer.h:53
 TApplicationServer.h:54
 TApplicationServer.h:55
 TApplicationServer.h:56
 TApplicationServer.h:57
 TApplicationServer.h:58
 TApplicationServer.h:59
 TApplicationServer.h:60
 TApplicationServer.h:61
 TApplicationServer.h:62
 TApplicationServer.h:63
 TApplicationServer.h:64
 TApplicationServer.h:65
 TApplicationServer.h:66
 TApplicationServer.h:67
 TApplicationServer.h:68
 TApplicationServer.h:69
 TApplicationServer.h:70
 TApplicationServer.h:71
 TApplicationServer.h:72
 TApplicationServer.h:73
 TApplicationServer.h:74
 TApplicationServer.h:75
 TApplicationServer.h:76
 TApplicationServer.h:77
 TApplicationServer.h:78
 TApplicationServer.h:79
 TApplicationServer.h:80
 TApplicationServer.h:81
 TApplicationServer.h:82
 TApplicationServer.h:83
 TApplicationServer.h:84
 TApplicationServer.h:85
 TApplicationServer.h:86
 TApplicationServer.h:87
 TApplicationServer.h:88
 TApplicationServer.h:89
 TApplicationServer.h:90
 TApplicationServer.h:91
 TApplicationServer.h:92
 TApplicationServer.h:93
 TApplicationServer.h:94
 TApplicationServer.h:95
 TApplicationServer.h:96
 TApplicationServer.h:97
 TApplicationServer.h:98
 TApplicationServer.h:99
 TApplicationServer.h:100
 TApplicationServer.h:101
 TApplicationServer.h:102
 TApplicationServer.h:103
 TApplicationServer.h:104
 TApplicationServer.h:105
 TApplicationServer.h:106
 TApplicationServer.h:107
 TApplicationServer.h:108
 TApplicationServer.h:109
 TApplicationServer.h:110
 TApplicationServer.h:111
 TApplicationServer.h:112
 TApplicationServer.h:113
 TApplicationServer.h:114
 TApplicationServer.h:115
 TApplicationServer.h:116
 TApplicationServer.h:117
 TApplicationServer.h:118
 TApplicationServer.h:119
 TApplicationServer.h:120
 TApplicationServer.h:121
 TApplicationServer.h:122
 TApplicationServer.h:123
 TApplicationServer.h:124
 TApplicationServer.h:125
 TApplicationServer.h:126
 TApplicationServer.h:127
 TApplicationServer.h:128
 TApplicationServer.h:129
 TApplicationServer.h:130
 TApplicationServer.h:131
 TApplicationServer.h:132
 TApplicationServer.h:133
 TApplicationServer.h:134
 TApplicationServer.h:135
 TApplicationServer.h:136
 TApplicationServer.h:137
 TApplicationServer.h:138
 TApplicationServer.h:139
 TApplicationServer.h:140
 TApplicationServer.h:141
 TApplicationServer.h:142
 TApplicationServer.h:143
 TApplicationServer.h:144
 TApplicationServer.h:145