diff Framework/Toolbox/OrthancApiClient.cpp @ 271:46c5296d867e am-2

OracleWebService and BasicSdlApplicationContext using the same global mutex
author am@osimis.io
date Thu, 23 Aug 2018 17:12:54 +0200
parents 2d64f4d39610
children 3897f9f28cfa
line wrap: on
line diff
--- a/Framework/Toolbox/OrthancApiClient.cpp	Thu Aug 23 14:45:04 2018 +0200
+++ b/Framework/Toolbox/OrthancApiClient.cpp	Thu Aug 23 17:12:54 2018 +0200
@@ -58,7 +58,7 @@
   // Once the response is ready, it will emit a message to the responseObserver
   // the responseObserver must handle only that message (and not all messages from the OrthancApiClient)
   class OrthancApiClient::BaseRequest:
-      public IObserver,
+//      public IObserver,
       public IObservable,
       public Orthanc::IDynamicObject
   {
@@ -75,7 +75,8 @@
                    const std::string& uri,
                    MessageType messageToEmitWhenResponseReady,
                    OrthancApiClient::Mode mode)
-      : IObserver(orthanc.broker_),
+      :
+        //IObserver(orthanc.broker_),
         IObservable(orthanc.broker_),
         uri_(uri),
         orthanc_(orthanc),
@@ -85,30 +86,30 @@
       // this object will emit only a single message, the one the final responseObserver is expecting
       DeclareEmittableMessage(messageToEmitWhenResponseReady);
 
-      // this object is observing the OrthancApi so it must handle all messages
-      DeclareHandledMessage(MessageType_OrthancApi_InternalGetJsonResponseReady);
-      DeclareIgnoredMessage(MessageType_OrthancApi_InternalGetJsonResponseError);
+//      // this object is observing the OrthancApi so it must handle all messages
+//      DeclareHandledMessage(MessageType_OrthancApi_InternalGetJsonResponseReady);
+//      DeclareIgnoredMessage(MessageType_OrthancApi_InternalGetJsonResponseError);
 
-      orthanc_.RegisterObserver(*this);
+      //orthanc_.RegisterObserver(*this);
       this->RegisterObserver(responseObserver);
     }
     virtual ~BaseRequest() {}
 
-    // mainly maps OrthancApi internal messages to a message that is expected by the responseObserver
-    virtual void HandleMessage(IObservable& from, const IMessage& message)
-    {
-      switch (message.GetType())
-      {
-        case MessageType_OrthancApi_InternalGetJsonResponseReady:
-      {
-        const OrthancApiClient::InternalGetJsonResponseReadyMessage& messageReceived = dynamic_cast<const OrthancApiClient::InternalGetJsonResponseReadyMessage&>(message);
-        EmitMessage(OrthancApiClient::GetJsonResponseReadyMessage(messageToEmitWhenResponseReady_, messageReceived.request_->uri_, messageReceived.response_));
-        orthanc_.ReleaseRequest(messageReceived.request_);
-      }; break;
-      default:
-        throw MessageNotDeclaredException(message.GetType());
-      }
-    }
+//    // mainly maps OrthancApi internal messages to a message that is expected by the responseObserver
+//    virtual void HandleMessage(IObservable& from, const IMessage& message)
+//    {
+//      switch (message.GetType())
+//      {
+//        case MessageType_OrthancApi_InternalGetJsonResponseReady:
+//      {
+//        const OrthancApiClient::InternalGetJsonResponseReadyMessage& messageReceived = dynamic_cast<const OrthancApiClient::InternalGetJsonResponseReadyMessage&>(message);
+//        EmitMessage(OrthancApiClient::GetJsonResponseReadyMessage(messageToEmitWhenResponseReady_, messageReceived.request_->uri_, messageReceived.response_));
+//        orthanc_.ReleaseRequest(messageReceived.request_);
+//      }; break;
+//      default:
+//        throw MessageNotDeclaredException(message.GetType());
+//      }
+//    }
 
   };
 
@@ -139,20 +140,19 @@
         Json::Value response;
         if (MessagingToolbox::ParseJson(response, answer, answerSize))
         {
-          OrthancApiClient::InternalGetJsonResponseReadyMessage msg(request, response);
-          that_.EmitMessage(msg);
+          request->EmitMessage(OrthancApiClient::GetJsonResponseReadyMessage(request->messageToEmitWhenResponseReady_, request->uri_, response));
         }
         else
         {
-          OrthancApiClient::InternalGetJsonResponseErrorMessage msg(request);
-          that_.EmitMessage(msg);
+//          OrthancApiClient::InternalGetJsonResponseErrorMessage msg(request);
+//          that_.EmitMessage(msg);
         }
       };  break;
 
       default:
-        that_.ReleaseRequest(request);
         throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
       }
+      that_.ReleaseRequest(request);
     }
 
     virtual void OnHttpRequestError(const std::string& uri,
@@ -164,14 +164,15 @@
       {
       case OrthancApiClient::Mode_GetJson:
       {
-        OrthancApiClient::InternalGetJsonResponseErrorMessage msg(request);
-        that_.EmitMessage(msg);
+//        OrthancApiClient::InternalGetJsonResponseErrorMessage msg(request);
+//        that_.EmitMessage(msg);
+          // TODO: the request shall send an error message
       };  break;
 
       default:
-        that_.ReleaseRequest(request);
         throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
       }
+      that_.ReleaseRequest(request);
     }
   };