Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
XrdProofdClient.h
Go to the documentation of this file.
1 // @(#)root/proofd:$Id$
2 // Author: G. Ganis June 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, 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_XrdProofdClient
13 #define ROOT_XrdProofdClient
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // XrdProofdClient //
18 // //
19 // Author: G. Ganis, CERN, 2007 //
20 // //
21 // Auxiliary class describing a PROOF client. //
22 // Used by XrdProofdProtocol. //
23 // //
24 //////////////////////////////////////////////////////////////////////////
25 #include <list>
26 #include <vector>
27 
28 #include "XpdSysPthread.h"
29 
30 #include "XrdOuc/XrdOucString.hh"
31 
32 #include "XrdProofdAux.h"
33 #include "XrdProofdProtocol.h"
34 #include "XrdProofdResponse.h"
35 #include "XrdProofdSandbox.h"
36 
37 #define XPC_DEFMAXOLDLOGS 10
38 
39 class XrdNet;
40 class XrdClientID;
41 class XrdROOT;
42 
43 class XrdProofdClient {
44 
45  public:
46  XrdProofdClient(XrdProofUI ui,
47  bool master, bool changeown, XrdSysError *edest, const char *tmp, int rtime);
48 
49  virtual ~XrdProofdClient();
50 
51  inline const char *Group() const { return fUI.fGroup.c_str(); }
52  inline const char *User() const { return fUI.fUser.c_str(); }
53  inline bool IsValid() const { return fIsValid; }
54  bool Match(const char *usr, const char *grp = 0);
55  inline XrdSysRecMutex *Mutex() const { return (XrdSysRecMutex *)&fMutex; }
56  inline XrdROOT *ROOT() const { return fROOT; }
57  inline XrdProofdSandbox *Sandbox() const { return (XrdProofdSandbox *)&fSandbox; }
58  inline XrdProofUI UI() const { return fUI; }
59 
60  XrdProofdProofServ *GetServer(int psid);
61  XrdProofdProofServ *GetServer(XrdProofdProtocol *p);
62  void EraseServer(int psid);
63  int GetTopServers();
64 
65  int ResetClientSlot(int ic);
66  XrdProofdProtocol *GetProtocol(int ic);
67 
68  int GetClientID(XrdProofdProtocol *p);
69  int ReserveClientID(int cid);
70  int SetClientID(int cid, XrdProofdProtocol *p);
71  XrdProofdProofServ *GetFreeServObj();
72  XrdProofdProofServ *GetServObj(int id);
73 
74  void Broadcast(const char *msg);
75 
76  XrdOucString ExportSessions(XrdOucString &emsg, XrdProofdResponse *r = 0);
77  void SkipSessionsCheck(std::list<XrdProofdProofServ *> *active,
78  XrdOucString &emsg, XrdProofdResponse *r = 0);
79  void TerminateSessions(int srvtype, XrdProofdProofServ *ref,
80  const char *msg, XrdProofdPipe *pipe, bool changeown);
81  bool VerifySession(XrdProofdProofServ *xps, XrdProofdResponse *r = 0);
82 
83  void ResetSessions();
84 
85  void SetGroup(const char *g) { fUI.fGroup = g; }
86  void SetROOT(XrdROOT *r) { fROOT = r; }
87 
88  void SetValid(bool valid = 1) { fIsValid = valid; }
89 
90  int Size() const { return fClients.size(); }
91 
92  int Touch(bool reset = 0);
93 
94  int TrimSessionDirs() { return fSandbox.TrimSessionDirs(); }
95 
96  const char *AdminPath() const { return fAdminPath.c_str(); }
97 
98  private:
99 
100  XrdSysRecMutex fMutex; // Local mutex
101 
102  bool fChangeOwn; // TRUE if ownership must be changed where relevant
103  bool fIsValid; // TRUE if the instance is complete
104  bool fAskedToTouch; // TRUE if a touch request has already been sent for this client
105  int fReconnectTimeOut; // Time given for disconnected clients to reconnect
106 
107  XrdProofUI fUI; // user info
108  XrdROOT *fROOT; // ROOT vers instance to be used for proofserv
109 
110  XrdProofdSandbox fSandbox; // Clients sandbox
111 
112  XrdOucString fAdminPath; // Admin path for this client
113 
114  std::vector<XrdProofdProofServ *> fProofServs; // Allocated ProofServ sessions
115  std::vector<XrdClientID *> fClients; // Attached Client sessions
116 };
117 
118 //////////////////////////////////////////////////////////////////////////
119 // //
120 // XrdClientID //
121 // //
122 // Authors: G. Ganis, CERN, 2005 //
123 // //
124 // Mapping of clients and stream IDs //
125 // //
126 //////////////////////////////////////////////////////////////////////////
127 class XrdClientID {
128 private:
129  XrdProofdProtocol *fP;
130  XrdProofdResponse *fR;
131  unsigned short fSid;
132  int fResetTime;
133 
134  void SetR() { fR = (fP && fSid > 0) ? fP->Response(fSid) : 0;}
135 public:
136  XrdClientID(XrdProofdProtocol *pt = 0, unsigned short id = 0)
137  { fP = pt; fSid = id; SetR(); fResetTime = -1; }
138  ~XrdClientID() { }
139 
140  XrdProofdClient *C() const { return fP->Client(); }
141  bool IsValid() const { return (fP != 0); }
142  XrdProofdProtocol *P() const { return fP; }
143  XrdProofdResponse *R() const { return fR; }
144  void Reset() { fP = 0; fSid = 0; SetR(); fResetTime = time(0); }
145  int ResetTime() { return fResetTime; }
146  void SetP(XrdProofdProtocol *p) { fP = p; SetR();}
147  void SetSid(unsigned short sid) { fSid = sid; SetR();}
148  unsigned short Sid() const { return fSid; }
149 };
150 
151 #endif