Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TQConnection.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Valeriy Onuchin & Fons Rademakers 15/10/2000
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_TQConnection
13 #define ROOT_TQConnection
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TQConnection class is an internal class, used in the object //
18 // communication mechanism. //
19 // //
20 // TQConnection: //
21 // - is a list of signal_lists containing pointers //
22 // to this connection //
23 // - receiver is the object to which slot-method is applied //
24 // //
25 // This implementation is provided by //
26 // Valeriy Onuchin (onuchin@sirius.ihep.su). //
27 // //
28 //////////////////////////////////////////////////////////////////////////
29 
30 #include "TInterpreter.h"
31 #include "TQObject.h"
32 #include "TVirtualQConnection.h"
33 
34 class TQSlot;
35 
36 
37 class TQConnection : public TVirtualQConnection, public TQObject {
38 protected:
39  TQSlot *fSlot = 0; // slot-method calling interface
40  void *fReceiver = 0; // ptr to object to which slot is applied
41  TString fClassName; // class name of the receiver
42 
43  virtual void PrintCollectionHeader(Option_t* option) const override;
44 
45  Bool_t CheckSlot(Int_t nargs) const;
46  void *GetSlotAddress() const;
47  CallFunc_t *LockSlot() const;
48  void UnLockSlot(TQSlot *) const;
49  virtual CallFunc_t *GetSlotCallFunc() const override;
50 
51  TQConnection &operator=(const TQConnection &) = delete;
52 
53  virtual void SetArg(Long_t param) override { SetArgImpl(param); }
54  virtual void SetArg(ULong_t param) override { SetArgImpl(param); }
55  virtual void SetArg(Float_t param) override { SetArgImpl(param); }
56  virtual void SetArg(Double_t param) override { SetArgImpl(param); }
57  virtual void SetArg(Long64_t param) override { SetArgImpl(param); }
58  virtual void SetArg(ULong64_t param) override { SetArgImpl(param); }
59  virtual void SetArg(const char * param) override { SetArgImpl(param); }
60 
61  virtual void SetArg(const Long_t *params, Int_t nparam = -1) override;
62 
63  template <typename T> void SetArgImpl(T arg)
64  {
65  CallFunc_t *func = GetSlotCallFunc();
66  gInterpreter->CallFunc_SetArg(func, arg);
67  }
68 
69  virtual void SendSignal() override
70  {
71  CallFunc_t *func = LockSlot();
72 
73  void *address = GetSlotAddress();
74  TQSlot *s = fSlot;
75 
76  gInterpreter->CallFunc_Exec(func, address);
77 
78  UnLockSlot(s);
79  };
80 
81 public:
82  TQConnection() {}
83  TQConnection(TClass* cl, void *receiver, const char *method_name);
84  TQConnection(const char *class_name, void *receiver,
85  const char *method_name);
86  TQConnection(const TQConnection &con);
87  virtual ~TQConnection();
88 
89  const char *GetName() const override;
90  void *GetReceiver() const { return fReceiver; }
91  const char *GetClassName() const { return fClassName; }
92  void Destroyed() override; // *SIGNAL*
93 
94  void ExecuteMethod(Int_t nargs, va_list va) = delete;
95  template <typename... T> inline void ExecuteMethod(const T&... params)
96  {
97  if (!CheckSlot(sizeof...(params))) return;
98  SetArgs(params...);
99  SendSignal();
100  }
101 
102  template <typename... T> inline void ExecuteMethod(Int_t /* nargs */, const T&... params)
103  {
104  ExecuteMethod(params...);
105  }
106 
107  // FIXME: Remove and fallback to the variadic template.
108  // FIXME: Remove duplication of code in SendSignal and ExecuteMethod overloads.
109  void ExecuteMethod();
110  void ExecuteMethod(Long_t param);
111  void ExecuteMethod(Long64_t param);
112  void ExecuteMethod(Double_t param);
113  void ExecuteMethod(Long_t *params, Int_t nparam = -1);
114  void ExecuteMethod(const char *params);
115  void ls(Option_t *option="") const override;
116 
117  ClassDefOverride(TQConnection,0) // Internal class used in the object communication mechanism
118 };
119 
120 R__EXTERN char *gTQSlotParams; // used to pass string parameters
121 
122 #endif