Logo ROOT  
Reference Guide
TMessageHandler.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Rene Brun 11/11/99
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_TMessageHandler
13 #define ROOT_TMessageHandler
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TMessageHandler //
19 // //
20 // Handle messages that might be generated by the system. //
21 // By default a handler only keeps track of the different messages //
22 // generated for a specific class. By deriving from this class and //
23 // overriding Notify() one can implement custom message handling. //
24 // In Notify() one has access to the message id and the object //
25 // generating the message. One can install more than one message //
26 // handler per class. A message handler can be removed or again //
27 // added when needed. //
28 // //
29 //////////////////////////////////////////////////////////////////////////
30 
31 #include "TNamed.h"
32 #include "TQObject.h"
33 
34 class TMessageHandler : public TNamed, public TQObject {
35 
36 protected:
37  const TClass *fClass; // class for which message has to be handled
38  const TObject *fMessObj; // object generating message
39  Int_t fMessId; // message id (often matching specific enum in fClass)
40  Int_t fSize; // number of different messages handled
41  Int_t *fCnts; // count per message
42  Int_t *fMessIds; // message ids
43  Bool_t fDerived; // if true handle messages also for derived classes
44 
45  void *GetSender() { return this; } //used to set gTQSender
46 
47 public:
48  TMessageHandler(const TClass *cl, Bool_t derived = kTRUE);
49  TMessageHandler(const char *cl, Bool_t derived = kTRUE);
50  virtual ~TMessageHandler();
51 
52  Int_t GetSize() const { return fSize; }
53  virtual Int_t GetMessageCount(Int_t messId) const;
54  virtual Int_t GetTotalMessageCount() const;
55  Bool_t HandleDerived() const { return fDerived; }
56  virtual void HandleMessage(Int_t id, const TObject *obj);
57 
58  virtual void Print(Option_t *option= "") const;
59 
60  virtual void Add();
61  virtual void Remove();
62  virtual Bool_t Notify();
63 
64  virtual void Added() { Emit("Added()"); } //*SIGNAL*
65  virtual void Removed() { Emit("Removed()"); } //*SIGNAL*
66  virtual void Notified() { Emit("Notified()"); } //*SIGNAL*
67 
68  ClassDef(TMessageHandler,0) // Generic message handler
69 };
70 
71 #endif
TMessageHandler::HandleMessage
virtual void HandleMessage(Int_t id, const TObject *obj)
Store message origin, keep statistics and call Notify().
Definition: TMessageHandler.cxx:133
TMessageHandler
Handle messages that might be generated by the system.
Definition: TMessageHandler.h:34
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TMessageHandler::HandleDerived
Bool_t HandleDerived() const
Definition: TMessageHandler.h:55
TMessageHandler::~TMessageHandler
virtual ~TMessageHandler()
Clean up the message handler.
Definition: TMessageHandler.cxx:82
Option_t
const char Option_t
Definition: RtypesCore.h:66
TMessageHandler::Notified
virtual void Notified()
Definition: TMessageHandler.h:66
TNamed.h
TMessageHandler::Added
virtual void Added()
Definition: TMessageHandler.h:64
Int_t
int Int_t
Definition: RtypesCore.h:45
TMessageHandler::fMessObj
const TObject * fMessObj
Definition: TMessageHandler.h:38
TMessageHandler::GetMessageCount
virtual Int_t GetMessageCount(Int_t messId) const
Return counter for message with ID=messid.
Definition: TMessageHandler.cxx:108
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
bool
TMessageHandler::fDerived
Bool_t fDerived
Definition: TMessageHandler.h:43
TMessageHandler::fSize
Int_t fSize
Definition: TMessageHandler.h:40
TMessageHandler::fMessIds
Int_t * fMessIds
Definition: TMessageHandler.h:42
TMessageHandler::TMessageHandler
TMessageHandler(const TClass *cl, Bool_t derived=kTRUE)
Create a new message handler for class cl and add it to the list of message handlers.
Definition: TMessageHandler.cxx:41
TQObject.h
TQObject
This is the ROOT implementation of the Qt object communication mechanism (see also http://www....
Definition: TQObject.h:48
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
TMessageHandler::fMessId
Int_t fMessId
Definition: TMessageHandler.h:39
TMessageHandler::fClass
const TClass * fClass
Definition: TMessageHandler.h:37
TMessageHandler::GetSize
Int_t GetSize() const
Definition: TMessageHandler.h:52
TMessageHandler::Notify
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition: TMessageHandler.cxx:184
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TMessageHandler::fCnts
Int_t * fCnts
Definition: TMessageHandler.h:41
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TMessageHandler::GetTotalMessageCount
virtual Int_t GetTotalMessageCount() const
Return total number of messages.
Definition: TMessageHandler.cxx:120
TMessageHandler::Print
virtual void Print(Option_t *option="") const
Print statistics for this message handler.
Definition: TMessageHandler.cxx:200
TMessageHandler::Removed
virtual void Removed()
Definition: TMessageHandler.h:65
TMessageHandler::Add
virtual void Add()
Add this message handler to the list of messages handlers.
Definition: TMessageHandler.cxx:93
TMessageHandler::Remove
virtual void Remove()
Remove this message handler from the list of messages handlers.
Definition: TMessageHandler.cxx:235
TQObject::Emit
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TMessageHandler::GetSender
void * GetSender()
Definition: TMessageHandler.h:45
int