annotate Platforms/Wasm/WasmWebService.h @ 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
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 {
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 253
diff changeset
26 printf("WasmWebService::GetInstance(): broker not initialized\n");
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
27 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
28 }
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
29 static WasmWebService instance(*broker_);
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
30 return instance;
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
31 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
32
253
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
33 static void SetBroker(MessageBroker& broker)
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
34 {
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
35 broker_ = &broker;
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
8ff70c04c6df IObservable/IObserver now working in WASM too
am@osimis.io
parents: 240
diff changeset
38 void SetBaseUri(const std::string baseUri);
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
39
303
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
40 virtual void GetAsync(const std::string& uri,
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
41 const Headers& headers,
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
42 Orthanc::IDynamicObject* payload,
303
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
43 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallable,
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
44 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallable);
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
45
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
46 virtual void PostAsync(const std::string& uri,
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
47 const Headers& headers,
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
48 const std::string& body,
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
49 Orthanc::IDynamicObject* payload,
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
50 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallable,
ed1a4302154f new messages in wasm too
am@osimis.io
parents: 299
diff changeset
51 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallable);
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 257
diff changeset
52
221
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
53 virtual void Start()
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
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
57 virtual void Stop()
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
58 {
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
59 }
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
60 };
d7b2590744f8 wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff changeset
61 }