mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-23 11:47:35 +08:00
BasicFileSeverBackend style fixes
This commit is contained in:
@@ -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() { }
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user