Mercurial > hg > orthanc-stone
comparison Applications/StoneApplicationContext.cpp @ 418:c23df8b3433b
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 15 Nov 2018 18:32:48 +0100 |
parents | aee3d7941c9b |
children | b70e9be013e4 |
comparison
equal
deleted
inserted
replaced
417:aee3d7941c9b | 418:c23df8b3433b |
---|---|
23 | 23 |
24 #include <Core/OrthancException.h> | 24 #include <Core/OrthancException.h> |
25 | 25 |
26 namespace OrthancStone | 26 namespace OrthancStone |
27 { | 27 { |
28 void StoneApplicationContext::InitializeOrthanc() | |
29 { | |
30 if (webService_ == NULL) | |
31 { | |
32 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
33 } | |
34 | |
35 orthanc_.reset(new OrthancApiClient(broker_, *webService_, orthancBaseUrl_)); | |
36 } | |
37 | |
38 | |
28 IWebService& StoneApplicationContext::GetWebService() | 39 IWebService& StoneApplicationContext::GetWebService() |
29 { | 40 { |
30 if (webService_ == NULL) | 41 if (webService_ == NULL) |
31 { | 42 { |
32 throw Orthanc::ErrorCode_BadSequenceOfCalls; | 43 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
33 } | 44 } |
34 | 45 |
35 return *webService_; | 46 return *webService_; |
36 } | 47 } |
37 | 48 |
49 | |
38 OrthancApiClient& StoneApplicationContext::GetOrthancApiClient() | 50 OrthancApiClient& StoneApplicationContext::GetOrthancApiClient() |
39 { | 51 { |
40 if (orthanc_.get() == NULL) | 52 if (orthanc_.get() == NULL) |
41 { | 53 { |
42 throw Orthanc::ErrorCode_BadSequenceOfCalls; | 54 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
43 } | 55 } |
44 | 56 |
45 return *orthanc_; | 57 return *orthanc_; |
46 } | 58 } |
47 | 59 |
48 void StoneApplicationContext::Initialize(MessageBroker& broker, | 60 |
49 IWebService& webService, | 61 void StoneApplicationContext::SetWebService(IWebService& webService) |
50 const std::string& orthancBaseUrl) | |
51 { | 62 { |
52 webService_ = &webService; | 63 webService_ = &webService; |
53 orthanc_.reset(new OrthancApiClient(broker, webService, orthancBaseUrl)); | 64 InitializeOrthanc(); |
65 } | |
66 | |
67 | |
68 void StoneApplicationContext::SetOrthancBaseUrl(const std::string& baseUrl) | |
69 { | |
70 // Make sure the base url ends with "/" | |
71 if (baseUrl.empty() || | |
72 baseUrl[baseUrl.size() - 1] != '/') | |
73 { | |
74 orthancBaseUrl_ = baseUrl + "/"; | |
75 } | |
76 else | |
77 { | |
78 orthancBaseUrl_ = baseUrl; | |
79 } | |
80 | |
81 if (webService_ != NULL) | |
82 { | |
83 InitializeOrthanc(); | |
84 } | |
54 } | 85 } |
55 } | 86 } |