diff options
author | jeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-23 06:48:11 +0000 |
---|---|---|
committer | jeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-23 06:48:11 +0000 |
commit | 90416efc49a4abc14dd15b7dcca66157be3fb822 (patch) | |
tree | 36a5bda7fe43b102fefb788992e8a52c04118463 /base/mac | |
parent | 71537725fccd65a9c4c009d500276f63424a8710 (diff) | |
download | chromium_src-90416efc49a4abc14dd15b7dcca66157be3fb822.zip chromium_src-90416efc49a4abc14dd15b7dcca66157be3fb822.tar.gz chromium_src-90416efc49a4abc14dd15b7dcca66157be3fb822.tar.bz2 |
Implement support for USB Xbox360 controllers without a driver on Mac.
Without this patch, users have to install a driver that exposes a standard HID
device for the controller. Unfortunately, apart from the problems with
requiring users to install a driver, the only such available driver
(http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver)
crashes the kernel when the controller is unplugged.
This change uses IOKit to talk directly to the Xbox controller without the need
for a driver, and exposes it through the normal HTML5 gamepad API.
BUG=232238
R=scottmg@chromium.org
Review URL: https://chromiumcodereview.appspot.com/14328036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201717 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/mac')
-rw-r--r-- | base/mac/scoped_ioplugininterface.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/base/mac/scoped_ioplugininterface.h b/base/mac/scoped_ioplugininterface.h new file mode 100644 index 0000000..503980c --- /dev/null +++ b/base/mac/scoped_ioplugininterface.h @@ -0,0 +1,76 @@ +// Copyright (c) 2012 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 BASE_MAC_SCOPED_IOPLUGININTERFACE_H_ +#define BASE_MAC_SCOPED_IOPLUGININTERFACE_H_ + +#include <IOKit/IOKitLib.h> + +#include "base/basictypes.h" +#include "base/compiler_specific.h" + +namespace base { +namespace mac { + +// Just like ScopedCFTypeRef but for IOCFPlugInInterface and friends +// (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular). +template<typename T> +class ScopedIOPluginInterface { + public: + typedef T** InterfaceT; + typedef InterfaceT element_type; + + explicit ScopedIOPluginInterface(InterfaceT object = NULL) + : object_(object) { + } + + ~ScopedIOPluginInterface() { + if (object_) + (*object_)->Release(object_); + } + + void reset(InterfaceT object = NULL) { + if (object_) + (*object_)->Release(object_); + object_ = object; + } + + bool operator==(InterfaceT that) const { + return object_ == that; + } + + bool operator!=(InterfaceT that) const { + return object_ != that; + } + + operator InterfaceT() const { + return object_; + } + + InterfaceT get() const { + return object_; + } + + void swap(ScopedIOPluginInterface& that) { + InterfaceT temp = that.object_; + that.object_ = object_; + object_ = temp; + } + + InterfaceT release() WARN_UNUSED_RESULT { + InterfaceT temp = object_; + object_ = NULL; + return temp; + } + + private: + InterfaceT object_; + + DISALLOW_COPY_AND_ASSIGN(ScopedIOPluginInterface); +}; + +} // namespace mac +} // namespace base + +#endif // BASE_MAC_SCOPED_IOPLUGININTERFACE_H_ |