This source file includes following definitions.
- Create
- GetDevices
#include "device/serial/serial_device_enumerator_mac.h"
#include "base/file_util.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_util.h"
namespace device {
scoped_ptr<SerialDeviceEnumerator> SerialDeviceEnumerator::Create() {
return scoped_ptr<SerialDeviceEnumerator>(new SerialDeviceEnumeratorMac());
}
SerialDeviceEnumeratorMac::SerialDeviceEnumeratorMac() {}
SerialDeviceEnumeratorMac::~SerialDeviceEnumeratorMac() {}
void SerialDeviceEnumeratorMac::GetDevices(SerialDeviceInfoList* devices) {
const base::FilePath kDevRoot("/dev");
const int kFilesAndSymLinks =
base::FileEnumerator::FILES | base::FileEnumerator::SHOW_SYM_LINKS;
std::set<std::string> valid_patterns;
valid_patterns.insert("/dev/*Bluetooth*");
valid_patterns.insert("/dev/*Modem*");
valid_patterns.insert("/dev/*bluetooth*");
valid_patterns.insert("/dev/*modem*");
valid_patterns.insert("/dev/*serial*");
valid_patterns.insert("/dev/tty.*");
valid_patterns.insert("/dev/cu.*");
devices->clear();
base::FileEnumerator enumerator(kDevRoot, false, kFilesAndSymLinks);
do {
const base::FilePath next_device_path(enumerator.Next());
const std::string next_device = next_device_path.value();
if (next_device.empty())
break;
std::set<std::string>::const_iterator i = valid_patterns.begin();
for (; i != valid_patterns.end(); ++i) {
if (MatchPattern(next_device, *i)) {
linked_ptr<SerialDeviceInfo> info(new SerialDeviceInfo);
info->path = next_device;
devices->push_back(info);
break;
}
}
} while (true);
}
}