annotate Framework/Messages/IObservable.cpp @ 959:13e078adfb94 toa2019082301

Better error log in fetch failure callback + timeout 600sec in OrthancRestApiCommand + guard against dead controller access in PanSceneTracker + relaxed DicomStructureSet AddReferenceSlice method to accept extraneous adds of the same slice (while trying to understand how it happens in the first place)
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 23 Aug 2019 14:16:45 +0200
parents f0008c55e5f7
children 38409549db43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
439
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 403
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "IObservable.h"
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include <Core/OrthancException.h>
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <cassert>
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 namespace OrthancStone
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 IObservable::~IObservable()
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 // delete all callables (this will also unregister them from the broker)
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 for (Callables::const_iterator it = callables_.begin();
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 it != callables_.end(); ++it)
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 for (std::set<ICallable*>::const_iterator
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 it2 = it->second.begin(); it2 != it->second.end(); ++it2)
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 delete *it2;
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 // unregister the forwarders but don't delete them (they'll be
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 // deleted by the observable they are observing as any other
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 // callable)
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 for (Forwarders::iterator it = forwarders_.begin();
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 it != forwarders_.end(); ++it)
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 IMessageForwarder* fw = *it;
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 broker_.Unregister(dynamic_cast<IObserver&>(*fw));
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 void IObservable::RegisterObserverCallback(ICallable* callable)
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 if (callable == NULL)
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
643
f0008c55e5f7 getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 623
diff changeset
62 const MessageIdentifier& id = callable->GetMessageIdentifier();
f0008c55e5f7 getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 623
diff changeset
63 callables_[id].insert(callable);
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
428
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
66 void IObservable::Unregister(IObserver *observer)
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
67 {
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
68 // delete all callables from this observer
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
69 for (Callables::iterator itCallableSet = callables_.begin();
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
70 itCallableSet != callables_.end(); ++itCallableSet)
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
71 {
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
72 for (std::set<ICallable*>::const_iterator
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
73 itCallable = itCallableSet->second.begin(); itCallable != itCallableSet->second.end(); )
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
74 {
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
75 if ((*itCallable)->GetObserver() == observer)
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
76 {
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
77 delete *itCallable;
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
78 itCallableSet->second.erase(itCallable++);
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
79 }
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
80 else
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
81 ++itCallable;
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
82 }
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
83 }
751fb354149e ability to change the scene of the RadiographyWidget
am@osimis.io
parents: 403
diff changeset
84 }
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
623
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
86 void IObservable::EmitMessageInternal(const IObserver* receiver,
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
87 const IMessage& message)
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
643
f0008c55e5f7 getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 623
diff changeset
89 Callables::const_iterator found = callables_.find(message.GetIdentifier());
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 if (found != callables_.end())
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 for (std::set<ICallable*>::const_iterator
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 it = found->second.begin(); it != found->second.end(); ++it)
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 assert(*it != NULL);
623
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
97
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
98 const IObserver* observer = (*it)->GetObserver();
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
99 if (broker_.IsActive(*observer))
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
623
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
101 if (receiver == NULL || // Are we broadcasting?
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
102 observer == receiver) // Not broadcasting, but this is the receiver
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
103 {
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
104 (*it)->Apply(message);
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
105 }
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
623
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
111
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
112 void IObservable::BroadcastMessage(const IMessage& message)
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
113 {
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
114 EmitMessageInternal(NULL, message);
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
115 }
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
116
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
117
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
118 void IObservable::EmitMessage(const IObserver& observer,
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
119 const IMessage& message)
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
120 {
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
121 EmitMessageInternal(&observer, message);
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
122 }
42dadae61fa9 renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 440
diff changeset
123
403
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 void IObservable::RegisterForwarder(IMessageForwarder* forwarder)
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 if (forwarder == NULL)
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 forwarders_.insert(forwarder);
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
99e31898910e IObservable.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }