Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TMonitor.h
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Fons Rademakers 09/01/97
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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_TMonitor
13 #define ROOT_TMonitor
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TMonitor //
19 // //
20 // This class monitors activity on a number of network sockets. //
21 // The actual monitoring is done by TSystem::DispatchOneEvent(). //
22 // Typical usage: create a TMonitor object. Register a number of //
23 // TSocket objects and call TMonitor::Select(). Select() returns the //
24 // socket object which has data waiting. TSocket objects can be added, //
25 // removed, (temporary) enabled or disabled. //
26 // //
27 //////////////////////////////////////////////////////////////////////////
28 
29 #include "TObject.h"
30 #include "TQObject.h"
31 
32 class TList;
33 class TSocket;
34 
35 
36 class TMonitor : public TObject, public TQObject {
37 
38 friend class TSocketHandler;
39 friend class TTimeOutTimer;
40 friend class TXSlave;
41 friend class TXSocket;
42 
43 private:
44  TList *fActive; //list of sockets to monitor
45  TList *fDeActive; //list of (temporary) disabled sockets
46  TSocket *fReady; //socket which is ready to be read or written
47  Bool_t fMainLoop; //true if monitoring sockets within the main event loop
48  Bool_t fInterrupt; //flags an interrupt to Select
49 
50  void SetReady(TSocket *sock);
51  void *GetSender() { return this; } // used to get gTQSender
52 
53 public:
54  enum EInterest { kRead = 1, kWrite = 2 };
55 
56  TMonitor(Bool_t mainloop = kTRUE);
57  TMonitor(const TMonitor &m);
58  virtual ~TMonitor();
59 
60  virtual void Add(TSocket *sock, Int_t interest = kRead);
61  virtual void SetInterest(TSocket *sock, Int_t interest = kRead);
62  virtual void Remove(TSocket *sock);
63  virtual void RemoveAll();
64 
65  virtual void Activate(TSocket *sock);
66  virtual void ActivateAll();
67  virtual void DeActivate(TSocket *sock);
68  virtual void DeActivateAll();
69  virtual void Ready(TSocket *sock); // *SIGNAL*
70 
71  void Interrupt() { fInterrupt = kTRUE; }
72  void ResetInterrupt() { fInterrupt = kFALSE; }
73 
74  TSocket *Select();
75  TSocket *Select(Long_t timeout);
76  Int_t Select(TList *rdready, TList *wrready, Long_t timeout);
77 
78  Int_t GetActive(Long_t timeout = -1) const;
79  Int_t GetDeActive() const;
80  TList *GetListOfActives() const;
81  TList *GetListOfDeActives() const;
82 
83  Bool_t IsActive(TSocket *s) const;
84 
85  ClassDef(TMonitor,0) //Monitor activity on a set of TSocket objects
86 };
87 
88 #endif