blob: ed29cb8f2385cafb0fdd2a4524928fb650d1ee20 [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 <lib/usb-peripheral-utils/event-watcher.h>
namespace usb_peripheral_utils {
EventWatcher::EventWatcher(async::Loop& loop,
fidl::ServerEnd<fuchsia_hardware_usb_peripheral::Events> svc,
size_t functions)
: loop_(loop), functions_(functions) {
fidl::BindServer(loop.dispatcher(), std::move(svc), this);
}
void EventWatcher::FunctionRegistered(FunctionRegisteredCompleter::Sync& completer) {
functions_registered_++;
if (all_functions_registered()) {
loop_.Quit();
completer.Close(ZX_ERR_CANCELED);
} else {
completer.Reply();
}
}
void EventWatcher::FunctionsCleared(FunctionsClearedCompleter::Sync& completer) {
all_functions_cleared_ = true;
loop_.Quit();
completer.Close(ZX_ERR_CANCELED);
}
} // namespace usb_peripheral_utils