comparison Framework/Messages/LockingEmitter.h @ 1074:229ea1389845 broker

LockingEmitter.cpp
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Oct 2019 13:48:52 +0200
parents e713f1a99861
children 81b29bc7c3d4
comparison
equal deleted inserted replaced
1073:8d3936f06541 1074:229ea1389845
21 #pragma once 21 #pragma once
22 22
23 #include "IMessageEmitter.h" 23 #include "IMessageEmitter.h"
24 #include "IObservable.h" 24 #include "IObservable.h"
25 25
26 #include <boost/thread.hpp> 26 #include <Core/Enumerations.h> // For ORTHANC_OVERRIDE
27
28 #include <boost/thread/shared_mutex.hpp>
27 29
28 namespace OrthancStone 30 namespace OrthancStone
29 { 31 {
30 /** 32 /**
31 * This class is used when using the ThreadedOracle : since messages 33 * This class is used when using the ThreadedOracle : since messages
41 private: 43 private:
42 boost::shared_mutex mutex_; 44 boost::shared_mutex mutex_;
43 IObservable oracleObservable_; 45 IObservable oracleObservable_;
44 46
45 public: 47 public:
46 virtual void EmitMessage(const IObserver& observer, 48 virtual void EmitMessage(IObserver& observer,
47 const IMessage& message) ORTHANC_OVERRIDE 49 const IMessage& message) ORTHANC_OVERRIDE;
48 {
49 try
50 {
51 boost::unique_lock<boost::shared_mutex> lock(mutex_);
52 oracleObservable_.EmitMessage(observer, message);
53 }
54 catch (Orthanc::OrthancException& e)
55 {
56 LOG(ERROR) << "Exception while emitting a message: " << e.What();
57 }
58 }
59 50
60 51
61 class ReaderLock : public boost::noncopyable 52 class ReaderLock : public boost::noncopyable
62 { 53 {
63 private: 54 private:
64 LockingEmitter& that_; 55 LockingEmitter& that_;
65 boost::shared_lock<boost::shared_mutex> lock_; 56 boost::shared_lock<boost::shared_mutex> lock_;
66 57
67 public: 58 public:
68 ReaderLock(LockingEmitter& that) : 59 ReaderLock(LockingEmitter& that) :
69 that_(that), 60 that_(that),
70 lock_(that.mutex_) 61 lock_(that.mutex_)
71 { 62 {
72 } 63 }
73 }; 64 };
74 65
75 66
79 LockingEmitter& that_; 70 LockingEmitter& that_;
80 boost::unique_lock<boost::shared_mutex> lock_; 71 boost::unique_lock<boost::shared_mutex> lock_;
81 72
82 public: 73 public:
83 WriterLock(LockingEmitter& that) : 74 WriterLock(LockingEmitter& that) :
84 that_(that), 75 that_(that),
85 lock_(that.mutex_) 76 lock_(that.mutex_)
86 { 77 {
87 } 78 }
88 79
89 IObservable& GetOracleObservable() 80 IObservable& GetOracleObservable()
90 { 81 {