Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BufferManager: add mutex, configuration from file, empty constructor workflow et al #65

Merged
merged 7 commits into from
Feb 9, 2021

Conversation

Nicogene
Copy link
Member

@Nicogene Nicogene commented Feb 5, 2021

{
    "filename": "buffer_manager_test_conf_file",
    "n_samples": 20,
    "save_period": 1.0,
    "data_threshold": 10,
    "auto_save": true,
    "save_periodically": true,
    "channels": [
        ["one",[1,1]],
        ["two",[1,1]]
    ]
  }

For now we used the json library just importing the json.hpp file, this has to be in the future to an "extern" folder or better with the cmake FetchContent mechanism.

Please review code.

cc @traversaro @S-Dafarra @GiulioRomualdi

- The ChannelInfo has been changed from a struct of two elements to a
std::pair, in order to be easily handled with the json file conf.
- All the flags, options of the BufferManager have been put in the BufferConfig
- The empty constructor is allowed now, for this we added all the functions
needed for configuring a default BufferManager(It fixes #60)
- The mutex has been added in saveToFile(partially address #9
- Now the periodicSave, saves only the variables that go above the
data_treshold specified
if (ok && _bufferConfig.save_periodically) {
ok = ok && enablePeriodicSave(_bufferConfig.save_period);
}
// TODO ROLL BACK IN CASE OF FAILURE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do not plan to address these, please open issues for any open points. TODO in the code get forgotten quite easily, better to open issues to track then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #72 opened

Comment on lines 78 to 84
bool configureFromFile(const std::string& config_filename) {
// read a JSON file
std::ifstream input_stream(config_filename);
nlohmann::json jason_file;
input_stream >> jason_file;
return configure(jason_file.get<yarp::telemetry::BufferConfig>());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we have this as a free function instead, something like bool configureFromJSONFile(BufferManager& manager, const std::string& config_filename) ?
This would avoid needles coupling of the specific configuration method with the BufferManager class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been addressed in b5b431e.

Instead of BufferManager I put as I/O BufferConfig, in order to avoid circular dependencies

@Nicogene
Copy link
Member Author

Nicogene commented Feb 5, 2021

Before merging this maybe we should address #66 that seems straightforward and in this way, we avoid having so many additions

@Nicogene Nicogene force-pushed the feat/mutexFileConfEmptyCons branch from 5ae9a26 to eaa72fd Compare February 8, 2021 09:36
CMakeLists.txt Outdated
@@ -62,6 +62,23 @@ find_package(matioCpp REQUIRED)
find_package(Boost REQUIRED)
find_package(Threads REQUIRED)

option(YARP_TELEMETRY_USES_SYSTEM_nlohmann_json OFF)
if(YARP_TELEMETRY_USES_SYSTEM_nlohmann_json)
find_package(nlohmann_json 3.9.0 REQUIRED)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really require 3.9? Ubuntu 20.04 ships with 3.7 in apt (https://repology.org/project/nlohmann-json/versions), I would try to at least enable it, if then it does not work we can fix it to the minimum working version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need 3.9.0 for this macro. But we can write the functions by hand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we actually need 3.9 then it is ok for me!

@Nicogene
Copy link
Member Author

Nicogene commented Feb 8, 2021

Looking https://github.com/robotology-playground/yarp-telemetry/pull/65/checks?check_run_id=1853547617 seems that someone is putting BUILD_TESTING to true

@Nicogene
Copy link
Member Author

Nicogene commented Feb 8, 2021

Here is why nlohmann/json#2513, we need 3.9.2(that is unreleased)

@traversaro
Copy link
Member

Here is why nlohmann/json#2513, we need 3.9.2(that is unreleased)

FetchContent can also use a specific commit, and then we can switch to 3.9.2 once is released.

@Nicogene Nicogene force-pushed the feat/mutexFileConfEmptyCons branch from eaa72fd to 857945e Compare February 8, 2021 10:08
@Nicogene
Copy link
Member Author

Nicogene commented Feb 8, 2021

FetchContent can also use a specific commit, and then we can switch to 3.9.2 once is released.

I put develop branch

In this way we can have multiple parsers implementation and keep the parser library as private dependency
@Nicogene Nicogene requested a review from traversaro February 9, 2021 11:10
@Nicogene Nicogene merged commit c6b9222 into master Feb 9, 2021
@Nicogene Nicogene deleted the feat/mutexFileConfEmptyCons branch February 9, 2021 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment