blob: 185e670664daf0a29c09e8ec6e6c33b9ac04ac1c [file] [log] [blame]
// Copyright 2019 The Fuchsia 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 "src/devices/tests/ddk-fidl-test/fidl-llcpp-driver.h"
#include <lib/ddk/binding_driver.h>
#include <lib/ddk/debug.h>
#include <lib/ddk/driver.h>
#include <lib/ddk/platform-defs.h>
#include <lib/fit/function.h>
#include <memory>
#include <ddktl/device.h>
#include <fbl/alloc_checker.h>
#include <fbl/auto_lock.h>
namespace fidl {
zx_status_t DdkFidlDevice::Create(void* ctx, zx_device_t* dev) {
fbl::AllocChecker ac;
std::unique_ptr<DdkFidlDevice> test_dev(new (&ac) DdkFidlDevice(dev));
if (!ac.check()) {
zxlogf(ERROR, "DdkFidlDevice::Create: no memory to allocate device!");
zx_status_t status;
if ((status = test_dev->Bind()) != ZX_OK) {
zxlogf(ERROR, "DdkFidlDevice::Create: Bind failed");
return status;
// devmgr is now in charge of the device.
[[maybe_unused]] auto* dummy = test_dev.release();
return ZX_OK;
void DdkFidlDevice::GetChannel(GetChannelCompleter::Sync& completer) {
zx::channel local;
zx::channel remote;
zx::channel::create(0, &local, &remote);
[[maybe_unused]] auto dummy = local.release();
zx_status_t DdkFidlDevice::Bind() { return DdkAdd("ddk-fidl"); }
void DdkFidlDevice::DdkRelease() { delete this; }
constexpr zx_driver_ops_t driver_ops = []() {
zx_driver_ops_t driver_ops = {};
driver_ops.version = DRIVER_OPS_VERSION;
driver_ops.bind = DdkFidlDevice::Create;
return driver_ops;
} // namespace fidl
ZIRCON_DRIVER(ddk_fidl, fidl::driver_ops, "zircon", "0.1");