blob: 329ce1f4e80fd999da1525319f45de3fa81db4ed [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 <fuchsia/feedback/cpp/fidl.h>
#include <lib/async/dispatcher.h>
#include <lib/fit/bridge.h>
#include <lib/fit/promise.h>
#include <lib/sys/cpp/service_directory.h>
#include <lib/zx/time.h>
#include <memory>
#include "src/lib/fxl/functional/cancelable_callback.h"
#include "src/lib/fxl/macros.h"
namespace fuchsia {
namespace crash {
// Wraps around fuchsia::feedback::DataProviderPtr to handle establishing the
// connection, losing the connection, waiting for the callback, enforcing a
// timeout, etc.
class FeedbackDataProvider {
FeedbackDataProvider(async_dispatcher_t* dispatcher,
std::shared_ptr<::sys::ServiceDirectory> services);
fit::promise<fuchsia::feedback::Data> GetData(zx::duration timeout);
async_dispatcher_t* dispatcher_;
const std::shared_ptr<::sys::ServiceDirectory> services_;
fuchsia::feedback::DataProviderPtr data_provider_;
// We use a shared_ptr to share the bridge between this and the async loop on
// which we post the delayed task to timeout.
std::shared_ptr<fit::bridge<fuchsia::feedback::Data>> done_;
// We wrap the delayed task we post on the async loop to timeout in a
// CancelableClosure so we can cancel it if we are done another way.
fxl::CancelableClosure done_after_timeout_;
} // namespace crash
} // namespace fuchsia