comparison Framework/Messages/LockingEmitter.h @ 1097:4383382db01d broker

deprecating LockingEmitter
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Oct 2019 22:31:18 +0200
parents f72d1ab42932
children 17660df24c36
comparison
equal deleted inserted replaced
1096:97cbb2c31a65 1097:4383382db01d
30 30
31 #include <boost/thread/shared_mutex.hpp> 31 #include <boost/thread/shared_mutex.hpp>
32 32
33 namespace OrthancStone 33 namespace OrthancStone
34 { 34 {
35 /** 35 namespace Deprecated
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 IMessageEmitter
45 { 36 {
46 private: 37 /**
47 boost::shared_mutex mutex_; 38 * This class is used when using the ThreadedOracle : since messages
48 IObservable oracleObservable_; 39 * can be sent from multiple Oracle threads, this IMessageEmitter
40 * implementation serializes the callbacks.
41 *
42 * The internal mutex used in Oracle messaging can also be used to
43 * protect the application data. Thus, this class can be used as a single
44 * application-wide mutex.
45 */
46 class LockingEmitter : public IMessageEmitter
47 {
48 private:
49 boost::shared_mutex mutex_;
50 IObservable oracleObservable_;
49 51
50 public: 52 public:
51 virtual void EmitMessage(boost::weak_ptr<IObserver>& observer, 53 virtual void EmitMessage(boost::weak_ptr<IObserver>& observer,
52 const IMessage& message) ORTHANC_OVERRIDE; 54 const IMessage& message) ORTHANC_OVERRIDE;
53 55
54 56
55 class ReaderLock : public boost::noncopyable 57 class ReaderLock : public boost::noncopyable
56 { 58 {
57 private: 59 private:
58 LockingEmitter& that_; 60 LockingEmitter& that_;
59 boost::shared_lock<boost::shared_mutex> lock_; 61 boost::shared_lock<boost::shared_mutex> lock_;
60 62
61 public: 63 public:
62 ReaderLock(LockingEmitter& that) : 64 ReaderLock(LockingEmitter& that) :
63 that_(that), 65 that_(that),
64 lock_(that.mutex_) 66 lock_(that.mutex_)
65 { 67 {
66 } 68 }
67 }; 69 };
68 70
69 71
70 class WriterLock : public boost::noncopyable 72 class WriterLock : public boost::noncopyable
71 { 73 {
72 private: 74 private:
73 LockingEmitter& that_; 75 LockingEmitter& that_;
74 boost::unique_lock<boost::shared_mutex> lock_; 76 boost::unique_lock<boost::shared_mutex> lock_;
75 77
76 public: 78 public:
77 WriterLock(LockingEmitter& that) : 79 WriterLock(LockingEmitter& that) :
78 that_(that), 80 that_(that),
79 lock_(that.mutex_) 81 lock_(that.mutex_)
80 { 82 {
81 } 83 }
82 84
83 IObservable& GetOracleObservable() 85 IObservable& GetOracleObservable()
84 { 86 {
85 return that_.oracleObservable_; 87 return that_.oracleObservable_;
86 } 88 }
89 };
87 }; 90 };
88 }; 91 }
89 } 92 }