derive context settings from configuration file - #12432
Conversation
| auto it = _values.find(key); | ||
| return it != _values.end(); | ||
| auto it = _j.find(key); | ||
| return it != _j.end() && it->is_string(); |
There was a problem hiding this comment.
Why check for string? Don't we support other values?
There was a problem hiding this comment.
Because, at least in rs-config, and in this PR, I didn't want to change any existing functionality: tools will keep behaving the same.
There was a problem hiding this comment.
My main goal was to make rs-config compatible with raw json -- before, it couldn't even load -- and able to keep non-string content intact.
There was a problem hiding this comment.
So in the next PR this is about to change?
There was a problem hiding this comment.
No, I'm not touching it again without a good reason.
| std::map<std::string, std::string> _values; | ||
| std::map<std::string, std::string> _defaults; | ||
| std::string _filename; | ||
| nlohmann::json _j; |
There was a problem hiding this comment.
_j does not imply the member meaning, just the type. _config?
There was a problem hiding this comment.
It's the underlying json object. I can name it _json, but I don't know if that adds much...
There was a problem hiding this comment.
The name should not change if we decide to switch from JSON to XML or other.
The meaning of this variable is to hold the configuration in memory.
There was a problem hiding this comment.
_data? _map? _key_value? Anything you pick is meaningless. :)
Let's be realistic. It's a file with an extension of .json.
| std::string _filename; | ||
| nlohmann::json _j; | ||
| }; | ||
| } No newline at end of file |
| namespace librealsense { | ||
|
|
||
|
|
||
| static nlohmann::json load_config() |
There was a problem hiding this comment.
I think it might be useful to have a load/save_json( filename ) utility. I know that Noa has a task concerning saving and parsing json content.
There was a problem hiding this comment.
Not quite sure why, it's very straightforward as you see...
| // Take the global 'context' settings out of the configuration | ||
| nlohmann::json settings; | ||
| if( auto global_context = rsutils::json::nested( config, "context" ) ) | ||
| merge_settings( settings, global_context, "global config-file/context" ); |
There was a problem hiding this comment.
I thought that the parameter order should be switched.
As I understand specified context_settings should override executable settings that in turn override global setting
There was a problem hiding this comment.
That's exactly what it does
Here it take empty settings and "merges" the global, so we get global.
| nlohmann::json settings = nlohmann::json::object(); | ||
| if( only_sw_arg.getValue() ) | ||
| { | ||
| settings["dds"]["enabled"] = true; // override global dds:false or dds/enabled:false, if any |
There was a problem hiding this comment.
I think this should be true only if BUILD_WITH_DDS is set
There was a problem hiding this comment.
Doesn't hurt, but OK.
Do you think it makes sense to enable DDS automatically if we see "sw-only" device-mask (i.e., override enabled=false if device-mask is sw-only)?
There was a problem hiding this comment.
No, could be playback or future type devices. If settings set to disable then leave disabled
| } | ||
|
|
||
|
|
||
| static nlohmann::json load_config() |
There was a problem hiding this comment.
This makes my point about a utility stronger :-)
The 3 static functions should probably all be in rsutils
There was a problem hiding this comment.
Two. I thought the same but I don't think it belongs in rsutils.
Load config shouldn't know about RS2_CONFIG_FILENAME. It can get the filename. But then what're we adding? The exception handling? The error would be different, I could make it "failed to load json file: ..." but then I just don't feel the function adds much.
Same with merge_settings: it's just a wrapper around merge_patch with error handling.
In the end I decided to just keep as is. You think I should make rsutils::json::load_file() and rsutils::json::merge?
There was a problem hiding this comment.
load_file in rsutils makes less and less sense to me (no filename generation; if would have to return bool to denote if the file was there, so you'd have to handle it in the caller). I prefer to just embed directly in load_settings.
merge_patch is a weird name and I can see introducing rsutils::json::merge() or json::patch with maybe an optional name for error handling.
There was a problem hiding this comment.
Anyway:
- added
rsutils::json::patch() - added
rsutils::json::load_settingsthat does the basic global+app merge
Continuation (2/3) of previous PR for persistent DDS settings.
RS2_CONFIG_FILENAMEcommon/rs-confignow can read non-string JSON valuescontextkey, merged with:"inherit":falseE.g.:
{ "context": { "dds": { "enabled": false, "domain": 5 } }, "realsense-viewer": { "context": { "dds": { "enabled": true, "device": { "metadata": { "reliability": "best-effort" } } } } }, ... }Tracked on [LRS-963]