feat(src): added device sort function

This commit is contained in:
Osenberg 2019-03-29 20:18:53 +08:00
parent b2f6120fa5
commit 9716c20bca

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include "mynteye/device/utils.h" #include "mynteye/device/utils.h"
#include <algorithm>
#include <cstdlib> #include <cstdlib>
#include "mynteye/logger.h" #include "mynteye/logger.h"
@ -20,10 +21,14 @@
#include "mynteye/device/context.h" #include "mynteye/device/context.h"
#include "mynteye/device/device.h" #include "mynteye/device/device.h"
#include "mynteye/logger.h"
MYNTEYE_BEGIN_NAMESPACE MYNTEYE_BEGIN_NAMESPACE
bool sort_sn(std::shared_ptr<Device> device1,
std::shared_ptr<Device> device2) {
return device1->GetInfo(Info::SERIAL_NUMBER) <
device2->GetInfo(Info::SERIAL_NUMBER);
}
namespace device { namespace device {
std::shared_ptr<Device> select() { std::shared_ptr<Device> select() {
@ -37,6 +42,9 @@ std::shared_ptr<Device> select() {
return nullptr; return nullptr;
} }
if (n > 1)
sort(devices.begin(), devices.end(), sort_sn);
LOG(INFO) << "MYNT EYE devices:"; LOG(INFO) << "MYNT EYE devices:";
for (std::size_t i = 0; i < n; i++) { for (std::size_t i = 0; i < n; i++) {
auto &&device = devices[i]; auto &&device = devices[i];