diff 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
line wrap: on
line diff
--- a/Applications/StoneApplicationContext.cpp	Thu Nov 15 17:28:15 2018 +0100
+++ b/Applications/StoneApplicationContext.cpp	Thu Nov 15 18:32:48 2018 +0100
@@ -25,31 +25,62 @@
 
 namespace OrthancStone
 {
+  void StoneApplicationContext::InitializeOrthanc()
+  {
+    if (webService_ == NULL)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+    }
+
+    orthanc_.reset(new OrthancApiClient(broker_, *webService_, orthancBaseUrl_));
+  }
+
+
   IWebService& StoneApplicationContext::GetWebService()
   {
     if (webService_ == NULL)
     {
-      throw Orthanc::ErrorCode_BadSequenceOfCalls;
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
     
     return *webService_;
   }
 
+  
   OrthancApiClient& StoneApplicationContext::GetOrthancApiClient()
   {
     if (orthanc_.get() == NULL)
     {
-      throw Orthanc::ErrorCode_BadSequenceOfCalls;
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
     
     return *orthanc_;
   }
 
-  void StoneApplicationContext::Initialize(MessageBroker& broker,
-                                           IWebService& webService,
-                                           const std::string& orthancBaseUrl)
+  
+  void StoneApplicationContext::SetWebService(IWebService& webService)
   {
     webService_ = &webService;
-    orthanc_.reset(new OrthancApiClient(broker, webService, orthancBaseUrl));
+    InitializeOrthanc();
+  }
+
+
+  void StoneApplicationContext::SetOrthancBaseUrl(const std::string& baseUrl)
+  {
+    // Make sure the base url ends with "/"
+    if (baseUrl.empty() ||
+        baseUrl[baseUrl.size() - 1] != '/')
+    {
+      orthancBaseUrl_ = baseUrl + "/";
+    }
+    else
+    {
+      orthancBaseUrl_ = baseUrl;
+    }
+
+    if (webService_ != NULL)
+    {
+      InitializeOrthanc();
+    }
   }
 }