Logo ROOT   6.08/07
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 #ifndef ROOT_TNamed
32 #include "TNamed.h"
33 #endif
34 #ifndef ROOT_TQObject
35 #include "TQObject.h"
36 #endif
37 
38 class TMessageHandler : public TNamed, public TQObject {
39 
40 protected:
41  const TClass *fClass; // class for which message has to be handled
42  const TObject *fMessObj; // object generating message
43  Int_t fMessId; // message id (often matching specific enum in fClass)
44  Int_t fSize; // number of different messages handled
45  Int_t *fCnts; // count per message
46  Int_t *fMessIds; // message ids
47  Bool_t fDerived; // if true handle messages also for derived classes
48 
49  void *GetSender() { return this; } //used to set gTQSender
50 
51 public:
52  TMessageHandler(const TClass *cl, Bool_t derived = kTRUE);
53  TMessageHandler(const char *cl, Bool_t derived = kTRUE);
54  virtual ~TMessageHandler();
55 
56  Int_t GetSize() const { return fSize; }
57  virtual Int_t GetMessageCount(Int_t messId) const;
58  virtual Int_t GetTotalMessageCount() const;
59  Bool_t HandleDerived() const { return fDerived; }
60  virtual void HandleMessage(Int_t id, const TObject *obj);
61 
62  virtual void Print(Option_t *option= "") const;
63 
64  virtual void Add();
65  virtual void Remove();
66  virtual Bool_t Notify();
67 
68  virtual void Added() { Emit("Added()"); } //*SIGNAL*
69  virtual void Removed() { Emit("Removed()"); } //*SIGNAL*
70  virtual void Notified() { Emit("Notified()"); } //*SIGNAL*
71 
72  ClassDef(TMessageHandler,0) // Generic message handler
73 };
74 
75 #endif
virtual Int_t GetMessageCount(Int_t messId) const
Return counter for message with ID=messid.
Handle messages that might be generated by the system.
const char Option_t
Definition: RtypesCore.h:62
virtual void Removed()
virtual void Add()
Add this message handler to the list of messages handlers.
virtual void HandleMessage(Int_t id, const TObject *obj)
Store message origin, keep statistics and call Notify().
This is the ROOT implementation of the Qt object communication mechanism (see also http://www...
Definition: TQObject.h:53
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:254
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:561
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Bool_t HandleDerived() const
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual void Notified()
virtual ~TMessageHandler()
Clean up the message handler.
virtual void Added()
virtual void Print(Option_t *option="") const
Print statistics for this message handler.
virtual void Remove()
Remove this message handler from the list of messages handlers.
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Int_t GetTotalMessageCount() const
Return total number of messages.
Int_t GetSize() const
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.
const Bool_t kTRUE
Definition: Rtypes.h:91
const TObject * fMessObj
const TClass * fClass