libcamera: v4l2_controls: Turn V4L2ControlInfoMap into a class
In preparation for extending V4L2ControlInfoMap with control idmap support, turn it into a real class. Make it inherit from std::map<> instead of wrapping it to keep the API simple. V4L2ControlInfoMap is meant to be constructed with a set of control info, and never modified afterwards. To ensure this, inherit from std::map<> with private access specifier, and explicitly expose the std::map<> methods that do not allow insertion or removal of elements. A custom move assignment operator is implemented to allow efficient construction of the V4L2ControlInfoMap. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Tested-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
90d0f193eb
commit
2fe723440a
3 changed files with 40 additions and 5 deletions
|
@ -43,7 +43,21 @@ private:
|
|||
ControlRange range_;
|
||||
};
|
||||
|
||||
using V4L2ControlInfoMap = std::map<unsigned int, V4L2ControlInfo>;
|
||||
class V4L2ControlInfoMap : private std::map<unsigned int, V4L2ControlInfo>
|
||||
{
|
||||
public:
|
||||
V4L2ControlInfoMap &operator=(std::map<unsigned int, V4L2ControlInfo> &&info);
|
||||
|
||||
using std::map<unsigned int, V4L2ControlInfo>::begin;
|
||||
using std::map<unsigned int, V4L2ControlInfo>::cbegin;
|
||||
using std::map<unsigned int, V4L2ControlInfo>::end;
|
||||
using std::map<unsigned int, V4L2ControlInfo>::cend;
|
||||
using std::map<unsigned int, V4L2ControlInfo>::at;
|
||||
using std::map<unsigned int, V4L2ControlInfo>::empty;
|
||||
using std::map<unsigned int, V4L2ControlInfo>::size;
|
||||
using std::map<unsigned int, V4L2ControlInfo>::count;
|
||||
using std::map<unsigned int, V4L2ControlInfo>::find;
|
||||
};
|
||||
|
||||
class V4L2Control
|
||||
{
|
||||
|
|
|
@ -156,10 +156,28 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)
|
|||
*/
|
||||
|
||||
/**
|
||||
* \typedef V4L2ControlInfoMap
|
||||
* \class V4L2ControlInfoMap
|
||||
* \brief A map of control ID to V4L2ControlInfo
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Move assignment operator from plain map
|
||||
* \param[in] info The control info map
|
||||
*
|
||||
* Populate the map by replacing its contents with those of \a info using move
|
||||
* semantics. Upon return the \a info map will be empty.
|
||||
*
|
||||
* This is the only supported way to populate a V4L2ControlInfoMap.
|
||||
*
|
||||
* \return The populated V4L2ControlInfoMap
|
||||
*/
|
||||
V4L2ControlInfoMap &V4L2ControlInfoMap::operator=(std::map<unsigned int, V4L2ControlInfo> &&info)
|
||||
{
|
||||
std::map<unsigned int, V4L2ControlInfo>::operator=(std::move(info));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* \class V4L2Control
|
||||
* \brief A V4L2 control value
|
||||
|
|
|
@ -340,6 +340,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp)
|
|||
*/
|
||||
void V4L2Device::listControls()
|
||||
{
|
||||
std::map<unsigned int, V4L2ControlInfo> ctrls;
|
||||
struct v4l2_query_ext_ctrl ctrl = {};
|
||||
|
||||
/* \todo Add support for menu and compound controls. */
|
||||
|
@ -368,10 +369,12 @@ void V4L2Device::listControls()
|
|||
continue;
|
||||
}
|
||||
|
||||
controls_.emplace(std::piecewise_construct,
|
||||
ctrls.emplace(std::piecewise_construct,
|
||||
std::forward_as_tuple(ctrl.id),
|
||||
std::forward_as_tuple(ctrl));
|
||||
}
|
||||
|
||||
controls_ = std::move(ctrls);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue