libcamera: base: Rename FileDescriptor to SharedFD
Now that we have a UniqueFD class, the name FileDescriptor is ambiguous. Rename it to SharedFD. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
@@ -31,7 +31,7 @@ LOG_DEFINE_CATEGORY(IPADataSerializer)
|
||||
*
|
||||
* \todo Harden the vector and map deserializer
|
||||
*
|
||||
* \todo For FileDescriptors, instead of storing a validity flag, store an
|
||||
* \todo For SharedFDs, instead of storing a validity flag, store an
|
||||
* index into the fd array. This will allow us to use views instead of copying.
|
||||
*/
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace {
|
||||
* \param[in] cs ControlSerializer
|
||||
*
|
||||
* This version of deserialize() can be used if the object type \a T and its
|
||||
* members don't have any FileDescriptor.
|
||||
* members don't have any SharedFD.
|
||||
*
|
||||
* \a cs is only necessary if the object type \a T or its members contain
|
||||
* ControlList or ControlInfoMap.
|
||||
@@ -132,7 +132,7 @@ namespace {
|
||||
* \param[in] cs ControlSerializer
|
||||
*
|
||||
* This version of deserialize() can be used if the object type \a T and its
|
||||
* members don't have any FileDescriptor.
|
||||
* members don't have any SharedFD.
|
||||
*
|
||||
* \a cs is only necessary if the object type \a T or its members contain
|
||||
* ControlList or ControlInfoMap.
|
||||
@@ -143,7 +143,7 @@ namespace {
|
||||
/**
|
||||
* \fn template<typename T> IPADataSerializer<T>::deserialize(
|
||||
* const std::vector<uint8_t> &data,
|
||||
* const std::vector<FileDescriptor> &fds,
|
||||
* const std::vector<SharedFD> &fds,
|
||||
* ControlSerializer *cs = nullptr)
|
||||
* \brief Deserialize byte vector and fd vector into an object
|
||||
* \tparam T Type of object to deserialize to
|
||||
@@ -152,7 +152,7 @@ namespace {
|
||||
* \param[in] cs ControlSerializer
|
||||
*
|
||||
* This version of deserialize() (or the iterator version) must be used if
|
||||
* the object type \a T or its members contain FileDescriptor.
|
||||
* the object type \a T or its members contain SharedFD.
|
||||
*
|
||||
* \a cs is only necessary if the object type \a T or its members contain
|
||||
* ControlList or ControlInfoMap.
|
||||
@@ -164,8 +164,8 @@ namespace {
|
||||
* \fn template<typename T> IPADataSerializer::deserialize(
|
||||
* std::vector<uint8_t>::const_iterator dataBegin,
|
||||
* std::vector<uint8_t>::const_iterator dataEnd,
|
||||
* std::vector<FileDescriptor>::const_iterator fdsBegin,
|
||||
* std::vector<FileDescriptor>::const_iterator fdsEnd,
|
||||
* std::vector<SharedFD>::const_iterator fdsBegin,
|
||||
* std::vector<SharedFD>::const_iterator fdsEnd,
|
||||
* ControlSerializer *cs = nullptr)
|
||||
* \brief Deserialize byte vector and fd vector into an object
|
||||
* \tparam T Type of object to deserialize to
|
||||
@@ -176,7 +176,7 @@ namespace {
|
||||
* \param[in] cs ControlSerializer
|
||||
*
|
||||
* This version of deserialize() (or the vector version) must be used if
|
||||
* the object type \a T or its members contain FileDescriptor.
|
||||
* the object type \a T or its members contain SharedFD.
|
||||
*
|
||||
* \a cs is only necessary if the object type \a T or its members contain
|
||||
* ControlList or ControlInfoMap.
|
||||
@@ -189,7 +189,7 @@ namespace {
|
||||
#define DEFINE_POD_SERIALIZER(type) \
|
||||
\
|
||||
template<> \
|
||||
std::tuple<std::vector<uint8_t>, std::vector<FileDescriptor>> \
|
||||
std::tuple<std::vector<uint8_t>, std::vector<SharedFD>> \
|
||||
IPADataSerializer<type>::serialize(const type &data, \
|
||||
[[maybe_unused]] ControlSerializer *cs) \
|
||||
{ \
|
||||
@@ -217,7 +217,7 @@ type IPADataSerializer<type>::deserialize(const std::vector<uint8_t> &data, \
|
||||
\
|
||||
template<> \
|
||||
type IPADataSerializer<type>::deserialize(const std::vector<uint8_t> &data, \
|
||||
[[maybe_unused]] const std::vector<FileDescriptor> &fds, \
|
||||
[[maybe_unused]] const std::vector<SharedFD> &fds, \
|
||||
ControlSerializer *cs) \
|
||||
{ \
|
||||
return deserialize(data.cbegin(), data.end(), cs); \
|
||||
@@ -226,8 +226,8 @@ type IPADataSerializer<type>::deserialize(const std::vector<uint8_t> &data, \
|
||||
template<> \
|
||||
type IPADataSerializer<type>::deserialize(std::vector<uint8_t>::const_iterator dataBegin, \
|
||||
std::vector<uint8_t>::const_iterator dataEnd, \
|
||||
[[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsBegin, \
|
||||
[[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsEnd, \
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsBegin, \
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd, \
|
||||
ControlSerializer *cs) \
|
||||
{ \
|
||||
return deserialize(dataBegin, dataEnd, cs); \
|
||||
@@ -251,7 +251,7 @@ DEFINE_POD_SERIALIZER(double)
|
||||
* function parameter serdes).
|
||||
*/
|
||||
template<>
|
||||
std::tuple<std::vector<uint8_t>, std::vector<FileDescriptor>>
|
||||
std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
|
||||
IPADataSerializer<std::string>::serialize(const std::string &data,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
{
|
||||
@@ -278,7 +278,7 @@ IPADataSerializer<std::string>::deserialize(std::vector<uint8_t>::const_iterator
|
||||
template<>
|
||||
std::string
|
||||
IPADataSerializer<std::string>::deserialize(const std::vector<uint8_t> &data,
|
||||
[[maybe_unused]] const std::vector<FileDescriptor> &fds,
|
||||
[[maybe_unused]] const std::vector<SharedFD> &fds,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
{
|
||||
return { data.cbegin(), data.cend() };
|
||||
@@ -288,8 +288,8 @@ template<>
|
||||
std::string
|
||||
IPADataSerializer<std::string>::deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
[[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsEnd,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
{
|
||||
return { dataBegin, dataEnd };
|
||||
@@ -307,7 +307,7 @@ IPADataSerializer<std::string>::deserialize(std::vector<uint8_t>::const_iterator
|
||||
* be used. The serialized ControlInfoMap will have zero length.
|
||||
*/
|
||||
template<>
|
||||
std::tuple<std::vector<uint8_t>, std::vector<FileDescriptor>>
|
||||
std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
|
||||
IPADataSerializer<ControlList>::serialize(const ControlList &data, ControlSerializer *cs)
|
||||
{
|
||||
if (!cs)
|
||||
@@ -407,7 +407,7 @@ IPADataSerializer<ControlList>::deserialize(const std::vector<uint8_t> &data,
|
||||
template<>
|
||||
ControlList
|
||||
IPADataSerializer<ControlList>::deserialize(const std::vector<uint8_t> &data,
|
||||
[[maybe_unused]] const std::vector<FileDescriptor> &fds,
|
||||
[[maybe_unused]] const std::vector<SharedFD> &fds,
|
||||
ControlSerializer *cs)
|
||||
{
|
||||
return deserialize(data.cbegin(), data.end(), cs);
|
||||
@@ -417,8 +417,8 @@ template<>
|
||||
ControlList
|
||||
IPADataSerializer<ControlList>::deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
[[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsEnd,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd,
|
||||
ControlSerializer *cs)
|
||||
{
|
||||
return deserialize(dataBegin, dataEnd, cs);
|
||||
@@ -431,7 +431,7 @@ IPADataSerializer<ControlList>::deserialize(std::vector<uint8_t>::const_iterator
|
||||
* X bytes - Serialized ControlInfoMap (using ControlSerializer)
|
||||
*/
|
||||
template<>
|
||||
std::tuple<std::vector<uint8_t>, std::vector<FileDescriptor>>
|
||||
std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
|
||||
IPADataSerializer<ControlInfoMap>::serialize(const ControlInfoMap &map,
|
||||
ControlSerializer *cs)
|
||||
{
|
||||
@@ -493,7 +493,7 @@ IPADataSerializer<ControlInfoMap>::deserialize(const std::vector<uint8_t> &data,
|
||||
template<>
|
||||
ControlInfoMap
|
||||
IPADataSerializer<ControlInfoMap>::deserialize(const std::vector<uint8_t> &data,
|
||||
[[maybe_unused]] const std::vector<FileDescriptor> &fds,
|
||||
[[maybe_unused]] const std::vector<SharedFD> &fds,
|
||||
ControlSerializer *cs)
|
||||
{
|
||||
return deserialize(data.cbegin(), data.end(), cs);
|
||||
@@ -503,30 +503,30 @@ template<>
|
||||
ControlInfoMap
|
||||
IPADataSerializer<ControlInfoMap>::deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
[[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsEnd,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd,
|
||||
ControlSerializer *cs)
|
||||
{
|
||||
return deserialize(dataBegin, dataEnd, cs);
|
||||
}
|
||||
|
||||
/*
|
||||
* FileDescriptors are serialized into four bytes that tells if the
|
||||
* FileDescriptor is valid or not. If it is valid, then for serialization
|
||||
* the fd will be written to the fd vector, or for deserialization the
|
||||
* fd vector const_iterator will be valid.
|
||||
* SharedFD instances are serialized into four bytes that tells if the SharedFD
|
||||
* is valid or not. If it is valid, then for serialization the fd will be
|
||||
* written to the fd vector, or for deserialization the fd vector const_iterator
|
||||
* will be valid.
|
||||
*
|
||||
* This validity is necessary so that we don't send -1 fd over sendmsg(). It
|
||||
* also allows us to simply send the entire fd vector into the deserializer
|
||||
* and it will be recursively consumed as necessary.
|
||||
*/
|
||||
template<>
|
||||
std::tuple<std::vector<uint8_t>, std::vector<FileDescriptor>>
|
||||
IPADataSerializer<FileDescriptor>::serialize(const FileDescriptor &data,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
|
||||
IPADataSerializer<SharedFD>::serialize(const SharedFD &data,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
{
|
||||
std::vector<uint8_t> dataVec;
|
||||
std::vector<FileDescriptor> fdVec;
|
||||
std::vector<SharedFD> fdVec;
|
||||
|
||||
/*
|
||||
* Store as uint32_t to prepare for conversion from validity flag
|
||||
@@ -542,11 +542,11 @@ IPADataSerializer<FileDescriptor>::serialize(const FileDescriptor &data,
|
||||
}
|
||||
|
||||
template<>
|
||||
FileDescriptor IPADataSerializer<FileDescriptor>::deserialize([[maybe_unused]] std::vector<uint8_t>::const_iterator dataBegin,
|
||||
[[maybe_unused]] std::vector<uint8_t>::const_iterator dataEnd,
|
||||
std::vector<FileDescriptor>::const_iterator fdsBegin,
|
||||
std::vector<FileDescriptor>::const_iterator fdsEnd,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
SharedFD IPADataSerializer<SharedFD>::deserialize([[maybe_unused]] std::vector<uint8_t>::const_iterator dataBegin,
|
||||
[[maybe_unused]] std::vector<uint8_t>::const_iterator dataEnd,
|
||||
std::vector<SharedFD>::const_iterator fdsBegin,
|
||||
std::vector<SharedFD>::const_iterator fdsEnd,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
{
|
||||
ASSERT(std::distance(dataBegin, dataEnd) >= 4);
|
||||
|
||||
@@ -554,13 +554,13 @@ FileDescriptor IPADataSerializer<FileDescriptor>::deserialize([[maybe_unused]] s
|
||||
|
||||
ASSERT(!(valid && std::distance(fdsBegin, fdsEnd) < 1));
|
||||
|
||||
return valid ? *fdsBegin : FileDescriptor();
|
||||
return valid ? *fdsBegin : SharedFD();
|
||||
}
|
||||
|
||||
template<>
|
||||
FileDescriptor IPADataSerializer<FileDescriptor>::deserialize(const std::vector<uint8_t> &data,
|
||||
const std::vector<FileDescriptor> &fds,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
SharedFD IPADataSerializer<SharedFD>::deserialize(const std::vector<uint8_t> &data,
|
||||
const std::vector<SharedFD> &fds,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
{
|
||||
return deserialize(data.cbegin(), data.end(), fds.cbegin(), fds.end());
|
||||
}
|
||||
@@ -568,22 +568,22 @@ FileDescriptor IPADataSerializer<FileDescriptor>::deserialize(const std::vector<
|
||||
/*
|
||||
* FrameBuffer::Plane is serialized as:
|
||||
*
|
||||
* 4 byte - FileDescriptor
|
||||
* 4 byte - SharedFD
|
||||
* 4 bytes - uint32_t Offset
|
||||
* 4 bytes - uint32_t Length
|
||||
*/
|
||||
template<>
|
||||
std::tuple<std::vector<uint8_t>, std::vector<FileDescriptor>>
|
||||
std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
|
||||
IPADataSerializer<FrameBuffer::Plane>::serialize(const FrameBuffer::Plane &data,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
{
|
||||
std::vector<uint8_t> dataVec;
|
||||
std::vector<FileDescriptor> fdsVec;
|
||||
std::vector<SharedFD> fdsVec;
|
||||
|
||||
std::vector<uint8_t> fdBuf;
|
||||
std::vector<FileDescriptor> fdFds;
|
||||
std::vector<SharedFD> fdFds;
|
||||
std::tie(fdBuf, fdFds) =
|
||||
IPADataSerializer<FileDescriptor>::serialize(data.fd);
|
||||
IPADataSerializer<SharedFD>::serialize(data.fd);
|
||||
dataVec.insert(dataVec.end(), fdBuf.begin(), fdBuf.end());
|
||||
fdsVec.insert(fdsVec.end(), fdFds.begin(), fdFds.end());
|
||||
|
||||
@@ -597,13 +597,13 @@ template<>
|
||||
FrameBuffer::Plane
|
||||
IPADataSerializer<FrameBuffer::Plane>::deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
std::vector<FileDescriptor>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsEnd,
|
||||
std::vector<SharedFD>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd,
|
||||
[[maybe_unused]] ControlSerializer *cs)
|
||||
{
|
||||
FrameBuffer::Plane ret;
|
||||
|
||||
ret.fd = IPADataSerializer<FileDescriptor>::deserialize(dataBegin, dataBegin + 4,
|
||||
ret.fd = IPADataSerializer<SharedFD>::deserialize(dataBegin, dataBegin + 4,
|
||||
fdsBegin, fdsBegin + 1);
|
||||
ret.offset = readPOD<uint32_t>(dataBegin, 4, dataEnd);
|
||||
ret.length = readPOD<uint32_t>(dataBegin, 8, dataEnd);
|
||||
@@ -614,7 +614,7 @@ IPADataSerializer<FrameBuffer::Plane>::deserialize(std::vector<uint8_t>::const_i
|
||||
template<>
|
||||
FrameBuffer::Plane
|
||||
IPADataSerializer<FrameBuffer::Plane>::deserialize(const std::vector<uint8_t> &data,
|
||||
const std::vector<FileDescriptor> &fds,
|
||||
const std::vector<SharedFD> &fds,
|
||||
ControlSerializer *cs)
|
||||
{
|
||||
return deserialize(data.cbegin(), data.end(), fds.cbegin(), fds.end(), cs);
|
||||
|
||||
Reference in New Issue
Block a user