summaryrefslogtreecommitdiffstats
path: root/device/serial/serial_device_enumerator_win.cc
blob: 124c6b720466909d811e86384d65f2c616de8596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "device/serial/serial_device_enumerator_win.h"

#include <windows.h>

#include "base/memory/scoped_ptr.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/registry.h"

namespace device {

// static
scoped_ptr<SerialDeviceEnumerator> SerialDeviceEnumerator::Create() {
  return scoped_ptr<SerialDeviceEnumerator>(new SerialDeviceEnumeratorWin());
}

SerialDeviceEnumeratorWin::SerialDeviceEnumeratorWin() {}

SerialDeviceEnumeratorWin::~SerialDeviceEnumeratorWin() {}

// TODO(rockot): Query the system for more information than just device paths.
// This may or may not require using a different strategy than scanning the
// registry location below.
mojo::Array<serial::DeviceInfoPtr> SerialDeviceEnumeratorWin::GetDevices() {
  base::win::RegistryValueIterator iter_key(
      HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM\\");
  mojo::Array<serial::DeviceInfoPtr> devices(0);
  for (; iter_key.Valid(); ++iter_key) {
    serial::DeviceInfoPtr info(serial::DeviceInfo::New());
    info->path = base::UTF16ToASCII(iter_key.Value());
    devices.push_back(info.Pass());
  }
  return devices.Pass();
}

}  // namespace device