GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4LinkProxy.cxx
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4LinkProxy.h"
15 
16 #include "TGo4ObjectManager.h"
17 
19  TGo4Proxy()
20 {
21 }
22 
24  TGo4Proxy(),
25  fLink(linkedslot)
26 {
27 }
28 
30 {
31 }
32 
34 {
35  auto om = slot->GetOM();
36  if (om)
37  om->RegisterLink(fLink, slot);
38 }
39 
41 {
42  auto om = slot->GetOM();
43  if (om) {
44  // this is workaround a problem, that in TGo4Slot destructor CleanProxy
45  // called before Event(this, evDelete)
46  // For that situation we retranslate evDelete message before link will dissaper from OM
47  if (slot->DoingDelete())
49 
50  om->UnregisterLink(slot);
51  }
52 }
53 
54 std::unique_ptr<TGo4Access> TGo4LinkProxy::ProvideAccess(const char *name)
55 {
56  return fLink ? fLink->ProvideSlotAccess(name) : nullptr;
57 }
58 
60 {
61  return fLink ? fLink->MakeLevelIter() : nullptr;
62 }
63 
64 void TGo4LinkProxy::WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs)
65 {
66  if (!onlyobjs) {
67  TString linkname;
68  if (fLink)
69  fLink->ProduceFullName(linkname);
70 
71  slot->SetPar("LinkProxy::LinkName", linkname.Length() > 0 ? linkname.Data() : nullptr);
72  }
73 }
74 
75 void TGo4LinkProxy::ReadData(TGo4Slot *slot, TDirectory *dir)
76 {
77  const char *linkname = slot->GetPar("LinkProxy::LinkName");
78  if (linkname)
79  fLink = slot->GetOM()->GetSlot(linkname);
80 }
81 
83 {
85 }
86 
88 {
89  return fLink ? fLink->GetSlotClassName() : nullptr;
90 }
91 
92 Bool_t TGo4LinkProxy::IsAcceptObject(TClass *cl) const
93 {
94  return fLink ? fLink->IsAcceptObject(cl) : kFALSE;
95 }
96 
97 Bool_t TGo4LinkProxy::AssignObject(TGo4Slot *slot, TObject *obj, Bool_t owner)
98 {
99  return fLink ? fLink->AssignObject(obj, owner) : kFALSE;
100 }
101 
103 {
104  return fLink ? fLink->GetAssignedObject() : nullptr;
105 }
106 
107 Bool_t TGo4LinkProxy::ProcessEvent(TGo4Slot *slot, TGo4Slot *source, Int_t id, void *param)
108 {
109  if ((id == TGo4Slot::evDelete) && (source == fLink)) {
110  // next line very important.
111  // If master slot says that it will be deleted, we just
112  // brake dependency from it and "forgot" that it is existing
113  // As a result, access to master object will be canceled
114  // After we delete slot with our link proxy.
115  // For instance, if marker is assigned to histogram, and histogram
116  // is deleted (file closed), marker cannot access histogram pointer
117  // and will be reassigned to null histogram even when master slot is
118  // able to provide histogram pointer.
119  fLink = nullptr;
120  slot->Delete();
121 // delete slot;
122  // we delete slot with timer afterwards
123 
124 // TGo4ObjectManager *om = slot->GetOM();
125  // om->UnregisterLink(slot);
126 // om->DeleteObject(slot);
127 
128 // slot->ForwardEvent(slot, TGo4Slot::evObjDeleted);
129 
130  return kFALSE;
131  }
132 
133  // emulate that message come from this slot, not from master link
134  slot->ForwardEvent(slot, id, param);
135 
136  return kFALSE;
137 }
std::unique_ptr< TGo4Access > ProvideAccess(const char *name) override
Bool_t IsAcceptObject(TClass *cl) const
Definition: TGo4Slot.cxx:339
Bool_t IsAcceptObject(TClass *cl) const override
TGo4Slot * fLink
Definition: TGo4LinkProxy.h:48
void Initialize(TGo4Slot *slot) override
virtual ~TGo4LinkProxy()
TGo4LevelIter * MakeLevelIter() const
Definition: TGo4Slot.cxx:382
void WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs) override
void RegisterLink(TGo4Slot *source, TGo4Slot *target, Bool_t exapndchilds=kFALSE)
Int_t GetObjectKind() const override
TObject * GetAssignedObject()
Definition: TGo4Slot.cxx:356
Bool_t DoingDelete() const
Definition: TGo4Slot.h:125
Bool_t AssignObject(TGo4Slot *slot, TObject *obj, Bool_t owner) override
TGo4Slot * GetSlot(const char *name, Bool_t force=kFALSE)
Definition: TGo4Slot.cxx:451
TGo4LevelIter * MakeIter() override
void RetranslateEvent(TGo4Slot *source, Int_t id, void *param=nullptr)
const char * GetPar(const char *name) const
Definition: TGo4Slot.cxx:598
std::unique_ptr< TGo4Access > ProvideSlotAccess(const char *name)
Definition: TGo4Slot.cxx:395
void ReadData(TGo4Slot *slot, TDirectory *dir) override
Bool_t AssignObject(TObject *obj, Bool_t owner)
Definition: TGo4Slot.cxx:344
void ForwardEvent(TGo4Slot *source, Int_t id, void *param=nullptr)
Definition: TGo4Slot.cxx:565
void Finalize(TGo4Slot *slot) override
const char * GetSlotClassName() const
Definition: TGo4Slot.cxx:334
const char * GetContainedClassName() const override
virtual TGo4ObjectManager * GetOM() const
Definition: TGo4Slot.cxx:282
TObject * GetAssignedObject() override
void Delete(Option_t *opt="") override
Definition: TGo4Slot.cxx:171
void SetPar(const char *name, const char *value)
Definition: TGo4Slot.cxx:586
Bool_t ProcessEvent(TGo4Slot *slot, TGo4Slot *source, Int_t id, void *param) override
Int_t GetSlotKind() const
Definition: TGo4Slot.cxx:329
virtual void ProduceFullName(TString &name, TGo4Slot *toparent=nullptr)
Definition: TGo4Slot.cxx:264