[fsl] Replace VFS dispatcher with new mechanism.
The libfs serving mechanism is now based on libasync so we no longer
need a separate dispatcher. Updated existing code to use the new
mechanism.
Fixed a bunch of missing header includes for fsl::MessageLoop downstream.
Change-Id: Ieabaa69bde405567526715ee6915868f822bfad9
diff --git a/bin/ui/sketchy/app.h b/bin/ui/sketchy/app.h
index 42a08be..0c3c21f 100644
--- a/bin/ui/sketchy/app.h
+++ b/bin/ui/sketchy/app.h
@@ -4,11 +4,12 @@
#pragma once
-#include "lib/app/cpp/application_context.h"
-#include "lib/ui/fun/sketchy/fidl/canvas.fidl-common.h"
-#include "garnet/bin/ui/sketchy/canvas.h"
#include "escher/escher.h"
+#include "garnet/bin/ui/sketchy/canvas.h"
+#include "lib/app/cpp/application_context.h"
#include "lib/fidl/cpp/bindings/binding_set.h"
+#include "lib/fsl/tasks/message_loop.h"
+#include "lib/ui/fun/sketchy/fidl/canvas.fidl-common.h"
namespace sketchy_service {
diff --git a/bin/ui/view_manager/view_registry.cc b/bin/ui/view_manager/view_registry.cc
index a119675..e4b8e6b 100644
--- a/bin/ui/view_manager/view_registry.cc
+++ b/bin/ui/view_manager/view_registry.cc
@@ -8,17 +8,18 @@
#include <cmath>
#include <utility>
-#include "lib/app/cpp/connect.h"
-#include "lib/ui/scenic/client/resources.h"
-#include "lib/ui/input/cpp/formatting.h"
-#include "lib/ui/input/fidl/ime_service.fidl.h"
-#include "lib/ui/views/cpp/formatting.h"
#include "garnet/bin/ui/view_manager/view_impl.h"
#include "garnet/bin/ui/view_manager/view_tree_impl.h"
+#include "lib/app/cpp/connect.h"
+#include "lib/fsl/tasks/message_loop.h"
#include "lib/fxl/functional/make_copyable.h"
#include "lib/fxl/logging.h"
#include "lib/fxl/memory/weak_ptr.h"
#include "lib/fxl/strings/string_printf.h"
+#include "lib/ui/input/cpp/formatting.h"
+#include "lib/ui/input/fidl/ime_service.fidl.h"
+#include "lib/ui/scenic/client/resources.h"
+#include "lib/ui/views/cpp/formatting.h"
namespace view_manager {
namespace {
diff --git a/examples/ui/shadertoy/client/main.cc b/examples/ui/shadertoy/client/main.cc
index 2e21368..8197739 100644
--- a/examples/ui/shadertoy/client/main.cc
+++ b/examples/ui/shadertoy/client/main.cc
@@ -5,10 +5,10 @@
#include <trace-provider/provider.h>
#include "garnet/examples/ui/shadertoy/client/view.h"
-#include "lib/ui/view_framework/view_provider_app.h"
+#include "lib/fsl/tasks/message_loop.h"
#include "lib/fxl/command_line.h"
#include "lib/fxl/log_settings_command_line.h"
-#include "lib/fsl/tasks/message_loop.h"
+#include "lib/ui/view_framework/view_provider_app.h"
int main(int argc, const char** argv) {
auto command_line = fxl::CommandLineFromArgcArgv(argc, argv);
diff --git a/examples/ui/shadertoy/client/view.h b/examples/ui/shadertoy/client/view.h
index f04b6fe..56a5747 100644
--- a/examples/ui/shadertoy/client/view.h
+++ b/examples/ui/shadertoy/client/view.h
@@ -4,12 +4,13 @@
#pragma once
-#include "lib/app/cpp/application_context.h"
#include "garnet/examples/ui/shadertoy/service/services/shadertoy.fidl.h"
#include "garnet/examples/ui/shadertoy/service/services/shadertoy_factory.fidl.h"
+#include "lib/app/cpp/application_context.h"
+#include "lib/fsl/tasks/message_loop.h"
+#include "lib/fxl/macros.h"
#include "lib/ui/scenic/client/resources.h"
#include "lib/ui/view_framework/base_view.h"
-#include "lib/fxl/macros.h"
namespace shadertoy_client {
diff --git a/examples/ui/shadertoy/service/main.cc b/examples/ui/shadertoy/service/main.cc
index 9db8f4f..e5acf50 100644
--- a/examples/ui/shadertoy/service/main.cc
+++ b/examples/ui/shadertoy/service/main.cc
@@ -4,12 +4,13 @@
#include <trace-provider/provider.h>
-#include "lib/app/cpp/application_context.h"
-#include "garnet/examples/ui/shadertoy/service/app.h"
#include "escher/escher.h"
#include "escher/escher_process_init.h"
#include "escher/vk/vulkan_device_queues.h"
#include "escher/vk/vulkan_instance.h"
+#include "garnet/examples/ui/shadertoy/service/app.h"
+#include "lib/app/cpp/application_context.h"
+#include "lib/fsl/tasks/message_loop.h"
// This is the main() function for the service that implements the
// ShadertoyFactory API.
diff --git a/examples/ui/sketchy/app.h b/examples/ui/sketchy/app.h
index d56dffc..fcbf562 100644
--- a/examples/ui/sketchy/app.h
+++ b/examples/ui/sketchy/app.h
@@ -4,12 +4,13 @@
#pragma once
-#include "lib/app/cpp/application_context.h"
#include "garnet/examples/ui/sketchy/scene.h"
+#include "lib/app/cpp/application_context.h"
+#include "lib/fsl/tasks/message_loop.h"
#include "lib/ui/scenic/client/session.h"
-#include "lib/ui/sketchy/canvas.h"
#include "lib/ui/scenic/fidl/display_info.fidl-common.h"
#include "lib/ui/scenic/fidl/scene_manager.fidl.h"
+#include "lib/ui/sketchy/canvas.h"
namespace sketchy_example {
diff --git a/lib/farfs/file_system.cc b/lib/farfs/file_system.cc
index 3ecb5eb..96432e5 100644
--- a/lib/farfs/file_system.cc
+++ b/lib/farfs/file_system.cc
@@ -6,6 +6,8 @@
#include <fcntl.h>
+#include "lib/fsl/tasks/message_loop.h"
+
namespace archive {
namespace {
@@ -23,7 +25,7 @@
fbl::RefPtr<vmofs::VnodeDir> CreateDirectory() {
size_t count = names.size();
fbl::Array<fbl::StringPiece> names_array(new fbl::StringPiece[count],
- count);
+ count);
fbl::Array<fbl::RefPtr<vmofs::Vnode>> children_array(
new fbl::RefPtr<vmofs::Vnode>[count], count);
for (size_t i = 0; i < count; ++i) {
@@ -68,7 +70,7 @@
}
fbl::RefPtr<vmofs::VnodeFile> CreateFile(zx_handle_t vmo,
- const DirectoryTableEntry& entry) {
+ const DirectoryTableEntry& entry) {
return fbl::AdoptRef(
new vmofs::VnodeFile(vmo, entry.data_offset, entry.data_length));
}
@@ -83,7 +85,8 @@
} // namespace
-FileSystem::FileSystem(zx::vmo vmo) : vmo_(vmo.get()), vfs_(&dispatcher_) {
+FileSystem::FileSystem(zx::vmo vmo)
+ : vmo_(vmo.get()), vfs_(fsl::MessageLoop::GetCurrent()->async()) {
uint64_t num_bytes = 0;
zx_status_t status = vmo.get_size(&num_bytes);
if (status != ZX_OK)
@@ -98,8 +101,8 @@
FileSystem::~FileSystem() = default;
bool FileSystem::Serve(zx::channel channel) {
- return directory_ && vfs_.ServeDirectory(directory_,
- std::move(channel)) == ZX_OK;
+ return directory_ &&
+ vfs_.ServeDirectory(directory_, std::move(channel)) == ZX_OK;
}
zx::channel FileSystem::OpenAsDirectory() {
diff --git a/lib/farfs/file_system.h b/lib/farfs/file_system.h
index 1bac0de..5c788ff 100644
--- a/lib/farfs/file_system.h
+++ b/lib/farfs/file_system.h
@@ -5,15 +5,15 @@
#ifndef APPLICATION_LIB_FARFS_FARFS_H_
#define APPLICATION_LIB_FARFS_FARFS_H_
+#include <fs/managed-vfs.h>
+#include <vmofs/vmofs.h>
#include <zx/channel.h>
#include <zx/vmo.h>
-#include <vmofs/vmofs.h>
#include <memory>
#include "garnet/lib/far/archive_reader.h"
#include "lib/fxl/files/unique_fd.h"
-#include "lib/fsl/vfs/vfs_dispatcher.h"
namespace archive {
@@ -47,8 +47,7 @@
// The owning reference to the vmo is stored inside |reader_| as a file
/// descriptor.
zx_handle_t vmo_;
- fs::Vfs vfs_;
- fsl::VFSDispatcher dispatcher_;
+ fs::ManagedVfs vfs_;
std::unique_ptr<ArchiveReader> reader_;
fbl::RefPtr<vmofs::VnodeDir> directory_;
};
diff --git a/public/lib/fsl/BUILD.gn b/public/lib/fsl/BUILD.gn
index d2550b9..d047730 100644
--- a/public/lib/fsl/BUILD.gn
+++ b/public/lib/fsl/BUILD.gn
@@ -22,7 +22,6 @@
"//garnet/public/lib/fsl/socket",
"//garnet/public/lib/fsl/tasks",
"//garnet/public/lib/fsl/threading",
- "//garnet/public/lib/fsl/vfs",
"//garnet/public/lib/fsl/vmo",
"//garnet/public/lib/fsl/waiter",
]
diff --git a/public/lib/fsl/tasks/BUILD.gn b/public/lib/fsl/tasks/BUILD.gn
index 0e7a2c4..3283198 100644
--- a/public/lib/fsl/tasks/BUILD.gn
+++ b/public/lib/fsl/tasks/BUILD.gn
@@ -17,6 +17,7 @@
]
libs = [
"async-default",
+ "fdio",
"zircon",
]
public_deps = [
diff --git a/public/lib/fsl/vfs/BUILD.gn b/public/lib/fsl/vfs/BUILD.gn
deleted file mode 100644
index ff08091..0000000
--- a/public/lib/fsl/vfs/BUILD.gn
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright 2017 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.
-
-source_set("vfs") {
- visibility = [ "//garnet/public/lib/fsl/*" ]
-
- sources = [
- "vfs_dispatcher.cc",
- "vfs_dispatcher.h",
- "vfs_handler.cc",
- "vfs_handler.h",
- ]
-
- libs = [ "fdio" ]
-
- defines = [ "_ALL_SOURCE=1" ]
-
- public_deps = [
- "//garnet/public/lib/fxl",
- "//garnet/public/lib/fsl/tasks",
- "//zircon/system/ulib/fs",
- "//zircon/system/ulib/zx",
- ]
-
- deps = [
- "//zircon/system/ulib/fbl",
- ]
-}
diff --git a/public/lib/fsl/vfs/vfs_dispatcher.cc b/public/lib/fsl/vfs/vfs_dispatcher.cc
deleted file mode 100644
index c810a2d..0000000
--- a/public/lib/fsl/vfs/vfs_dispatcher.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2017 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/fsl/vfs/vfs_dispatcher.h"
-
-#include <fdio/remoteio.h>
-
-#include "lib/fsl/vfs/vfs_handler.h"
-
-namespace fsl {
-
-VFSDispatcher::VFSDispatcher() = default;
-
-VFSDispatcher::~VFSDispatcher() {
- for (auto handler : std::move(handlers_))
- delete handler;
-}
-
-zx_status_t VFSDispatcher::AddVFSHandler(zx::channel channel,
- fs::vfs_dispatcher_cb_t callback,
- void* iostate) {
- VFSHandler* handler = new VFSHandler(this);
- handler->Start(std::move(channel), callback, iostate);
- handlers_.insert(handler);
- return ZX_OK;
-}
-
-void VFSDispatcher::Stop(VFSHandler* handler) {
- handlers_.erase(handler);
- delete handler;
-}
-
-} // namespace fsl
diff --git a/public/lib/fsl/vfs/vfs_dispatcher.h b/public/lib/fsl/vfs/vfs_dispatcher.h
deleted file mode 100644
index fd41075..0000000
--- a/public/lib/fsl/vfs/vfs_dispatcher.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2017 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 LIB_FSL_VFS_VFS_DISPATCHER_H_
-#define LIB_FSL_VFS_VFS_DISPATCHER_H_
-
-#include <fs/dispatcher.h>
-
-#include <memory>
-#include <set>
-
-#include "lib/fxl/fxl_export.h"
-#include "lib/fxl/macros.h"
-#include "lib/fsl/vfs/vfs_handler.h"
-
-namespace fsl {
-
-class FXL_EXPORT VFSDispatcher : public fs::Dispatcher {
- public:
- VFSDispatcher();
- ~VFSDispatcher() override;
-
- zx_status_t AddVFSHandler(zx::channel channel,
- fs::vfs_dispatcher_cb_t callback,
- void* iostate) final;
- void Stop(VFSHandler* handler);
-
- private:
- std::set<VFSHandler*> handlers_;
-
- FXL_DISALLOW_COPY_AND_ASSIGN(VFSDispatcher);
-};
-
-} // namespace fsl
-
-#endif // LIB_FSL_VFS_VFS_DISPATCHER_H_
diff --git a/public/lib/fsl/vfs/vfs_handler.cc b/public/lib/fsl/vfs/vfs_handler.cc
deleted file mode 100644
index 612f043..0000000
--- a/public/lib/fsl/vfs/vfs_handler.cc
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2017 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/fsl/vfs/vfs_handler.h"
-
-#include <fdio/remoteio.h>
-
-#include "lib/fsl/vfs/vfs_dispatcher.h"
-
-namespace fsl {
-
-VFSHandler::VFSHandler(VFSDispatcher* dispatcher)
- : dispatcher_(dispatcher), key_(0), iostate_(nullptr) {
- FXL_DCHECK(dispatcher_);
-}
-
-VFSHandler::~VFSHandler() {
- if (key_) {
- fsl::MessageLoop::GetCurrent()->RemoveHandler(key_);
- key_ = 0;
- zxrio_handler(ZX_HANDLE_INVALID, (void*)callback_, iostate_);
- }
-}
-
-void VFSHandler::Start(zx::channel channel,
- fs::vfs_dispatcher_cb_t callback,
- void* iostate) {
- FXL_DCHECK(!channel_);
- channel_ = std::move(channel);
- callback_ = callback;
- iostate_ = iostate;
- key_ = fsl::MessageLoop::GetCurrent()->AddHandler(
- this, channel_.get(), ZX_CHANNEL_READABLE | ZX_CHANNEL_PEER_CLOSED);
-}
-
-void VFSHandler::OnHandleReady(zx_handle_t handle,
- zx_signals_t pending,
- uint64_t count) {
- if (pending & ZX_CHANNEL_READABLE) {
- zx_status_t status =
- zxrio_handler(channel_.get(), (void*)callback_, iostate_);
- if (status == ZX_OK)
- return;
- Stop(status < 0);
- } else {
- FXL_DCHECK(pending & ZX_CHANNEL_PEER_CLOSED);
- Stop(true);
- }
-}
-
-void VFSHandler::OnHandleError(zx_handle_t handle, zx_status_t error) {
- FXL_DLOG(ERROR) << "VFSHandler::OnHandleError error=" << error;
- Stop(true);
-}
-
-void VFSHandler::Stop(bool needs_close) {
- FXL_DCHECK(key_);
- fsl::MessageLoop::GetCurrent()->RemoveHandler(key_);
- key_ = 0;
- if (needs_close)
- zxrio_handler(ZX_HANDLE_INVALID, (void*)callback_, iostate_);
- dispatcher_->Stop(this);
- // We're deleted now.
-}
-
-} // namespace fsl
diff --git a/public/lib/fsl/vfs/vfs_handler.h b/public/lib/fsl/vfs/vfs_handler.h
deleted file mode 100644
index 2105596..0000000
--- a/public/lib/fsl/vfs/vfs_handler.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2017 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 LIB_FSL_VFS_VFS_HANDLER_H_
-#define LIB_FSL_VFS_VFS_HANDLER_H_
-
-#include <fs/dispatcher.h>
-#include <zx/channel.h>
-
-#include "lib/fxl/fxl_export.h"
-#include "lib/fsl/tasks/message_loop.h"
-#include "lib/fsl/tasks/message_loop_handler.h"
-
-namespace fsl {
-class VFSDispatcher;
-
-class FXL_EXPORT VFSHandler : public MessageLoopHandler {
- public:
- explicit VFSHandler(VFSDispatcher* dispatcher);
- ~VFSHandler() override;
-
- void Start(zx::channel channel,
- fs::vfs_dispatcher_cb_t callback,
- void* iostate);
-
- private:
- // |MessageLoopHandler| implementation:
- void OnHandleReady(zx_handle_t handle,
- zx_signals_t pending,
- uint64_t count) override;
- void OnHandleError(zx_handle_t handle, zx_status_t error) override;
-
- void Stop(bool needs_close);
-
- VFSDispatcher* dispatcher_;
- MessageLoop::HandlerKey key_;
- zx::channel channel_;
- fs::vfs_dispatcher_cb_t callback_;
- void* iostate_;
-
- FXL_DISALLOW_COPY_AND_ASSIGN(VFSHandler);
-};
-
-} // namespace fsl
-
-#endif // LIB_FSL_VFS_VFS_HANDLER_H_
diff --git a/public/lib/svc/cpp/service_namespace.cc b/public/lib/svc/cpp/service_namespace.cc
index a06e608..9986ee1 100644
--- a/public/lib/svc/cpp/service_namespace.cc
+++ b/public/lib/svc/cpp/service_namespace.cc
@@ -5,21 +5,23 @@
#include "lib/svc/cpp/service_namespace.h"
#include <fcntl.h>
-#include <zircon/device/vfs.h>
#include <fdio/util.h>
+#include <zircon/device/vfs.h>
#include <utility>
+#include "lib/fsl/tasks/message_loop.h"
#include "lib/fxl/files/unique_fd.h"
namespace app {
ServiceNamespace::ServiceNamespace()
- : directory_(fbl::AdoptRef(new svcfs::VnodeDir())) {}
+ : vfs_(fsl::MessageLoop::GetCurrent()->async()),
+ directory_(fbl::AdoptRef(new svcfs::VnodeDir())) {}
ServiceNamespace::ServiceNamespace(
fidl::InterfaceRequest<app::ServiceProvider> request)
- : vfs_(&dispatcher_), directory_(fbl::AdoptRef(new svcfs::VnodeDir())) {
+ : ServiceNamespace() {
AddBinding(std::move(request));
}
diff --git a/public/lib/svc/cpp/service_namespace.h b/public/lib/svc/cpp/service_namespace.h
index 087c8b9..43324e1 100644
--- a/public/lib/svc/cpp/service_namespace.h
+++ b/public/lib/svc/cpp/service_namespace.h
@@ -5,9 +5,10 @@
#ifndef APPLICATION_LIB_SVC_SERVICE_NAMESPACE_H_
#define APPLICATION_LIB_SVC_SERVICE_NAMESPACE_H_
-#include <zx/channel.h>
#include <fbl/ref_ptr.h>
+#include <fs/managed-vfs.h>
#include <svcfs/svcfs.h>
+#include <zx/channel.h>
#include <functional>
#include <string>
@@ -17,7 +18,6 @@
#include "lib/app/fidl/service_provider.fidl.h"
#include "lib/fidl/cpp/bindings/binding_set.h"
#include "lib/fxl/macros.h"
-#include "lib/fsl/vfs/vfs_dispatcher.h"
namespace app {
@@ -120,8 +120,7 @@
std::unordered_map<std::string, ServiceConnector> name_to_service_connector_;
- fs::Vfs vfs_;
- fsl::VFSDispatcher dispatcher_;
+ fs::ManagedVfs vfs_;
fbl::RefPtr<svcfs::VnodeDir> directory_;
fidl::BindingSet<app::ServiceProvider> bindings_;
diff --git a/public/lib/svc/cpp/service_provider_bridge.cc b/public/lib/svc/cpp/service_provider_bridge.cc
index 5dde184..67b37b4 100644
--- a/public/lib/svc/cpp/service_provider_bridge.cc
+++ b/public/lib/svc/cpp/service_provider_bridge.cc
@@ -5,15 +5,18 @@
#include "lib/svc/cpp/service_provider_bridge.h"
#include <fcntl.h>
-#include <zircon/device/vfs.h>
#include <fdio/util.h>
+#include <zircon/device/vfs.h>
#include <utility>
+#include "lib/fsl/tasks/message_loop.h"
+
namespace app {
ServiceProviderBridge::ServiceProviderBridge()
- : vfs_(&dispatcher_), directory_(fbl::AdoptRef(new svcfs::VnodeProviderDir())) {
+ : vfs_(fsl::MessageLoop::GetCurrent()->async()),
+ directory_(fbl::AdoptRef(new svcfs::VnodeProviderDir())) {
directory_->SetServiceProvider(this);
}
diff --git a/public/lib/svc/cpp/service_provider_bridge.h b/public/lib/svc/cpp/service_provider_bridge.h
index e94cdbb..6c393ac 100644
--- a/public/lib/svc/cpp/service_provider_bridge.h
+++ b/public/lib/svc/cpp/service_provider_bridge.h
@@ -5,9 +5,10 @@
#ifndef APPLICATION_LIB_SVC_SERVICE_PROVIDER_BRIDGE_H_
#define APPLICATION_LIB_SVC_SERVICE_PROVIDER_BRIDGE_H_
-#include <zx/channel.h>
#include <fbl/ref_ptr.h>
+#include <fs/managed-vfs.h>
#include <svcfs/svcfs.h>
+#include <zx/channel.h>
#include <functional>
#include <string>
@@ -17,7 +18,6 @@
#include "lib/app/fidl/service_provider.fidl.h"
#include "lib/fidl/cpp/bindings/binding_set.h"
#include "lib/fxl/macros.h"
-#include "lib/fsl/vfs/vfs_dispatcher.h"
namespace app {
@@ -70,8 +70,7 @@
void ConnectToService(const fidl::String& service_name,
zx::channel channel) override;
- fs::Vfs vfs_;
- fsl::VFSDispatcher dispatcher_;
+ fs::ManagedVfs vfs_;
fidl::BindingSet<app::ServiceProvider> bindings_;
fbl::RefPtr<svcfs::VnodeProviderDir> directory_;
diff --git a/public/lib/ui/sketchy/canvas.cc b/public/lib/ui/sketchy/canvas.cc
index 0df7f83..c509ded 100644
--- a/public/lib/ui/sketchy/canvas.cc
+++ b/public/lib/ui/sketchy/canvas.cc
@@ -4,6 +4,8 @@
#include "lib/ui/sketchy/canvas.h"
+#include "lib/fsl/tasks/message_loop.h"
+
namespace sketchy_lib {
Canvas::Canvas(app::ApplicationContext* context)