comparison Framework/Deprecated/Messages/LockingEmitter.h @ 1226:05d05cba0f4f broker

explicitely tagging LockingEmitter as deprecated
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 08 Dec 2019 11:57:46 +0100
parents Framework/Messages/LockingEmitter.h@17660df24c36
children 0ca50d275b9a
comparison
equal deleted inserted replaced
1225:16738485e457 1226:05d05cba0f4f
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 #pragma once
22
23 #include <Core/Enumerations.h>
24 #include <Core/OrthancException.h>
25
26 #include "../../Messages/IMessageEmitter.h"
27 #include "../../Messages/IObservable.h"
28
29 #include <Core/Enumerations.h> // For ORTHANC_OVERRIDE
30
31 #include <boost/thread/shared_mutex.hpp>
32
33 namespace Deprecated
34 {
35 /**
36 * This class is used when using the ThreadedOracle : since messages
37 * can be sent from multiple Oracle threads, this IMessageEmitter
38 * implementation serializes the callbacks.
39 *
40 * The internal mutex used in Oracle messaging can also be used to
41 * protect the application data. Thus, this class can be used as a single
42 * application-wide mutex.
43 */
44 class LockingEmitter : public OrthancStone::IMessageEmitter
45 {
46 private:
47 boost::shared_mutex mutex_;
48 OrthancStone::IObservable oracleObservable_;
49
50 public:
51 virtual void EmitMessage(boost::weak_ptr<OrthancStone::IObserver> observer,
52 const OrthancStone::IMessage& message) ORTHANC_OVERRIDE;
53
54
55 class ReaderLock : public boost::noncopyable
56 {
57 private:
58 LockingEmitter& that_;
59 boost::shared_lock<boost::shared_mutex> lock_;
60
61 public:
62 ReaderLock(LockingEmitter& that) :
63 that_(that),
64 lock_(that.mutex_)
65 {
66 }
67 };
68
69
70 class WriterLock : public boost::noncopyable
71 {
72 private:
73 LockingEmitter& that_;
74 boost::unique_lock<boost::shared_mutex> lock_;
75
76 public:
77 WriterLock(LockingEmitter& that) :
78 that_(that),
79 lock_(that.mutex_)
80 {
81 }
82
83 OrthancStone::IObservable& GetOracleObservable()
84 {
85 return that_.oracleObservable_;
86 }
87 };
88 };
89 }