Commit 57b5e808 authored by Vivien Didelot's avatar Vivien Didelot

daemon: (VideoPreference) ensure active device is plugged

The active device is read from the configuration. But the device might
be unplugged. If so, set the active device to the next plugged one.

Refs #46200

Change-Id: I29ce8f577e64c49a27c74fbe6c9aa97f4910dcee
parent 5bd4abe4
......@@ -29,6 +29,7 @@
* as that of the covered work.
*/
#include <algorithm>
#include <sstream>
#include "config/yamlemitter.h"
......@@ -299,8 +300,17 @@ VideoPreference::unserialize(const Conf::YamlNode &node)
deviceList_.push_back(device);
}
/* make first device active by default */
active_ = deviceList_.begin();
/*
* The first device in the configuration is the last active one.
* If it is unplugged, assign the next one.
*/
const auto plugged = getDeviceList();
for (active_ = deviceList_.begin();
active_ != deviceList_.end();
++active_)
if (std::find(plugged.begin(), plugged.end(),
(*active_).name) != plugged.end())
break;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment