+ auto strong = amcp.lock();
+ if (strong)
+ strong->parse(wcmd);
+ else
+ break;
+ }
+};
+
+bool run(const std::wstring& config_file_name, tbb::atomic<bool>& should_wait_for_keypress)
+{
+ std::promise<bool> shutdown_server_now;
+ std::future<bool> shutdown_server = shutdown_server_now.get_future();
+
+ print_info();
+
+ // Create server object which initializes channels, protocols and controllers.
+ std::unique_ptr<server> caspar_server(new server(shutdown_server_now));
+
+ // For example CEF resets the global locale, so this is to reset it back to "our" preference.
+ setup_global_locale();
+
+ // Print environment information.
+ print_system_info(caspar_server->get_system_info_provider_repo());
+
+ std::wstringstream str;
+ boost::property_tree::xml_writer_settings<std::wstring> w(' ', 3);
+ boost::property_tree::write_xml(str, env::properties(), w);
+ CASPAR_LOG(info) << config_file_name << L":\n-----------------------------------------\n" << str.str() << L"-----------------------------------------";
+
+ {
+ CASPAR_SCOPED_CONTEXT_MSG(config_file_name + L": ")
+ caspar_server->start();
+ }
+
+ // Create a dummy client which prints amcp responses to console.
+ auto console_client = spl::make_shared<IO::ConsoleClientInfo>();
+
+ // Create a amcp parser for console commands.
+ std::shared_ptr<IO::protocol_strategy<wchar_t>> amcp = spl::make_shared<caspar::IO::delimiter_based_chunking_strategy_factory<wchar_t>>(
+ L"\r\n",
+ spl::make_shared<caspar::IO::legacy_strategy_adapter_factory>(
+ spl::make_shared<protocol::amcp::AMCPProtocolStrategy>(
+ L"Console",
+ caspar_server->get_amcp_command_repository())))->create(console_client);
+ std::weak_ptr<IO::protocol_strategy<wchar_t>> weak_amcp = amcp;
+
+ // Use separate thread for the blocking console input, will be terminated
+ // anyway when the main thread terminates.
+ boost::thread stdin_thread(std::bind(do_run, weak_amcp, std::ref(shutdown_server_now), std::ref(should_wait_for_keypress))); //compiler didn't like lambda here...
+ stdin_thread.detach();
+ bool should_restart = shutdown_server.get();
+ amcp.reset();
+
+ while (weak_amcp.lock());
+
+ return should_restart;