MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / getOrCreateUnitId

Method getOrCreateUnitId

OpenHD/ohd_common/src/openhd_settings_directories.cpp:33–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31#include "openhd_util_filesystem.h"
32
33std::string openhd::getOrCreateUnitId() {
34 generateSettingsDirectoryIfNonExists();
35 auto unit_id_opt = OHDFilesystemUtil::opt_read_file(get_unit_id_file_path());
36 if (unit_id_opt.has_value()) {
37 std::string unit_id = unit_id_opt.value();
38 // openhd::log::get_default()->debug("Read unit id:{}",unit_id);
39 return unit_id;
40 }
41 // No unit id exists yet - create new one
42 // generate new unit id
43 // See https://www.boost.org/doc/libs/1_62_0/libs/uuid/uuid.html
44 // const boost::uuids::uuid _uuid = boost::uuids::random_generator()();
45 // unit_id = to_string(_uuid);
46 std::string unit_id = create_unit_it_temporary();
47 OHDFilesystemUtil::write_file(get_unit_id_file_path(), unit_id);
48 openhd::log::get_default()->info("Created new unit id:{}", unit_id);
49 return unit_id;
50}
51
52void openhd::clean_all_settings() {
53 openhd::log::get_default()->debug("clean_all_settings()");

Callers

nothing calls this directly

Calls 2

get_unit_id_file_pathFunction · 0.85
create_unit_it_temporaryFunction · 0.85

Tested by

no test coverage detected