annotate Framework/Messages/IObserver.cpp @ 1284:1bb54005e2bd bugs/2020-02-invisible-slice

merged default into branch
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 11 Feb 2020 14:38:36 +0100
parents db759fb1d6e6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1048
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1262
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
1048
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "IObserver.h"
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "IMessage.h"
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../StoneException.h"
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <Core/Logging.h>
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <Core/Toolbox.h>
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 namespace OrthancStone
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 {
1262
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
32 static const uint64_t IObserver_FIRST_UNIQUE_ID = 10973;
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
33 static uint64_t IObserver_nextUniqueId = IObserver_FIRST_UNIQUE_ID;
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
34
1048
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 IObserver::IObserver(MessageBroker& broker)
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 : broker_(broker)
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
1262
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
38 AssignFingerprint();
1048
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 broker_.Register(*this);
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 IObserver::~IObserver()
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 try
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
1262
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
46 LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::~IObserver : fingerprint_[0] == " << fingerprint_[0];
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
47 fingerprint_[0] = 0xdeadbeef;
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
48 fingerprint_[1] = 0xdeadbeef;
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
49 fingerprint_[2] = 0xdeadbeef;
1048
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 broker_.Unregister(*this);
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 catch (const Orthanc::OrthancException& e)
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 if (e.HasDetails())
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 LOG(ERROR) << "OrthancException in ~IObserver: " << e.What() << " Details: " << e.GetDetails();
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 else
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 LOG(ERROR) << "OrthancException in ~IObserver: " << e.What();
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 catch (const std::exception& e)
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 LOG(ERROR) << "std::exception in ~IObserver: " << e.what();
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 catch (...)
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 LOG(ERROR) << "Unknown exception in ~IObserver";
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
1262
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
73 static const int64_t IObserver_UNIQUE_ID_MAGIC_NUMBER = 2742024;
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
74
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
75 void IObserver::AssignFingerprint()
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
76 {
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
77 fingerprint_[0] = IObserver_nextUniqueId;
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
78 fingerprint_[1] = fingerprint_[0] / 2;
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
79 fingerprint_[2] = fingerprint_[1] + IObserver_UNIQUE_ID_MAGIC_NUMBER;
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
80 IObserver_nextUniqueId++;
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
81 }
1048
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 bool IObserver::DoesFingerprintLookGood() const
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
1276
db759fb1d6e6 Added debug message if observer invalid
Benjamin Golinvaux <bgo@osimis.io>
parents: 1270
diff changeset
85 bool ok = (fingerprint_[0] >= IObserver_FIRST_UNIQUE_ID) &&
1262
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
86 (fingerprint_[1] == fingerprint_[0] / 2) &&
ca2058bd74ef Changed fingerprint from uuid_t to int64_t + poor man's
Benjamin Golinvaux <bgo@osimis.io>
parents: 1048
diff changeset
87 (fingerprint_[2] == fingerprint_[1] + IObserver_UNIQUE_ID_MAGIC_NUMBER);
1276
db759fb1d6e6 Added debug message if observer invalid
Benjamin Golinvaux <bgo@osimis.io>
parents: 1270
diff changeset
88 if(!ok)
db759fb1d6e6 Added debug message if observer invalid
Benjamin Golinvaux <bgo@osimis.io>
parents: 1270
diff changeset
89 {
db759fb1d6e6 Added debug message if observer invalid
Benjamin Golinvaux <bgo@osimis.io>
parents: 1270
diff changeset
90 LOG(INFO) << "Fingerprint not valid: " << " fingerprint_[0] = " << fingerprint_[0] << " fingerprint_[1] = " << fingerprint_[1]<< " fingerprint_[2] = " << fingerprint_[2];
db759fb1d6e6 Added debug message if observer invalid
Benjamin Golinvaux <bgo@osimis.io>
parents: 1270
diff changeset
91 }
db759fb1d6e6 Added debug message if observer invalid
Benjamin Golinvaux <bgo@osimis.io>
parents: 1270
diff changeset
92 return ok;
1048
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 }
f6be9412e42a cleaning up IObservable.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }