From 60e83cc208083b7759fded7302c193d34c02cb1a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 6 Jul 2023 23:09:08 +0200 Subject: Patch from Aaron Boxer adding initial support for GPU-powered J2K encoding via his tool "grok". --- src/lib/config.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src/lib/config.h') diff --git a/src/lib/config.h b/src/lib/config.h index 0a332bcbb..0c9affbb6 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -618,6 +618,28 @@ public: return _allow_smpte_bv20; } + std::string gpu_binary_location () const { + return _gpu_binary_location; + } + + bool enable_gpu () const { + return _enable_gpu; + } + + int selected_gpu () const { + return _selected_gpu; + } + std::string gpu_license_server () const { + return _gpu_license_server; + } + + int gpu_license_port () const { + return _gpu_license_port; + } + std::string gpu_license () const { + return _gpu_license; + } + int isdcf_name_part_length() const { return _isdcf_name_part_length; } @@ -1198,11 +1220,29 @@ public: void set_allow_smpte_bv20(bool allow) { maybe_set(_allow_smpte_bv20, allow, ALLOW_SMPTE_BV20); } - + void set_gpu_binary_location (std::string location) { + maybe_set (_gpu_binary_location, location); + } + void set_enable_gpu (bool enable) { + maybe_set (_enable_gpu, enable); + } + void set_selected_gpu (int selected) { + maybe_set (_selected_gpu, selected); + } + void set_gpu_license_server (std::string s) { + maybe_set (_gpu_license_server, s); + } + void set_gpu_license_port (int p) { + maybe_set (_gpu_license_port, p); + } + void set_gpu_license (std::string p) { + maybe_set (_gpu_license, p); + } void set_isdcf_name_part_length(int length) { maybe_set(_isdcf_name_part_length, length, ISDCF_NAME_PART_LENGTH); } + void changed (Property p = OTHER); boost::signals2::signal Changed; /** Emitted if read() failed on an existing Config file. There is nothing @@ -1443,6 +1483,14 @@ private: bool _allow_smpte_bv20; int _isdcf_name_part_length; + /* GPU */ + bool _enable_gpu; + std::string _gpu_binary_location; + int _selected_gpu; + std::string _gpu_license_server; + int _gpu_license_port; + std::string _gpu_license; + ExportConfig _export; static int const _current_version; -- cgit v1.2.3 From 9ba80f8c08dbfbf1b4eafa8fcb40001a55bbbf0e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 24 Sep 2023 17:23:57 +0200 Subject: Use boost::filesystem::path for gpu_binary_location(). --- src/lib/config.cc | 2 +- src/lib/config.h | 13 +++++++--- src/lib/grok/context.h | 55 ++++++++++++++++++++++++++---------------- src/lib/grok/messenger.h | 28 +++++++++++++++------ src/wx/grok/gpu_config_panel.h | 12 ++++----- 5 files changed, 71 insertions(+), 39 deletions(-) (limited to 'src/lib/config.h') diff --git a/src/lib/config.cc b/src/lib/config.cc index bbb3eef27..a4ee4ad99 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -1133,7 +1133,7 @@ Config::write_config () const /* [XML] ISDCFNamePartLength Maximum length of the "name" part of an ISDCF name, which should be 14 according to the standard */ root->add_child("ISDCFNamePartLength")->add_child_text(raw_convert(_isdcf_name_part_length)); - root->add_child("GpuBinaryLocation")->add_child_text (_gpu_binary_location); + root->add_child("GpuBinaryLocation")->add_child_text (_gpu_binary_location.string()); root->add_child("EnableGpu")->add_child_text ((_enable_gpu ? "1" : "0")); root->add_child("SelectedGpu")->add_child_text (raw_convert (_selected_gpu)); root->add_child("GpuLicenseServer")->add_child_text (_gpu_license_server); diff --git a/src/lib/config.h b/src/lib/config.h index 0c9affbb6..9aba9e9d2 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -618,7 +618,7 @@ public: return _allow_smpte_bv20; } - std::string gpu_binary_location () const { + boost::filesystem::path gpu_binary_location() const { return _gpu_binary_location; } @@ -1220,24 +1220,31 @@ public: void set_allow_smpte_bv20(bool allow) { maybe_set(_allow_smpte_bv20, allow, ALLOW_SMPTE_BV20); } - void set_gpu_binary_location (std::string location) { + + void set_gpu_binary_location(boost::filesystem::path location) { maybe_set (_gpu_binary_location, location); } + void set_enable_gpu (bool enable) { maybe_set (_enable_gpu, enable); } + void set_selected_gpu (int selected) { maybe_set (_selected_gpu, selected); } + void set_gpu_license_server (std::string s) { maybe_set (_gpu_license_server, s); } + void set_gpu_license_port (int p) { maybe_set (_gpu_license_port, p); } + void set_gpu_license (std::string p) { maybe_set (_gpu_license, p); } + void set_isdcf_name_part_length(int length) { maybe_set(_isdcf_name_part_length, length, ISDCF_NAME_PART_LENGTH); } @@ -1485,7 +1492,7 @@ private: /* GPU */ bool _enable_gpu; - std::string _gpu_binary_location; + boost::filesystem::path _gpu_binary_location; int _selected_gpu; std::string _gpu_license_server; int _gpu_license_port; diff --git a/src/lib/grok/context.h b/src/lib/grok/context.h index 72e62c4fa..3e4144d07 100644 --- a/src/lib/grok/context.h +++ b/src/lib/grok/context.h @@ -74,12 +74,22 @@ struct FrameProxy { }; struct DcpomaticContext { - DcpomaticContext(std::shared_ptr film, Writer& writer, - EventHistory &history, const std::string &location) : - film_(film), writer_(writer), - history_(history), location_(location), - width_(0), height_(0) - {} + DcpomaticContext( + std::shared_ptr film, + Writer& writer, + EventHistory& history, + boost::filesystem::path const& location + ) + : film_(film) + , writer_(writer) + , history_(history) + , _location(location) + , width_(0) + , height_(0) + { + + } + void setDimensions(uint32_t w, uint32_t h) { width_ = w; height_ = h; @@ -87,7 +97,7 @@ struct DcpomaticContext { std::shared_ptr film_; Writer& writer_; EventHistory &history_; - std::string location_; + boost::filesystem::path _location; uint32_t width_; uint32_t height_; }; @@ -100,12 +110,13 @@ public: launched_(false) { if (Config::instance()->enable_gpu ()) { - boost::filesystem::path folder(dcpomaticContext_.location_); + boost::filesystem::path folder(dcpomaticContext_._location); boost::filesystem::path binaryPath = folder / "grk_compress"; if (!boost::filesystem::exists(binaryPath)) { - getMessengerLogger()->error("Invalid binary location %s", - dcpomaticContext_.location_.c_str()); - return; + getMessengerLogger()->error( + "Invalid binary location %s", dcpomaticContext_._location.c_str() + ); + return; } auto proc = [this](const std::string& str) { try { @@ -166,16 +177,18 @@ public: auto s = dcpv.get_size(); dcpomaticContext_.setDimensions(s.width, s.height); auto config = Config::instance(); - messenger_->launchGrok(dcpomaticContext_.location_, - dcpomaticContext_.width_,dcpomaticContext_.width_, - dcpomaticContext_.height_, - 3, 12, device, - dcpomaticContext_.film_->resolution() == Resolution::FOUR_K, - dcpomaticContext_.film_->video_frame_rate(), - dcpomaticContext_.film_->j2k_bandwidth(), - config->gpu_license_server(), - config->gpu_license_port(), - config->gpu_license()); + messenger_->launchGrok( + dcpomaticContext_._location, + dcpomaticContext_.width_,dcpomaticContext_.width_, + dcpomaticContext_.height_, + 3, 12, device, + dcpomaticContext_.film_->resolution() == Resolution::FOUR_K, + dcpomaticContext_.film_->video_frame_rate(), + dcpomaticContext_.film_->j2k_bandwidth(), + config->gpu_license_server(), + config->gpu_license_port(), + config->gpu_license() + ); } launched_ = messenger_->waitForClientInit(); diff --git a/src/lib/grok/messenger.h b/src/lib/grok/messenger.h index 008e58dd2..5cb21a1cd 100644 --- a/src/lib/grok/messenger.h +++ b/src/lib/grok/messenger.h @@ -542,11 +542,22 @@ struct Messenger sendQueue.push(oss.str()); } - void launchGrok(const std::string &dir, uint32_t width, uint32_t stride, - uint32_t height, uint32_t samplesPerPixel, uint32_t depth, - int device, bool is4K, uint32_t fps, uint32_t bandwidth, - const std::string server, uint32_t port, - const std::string license) + + void launchGrok( + boost::filesystem::path const& dir, + uint32_t width, + uint32_t stride, + uint32_t height, + uint32_t samplesPerPixel, + uint32_t depth, + int device, + bool is4K, + uint32_t fps, + uint32_t bandwidth, + const std::string server, + uint32_t port, + const std::string license + ) { std::unique_lock lk(shutdownMutex_); @@ -640,13 +651,14 @@ struct Messenger protected: std::condition_variable clientInitializedCondition_; private: - void launch(const std::string &cmd, const std::string &dir) + void launch(std::string const& cmd, boost::filesystem::path const& dir) { // Change the working directory if(!dir.empty()) { - if(chdir(dir.c_str()) != 0) - { + boost::system::error_code ec; + boost::filesystem::current_path(dir, ec); + if (ec) { getMessengerLogger()->error("Error: failed to change the working directory"); return; } diff --git a/src/wx/grok/gpu_config_panel.h b/src/wx/grok/gpu_config_panel.h index 88163ae0c..a0f2a1f7f 100644 --- a/src/wx/grok/gpu_config_panel.h +++ b/src/wx/grok/gpu_config_panel.h @@ -21,15 +21,15 @@ #pragma once -static std::vector get_gpu_names(std::string binary, std::string filename) +static std::vector get_gpu_names(boost::filesystem::path binary, boost::filesystem::path filename) { // Execute the GPU listing program and redirect its output to a file - if (std::system((binary + " > " + filename).c_str()) < 0) { + if (std::system((binary.string() + " > " + filename.string()).c_str()) < 0) { return {}; } std::vector gpu_names; - std::ifstream file(filename); + std::ifstream file(filename.c_str()); if (file.is_open()) { std::string line; @@ -57,8 +57,8 @@ public: } void update(void) { auto cfg = Config::instance(); - auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister"; - auto lister_file = cfg->gpu_binary_location () + "/" + "gpus.txt"; + auto lister_binary = cfg->gpu_binary_location() / "gpu_lister"; + auto lister_file = cfg->gpu_binary_location () / "gpus.txt"; if (boost::filesystem::exists(lister_binary)) { auto gpu_names = get_gpu_names(lister_binary, lister_file); @@ -160,7 +160,7 @@ private: auto config = Config::instance (); checked_set (_enable_gpu, config->enable_gpu()); - _binary_location->SetPath(config->gpu_binary_location ()); + _binary_location->SetPath(std_to_wx(config->gpu_binary_location().string())); _gpu_list_control->update(); _gpu_list_control->setSelection(config->selected_gpu()); checked_set (_server, config->gpu_license_server()); -- cgit v1.2.3 From 617b8cd303b4a96621a207724c55bed1d749b10c Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 6 Oct 2023 22:42:44 +0200 Subject: Clean up grok's presence in the config file and make sure it's optional. It should be allowed to not have any grok stuff in the config file, and we should generally call it grok rather than GPU in case other non-grok GPU stuff arrives in the future. --- src/lib/config.cc | 66 ++++++++++++++++++++++++---------- src/lib/config.h | 74 +++++++++++++------------------------- src/lib/grok/context.h | 11 +++--- src/lib/grok_j2k_encoder_thread.cc | 4 ++- src/lib/j2k_encoder.cc | 31 ++++++++++------ src/lib/j2k_encoder.h | 4 +-- src/wx/grok/gpu_config_panel.h | 69 ++++++++++++++++++++--------------- 7 files changed, 145 insertions(+), 114 deletions(-) (limited to 'src/lib/config.h') diff --git a/src/lib/config.cc b/src/lib/config.cc index 3a7442c39..938be090c 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -212,12 +212,9 @@ Config::set_defaults () set_notification_email_to_default (); set_cover_sheet_to_default (); - _gpu_binary_location = ""; - _enable_gpu = false; - _selected_gpu = 0; - _gpu_license_server = ""; - _gpu_license_port = 5000; - _gpu_license = ""; +#ifdef DCPOMATIC_GROK + _grok = boost::none; +#endif _main_divider_sash_position = {}; _main_content_divider_sash_position = {}; @@ -640,12 +637,11 @@ try _allow_smpte_bv20 = f.optional_bool_child("AllowSMPTEBv20").get_value_or(false); _isdcf_name_part_length = f.optional_number_child("ISDCFNamePartLength").get_value_or(14); - _enable_gpu = f.optional_bool_child("EnableGPU").get_value_or(false); - _gpu_binary_location = f.string_child("GPUBinaryLocation"); - _selected_gpu = f.number_child("SelectedGPU"); - _gpu_license_server = f.string_child ("GPULicenseServer"); - _gpu_license_port = f.number_child ("GPULicensePort"); - _gpu_license = f.string_child("GPULicense"); +#ifdef DCPOMATIC_GROK + if (auto grok = f.optional_node_child("Grok")) { + _grok = Grok(grok); + } +#endif _export.read(f.optional_node_child("Export")); } @@ -1133,12 +1129,11 @@ Config::write_config () const /* [XML] ISDCFNamePartLength Maximum length of the "name" part of an ISDCF name, which should be 14 according to the standard */ root->add_child("ISDCFNamePartLength")->add_child_text(raw_convert(_isdcf_name_part_length)); - root->add_child("GPUBinaryLocation")->add_child_text (_gpu_binary_location.string()); - root->add_child("EnableGPU")->add_child_text ((_enable_gpu ? "1" : "0")); - root->add_child("SelectedGPU")->add_child_text (raw_convert (_selected_gpu)); - root->add_child("GPULicenseServer")->add_child_text (_gpu_license_server); - root->add_child("GPULicensePort")->add_child_text (raw_convert (_gpu_license_port)); - root->add_child("GPULicense")->add_child_text (_gpu_license); +#ifdef DCPOMATIC_GROK + if (_grok) { + _grok->as_xml(root->add_child("Grok")); + } +#endif _export.write(root->add_child("Export")); @@ -1660,3 +1655,38 @@ Config::initial_path(string id) const return iter->second; } + +#ifdef DCPOMATIC_GROK + +Config::Grok::Grok(cxml::ConstNodePtr node) + : enable(node->bool_child("Enable")) + , binary_location(node->string_child("BinaryLocation")) + , selected(node->number_child("Selected")) + , licence_server(node->string_child("LicenceServer")) + , licence_port(node->number_child("LicencePort")) + , licence(node->string_child("Licence")) +{ + +} + + +void +Config::Grok::as_xml(xmlpp::Element* node) const +{ + node->add_child("BinaryLocation")->add_child_text(binary_location.string()); + node->add_child("Enable")->add_child_text((enable ? "1" : "0")); + node->add_child("Selected")->add_child_text(raw_convert(selected)); + node->add_child("LicenceServer")->add_child_text(licence_server); + node->add_child("LicencePort")->add_child_text(raw_convert(licence_port)); + node->add_child("Licence")->add_child_text(licence); +} + + +void +Config::set_grok(Grok const& grok) +{ + _grok = grok; + changed(OTHER); +} + +#endif diff --git a/src/lib/config.h b/src/lib/config.h index 9aba9e9d2..eaf85451d 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -618,27 +618,27 @@ public: return _allow_smpte_bv20; } - boost::filesystem::path gpu_binary_location() const { - return _gpu_binary_location; - } - - bool enable_gpu () const { - return _enable_gpu; - } - - int selected_gpu () const { - return _selected_gpu; - } - std::string gpu_license_server () const { - return _gpu_license_server; - } +#ifdef DCPOMATIC_GROK + class Grok + { + public: + Grok() = default; + Grok(cxml::ConstNodePtr node); + + void as_xml(xmlpp::Element* node) const; + + bool enable = false; + boost::filesystem::path binary_location; + int selected = 0; + std::string licence_server; + int licence_port = 5000; + std::string licence; + }; - int gpu_license_port () const { - return _gpu_license_port; - } - std::string gpu_license () const { - return _gpu_license; + boost::optional grok() const { + return _grok; } +#endif int isdcf_name_part_length() const { return _isdcf_name_part_length; @@ -1221,29 +1221,9 @@ public: maybe_set(_allow_smpte_bv20, allow, ALLOW_SMPTE_BV20); } - void set_gpu_binary_location(boost::filesystem::path location) { - maybe_set (_gpu_binary_location, location); - } - - void set_enable_gpu (bool enable) { - maybe_set (_enable_gpu, enable); - } - - void set_selected_gpu (int selected) { - maybe_set (_selected_gpu, selected); - } - - void set_gpu_license_server (std::string s) { - maybe_set (_gpu_license_server, s); - } - - void set_gpu_license_port (int p) { - maybe_set (_gpu_license_port, p); - } - - void set_gpu_license (std::string p) { - maybe_set (_gpu_license, p); - } +#ifdef DCPOMATIC_GROK + void set_grok(Grok const& grok); +#endif void set_isdcf_name_part_length(int length) { maybe_set(_isdcf_name_part_length, length, ISDCF_NAME_PART_LENGTH); @@ -1490,13 +1470,9 @@ private: bool _allow_smpte_bv20; int _isdcf_name_part_length; - /* GPU */ - bool _enable_gpu; - boost::filesystem::path _gpu_binary_location; - int _selected_gpu; - std::string _gpu_license_server; - int _gpu_license_port; - std::string _gpu_license; +#ifdef DCPOMATIC_GROK + boost::optional _grok; +#endif ExportConfig _export; diff --git a/src/lib/grok/context.h b/src/lib/grok/context.h index d27caa5f6..521faae8d 100644 --- a/src/lib/grok/context.h +++ b/src/lib/grok/context.h @@ -112,7 +112,8 @@ public: explicit GrokContext(DcpomaticContext* dcpomatic_context) : _dcpomatic_context(dcpomatic_context) { - if (!Config::instance()->enable_gpu()) { + auto grok = Config::instance()->grok().get_value_or({}); + if (!grok.enable) { return; } @@ -214,7 +215,7 @@ public: auto s = dcpv.get_size(); _dcpomatic_context->set_dimensions(s.width, s.height); - auto config = Config::instance(); + auto grok = Config::instance()->grok().get_value_or({}); if (!_messenger->launchGrok( _dcpomatic_context->location, _dcpomatic_context->width, @@ -226,9 +227,9 @@ public: _dcpomatic_context->film->resolution() == Resolution::FOUR_K, _dcpomatic_context->film->video_frame_rate(), _dcpomatic_context->film->j2k_bandwidth(), - config->gpu_license_server(), - config->gpu_license_port(), - config->gpu_license())) { + grok.licence_server, + grok.licence_port, + grok.licence)) { _launch_failed = true; return false; } diff --git a/src/lib/grok_j2k_encoder_thread.cc b/src/lib/grok_j2k_encoder_thread.cc index 79b80f694..79fb1bbae 100644 --- a/src/lib/grok_j2k_encoder_thread.cc +++ b/src/lib/grok_j2k_encoder_thread.cc @@ -39,7 +39,9 @@ try LOG_TIMING("encoder-pop thread=%1 frame=%2 eyes=%3", thread_id(), frame.index(), static_cast(frame.eyes())); - if (_context->launch(frame, Config::instance()->selected_gpu()) && _context->scheduleCompress(frame)) { + auto grok = Config::instance()->grok().get_value_or({}); + + if (_context->launch(frame, grok.selected) && _context->scheduleCompress(frame)) { frame_guard.cancel(); } } diff --git a/src/lib/j2k_encoder.cc b/src/lib/j2k_encoder.cc index 3bb7ccaed..e68402483 100644 --- a/src/lib/j2k_encoder.cc +++ b/src/lib/j2k_encoder.cc @@ -95,11 +95,14 @@ J2KEncoder::J2KEncoder(shared_ptr film, Writer& writer) : _film (film) , _history (200) , _writer (writer) +{ #ifdef DCPOMATIC_GROK - , _dcpomatic_context(new grk_plugin::DcpomaticContext(film, writer, _history, Config::instance()->gpu_binary_location())) - , _context(Config::instance()->enable_gpu() ? new grk_plugin::GrokContext(_dcpomatic_context) : nullptr) + auto grok = Config::instance()->grok().get_value_or({}); + _dcpomatic_context = new grk_plugin::DcpomaticContext(film, writer, _history, grok.binary_location); + if (grok.enable) { + _context = new grk_plugin::GrokContext(_dcpomatic_context); + } #endif -{ servers_list_changed (); } @@ -121,9 +124,14 @@ void J2KEncoder::servers_list_changed() { auto config = Config::instance(); +#ifdef DCPOMATIC_GROK + auto const grok_enable = config->grok().get_value_or({}).enable; +#else + auto const grok_enable = false; +#endif - auto const cpu = (config->enable_gpu() || config->only_servers_encode()) ? 0 : config->master_encoding_threads(); - auto const gpu = config->enable_gpu() ? config->master_encoding_threads() : 0; + auto const cpu = (grok_enable || config->only_servers_encode()) ? 0 : config->master_encoding_threads(); + auto const gpu = grok_enable ? config->master_encoding_threads() : 0; remake_threads(cpu, gpu, EncodeServerFinder::instance()->servers()); } @@ -141,16 +149,17 @@ J2KEncoder::begin () void J2KEncoder::pause() { - if (!Config::instance()->enable_gpu()) { +#ifdef DCPOMATIC_GROK + if (!Config::instance()->grok().get_value_or({}).enable) { return; } + return; terminate_threads (); /* Something might have been thrown during terminate_threads */ rethrow (); -#ifdef DCPOMATIC_GROK delete _context; _context = nullptr; #endif @@ -159,14 +168,14 @@ J2KEncoder::pause() void J2KEncoder::resume() { - if (!Config::instance()->enable_gpu()) { +#ifdef DCPOMATIC_GROK + if (!Config::instance()->grok().get_value_or({}).enable) { return; } -#ifdef DCPOMATIC_GROK _context = new grk_plugin::GrokContext(_dcpomatic_context); -#endif servers_list_changed(); +#endif } @@ -203,7 +212,7 @@ J2KEncoder::end() */ for (auto & i: _queue) { #ifdef DCPOMATIC_GROK - if (Config::instance()->enable_gpu ()) { + if (Config::instance()->grok().get_value_or({}).enable) { if (!_context->scheduleCompress(i)){ LOG_GENERAL (N_("[%1] J2KEncoder thread pushes frame %2 back onto queue after failure"), thread_id(), i.index()); // handle error diff --git a/src/lib/j2k_encoder.h b/src/lib/j2k_encoder.h index 0dbe654a4..6bfbaea49 100644 --- a/src/lib/j2k_encoder.h +++ b/src/lib/j2k_encoder.h @@ -127,8 +127,8 @@ private: boost::signals2::scoped_connection _server_found_connection; #ifdef DCPOMATIC_GROK - grk_plugin::DcpomaticContext* _dcpomatic_context; - grk_plugin::GrokContext *_context; + grk_plugin::DcpomaticContext* _dcpomatic_context = nullptr; + grk_plugin::GrokContext *_context = nullptr; #endif bool _ending = false; diff --git a/src/wx/grok/gpu_config_panel.h b/src/wx/grok/gpu_config_panel.h index 40e999181..cbf037592 100644 --- a/src/wx/grok/gpu_config_panel.h +++ b/src/wx/grok/gpu_config_panel.h @@ -59,9 +59,9 @@ public: void update() { - auto cfg = Config::instance(); - auto lister_binary = cfg->gpu_binary_location() / "gpu_lister"; - auto lister_file = cfg->gpu_binary_location () / "gpus.txt"; + auto grok = Config::instance()->grok().get_value_or({}); + auto lister_binary = grok.binary_location / "gpu_lister"; + auto lister_file = grok.binary_location / "gpus.txt"; if (boost::filesystem::exists(lister_binary)) { auto gpu_names = get_gpu_names(lister_binary, lister_file); @@ -84,7 +84,9 @@ private: { auto selection = _combo_box->GetSelection(); if (selection != wxNOT_FOUND) { - Config::instance()->set_selected_gpu(selection); + auto grok = Config::instance()->grok().get_value_or({}); + grok.selected = selection; + Config::instance()->set_grok(grok); } } @@ -141,68 +143,79 @@ private: table->Add(_port); add_label_to_sizer(table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _license = new PasswordEntry(_panel); - table->Add(_license->get_panel(), 1, wxEXPAND | wxALL); + _licence = new PasswordEntry(_panel); + table->Add(_licence->get_panel(), 1, wxEXPAND | wxALL); _enable_gpu->bind(&GPUPage::enable_gpu_changed, this); _binary_location->Bind(wxEVT_DIRPICKER_CHANGED, boost::bind (&GPUPage::binary_location_changed, this)); _server->Bind(wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this)); _port->Bind(wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this)); - _license->Changed.connect(boost::bind(&GPUPage::license_changed, this)); + _licence->Changed.connect(boost::bind(&GPUPage::licence_changed, this)); setup_sensitivity(); } void setup_sensitivity() { - auto config = Config::instance(); + auto grok = Config::instance()->grok().get_value_or({}); - _binary_location->Enable(config->enable_gpu()); - _gpu_list_control->Enable(config->enable_gpu()); - _server->Enable(config->enable_gpu()); - _port->Enable(config->enable_gpu()); - _license->get_panel()->Enable(config->enable_gpu()); + _binary_location->Enable(grok.enable); + _gpu_list_control->Enable(grok.enable); + _server->Enable(grok.enable); + _port->Enable(grok.enable); + _licence->get_panel()->Enable(grok.enable); } void config_changed() override { - auto config = Config::instance(); + auto grok = Config::instance()->grok().get_value_or({}); - checked_set(_enable_gpu, config->enable_gpu()); - _binary_location->SetPath(std_to_wx(config->gpu_binary_location().string())); + checked_set(_enable_gpu, grok.enable); + _binary_location->SetPath(std_to_wx(grok.binary_location.string())); _gpu_list_control->update(); - _gpu_list_control->set_selection(config->selected_gpu()); - checked_set(_server, config->gpu_license_server()); - checked_set(_port, config->gpu_license_port()); - checked_set(_license, config->gpu_license()); + _gpu_list_control->set_selection(grok.selected); + checked_set(_server, grok.licence_server); + checked_set(_port, grok.licence_port); + checked_set(_licence, grok.licence); } void enable_gpu_changed() { - auto config = Config::instance(); - config->set_enable_gpu(_enable_gpu->GetValue()); + auto grok = Config::instance()->grok().get_value_or({}); + grok.enable = _enable_gpu->GetValue(); + Config::instance()->set_grok(grok); + setup_sensitivity(); } void binary_location_changed() { - Config::instance()->set_gpu_binary_location(wx_to_std(_binary_location->GetPath())); + auto grok = Config::instance()->grok().get_value_or({}); + grok.binary_location = wx_to_std(_binary_location->GetPath()); + Config::instance()->set_grok(grok); + _gpu_list_control->update(); } void server_changed() { - Config::instance()->set_gpu_license_server(wx_to_std(_server->GetValue())); + auto grok = Config::instance()->grok().get_value_or({}); + grok.licence_server = wx_to_std(_server->GetValue()); + Config::instance()->set_grok(grok); } void port_changed() { - Config::instance()->set_gpu_license_port(_port->GetValue()); + auto grok = Config::instance()->grok().get_value_or({}); + grok.licence_port = _port->GetValue(); + Config::instance()->set_grok(grok); } - void license_changed() + void licence_changed() { - Config::instance()->set_gpu_license(_license->get()); + auto grok = Config::instance()->grok().get_value_or({}); + grok.licence = wx_to_std(_licence->get()); + Config::instance()->set_grok(grok); } CheckBox* _enable_gpu = nullptr; @@ -210,5 +223,5 @@ private: GpuList* _gpu_list_control = nullptr; wxTextCtrl* _server = nullptr; wxSpinCtrl* _port = nullptr; - PasswordEntry* _license = nullptr; + PasswordEntry* _licence = nullptr; }; -- cgit v1.2.3