Mercurial > hg > orthanc-stone
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 |
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 | 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 | 11 std::string baseUri_; |
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 | 15 WasmWebService(MessageBroker& broker) : |
16 IWebService(broker), | |
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 | 24 if (broker_ == NULL) |
25 { | |
255 | 26 printf("WasmWebService::GetInstance(): broker not initialized\n"); |
253 | 27 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
28 } | |
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 | 33 static void SetBroker(MessageBroker& broker) |
34 { | |
35 broker_ = &broker; | |
36 } | |
37 | |
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 | 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 | 43 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallable, |
44 MessageHandler<IWebService::HttpRequestErrorMessage>* failureCallable); | |
45 | |
46 virtual void PostAsync(const std::string& uri, | |
47 const Headers& headers, | |
48 const std::string& body, | |
49 Orthanc::IDynamicObject* payload, | |
50 MessageHandler<IWebService::HttpRequestSuccessMessage>* successCallable, | |
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 } |