(io): remove module::io::atoms and use `io::session::SReader` and `io::session::SWriter` everywhere
Description
All of module::io::atoms has been removed and replaced by module::io::session counterpart. Patch
and Filter
features of atoms have also been removed.
Additionally, a new preference system, using Boost property tree, has been implemented:
Preference
The class is thread safe and use RAII mechanism to load and store data from and to the preference file. In a service, the basic usage would be:
try
{
// Load
Preferences preferences;
std::string filename = preferences.get("debug.filename");
int level = preferences.get<int>("debug.level");
...
// Save
Preferences preferences;
preferences.put("debug.filename", "log.txt");
preferences.put("debug.level", 2);
}
catch(const ui::base::PreferencesDisabled&)
{
// Nothing to do..
}
Which will be translated into:
debug:
filename: "log.txt"
level: 2
Configuration
The configuration is done by static functions:
-
set_enabled: Enable or disable preference management as a whoole. All functions, including constructor will throw
PreferencesDisabled
exception if used while "disabled" -
set_password: Set an harcoded password to be used. It enables defacto the encryption
-
set_password_policy: Defines how and when a password is asked. @see sight::core::crypto::PasswordKeeper::PasswordPolicy for possible values.
NEVER
will never display any message box, but if a password has been set, the resulting preference file will still be encrypted. AnBadPassword
exception will be thrown instead of diplaying a message box, asking to renter the password. -
set_encryption_policy: Define when the preferences file is encrypted: @see sight::core::crypto::PasswordKeeper::EncryptionPolicy for possible values.
FORCE
will encrypt the file, even if no password is given. In this case a pseudo random password is used, which can be guessed if someone has access to the code. Another option is to use an harcoded password AND EncryptionPolicy::SALTED -
Module Configuration: All the above can be configured through the module ui_base parameters (@see sight::module::ui::base::Plugin) The preferences are enabled by default, without encryption. An example of configuration would be:
moduleParam( module_ui_base PARAM_LIST preferences_enabled preferences_password_policy preferences_encryption_policy preferences_password PARAM_VALUES true once salted a_bad_hardcoded_password )
Simple JSON serialization on filesystem
It is now possible to use SReader
and SWriter
to serialize a data object into a single JSON file (until the serializer class also store additional files like for Mesh or Image object).
SReader
This is achieved withe the archive
configuration node and its format
attribute:
-
filesystem
: Reads files from the filesystem. -
archive
: Reads files from an session archive. -
default
: uses the builtin default behavior which isarchive
XML sample configuration:
<service type="sight::module::io::session::SReader">
<inout key="data" uid="..." />
<dialog extension=".sample" description="Sample Sight session file" policy="always"/>
<password policy="once, encryption=salted"/>
<archive format="filesystem"/>
</service>
SWriter
This is achieved withe the archive
configuration node and its format
attribute:
-
filesystem
: Use the filesystem to store files. -
compatible
: Store files in a ZIP archive, with old deflate algorithm -
optimized
: Store files in a ZIP archive, with zstd algorithm -
default
: uses the builtin default behavior which is "optimized"
XML sample configuration:
<service type="sight::module::io::session::SWriter">
<in key="data" uid="..." />
<dialog extension=".sample" description="Sample Sight session file" policy="once"/>
<password policy="once", encryption=salted/>
<archive format="optimized"/>
</service>
Closes #776 (closed)
How to test it?
See the modified config and launch application / samples / tutorials, (most notably, applications with transfert function, cameraseries import / export)