// @(#)root/proof:$Id$
// Author: Fons Rademakers   14/02/97

/*************************************************************************
 * Copyright (C) 1995-2000, 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_TSlave
#define ROOT_TSlave


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TSlave                                                               //
//                                                                      //
// This class describes a PROOF slave server.                           //
// It contains information like the slaves host name, ordinal number,   //
// performance index, socket, etc. Objects of this class can only be    //
// created via TProof member functions.                                 //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif

class TFileHandler;
class TObjString;
class TProof;
class TSlave;
class TSocket;

// Special type for the hook to external function setting up authentication
// related stuff for old versions. For backward compatibility.
typedef Int_t (*OldSlaveAuthSetup_t)(TSocket *, Bool_t, TString, TString);

// Special type for the hook to the TSlave constructor, needed to avoid
// using the plugin manager
typedef TSlave *(*TSlave_t)(const char *url, const char *ord, Int_t perf,
                            const char *image, TProof *proof, Int_t stype,
                            const char *workdir, const char *msd, Int_t nwk);

class TSlave : public TObject {

friend class TProof;
friend class TProofLite;
friend class TSlaveLite;
friend class TXSlave;

public:

   enum ESlaveType { kMaster, kSlave };
   enum ESlaveStatus { kInvalid, kActive, kInactive };
   enum EStatusBits {
      kOutputRequested = BIT(15)       // If output has been requested
   };

private:

   static TSlave_t fgTXSlaveHook;

   TSlave(const TSlave &s) : TObject(s) { }
   TSlave(const char *host, const char *ord, Int_t perf,
          const char *image, TProof *proof, Int_t stype,
          const char *workdir, const char *msd, Int_t = 1);

   Int_t  OldAuthSetup(Bool_t master, TString wconf);
   void   Init(const char *host, Int_t port, Int_t stype);
   void   operator=(const TSlave &) { }

   static TSlave *Create(const char *url, const char *ord, Int_t perf,
                         const char *image, TProof *proof, Int_t stype,
                         const char *workdir, const char *msd, Int_t nwk = 1);

protected:
   TString       fName;      //slave's hostname
   TString       fImage;     //slave's image name
   TString       fProofWorkDir; //base proofserv working directory (info obtained from slave)
   TString       fWorkDir;   //slave's working directory (info obtained from slave)
   TString       fUser;      //slave's user id
   TString       fGroup;     //slave's group id
   Int_t         fPort;      //slave's port number
   TString       fOrdinal;   //slave's ordinal number
   Int_t         fPerfIdx;   //relative CPU performance index
   Int_t         fProtocol;  //slave's protocol level
   TSocket      *fSocket;    //socket to slave
   TProof       *fProof;     //proof cluster to which slave belongs
   TFileHandler *fInput;     //input handler related to this slave
   Long64_t      fBytesRead; //bytes read by slave (info is obtained from slave)
   Float_t       fRealTime;  //real time spent executing commands (info obtained from slave)
   Float_t       fCpuTime;   //CPU time spent executing commands (info obtained from slave)
   ESlaveType    fSlaveType; //type of slave (either kMaster or kSlave)
   Int_t         fStatus;    //remote return status
   Int_t         fParallel;  //number of active slaves
   TString       fMsd;       //mass storage domain of slave
   TString       fSessionTag;//unique tag for ths worker process

   TString       fROOTVers;  //ROOT version run by worker
   TString       fArchComp;  //Build architecture, compiler on worker (e.g. linux-gcc345)

   TSlave();
   virtual void  FlushSocket() { }
   void          Init(TSocket *s, Int_t stype);
   virtual void  Interrupt(Int_t type);
   virtual Int_t Ping();
   virtual TObjString *SendCoordinator(Int_t kind, const char *msg = 0, Int_t int2 = 0);
   virtual Int_t SendGroupPriority(const char * /*grp*/, Int_t /*priority*/) { return 0; }
   virtual void  SetAlias(const char *alias);
   void          SetSocket(TSocket *s) { fSocket = s; }
   virtual void  SetStatus(Int_t st) { fStatus = st; }
   virtual void  StopProcess(Bool_t abort, Int_t timeout);

public:
   virtual ~TSlave();

   virtual void   Close(Option_t *opt = "");

   Int_t          Compare(const TObject *obj) const;
   Bool_t         IsSortable() const { return kTRUE; }

   const char    *GetName() const { return fName; }
   const char    *GetImage() const { return fImage; }
   const char    *GetProofWorkDir() const { return fProofWorkDir; }
   const char    *GetWorkDir() const { return fWorkDir; }
   const char    *GetUser() const { return fUser; }
   const char    *GetGroup() const { return fGroup; }
   Int_t          GetPort() const { return fPort; }
   const char    *GetOrdinal() const { return fOrdinal; }
   Int_t          GetPerfIdx() const { return fPerfIdx; }
   Int_t          GetProtocol() const { return fProtocol; }
   TSocket       *GetSocket() const { return fSocket; }
   TProof        *GetProof() const { return fProof; }
   Long64_t       GetBytesRead() const { return fBytesRead; }
   Float_t        GetRealTime() const { return fRealTime; }
   Float_t        GetCpuTime() const { return fCpuTime; }
   Int_t          GetSlaveType() const { return (Int_t)fSlaveType; }
   Int_t          GetStatus() const { return fStatus; }
   Int_t          GetParallel() const { return fParallel; }
   const char    *GetMsd() const { return fMsd; }
   const char    *GetSessionTag() const { return fSessionTag; }
   TFileHandler  *GetInputHandler() const { return fInput; }
   void           SetInputHandler(TFileHandler *ih);

   const char    *GetArchCompiler() const { return fArchComp; }
   const char    *GetROOTVersion() const { return fROOTVers; }

   virtual Bool_t IsValid() const { return fSocket ? kTRUE : kFALSE; }

   virtual void   Print(Option_t *option="") const;

   virtual Int_t  SetupServ(Int_t stype, const char *conffile);

   virtual void   SetInterruptHandler(Bool_t /* on */) { }

   void           SetArchCompiler(const char *ac) { fArchComp = ac; }
   void           SetROOTVersion(const char *rv) { fROOTVers = rv; }

   void           SetSessionTag(const char *st) { fSessionTag = st; }

   static void    SetTXSlaveHook(TSlave_t xslavehook);

   virtual void   Touch() { }

   ClassDef(TSlave,0)  //PROOF slave server
};

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