diff Platforms/Wasm/WasmWebService.cpp @ 303:ed1a4302154f am-callable-and-promise

new messages in wasm too
author am@osimis.io
date Tue, 18 Sep 2018 18:17:26 +0200
parents 3897f9f28cfa
children 14ef1227120f
line wrap: on
line diff
--- a/Platforms/Wasm/WasmWebService.cpp	Tue Sep 18 18:04:53 2018 +0200
+++ b/Platforms/Wasm/WasmWebService.cpp	Tue Sep 18 18:17:26 2018 +0200
@@ -7,57 +7,22 @@
 extern "C" {
 #endif
 
-  extern void WasmWebService_ScheduleGetRequest(void* callback,
-                                                const char* uri,
-                                                const char* headersInJsonString,
-                                                void* payload);
-
-  extern void WasmWebService_NewScheduleGetRequest(void* callableSuccess,
-                                                void* callableFailure,
-                                                const char* uri,
-                                                const char* headersInJsonString,
-                                                void* payload);
-
-  extern void WasmWebService_SchedulePostRequest(void* callback,
-                                                 const char* uri,
-                                                 const char* headersInJsonString,
-                                                 const void* body,
-                                                 size_t bodySize,
-                                                 void* payload);
+  extern void WasmWebService_GetAsync(void* callableSuccess,
+                                      void* callableFailure,
+                                      const char* uri,
+                                      const char* headersInJsonString,
+                                      void* payload);
 
-  void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifyError(void* callback,
-                                                       const char* uri,
-                                                       void* payload)
-  {
-    if (callback == NULL)
-    {
-      throw;
-    }
-    else
-    {
-      reinterpret_cast<OrthancStone::IWebService::ICallback*>(callback)->
-        OnHttpRequestError(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload));
-    }
-  }
+  extern void WasmWebService_PostAsync(void* callableSuccess,
+                                       void* callableFailure,
+                                       const char* uri,
+                                       const char* headersInJsonString,
+                                       const void* body,
+                                       size_t bodySize,
+                                       void* payload);
 
-  void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifySuccess(void* callback,
-                                                         const char* uri,
-                                                         const void* body,
-                                                         size_t bodySize,
-                                                         void* payload)
-  {
-    if (callback == NULL)
-    {
-      throw;
-    }
-    else
-    {
-      reinterpret_cast<OrthancStone::IWebService::ICallback*>(callback)->
-        OnHttpRequestSuccess(uri, body, bodySize, reinterpret_cast<Orthanc::IDynamicObject*>(payload)); 
-   }
-  }
 
-  void EMSCRIPTEN_KEEPALIVE WasmWebService_NewNotifyError(void* failureCallable,
+  void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifyError(void* failureCallable,
                                                        const char* uri,
                                                        void* payload)
   {
@@ -67,12 +32,12 @@
     }
     else
     {
-      reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IWebService::NewHttpRequestErrorMessage>*>(failureCallable)->
-        Apply(OrthancStone::IWebService::NewHttpRequestErrorMessage(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload)));
+      reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IWebService::HttpRequestErrorMessage>*>(failureCallable)->
+        Apply(OrthancStone::IWebService::HttpRequestErrorMessage(uri, reinterpret_cast<Orthanc::IDynamicObject*>(payload)));
     }
   }
 
-  void EMSCRIPTEN_KEEPALIVE WasmWebService_NewNotifySuccess(void* successCallable,
+  void EMSCRIPTEN_KEEPALIVE WasmWebService_NotifySuccess(void* successCallable,
                                                          const char* uri,
                                                          const void* body,
                                                          size_t bodySize,
@@ -84,8 +49,8 @@
     }
     else
     {
-      reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IWebService::NewHttpRequestSuccessMessage>*>(successCallable)->
-        Apply(OrthancStone::IWebService::NewHttpRequestSuccessMessage(uri, body, bodySize, reinterpret_cast<Orthanc::IDynamicObject*>(payload)));
+      reinterpret_cast<OrthancStone::MessageHandler<OrthancStone::IWebService::HttpRequestSuccessMessage>*>(successCallable)->
+        Apply(OrthancStone::IWebService::HttpRequestSuccessMessage(uri, body, bodySize, reinterpret_cast<Orthanc::IDynamicObject*>(payload)));
    }
   }
 
@@ -134,40 +99,30 @@
     output = outputStr.str();
   }
 
-  void WasmWebService::ScheduleGetRequest(ICallback& callback,
-                                          const std::string& relativeUri,
-                                          const Headers& headers,
-                                          Orthanc::IDynamicObject* payload)
+  void WasmWebService::PostAsync(const std::string& relativeUri,
+                           const Headers& headers,
+                           const std::string& body,
+                           Orthanc::IDynamicObject* payload,
+                           MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallable,
+                           MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallable)
   {
     std::string uri = baseUri_ + relativeUri;
     std::string headersInJsonString;
     ToJsonString(headersInJsonString, headers);
-    WasmWebService_ScheduleGetRequest(&callback, uri.c_str(), headersInJsonString.c_str(), payload);
-  }
-
-  void WasmWebService::SchedulePostRequest(ICallback& callback,
-                                           const std::string& relativeUri,
-                                           const Headers& headers,
-                                           const std::string& body,
-                                           Orthanc::IDynamicObject* payload)
-  {
-    std::string uri = baseUri_ + relativeUri;
-    std::string headersInJsonString;
-    ToJsonString(headersInJsonString, headers);
-    WasmWebService_SchedulePostRequest(&callback, uri.c_str(), headersInJsonString.c_str(),
+    WasmWebService_PostAsync(successCallable, failureCallable, uri.c_str(), headersInJsonString.c_str(),
                                        body.c_str(), body.size(), payload);
   }
 
    void WasmWebService::GetAsync(const std::string& relativeUri,
                           const Headers& headers,
                           Orthanc::IDynamicObject* payload,
-                          MessageHandler<IWebService::NewHttpRequestSuccessMessage>* successCallable,
-                          MessageHandler<IWebService::NewHttpRequestErrorMessage>* failureCallable)
+                          MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallable,
+                          MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallable)
   {
     std::string uri = baseUri_ + relativeUri;
     std::string headersInJsonString;
     ToJsonString(headersInJsonString, headers);
-    WasmWebService_NewScheduleGetRequest(successCallable, failureCallable, uri.c_str(), headersInJsonString.c_str(), payload);
+    WasmWebService_GetAsync(successCallable, failureCallable, uri.c_str(), headersInJsonString.c_str(), payload);
   }
 
 }