Mercurial > hg > orthanc-stone
changeset 2284:5150a7999840 refactoring tip
using IMessage in new oracle
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Tue, 22 Sep 2026 19:03:59 +0200 |
| parents | e35645fac5f8 |
| children | |
| files | Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp OrthancStone/Sources/Oracle/IEnvironment.h OrthancStone/Sources/Oracle/IOracleClient.h OrthancStone/Sources/Oracle/OracleCallback.cpp OrthancStone/Sources/Oracle/OracleCallback.h OrthancStone/Sources/Oracle/ThreadedOracle.cpp OrthancStone/Sources/Platforms/Native/NativeEnvironment.cpp OrthancStone/Sources/Platforms/Native/NativeEnvironment.h OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyEnvironment.cpp OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyEnvironment.h OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOracle.cpp |
| diffstat | 12 files changed, 42 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp Tue Sep 22 18:30:40 2026 +0200 +++ b/Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp Tue Sep 22 19:03:59 2026 +0200 @@ -63,7 +63,7 @@ { public: virtual void HandleSuccessFromOracle(const OrthancStone::IOracleCommand& command, - const Orthanc::IDynamicObject& result) + const OrthancStone::IMessage& result) { LOG(ERROR) << "success!"; }
--- a/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp Tue Sep 22 18:30:40 2026 +0200 +++ b/Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp Tue Sep 22 19:03:59 2026 +0200 @@ -4882,13 +4882,13 @@ { public: virtual void HandleSuccessFromOracle(const OrthancStone::IOracleCommand& command, - const Orthanc::IDynamicObject& result) + const OrthancStone::IMessage& result) ORTHANC_OVERRIDE { LOG(ERROR) << "success!"; } virtual void HandleErrorFromOracle(const OrthancStone::IOracleCommand& command, - const Orthanc::OrthancException& error) + const Orthanc::OrthancException& error) ORTHANC_OVERRIDE { LOG(ERROR) << "error!"; }
--- a/OrthancStone/Sources/Oracle/IEnvironment.h Tue Sep 22 18:30:40 2026 +0200 +++ b/OrthancStone/Sources/Oracle/IEnvironment.h Tue Sep 22 19:03:59 2026 +0200 @@ -37,9 +37,15 @@ { } + /** + * NB: "command" and "result" must be pointers so that they can be + * queued, in order to uncouple the worker threads of the oracle + * from the mutex of the native environment. Check out + * "NativeEnvironment.cpp". + **/ virtual void NotifyOracleSuccess(const boost::weak_ptr<IOracleClient>& client, IOracleCommand* command /* takes ownership */, - Orthanc::IDynamicObject* result /* takes ownership */) = 0; + IMessage* result /* takes ownership */) = 0; virtual void NotifyOracleError(const boost::weak_ptr<IOracleClient>& client, IOracleCommand* command /* takes ownership */,
--- a/OrthancStone/Sources/Oracle/IOracleClient.h Tue Sep 22 18:30:40 2026 +0200 +++ b/OrthancStone/Sources/Oracle/IOracleClient.h Tue Sep 22 19:03:59 2026 +0200 @@ -23,6 +23,7 @@ #pragma once +#include "../Messages/IMessage.h" #include "IOracleCommand.h" #include <OrthancException.h> @@ -38,7 +39,7 @@ } virtual void HandleSuccessFromOracle(const IOracleCommand& command, - const Orthanc::IDynamicObject& result) = 0; + const IMessage& result) = 0; virtual void HandleErrorFromOracle(const IOracleCommand& command, const Orthanc::OrthancException& error) = 0;
--- a/OrthancStone/Sources/Oracle/OracleCallback.cpp Tue Sep 22 18:30:40 2026 +0200 +++ b/OrthancStone/Sources/Oracle/OracleCallback.cpp Tue Sep 22 19:03:59 2026 +0200 @@ -41,9 +41,9 @@ } - void OracleCallback::NotifySuccess(Orthanc::IDynamicObject* result) + void OracleCallback::NotifySuccess(IMessage* result) { - std::unique_ptr<Orthanc::IDynamicObject> protection(result); + std::unique_ptr<IMessage> protection(result); if (command_.get() == NULL) { @@ -67,4 +67,17 @@ environment_.NotifyOracleError(client_, command_.release(), error); } } + + + const IOracleCommand& OracleCallback::GetCommand() const + { + if (command_.get() == NULL) + { + throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); + } + else + { + return *command_; + } + } }
--- a/OrthancStone/Sources/Oracle/OracleCallback.h Tue Sep 22 18:30:40 2026 +0200 +++ b/OrthancStone/Sources/Oracle/OracleCallback.h Tue Sep 22 19:03:59 2026 +0200 @@ -39,8 +39,10 @@ const boost::shared_ptr<IOracleClient>& client, IOracleCommand* command /* takes ownership */); - void NotifySuccess(Orthanc::IDynamicObject* result); + void NotifySuccess(IMessage* result); void NotifyError(const Orthanc::OrthancException& error); + + const IOracleCommand& GetCommand() const; // TODO Refactoring - Remove this }; }
--- a/OrthancStone/Sources/Oracle/ThreadedOracle.cpp Tue Sep 22 18:30:40 2026 +0200 +++ b/OrthancStone/Sources/Oracle/ThreadedOracle.cpp Tue Sep 22 19:03:59 2026 +0200 @@ -509,7 +509,8 @@ if (*it != NULL && (*it)->GetExpirationTime() <= now) { - (*it)->GetCallback().NotifySuccess(new Orthanc::IDynamicObject); + const SleepOracleCommand& command = dynamic_cast<const SleepOracleCommand&>((*it)->GetCallback().GetCommand()); // TODO Refactoring - Remove this + (*it)->GetCallback().NotifySuccess(new SleepOracleCommand::TimeoutMessage(command)); delete *it; *it = NULL; }
--- a/OrthancStone/Sources/Platforms/Native/NativeEnvironment.cpp Tue Sep 22 18:30:40 2026 +0200 +++ b/OrthancStone/Sources/Platforms/Native/NativeEnvironment.cpp Tue Sep 22 19:03:59 2026 +0200 @@ -51,12 +51,12 @@ class NativeEnvironment::SuccessCompletion : public Completion { private: - std::unique_ptr<Orthanc::IDynamicObject> result_; + std::unique_ptr<IMessage> result_; public: SuccessCompletion(const boost::weak_ptr<IOracleClient>& client, IOracleCommand* command /* takes ownership */, - Orthanc::IDynamicObject* result /* takes ownership */) : + IMessage* result /* takes ownership */) : Completion(client, command), result_(result) { @@ -135,7 +135,7 @@ void NativeEnvironment::NotifyOracleSuccess(const boost::weak_ptr<IOracleClient>& client, IOracleCommand* command /* takes ownership */, - Orthanc::IDynamicObject* result /* takes ownership */) + IMessage* result /* takes ownership */) { oracleQueue_.Enqueue(new SuccessCompletion(client, command, result)); }
--- a/OrthancStone/Sources/Platforms/Native/NativeEnvironment.h Tue Sep 22 18:30:40 2026 +0200 +++ b/OrthancStone/Sources/Platforms/Native/NativeEnvironment.h Tue Sep 22 19:03:59 2026 +0200 @@ -58,7 +58,7 @@ virtual void NotifyOracleSuccess(const boost::weak_ptr<IOracleClient>& client, IOracleCommand* command /* takes ownership */, - Orthanc::IDynamicObject* result /* takes ownership */) ORTHANC_OVERRIDE; + IMessage* result /* takes ownership */) ORTHANC_OVERRIDE; virtual void NotifyOracleError(const boost::weak_ptr<IOracleClient>& client, IOracleCommand* command /* takes ownership */,
--- a/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyEnvironment.cpp Tue Sep 22 18:30:40 2026 +0200 +++ b/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyEnvironment.cpp Tue Sep 22 19:03:59 2026 +0200 @@ -27,10 +27,10 @@ { void WebAssemblyEnvironment::NotifyOracleSuccess(const boost::weak_ptr<IOracleClient>& client, IOracleCommand* command /* takes ownership */, - Orthanc::IDynamicObject* result /* takes ownership */) + IMessage* result /* takes ownership */) { std::unique_ptr<IOracleCommand> protection(command); - std::unique_ptr<Orthanc::IDynamicObject> protection2(result); + std::unique_ptr<IMessage> protection2(result); if (command == NULL || result == NULL)
--- a/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyEnvironment.h Tue Sep 22 18:30:40 2026 +0200 +++ b/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyEnvironment.h Tue Sep 22 19:03:59 2026 +0200 @@ -32,7 +32,7 @@ public: virtual void NotifyOracleSuccess(const boost::weak_ptr<IOracleClient>& client, IOracleCommand* command /* takes ownership */, - Orthanc::IDynamicObject* result /* takes ownership */) ORTHANC_OVERRIDE; + IMessage* result /* takes ownership */) ORTHANC_OVERRIDE; virtual void NotifyOracleError(const boost::weak_ptr<IOracleClient>& client, IOracleCommand* command /* takes ownership */,
--- a/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOracle.cpp Tue Sep 22 18:30:40 2026 +0200 +++ b/OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOracle.cpp Tue Sep 22 19:03:59 2026 +0200 @@ -884,7 +884,9 @@ static void TimeoutCallback(void *userData) { std::unique_ptr<OracleCallback> callback(reinterpret_cast<OracleCallback*>(userData)); - callback->NotifySuccess(new Orthanc::IDynamicObject); + + const SleepOracleCommand& command = dynamic_cast<const SleepOracleCommand&>(callback->GetCommand()); // TODO Refactoring - Remove this + callback->NotifySuccess(new SleepOracleCommand::TimeoutMessage(command)); }
