forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build a basic Mojo service framework for device/usb
BUG=492805 R=reillyg@chromium.org Review URL: https://codereview.chromium.org/1155163008 Cr-Commit-Position: refs/heads/master@{#331707}
- Loading branch information
Showing
26 changed files
with
970 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2015 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/usb/device_impl.h" | ||
#include "device/usb/type_converters.h" | ||
#include "device/usb/usb_device.h" | ||
|
||
namespace device { | ||
namespace usb { | ||
|
||
DeviceImpl::DeviceImpl(scoped_refptr<UsbDevice> device, | ||
mojo::InterfaceRequest<Device> request) | ||
: binding_(this, request.Pass()), | ||
device_(device), | ||
info_(DeviceInfo::From(*device)) { | ||
// TODO(rockot/reillyg): Support more than just the current configuration. | ||
// Also, converting configuration info should be done in the TypeConverter, | ||
// but GetConfiguration() is non-const so we do it here for now. | ||
const UsbConfigDescriptor* config = device->GetConfiguration(); | ||
info_->configurations = mojo::Array<ConfigurationInfoPtr>::New(0); | ||
if (config) | ||
info_->configurations.push_back(ConfigurationInfo::From(*config)); | ||
} | ||
|
||
DeviceImpl::~DeviceImpl() { | ||
} | ||
|
||
void DeviceImpl::GetDeviceInfo(const GetDeviceInfoCallback& callback) { | ||
callback.Run(info_.Clone()); | ||
} | ||
|
||
} // namespace usb | ||
} // namespace device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2015 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. | ||
|
||
#ifndef DEVICE_USB_DEVICE_IMPL_H_ | ||
#define DEVICE_USB_DEVICE_IMPL_H_ | ||
|
||
#include "base/macros.h" | ||
#include "base/memory/ref_counted.h" | ||
#include "device/usb/public/interfaces/device.mojom.h" | ||
#include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" | ||
#include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | ||
|
||
namespace device { | ||
|
||
class UsbDevice; | ||
|
||
namespace usb { | ||
|
||
// Implementation of the public Device interface. Instances of this class are | ||
// constructed by DeviceManagerImpl and are strongly bound to their MessagePipe | ||
// lifetime. | ||
class DeviceImpl : public Device { | ||
public: | ||
DeviceImpl(scoped_refptr<UsbDevice> device, | ||
mojo::InterfaceRequest<Device> request); | ||
~DeviceImpl() override; | ||
|
||
private: | ||
// Device implementation: | ||
void GetDeviceInfo(const GetDeviceInfoCallback& callback) override; | ||
|
||
mojo::StrongBinding<Device> binding_; | ||
|
||
scoped_refptr<UsbDevice> device_; | ||
DeviceInfoPtr info_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(DeviceImpl); | ||
}; | ||
|
||
} // namespace usb | ||
} // namespace device | ||
|
||
#endif // DEVICE_USB_DEVICE_IMPL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2015 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 "base/bind.h" | ||
#include "base/message_loop/message_loop.h" | ||
#include "base/run_loop.h" | ||
#include "device/usb/device_impl.h" | ||
#include "device/usb/mock_usb_device.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" | ||
|
||
namespace device { | ||
namespace usb { | ||
|
||
namespace { | ||
|
||
using DeviceImplTest = testing::Test; | ||
|
||
void ExpectDeviceInfoAndThen(uint16_t vendor_id, | ||
uint16_t product_id, | ||
const std::string& manufacturer, | ||
const std::string& product, | ||
const std::string& serial_number, | ||
const base::Closure& continuation, | ||
DeviceInfoPtr device_info) { | ||
EXPECT_EQ(vendor_id, device_info->vendor_id); | ||
EXPECT_EQ(product_id, device_info->product_id); | ||
EXPECT_EQ(manufacturer, device_info->manufacturer); | ||
EXPECT_EQ(product, device_info->product); | ||
EXPECT_EQ(serial_number, device_info->serial_number); | ||
continuation.Run(); | ||
} | ||
|
||
} // namespace | ||
|
||
// Test that the information returned via the Device::GetDeviceInfo matches that | ||
// of the underlying device. | ||
TEST_F(DeviceImplTest, GetDeviceInfo) { | ||
base::MessageLoop message_loop; | ||
scoped_refptr<MockUsbDevice> fake_device = | ||
new MockUsbDevice(0x1234, 0x5678, "ACME", "Frobinator", "ABCDEF"); | ||
DevicePtr device; | ||
EXPECT_CALL(*fake_device.get(), GetConfiguration()); | ||
new DeviceImpl(fake_device, mojo::GetProxy(&device)); | ||
|
||
base::RunLoop run_loop; | ||
device->GetDeviceInfo(base::Bind(&ExpectDeviceInfoAndThen, 0x1234, 0x5678, | ||
"ACME", "Frobinator", "ABCDEF", | ||
run_loop.QuitClosure())); | ||
run_loop.Run(); | ||
} | ||
|
||
} // namespace usb | ||
} // namespace device |
Oops, something went wrong.