Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Deprecated/Messages/LockingEmitter.h @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Deprecated/Messages/LockingEmitter.h@30deba7bc8e2 |
children |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
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-2020 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 <Enumerations.h> | |
24 #include <OrthancException.h> | |
25 | |
26 #include "../../Messages/IMessageEmitter.h" | |
27 #include "../../Messages/IObservable.h" | |
28 | |
29 #include <boost/thread/shared_mutex.hpp> | |
30 | |
31 namespace Deprecated | |
32 { | |
33 /** | |
34 * This class is used when using the ThreadedOracle : since messages | |
35 * can be sent from multiple Oracle threads, this IMessageEmitter | |
36 * implementation serializes the callbacks. | |
37 * | |
38 * The internal mutex used in Oracle messaging can also be used to | |
39 * protect the application data. Thus, this class can be used as a single | |
40 * application-wide mutex. | |
41 */ | |
42 class LockingEmitter : public OrthancStone::IMessageEmitter | |
43 { | |
44 private: | |
45 boost::shared_mutex mutex_; | |
46 OrthancStone::IObservable oracleObservable_; | |
47 | |
48 public: | |
49 virtual void EmitMessage(boost::weak_ptr<OrthancStone::IObserver> observer, | |
50 const OrthancStone::IMessage& message) ORTHANC_OVERRIDE; | |
51 | |
52 | |
53 class ReaderLock : public boost::noncopyable | |
54 { | |
55 private: | |
56 LockingEmitter& that_; | |
57 boost::shared_lock<boost::shared_mutex> lock_; | |
58 | |
59 public: | |
60 ReaderLock(LockingEmitter& that) : | |
61 that_(that), | |
62 lock_(that.mutex_) | |
63 { | |
64 } | |
65 }; | |
66 | |
67 | |
68 class WriterLock : public boost::noncopyable | |
69 { | |
70 private: | |
71 LockingEmitter& that_; | |
72 boost::unique_lock<boost::shared_mutex> lock_; | |
73 | |
74 public: | |
75 WriterLock(LockingEmitter& that) : | |
76 that_(that), | |
77 lock_(that.mutex_) | |
78 { | |
79 } | |
80 | |
81 OrthancStone::IObservable& GetOracleObservable() | |
82 { | |
83 return that_.oracleObservable_; | |
84 } | |
85 }; | |
86 }; | |
87 } |