Mercurial > hg > orthanc-stone
annotate Framework/Messages/LockingEmitter.h @ 1213:86a8266b8888 broker
moving the scene from IViewport to ViewportController
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 04 Dec 2019 17:54:10 +0100 |
parents | 17660df24c36 |
children |
rev | line source |
---|---|
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
1 /** |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
2 * Stone of Orthanc |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
6 * |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
11 * |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
16 * |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
19 **/ |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
20 |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
21 #pragma once |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
22 |
1071
6dd90b8d1589
Fixes related to refactorings in viewports.
Benjamin Golinvaux <bgo@osimis.io>
parents:
852
diff
changeset
|
23 #include <Core/Enumerations.h> |
6dd90b8d1589
Fixes related to refactorings in viewports.
Benjamin Golinvaux <bgo@osimis.io>
parents:
852
diff
changeset
|
24 #include <Core/OrthancException.h> |
6dd90b8d1589
Fixes related to refactorings in viewports.
Benjamin Golinvaux <bgo@osimis.io>
parents:
852
diff
changeset
|
25 |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
26 #include "IMessageEmitter.h" |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
27 #include "IObservable.h" |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
28 |
1074
229ea1389845
LockingEmitter.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1059
diff
changeset
|
29 #include <Core/Enumerations.h> // For ORTHANC_OVERRIDE |
229ea1389845
LockingEmitter.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1059
diff
changeset
|
30 |
229ea1389845
LockingEmitter.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1059
diff
changeset
|
31 #include <boost/thread/shared_mutex.hpp> |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
32 |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
33 namespace OrthancStone |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
34 { |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
35 namespace Deprecated |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
36 { |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
37 /** |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
38 * This class is used when using the ThreadedOracle : since messages |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
39 * can be sent from multiple Oracle threads, this IMessageEmitter |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
40 * implementation serializes the callbacks. |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
41 * |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
42 * The internal mutex used in Oracle messaging can also be used to |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
43 * protect the application data. Thus, this class can be used as a single |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
44 * application-wide mutex. |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
45 */ |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
46 class LockingEmitter : public IMessageEmitter |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
47 { |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
48 private: |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
49 boost::shared_mutex mutex_; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
50 IObservable oracleObservable_; |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
51 |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
52 public: |
1098
17660df24c36
simplification of IOracleRunner
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1097
diff
changeset
|
53 virtual void EmitMessage(boost::weak_ptr<IObserver> observer, |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
54 const IMessage& message) ORTHANC_OVERRIDE; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
55 |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
56 |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
57 class ReaderLock : public boost::noncopyable |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
58 { |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
59 private: |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
60 LockingEmitter& that_; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
61 boost::shared_lock<boost::shared_mutex> lock_; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
62 |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
63 public: |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
64 ReaderLock(LockingEmitter& that) : |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
65 that_(that), |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
66 lock_(that.mutex_) |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
67 { |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
68 } |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
69 }; |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
70 |
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
71 |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
72 class WriterLock : public boost::noncopyable |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
73 { |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
74 private: |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
75 LockingEmitter& that_; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
76 boost::unique_lock<boost::shared_mutex> lock_; |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
77 |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
78 public: |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
79 WriterLock(LockingEmitter& that) : |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
80 that_(that), |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
81 lock_(that.mutex_) |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
82 { |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
83 } |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
84 |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
85 IObservable& GetOracleObservable() |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
86 { |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
87 return that_.oracleObservable_; |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
88 } |
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
89 }; |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
90 }; |
1097
4383382db01d
deprecating LockingEmitter
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1083
diff
changeset
|
91 } |
843
67f9c27214c5
Removed extra logging + doc + added GuiAdapter and LockingEmitter
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
92 } |