5 #ifndef UAVCAN_PROTOCOL_FILE_SERVER_HPP_INCLUDED 6 #define UAVCAN_PROTOCOL_FILE_SERVER_HPP_INCLUDED 13 #include <uavcan/protocol/file/GetInfo.hpp> 14 #include <uavcan/protocol/file/GetDirectoryEntryInfo.hpp> 15 #include <uavcan/protocol/file/Read.hpp> 16 #include <uavcan/protocol/file/Write.hpp> 17 #include <uavcan/protocol/file/Delete.hpp> 29 typedef protocol::file::Path::FieldTypes::path
Path;
31 typedef protocol::file::Error
Error;
36 enum { ReadSize = protocol::file::Read::Response::FieldTypes::data::MaxSize };
41 static char getPathSeparator() {
return static_cast<char>(protocol::file::Path::SEPARATOR); }
49 virtual int16_t getInfo(
const Path& path,
uint64_t& out_size, EntryType& out_type) = 0;
73 return Error::NOT_IMPLEMENTED;
84 return Error::NOT_IMPLEMENTED;
94 EntryType& out_type, Path& out_entry_full_path)
99 (void)out_entry_full_path;
100 return Error::NOT_IMPLEMENTED;
115 void (BasicFileServer::*)(
const protocol::file::GetInfo::Request&, protocol::file::GetInfo::Response&)>
119 void (BasicFileServer::*)(
const protocol::file::Read::Request&, protocol::file::Read::Response&)>
125 void handleGetInfo(
const protocol::file::GetInfo::Request& req, protocol::file::GetInfo::Response& resp)
127 resp.error.value = backend_.getInfo(req.path.path, resp.size, resp.entry_type);
130 void handleRead(
const protocol::file::Read::Request& req, protocol::file::Read::Response& resp)
132 uint16_t inout_size = resp.data.capacity();
134 resp.data.resize(inout_size);
136 resp.error.value = backend_.read(req.path.path, req.offset, resp.data.begin(), inout_size);
138 if (resp.error.value != protocol::file::Error::OK)
143 if (inout_size > resp.data.capacity())
146 resp.error.value = protocol::file::Error::UNKNOWN_ERROR;
150 resp.data.resize(inout_size);
159 : get_info_srv_(node)
194 void (FileServer::*)(
const protocol::file::Write::Request&, protocol::file::Write::Response&)>
198 void (FileServer::*)(
const protocol::file::Delete::Request&, protocol::file::Delete::Response&)>
202 void (FileServer::*)(
const protocol::file::GetDirectoryEntryInfo::Request&,
203 protocol::file::GetDirectoryEntryInfo::Response&)>
210 void handleWrite(
const protocol::file::Write::Request& req, protocol::file::Write::Response& resp)
212 resp.error.value = backend_.write(req.path.path, req.offset, req.data.begin(), req.data.size());
215 void handleDelete(
const protocol::file::Delete::Request& req, protocol::file::Delete::Response& resp)
217 resp.error.value = backend_.remove(req.path.path);
221 protocol::file::GetDirectoryEntryInfo::Response& resp)
223 resp.error.value = backend_.getDirectoryEntryInfo(req.directory_path.path, req.entry_index,
224 resp.entry_type, resp.entry_full_path.path);
232 , get_directory_entry_info_srv_(node)
255 res = get_directory_entry_info_srv_.
start(
268 #endif // Include guard
static char getPathSeparator()
ServiceServer< protocol::file::Write, WriteCallback > write_srv_
void handleGetInfo(const protocol::file::GetInfo::Request &req, protocol::file::GetInfo::Response &resp)
BasicFileServer(INode &node, IFileServerBackend &backend)
void handleDelete(const protocol::file::Delete::Request &req, protocol::file::Delete::Response &resp)
FileServer(INode &node, IFileServerBackend &backend)
IFileServerBackend & backend_
Derived types can use it.
virtual int16_t getDirectoryEntryInfo(const Path &directory_path, const uint32_t entry_index, EntryType &out_type, Path &out_entry_full_path)
protocol::file::EntryType EntryType
void handleRead(const protocol::file::Read::Request &req, protocol::file::Read::Response &resp)
ServiceServer< protocol::file::Read, ReadCallback > read_srv_
virtual ~IFileServerBackend()
ServiceServer< protocol::file::Delete, DeleteCallback > delete_srv_
void handleGetDirectoryEntryInfo(const protocol::file::GetDirectoryEntryInfo::Request &req, protocol::file::GetDirectoryEntryInfo::Response &resp)
ServiceServer< protocol::file::GetInfo, GetInfoCallback > get_info_srv_
virtual int16_t write(const Path &path, const uint64_t offset, const uint8_t *buffer, const uint16_t size)
int start(const Callback &callback)
protocol::file::Error Error
void handleWrite(const protocol::file::Write::Request &req, protocol::file::Write::Response &resp)
ServiceServer< protocol::file::GetDirectoryEntryInfo, GetDirectoryEntryInfoCallback > get_directory_entry_info_srv_
protocol::file::Path::FieldTypes::path Path