Mercurial > hg > orthanc-stone
comparison Framework/Messages/IObserver.cpp @ 1048:f6be9412e42a
cleaning up IObservable.h
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Oct 2019 14:11:52 +0200 |
parents | |
children | ca2058bd74ef |
comparison
equal
deleted
inserted
replaced
1047:efc5b62b9539 | 1048:f6be9412e42a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "IObserver.h" | |
23 | |
24 #include "IMessage.h" | |
25 #include "../StoneException.h" | |
26 | |
27 #include <Core/Logging.h> | |
28 #include <Core/Toolbox.h> | |
29 | |
30 namespace OrthancStone | |
31 { | |
32 IObserver::IObserver(MessageBroker& broker) | |
33 : broker_(broker) | |
34 , fingerprint_() | |
35 { | |
36 // we store the fingerprint_ as a char array to avoid problems when | |
37 // reading it in a deceased object. | |
38 // remember this is panic-level code to track zombie object usage | |
39 std::string fingerprint = Orthanc::Toolbox::GenerateUuid(); | |
40 const char* fingerprintRaw = fingerprint.c_str(); | |
41 memcpy(fingerprint_, fingerprintRaw, 37); | |
42 broker_.Register(*this); | |
43 } | |
44 | |
45 | |
46 IObserver::~IObserver() | |
47 { | |
48 try | |
49 { | |
50 LOG(TRACE) << "IObserver(" << std::hex << this << std::dec << ")::~IObserver : fingerprint_ == " << fingerprint_; | |
51 const char* deadMarker = "deadbeef-dead-dead-0000-0000deadbeef"; | |
52 ORTHANC_ASSERT(strlen(deadMarker) == 36); | |
53 memcpy(fingerprint_, deadMarker, 37); | |
54 broker_.Unregister(*this); | |
55 } | |
56 catch (const Orthanc::OrthancException& e) | |
57 { | |
58 if (e.HasDetails()) | |
59 { | |
60 LOG(ERROR) << "OrthancException in ~IObserver: " << e.What() << " Details: " << e.GetDetails(); | |
61 } | |
62 else | |
63 { | |
64 LOG(ERROR) << "OrthancException in ~IObserver: " << e.What(); | |
65 } | |
66 } | |
67 catch (const std::exception& e) | |
68 { | |
69 LOG(ERROR) << "std::exception in ~IObserver: " << e.what(); | |
70 } | |
71 catch (...) | |
72 { | |
73 LOG(ERROR) << "Unknown exception in ~IObserver"; | |
74 } | |
75 } | |
76 | |
77 | |
78 bool IObserver::DoesFingerprintLookGood() const | |
79 { | |
80 for (size_t i = 0; i < 36; ++i) { | |
81 bool ok = false; | |
82 if (fingerprint_[i] >= 'a' && fingerprint_[i] <= 'f') | |
83 ok = true; | |
84 if (fingerprint_[i] >= '0' && fingerprint_[i] <= '9') | |
85 ok = true; | |
86 if (fingerprint_[i] == '-') | |
87 ok = true; | |
88 if (!ok) | |
89 return false; | |
90 } | |
91 return fingerprint_[36] == 0; | |
92 } | |
93 } |