# HG changeset patch # User Sebastien Jodogne # Date 1790096639 -7200 # Node ID 5150a79998407330fd93f34bc657e292b68e2bfa # Parent e35645fac5f8c8dc092a56c3cfc67333f03ea93f using IMessage in new oracle diff -r e35645fac5f8 -r 5150a7999840 Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp --- 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!"; } diff -r e35645fac5f8 -r 5150a7999840 Applications/StoneWebViewer/WebAssembly/StoneWebViewer.cpp --- 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!"; } diff -r e35645fac5f8 -r 5150a7999840 OrthancStone/Sources/Oracle/IEnvironment.h --- 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& client, IOracleCommand* command /* takes ownership */, - Orthanc::IDynamicObject* result /* takes ownership */) = 0; + IMessage* result /* takes ownership */) = 0; virtual void NotifyOracleError(const boost::weak_ptr& client, IOracleCommand* command /* takes ownership */, diff -r e35645fac5f8 -r 5150a7999840 OrthancStone/Sources/Oracle/IOracleClient.h --- 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 @@ -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; diff -r e35645fac5f8 -r 5150a7999840 OrthancStone/Sources/Oracle/OracleCallback.cpp --- 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 protection(result); + std::unique_ptr 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_; + } + } } diff -r e35645fac5f8 -r 5150a7999840 OrthancStone/Sources/Oracle/OracleCallback.h --- 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& 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 }; } diff -r e35645fac5f8 -r 5150a7999840 OrthancStone/Sources/Oracle/ThreadedOracle.cpp --- 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((*it)->GetCallback().GetCommand()); // TODO Refactoring - Remove this + (*it)->GetCallback().NotifySuccess(new SleepOracleCommand::TimeoutMessage(command)); delete *it; *it = NULL; } diff -r e35645fac5f8 -r 5150a7999840 OrthancStone/Sources/Platforms/Native/NativeEnvironment.cpp --- 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 result_; + std::unique_ptr result_; public: SuccessCompletion(const boost::weak_ptr& 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& client, IOracleCommand* command /* takes ownership */, - Orthanc::IDynamicObject* result /* takes ownership */) + IMessage* result /* takes ownership */) { oracleQueue_.Enqueue(new SuccessCompletion(client, command, result)); } diff -r e35645fac5f8 -r 5150a7999840 OrthancStone/Sources/Platforms/Native/NativeEnvironment.h --- 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& 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& client, IOracleCommand* command /* takes ownership */, diff -r e35645fac5f8 -r 5150a7999840 OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyEnvironment.cpp --- 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& client, IOracleCommand* command /* takes ownership */, - Orthanc::IDynamicObject* result /* takes ownership */) + IMessage* result /* takes ownership */) { std::unique_ptr protection(command); - std::unique_ptr protection2(result); + std::unique_ptr protection2(result); if (command == NULL || result == NULL) diff -r e35645fac5f8 -r 5150a7999840 OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyEnvironment.h --- 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& 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& client, IOracleCommand* command /* takes ownership */, diff -r e35645fac5f8 -r 5150a7999840 OrthancStone/Sources/Platforms/WebAssembly/WebAssemblyOracle.cpp --- 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 callback(reinterpret_cast(userData)); - callback->NotifySuccess(new Orthanc::IDynamicObject); + + const SleepOracleCommand& command = dynamic_cast(callback->GetCommand()); // TODO Refactoring - Remove this + callback->NotifySuccess(new SleepOracleCommand::TimeoutMessage(command)); }