From 53317eb90249f4f3df6501f68761e1c4c99e86c3 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Tue, 26 May 2015 20:37:58 +0300 Subject: [PATCH] BasicFileSeverBackend style fixes --- .../basic_file_server_backend.hpp | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/libuavcan_drivers/posix/include/uavcan_posix/basic_file_server_backend.hpp b/libuavcan_drivers/posix/include/uavcan_posix/basic_file_server_backend.hpp index c88bf8b731..7a02ee11e1 100644 --- a/libuavcan_drivers/posix/include/uavcan_posix/basic_file_server_backend.hpp +++ b/libuavcan_drivers/posix/include/uavcan_posix/basic_file_server_backend.hpp @@ -33,32 +33,28 @@ namespace uavcan_posix */ class BasicFileSeverBackend : public uavcan::IFileServerBackend { - enum { FilePermissions = 438 }; ///< 0o666 -public: +protected: /** - * * Back-end for uavcan.protocol.file.GetInfo. * Implementation of this method is required. * On success the method must return zero. */ - __attribute__((optimize("O0"))) virtual int16_t getInfo(const Path& path, uint64_t& out_crc64, uint32_t& out_size, EntryType& out_type) { - int rv = uavcan::protocol::file::Error::INVALID_VALUE; if (path.size() > 0) { - FirmwareCommon fw; fw.getFileInfo(path.c_str()); out_crc64 = fw.descriptor.image_crc; out_size = fw.descriptor.image_size; - // todo Using fixed flag FLAG_READABLE until we add file permission checks to return actual value. + // TODO Using fixed flag FLAG_READABLE until we add file permission checks to return actual value. + // TODO Check whether the object pointed by path is a file or a directory out_type.flags = uavcan::protocol::file::EntryType::FLAG_FILE | - uavcan::protocol::file::EntryType::FLAG_READABLE;; + uavcan::protocol::file::EntryType::FLAG_READABLE; rv = 0; } return rv; @@ -71,16 +67,12 @@ public: * if the end of file is reached. * On success the method must return zero. */ - __attribute__((optimize("O0"))) virtual int16_t read(const Path& path, const uint32_t offset, uint8_t* out_buffer, uint16_t& inout_size) { - int rv = uavcan::protocol::file::Error::INVALID_VALUE; if (path.size() > 0) { - - int fd = open(path.c_str(), O_RDONLY); if (fd < 0) @@ -89,38 +81,30 @@ public: } else { - if (::lseek(fd, offset, SEEK_SET) < 0) { rv = errno; } else { - //todo uses a read at offset to fill on EAGAIN - ssize_t len = ::read(fd, out_buffer, inout_size); + // TODO use a read at offset to fill on EAGAIN + ssize_t len = ::read(fd, out_buffer, inout_size); - if (len < 0) + if (len < 0) { rv = errno; } else { - - inout_size = len; + inout_size = len; rv = 0; } } - close(fd); + (void)close(fd); } } return rv; } - - BasicFileSeverBackend() { } - - - - }; }