comparison Applications/Sdl/SdlStoneApplicationRunner.cpp @ 385:6cc3ce74dc05

using message broker in widgets
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 Nov 2018 20:49:41 +0100
parents faccc4b07b92
children b70e9be013e4
comparison
equal deleted inserted replaced
384:d20d75f20c5d 385:6cc3ce74dc05
22 #if ORTHANC_ENABLE_SDL != 1 22 #if ORTHANC_ENABLE_SDL != 1
23 #error this file shall be included only with the ORTHANC_ENABLE_SDL set to 1 23 #error this file shall be included only with the ORTHANC_ENABLE_SDL set to 1
24 #endif 24 #endif
25 25
26 #include "SdlStoneApplicationRunner.h" 26 #include "SdlStoneApplicationRunner.h"
27 #include <boost/program_options.hpp>
28 27
29 #include "../../Framework/Toolbox/MessagingToolbox.h" 28 #include "../../Framework/Toolbox/MessagingToolbox.h"
29 #include "../../Platforms/Generic/OracleWebService.h"
30 #include "SdlEngine.h" 30 #include "SdlEngine.h"
31 31
32 #include <Core/Logging.h> 32 #include <Core/Logging.h>
33 #include <Core/HttpClient.h> 33 #include <Core/HttpClient.h>
34 #include <Core/Toolbox.h> 34 #include <Core/Toolbox.h>
35 #include <Core/OrthancException.h>
35 #include <Plugins/Samples/Common/OrthancHttpConnection.h> 36 #include <Plugins/Samples/Common/OrthancHttpConnection.h>
36 #include "../../Platforms/Generic/OracleWebService.h" 37
38 #include <boost/program_options.hpp>
37 39
38 namespace OrthancStone 40 namespace OrthancStone
39 { 41 {
40 void SdlStoneApplicationRunner::Initialize() 42 void SdlStoneApplicationRunner::Initialize()
41 { 43 {
42 SdlWindow::GlobalInitialize(); 44 SdlWindow::GlobalInitialize();
43 } 45 }
44 46
47
45 void SdlStoneApplicationRunner::DeclareCommandLineOptions(boost::program_options::options_description& options) 48 void SdlStoneApplicationRunner::DeclareCommandLineOptions(boost::program_options::options_description& options)
46 { 49 {
47 boost::program_options::options_description sdl("SDL options"); 50 boost::program_options::options_description sdl("SDL options");
48 sdl.add_options() 51 sdl.add_options()
49 ("width", boost::program_options::value<int>()->default_value(1024), "Initial width of the SDL window") 52 ("width", boost::program_options::value<int>()->default_value(1024), "Initial width of the SDL window")
52 ; 55 ;
53 56
54 options.add(sdl); 57 options.add(sdl);
55 } 58 }
56 59
60
57 void SdlStoneApplicationRunner::ParseCommandLineOptions(const boost::program_options::variables_map& parameters) 61 void SdlStoneApplicationRunner::ParseCommandLineOptions(const boost::program_options::variables_map& parameters)
58 { 62 {
59 if (!parameters.count("width") || 63 if (!parameters.count("width") ||
60 !parameters.count("height") || 64 !parameters.count("height") ||
61 !parameters.count("opengl")) 65 !parameters.count("opengl"))
83 } 87 }
84 else 88 else
85 { 89 {
86 LOG(WARNING) << "OpenGL is disabled, enable it with option \"--opengl=on\" for best performance"; 90 LOG(WARNING) << "OpenGL is disabled, enable it with option \"--opengl=on\" for best performance";
87 } 91 }
88
89 } 92 }
90 93
91 void SdlStoneApplicationRunner::Run(NativeStoneApplicationContext& context, const std::string& title, int argc, char* argv[]) 94
95 void SdlStoneApplicationRunner::Run(NativeStoneApplicationContext& context,
96 const std::string& title,
97 int argc,
98 char* argv[])
92 { 99 {
93 /************************************************************** 100 /**************************************************************
94 * Run the application inside a SDL window 101 * Run the application inside a SDL window
95 **************************************************************/ 102 **************************************************************/
96 103
97 LOG(WARNING) << "Starting the application"; 104 LOG(WARNING) << "Starting the application";
98 105
99 SdlWindow window(title.c_str(), width_, height_, enableOpenGl_); 106 SdlWindow window(title.c_str(), width_, height_, enableOpenGl_);
100 SdlEngine sdl(window, context); 107 SdlEngine sdl(window, context, broker_);
101 108
102 { 109 {
103 NativeStoneApplicationContext::GlobalMutexLocker locker(context); 110 NativeStoneApplicationContext::GlobalMutexLocker locker(context);
104 context.GetCentralViewport().Register(sdl); // (*) 111
112 locker.GetCentralViewport().RegisterObserverCallback(
113 new Callable<SdlEngine, IViewport::ViewportChangedMessage>
114 (sdl, &SdlEngine::OnViewportChanged));
115
116 //context.GetCentralViewport().Register(sdl); // (*)
105 } 117 }
106 118
107 context.Start(); 119 context.Start();
108 sdl.Run(); 120 sdl.Run();
109 121
113 // otherwise the application might crash, because the 125 // otherwise the application might crash, because the
114 // "SdlEngine" is an observer of the viewport (*) and the 126 // "SdlEngine" is an observer of the viewport (*) and the
115 // update thread started by "context.Start()" would call a 127 // update thread started by "context.Start()" would call a
116 // destructed object (the "SdlEngine" is deleted with the 128 // destructed object (the "SdlEngine" is deleted with the
117 // lexical scope). 129 // lexical scope).
130
131 // TODO Is this still true with message broker?
118 context.Stop(); 132 context.Stop();
119 } 133 }
120 134
135
121 void SdlStoneApplicationRunner::Finalize() 136 void SdlStoneApplicationRunner::Finalize()
122 { 137 {
123 SdlWindow::GlobalFinalize(); 138 SdlWindow::GlobalFinalize();
124 } 139 }
125
126
127 } 140 }