annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
1 #pragma once
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
2
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
3 #include <Framework/Toolbox/IWebService.h>
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
4 #include <Core/OrthancException.h>
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
5
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
6 namespace OrthancStone
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
7 {
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
8 class WasmWebService : public IWebService
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
9 {
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
10 private:
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
11 std::string baseUri_;
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
12 static MessageBroker* broker_;
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
13
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
14 // Private constructor => Singleton design pattern
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
15 WasmWebService(MessageBroker& broker) :
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
16 IWebService(broker),
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
17 baseUri_("../../") // note: this is configurable from the JS code by calling WasmWebService_SetBaseUri
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
18 {
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
19 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
20
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
21 public:
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
22 static WasmWebService& GetInstance()
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
23 {
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
24 if (broker_ == NULL)
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
25 {
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
26 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
27 }
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
28 static WasmWebService instance(*broker_);
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
29 return instance;
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
30 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
31
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
32 static void SetBroker(MessageBroker& broker)
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
33 {
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
34 broker_ = &broker;
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
35 }
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
36
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
37 void SetBaseUri(const std::string baseUri);
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
38
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
39 virtual void ScheduleGetRequest(ICallback& callback,
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
40 const std::string& uri,
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
41 Orthanc::IDynamicObject* payload);
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
42
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
43 virtual void SchedulePostRequest(ICallback& callback,
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
44 const std::string& uri,
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
45 const std::string& body,
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
46 Orthanc::IDynamicObject* payload);
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
47
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
48 virtual void Start()
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
49 {
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
50 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
51
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
52 virtual void Stop()
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
53 {
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
54 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
55 };
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
56 }