blob: e303eeb9147302733f87d80bbd13b66a210782b4 [file] [log] [blame] [edit]
// Copyright 2024 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.
#ifndef SRC_STORAGE_LIB_BLOCK_SERVER_FAKE_SERVER_H_
#define SRC_STORAGE_LIB_BLOCK_SERVER_FAKE_SERVER_H_
#include <fidl/fuchsia.hardware.block.volume/cpp/wire.h>
#include <lib/zx/vmo.h>
#include <memory>
#include "src/storage/lib/block_server/block_server.h"
namespace block_server {
/// Runs a BlockServer backed by a VMO.
class FakeServer {
public:
// Initialize a FakeServer. If `data` is set, it will be used as the initial contents of the
// device, and the size of the VMO must agree with `info`.
explicit FakeServer(const PartitionInfo& info, zx::vmo data = {});
~FakeServer();
FakeServer(FakeServer&&);
FakeServer& operator=(FakeServer&&);
FakeServer(const FakeServer&) = delete;
FakeServer& operator=(const FakeServer&) = delete;
// Serves a new connection. The FIDL handling is multiplexed onto a single per-server thread.
void Serve(fidl::ServerEnd<fuchsia_hardware_block_volume::Volume> request) {
server_->Serve(std::move(request));
}
private:
class FakeInterface;
std::unique_ptr<FakeInterface> interface_ = nullptr;
std::unique_ptr<BlockServer> server_ = nullptr;
};
} // namespace block_server
#endif // SRC_STORAGE_LIB_BLOCK_SERVER_FAKE_SERVER_H_