Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TApplicationRemote.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_TApplicationRemote
13 #define ROOT_TApplicationRemote
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TApplicationRemote //
18 // //
19 // TApplicationRemote maps a remote session. It starts a remote session //
20 // and takes care of redirecting the commands to be processed to the //
21 // remote session, to collect the graphic output objects and to display //
22 // them locally. //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #include "RRemoteProtocol.h"
27 #include "TApplication.h"
28 #include "TMD5.h"
29 #include "TUrl.h"
30 #include "TNamed.h"
31 #include "TMessage.h"
32 #include "TSysEvtHandler.h"
33 
34 
35 class THashList;
36 class TMonitor;
37 class TSocket;
38 class TBrowser;
39 class TRemoteObject;
40 class TSeqCollection;
41 
42 class TApplicationRemote : public TApplication {
43 
44 public:
45  enum ESendFileOpt {
46  kAscii = 0x0,
47  kBinary = 0x1,
48  kForce = 0x2
49  };
50  // TApplication specific bits
51  enum EStatusBits {
52  kCollecting = BIT(17) // TRUE while collecting from server
53  };
54 
55 private:
56  class TARFileStat : public TNamed {
57  public:
58  TARFileStat(const char *fn, TMD5 *md5, Long_t mt) :
59  TNamed(fn,fn), fMD5(*md5), fModtime(mt) { }
60  TMD5 fMD5; //file's md5
61  Long_t fModtime; //file's modification time
62  };
63 
64  TString fName; //Unique name identifying this instance
65  Int_t fProtocol; //server protocol version number
66  TUrl fUrl; //server's url
67  TSocket *fSocket; //socket connection to server
68  TMonitor *fMonitor; //monitor for the input socket
69  Bool_t fInterrupt; //flag interrupt state
70  TSignalHandler *fIntHandler; //interrupt signal handler (ctrl-c)
71 
72  TString fLogFilePath; //Full remote path to log file
73  THashList *fFileList; // List of files already uploaded
74 
75  TObject *fReceivedObject; // last received object
76  TSeqCollection *fRootFiles; // list of (remote) root files
77  TRemoteObject *fWorkingDir; // working (remote) directory
78 
79  static Int_t fgPortAttempts; // number of attempts to find a port
80  static Int_t fgPortLower; // lower bound for ports
81  static Int_t fgPortUpper; // upper bound for ports
82 
83  Int_t Broadcast(const TMessage &mess);
84  Int_t Broadcast(const char *mess, Int_t kind = kMESS_STRING, Int_t type = kRRT_Undef);
85  Int_t Broadcast(Int_t kind, Int_t type = kRRT_Undef) { return Broadcast(0, kind, type); }
86  Int_t BroadcastObject(const TObject *obj, Int_t kind = kMESS_OBJECT);
87  Int_t BroadcastRaw(const void *buffer, Int_t length);
88  Bool_t CheckFile(const char *file, Long_t modtime);
89  Int_t Collect(Long_t timeout = -1);
90  Int_t CollectInput();
91 
92  void RecvLogFile(Int_t size);
93 
94 public:
95  TApplicationRemote(const char *url, Int_t debug = 0, const char *script = 0);
96  virtual ~TApplicationRemote();
97 
98  virtual void Browse(TBrowser *b);
99  Bool_t IsFolder() const { return kTRUE; }
100  const char *ApplicationName() const { return fName; }
101  Long_t ProcessLine(const char *line, Bool_t /*sync*/ = kFALSE, Int_t *error = 0);
102 
103  Int_t SendFile(const char *file, Int_t opt = kAscii,
104  const char *rfile = 0);
105  Int_t SendObject(const TObject *obj);
106 
107  void Interrupt(Int_t type = kRRI_Hard);
108  Bool_t IsValid() const { return (fSocket) ? kTRUE : kFALSE; }
109 
110  void Print(Option_t *option="") const;
111 
112  void Terminate(Int_t status = 0);
113 
114  static void SetPortParam(Int_t lower = -1, Int_t upper = -1, Int_t attempts = -1);
115 
116  ClassDef(TApplicationRemote,0) //Remote Application Interface
117 };
118 
119 //
120 // TApplicationRemote Interrupt signal handler
121 //
122 class TARInterruptHandler : public TSignalHandler {
123 private:
124  TApplicationRemote *fApplicationRemote;
125 public:
126  TARInterruptHandler(TApplicationRemote *r)
127  : TSignalHandler(kSigInterrupt, kFALSE), fApplicationRemote(r) { }
128  Bool_t Notify();
129 };
130 
131 #endif