diff --git a/libuavcan_drivers/linux/apps/test_posix.cpp b/libuavcan_drivers/linux/apps/test_posix.cpp index be432e1f36..a59aa1c3ef 100644 --- a/libuavcan_drivers/linux/apps/test_posix.cpp +++ b/libuavcan_drivers/linux/apps/test_posix.cpp @@ -40,6 +40,29 @@ int main(int argc, const char** argv) ENFORCE(0 == std::system(("cat " + event_log_file).c_str())); } + /* + * Storage backend test + */ + { + using namespace uavcan::dynamic_node_id_server; + + uavcan_posix::dynamic_node_id_server::FileStorageBackend backend; + ENFORCE(0 <= backend.init("/tmp/uavcan_posix/dynamic_node_id_server/storage")); + + auto print_key = [&](const char* key) { + std::cout << static_cast(backend).get(key).c_str() << std::endl; + }; + + print_key("foobar"); + + static_cast(backend).set("foobar", "0123456789abcdef0123456789abcdef"); + static_cast(backend).set("the_answer", "42"); + + print_key("foobar"); + print_key("the_answer"); + print_key("nonexistent"); + } + return 0; } catch (const std::exception& ex) diff --git a/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp b/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp index 20346e588c..e0ccf7cd3d 100644 --- a/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp +++ b/libuavcan_drivers/posix/include/uavcan_posix/dynamic_node_id_server/file_storage_backend.hpp @@ -34,6 +34,8 @@ class FileStorageBackend : public uavcan::dynamic_node_id_server::IStorageBacken */ enum { MaxPathLength = 128 }; + enum { FilePermissions = 438 }; ///< 0o666 + /** * This type is used for the path */ @@ -76,7 +78,7 @@ class FileStorageBackend : public uavcan::dynamic_node_id_server::IStorageBacken using namespace std; PathString path = base_path.c_str(); path += key; - int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC); + int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, FilePermissions); if (fd >= 0) { write(fd, value.c_str(), value.size());