22 #include "devicenode.h" 23 #include "functionjob.h" 27 Device::Device(std::string name,
int mode) :
33 Device::Device(
const Device &dev) :
44 log_error() <<
"Key \"name\" missing or not a string in json configuration";
51 if (
nullptr != json_object_get(element,
"mode")) {
55 log_error() <<
"Mode specified with bad format";
65 if (!m_isConfigured) {
66 log_info() <<
"Mapping device " << m_name;
68 if (!container->mountDevice(m_name)) {
69 log_error() <<
"Unable to mount device " << m_name;
76 return chmod(m_name.c_str(), m_mode);
81 log_error() <<
"Could not 'chmod " << m_mode
82 <<
"' the mounted device " << m_name;
86 m_isConfigured =
true;
91 void Device::calculateDeviceMode(
const int appliedMode)
93 int modeResult = m_mode;
95 if (m_mode != appliedMode) {
97 ((appliedMode / 100) >= (m_mode / 100)) ?
98 modeResult = (appliedMode / 100) * 100 : modeResult = (m_mode / 100) * 100;
100 (((appliedMode / 10) % 10) >= ((m_mode / 10) % 10)) ?
101 modeResult += (((appliedMode / 10) % 10) * 10) : modeResult += (((m_mode / 10) % 10) * 10);
103 ((appliedMode % 10) >= (m_mode % 10)) ?
104 modeResult += (appliedMode % 10) : modeResult += (m_mode % 10);
108 if (modeResult > m_mode) {
109 m_isConfigured =
false;
114 const std::string Device::getName()
119 int Device::getMode()
124 bool Device::getIsconfigured ()
126 return m_isConfigured;
129 void Device::setMode(
int mode)
131 if ((mode/100) < 8 && (mode%100)/10 < 8 && (mode%10) < 8) {
bool activate(std::shared_ptr< ContainerAbstractInterface > container)
Activates this device by running mknod and chmod commands which are run in the container.
Run a C++ function lambda inside a SoftwareContainer.
bool parse(const json_t *element)
Configures this device by parsing the supplied JSON configuration string.
Developers guide to adding a config item:
static bool read(const json_t *element, const char *key, std::string &result)
Reads a string from a JSON Object.