annotate Framework/Messages/IObserver.h @ 976:3abc47e051c8

Added tag toa2019083101 for changeset e75fd08d6c75
author Benjamin Golinvaux <bgo@osimis.io>
date Sat, 31 Aug 2019 13:50:11 +0200
parents e75fd08d6c75
children 262a0244e9b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
1 /**
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
439
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 393
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
6 *
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
11 *
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
16 *
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
19 **/
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
20
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
21
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
22 #pragma once
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
23
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
24 #include "MessageBroker.h"
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 250
diff changeset
25 #include "IMessage.h"
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
26
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
27 #include <Core/Toolbox.h>
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
28
393
e7a494bdd956 removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 300
diff changeset
29 namespace OrthancStone
e7a494bdd956 removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 300
diff changeset
30 {
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
31 class IObserver : public boost::noncopyable
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
32 {
393
e7a494bdd956 removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 300
diff changeset
33 private:
e7a494bdd956 removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 300
diff changeset
34 MessageBroker& broker_;
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
35 // the following is a UUID that is used to disambiguate different observers
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
36 // that may have the same address
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
37 char fingerprint_[37];
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
38 public:
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
39 IObserver(MessageBroker& broker)
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
40 : broker_(broker)
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
41 , fingerprint_()
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
42 {
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
43 // we store the fingerprint_ as a char array to avoid problems when
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
44 // reading it in a deceased object.
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
45 // remember this is panic-level code to track zombie object usage
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
46 std::string fingerprint = Orthanc::Toolbox::GenerateUuid();
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
47 const char* fingerprintRaw = fingerprint.c_str();
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
48 ORTHANC_ASSERT(strlen(fingerprintRaw) == 36);
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
49 ORTHANC_ASSERT(fingerprintRaw[36] == 0);
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
50 memcpy(fingerprint_, fingerprintRaw, 37);
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
51 LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::IObserver : fingerprint_ == " << fingerprint_;
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
52 broker_.Register(*this);
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
53 }
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
54
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
55 virtual ~IObserver()
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
56 {
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
57 LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::~IObserver : fingerprint_ == " << fingerprint_;
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
58 broker_.Unregister(*this);
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
59 }
393
e7a494bdd956 removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 300
diff changeset
60
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
61 const char* GetFingerprint() const
973
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
62 {
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
63 return fingerprint_;
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
64 }
38409549db43 Log with addresses + added fingerprint mechanism to avoid calling zombie objects
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
65
975
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
66 bool DoesFingerprintLookGood() const
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
67 {
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
68 for (size_t i = 0; i < 36; ++i) {
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
69 bool ok = false;
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
70 if (fingerprint_[i] >= 'a' && fingerprint_[i] <= 'f')
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
71 ok = true;
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
72 if (fingerprint_[i] >= '0' && fingerprint_[i] <= '9')
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
73 ok = true;
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
74 if (fingerprint_[i] == '-')
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
75 ok = true;
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
76 if (!ok)
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
77 return false;
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
78 }
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
79 return fingerprint_[36] == 0;
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
80 }
e75fd08d6c75 Cleaning in ICallable + changed fingerprint to plain char array to allow for
Benjamin Golinvaux <bgo@osimis.io>
parents: 973
diff changeset
81
393
e7a494bdd956 removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 300
diff changeset
82 MessageBroker& GetBroker() const
e7a494bdd956 removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 300
diff changeset
83 {
e7a494bdd956 removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 300
diff changeset
84 return broker_;
e7a494bdd956 removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 300
diff changeset
85 }
250
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
86 };
5e642859267e added new Observable/Observer & MessageBroker (not used yet)
am@osimis.io
parents:
diff changeset
87 }