comparison Platforms/Wasm/WasmWebService.h @ 253:8ff70c04c6df am-2

IObservable/IObserver now working in WASM too
author am@osimis.io
date Tue, 03 Jul 2018 10:48:47 +0200
parents ddbb339ed4cf
children 65562a28fe05
comparison
equal deleted inserted replaced
252:40b21c1f8b8d 253:8ff70c04c6df
1 #pragma once 1 #pragma once
2 2
3 #include <Framework/Toolbox/IWebService.h> 3 #include <Framework/Toolbox/IWebService.h>
4 #include <Core/OrthancException.h>
4 5
5 namespace OrthancStone 6 namespace OrthancStone
6 { 7 {
7 class WasmWebService : public IWebService 8 class WasmWebService : public IWebService
8 { 9 {
9 private: 10 private:
10 std::string base_; 11 std::string baseUri_;
12 static MessageBroker* broker_;
11 13
12 // Private constructor => Singleton design pattern 14 // Private constructor => Singleton design pattern
13 WasmWebService() : 15 WasmWebService(MessageBroker& broker) :
14 base_("../../") // note: this is configurable from the JS code by calling WasmWebService_SetBaseUrl 16 IWebService(broker),
17 baseUri_("../../") // note: this is configurable from the JS code by calling WasmWebService_SetBaseUri
15 { 18 {
16 } 19 }
17 20
18 public: 21 public:
19 static WasmWebService& GetInstance() 22 static WasmWebService& GetInstance()
20 { 23 {
21 static WasmWebService instance; 24 if (broker_ == NULL)
25 {
26 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
27 }
28 static WasmWebService instance(*broker_);
22 return instance; 29 return instance;
23 } 30 }
24 31
25 void SetBaseUrl(const std::string base); 32 static void SetBroker(MessageBroker& broker)
33 {
34 broker_ = &broker;
35 }
36
37 void SetBaseUri(const std::string baseUri);
26 38
27 virtual void ScheduleGetRequest(ICallback& callback, 39 virtual void ScheduleGetRequest(ICallback& callback,
28 const std::string& uri, 40 const std::string& uri,
29 Orthanc::IDynamicObject* payload); 41 Orthanc::IDynamicObject* payload);
30 42