Skip to content

Commit

Permalink
Update for core_configuration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Jun 12, 2024
1 parent e3fab29 commit 20bd50b
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/bin/cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace {
void apply_core_configuration_function(std::function<void(std::shared_ptr<krbn::core_configuration::core_configuration>)> function) {
auto wait = pqrs::make_thread_wait();
krbn::configuration_monitor monitor(krbn::constants::get_user_core_configuration_file_path(),
geteuid());
geteuid(),
krbn::core_configuration::error_handling::loose);

monitor.core_configuration_updated.connect([wait, function](auto&& weak_core_configuration) {
if (auto core_configuration = weak_core_configuration.lock()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ class components_manager final : public pqrs::dispatcher::extra::dispatcher_clie

void start_child_components(void) {
configuration_monitor_ = std::make_shared<configuration_monitor>(constants::get_user_core_configuration_file_path(),
geteuid());
geteuid(),
krbn::core_configuration::error_handling::loose);
configuration_monitor_->core_configuration_updated.connect([](auto&& weak_core_configuration) {
if (auto c = weak_core_configuration.lock()) {
//
Expand Down
3 changes: 2 additions & 1 deletion src/core/grabber/include/grabber/device_grabber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
event_tap_monitor_->async_start();

configuration_monitor_ = std::make_unique<configuration_monitor>(user_core_configuration_file_path,
expected_user_core_configuration_file_owner);
expected_user_core_configuration_file_owner,
krbn::core_configuration::error_handling::loose);

configuration_monitor_->core_configuration_updated.connect([this](auto&& weak_core_configuration) {
if (auto core_configuration = weak_core_configuration.lock()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class libkrbn_configuration_monitor final : public pqrs::dispatcher::extra::disp
: dispatcher_client() {
monitor_ = std::make_unique<krbn::configuration_monitor>(
krbn::constants::get_user_core_configuration_file_path(),
geteuid());
geteuid(),
krbn::core_configuration::error_handling::loose);

auto wait = pqrs::make_thread_wait();

Expand Down
2 changes: 1 addition & 1 deletion src/lib/libkrbn/src/libkrbn_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool libkrbn_core_configuration_get_machine_specific_enable_multitouch_extension
if (auto c = get_current_core_configuration()) {
return c->get_machine_specific().get_entry().get_enable_multitouch_extension();
}
return krbn::core_configuration::details::machine_specific::entry::enable_multitouch_extension_default_value;
return false;
}

void libkrbn_core_configuration_set_machine_specific_enable_multitouch_extension(bool value) {
Expand Down
4 changes: 3 additions & 1 deletion src/share/core_configuration/configuration_json_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class value_t final : public base_t {
}

value_ = it->template get<T>();
} catch (...) {
} catch (std::exception& e) {
if (error_handling == error_handling::strict) {
throw;
} else {
logger::get_logger()->error(e.what());
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/share/core_configuration/core_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ class core_configuration final {
public:
core_configuration(const core_configuration&) = delete;

core_configuration(error_handling error_handling)
: core_configuration("", 0, error_handling) {
core_configuration(void)
: core_configuration("",
0,
krbn::core_configuration::error_handling::loose) {
}

core_configuration(const std::string& file_path,
Expand Down
5 changes: 4 additions & 1 deletion src/share/monitor/configuration_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class configuration_monitor final : public pqrs::dispatcher::extra::dispatcher_c

configuration_monitor(const std::string& user_core_configuration_file_path,
uid_t expected_user_core_configuration_file_owner,
core_configuration::error_handling error_handling,
const std::string& system_core_configuration_file_path = constants::get_system_core_configuration_file_path()) : dispatcher_client() {
std::vector<std::string> targets = {
user_core_configuration_file_path,
Expand All @@ -31,6 +32,7 @@ class configuration_monitor final : public pqrs::dispatcher::extra::dispatcher_c
file_monitor_->file_changed.connect([this,
user_core_configuration_file_path,
expected_user_core_configuration_file_owner,
error_handling,
system_core_configuration_file_path](auto&& changed_file_path,
auto&& changed_file_body) {
auto file_path = changed_file_path;
Expand Down Expand Up @@ -61,7 +63,8 @@ class configuration_monitor final : public pqrs::dispatcher::extra::dispatcher_c
}

auto c = std::make_shared<core_configuration::core_configuration>(file_path,
expected_user_core_configuration_file_owner);
expected_user_core_configuration_file_owner,
error_handling);

if (core_configuration_ && !c->is_loaded()) {
return;
Expand Down
4 changes: 2 additions & 2 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
all:
bash scripts/check-cmakelists.sh
@for d in `find lib src -type d | sort`; do \
@for d in `find src -type d | sort`; do \
if [ -f "$$d/Makefile" ]; then \
echo "[Test] $$d"; \
make -C $$d || exit 1; \
fi; \
done

clean:
@for d in `find lib src -type d | sort`; do \
@for d in `find src -type d | sort`; do \
if [ -f "$$d/Makefile" ]; then \
make -C $$d clean; \
fi; \
Expand Down
1 change: 1 addition & 0 deletions tests/src/configuration_monitor/src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class test_configuration_monitor final {
test_configuration_monitor(void) : count_(0) {
configuration_monitor_ = std::make_unique<krbn::configuration_monitor>("target/user.json",
geteuid(),
krbn::core_configuration::error_handling::loose,
"target/system.json");

configuration_monitor_->core_configuration_updated.connect([this](auto&& weak_core_configuration) {
Expand Down
3 changes: 2 additions & 1 deletion tests/src/manipulator/src/manipulator_factory_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ void run_manipulator_factory_test(void) {
},
}},
});
krbn::core_configuration::details::device device(json);
krbn::core_configuration::details::device device(json,
krbn::core_configuration::error_handling::loose);

auto device_id_1234_5678_keyboard = manipulator_conditions_helper.prepare_device(
pqrs::hid::vendor_id::value_t(1234), // vendor_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ void run_manipulator_conditions_test(void) {
}));
manipulator_environment.set_system_preferences_properties(system_preferences_properties);

auto core_configuration = std::make_shared<krbn::core_configuration::core_configuration>("json/core_configuration.json", geteuid());
auto core_configuration = std::make_shared<krbn::core_configuration::core_configuration>("json/core_configuration.json",
geteuid(),
krbn::core_configuration::error_handling::loose);
manipulator_environment.set_core_configuration(core_configuration);

krbn::async_file_writer::wait();
Expand Down Expand Up @@ -348,7 +350,9 @@ void run_manipulator_conditions_test(void) {
}));
manipulator_environment.set_system_preferences_properties(system_preferences_properties);

auto core_configuration = std::make_shared<krbn::core_configuration::core_configuration>("json/core_configuration.json", geteuid());
auto core_configuration = std::make_shared<krbn::core_configuration::core_configuration>("json/core_configuration.json",
geteuid(),
krbn::core_configuration::error_handling::loose);
manipulator_environment.set_core_configuration(core_configuration);

{
Expand Down

0 comments on commit 20bd50b

Please sign in to comment.