[samples] Update to new InstanceHandler class fxrev.dev/771113

Compilation errors discovered in migration from SDK
10.20221130.0.1 to 11.20221216.0.1 so this change includes
just those fixes.

Change-Id: I09c6f203132fa4ebed35899bdfa0cbb59b92a48b
Reviewed-on: https://fuchsia-review.googlesource.com/c/sdk-samples/drivers/+/779836
Reviewed-by: Renato Mangini Dias <mangini@google.com>
Commit-Queue: Wayne Piekarski <waynepie@google.com>
diff --git a/src/acpi_multiply/controller/acpi_controller.cc b/src/acpi_multiply/controller/acpi_controller.cc
index 0426a7b..c885601 100644
--- a/src/acpi_multiply/controller/acpi_controller.cc
+++ b/src/acpi_multiply/controller/acpi_controller.cc
@@ -21,17 +21,13 @@
 
   // Serve the fuchsia.hardware.acpi/Device protocol to clients through the
   // fuchsia.hardware.acpi/Service wrapper.
-  component::ServiceInstanceHandler handler;
-  fuchsia_hardware_acpi::Service::Handler service(&handler);
-  auto result =
-      service.add_device([this](fidl::ServerEnd<fuchsia_hardware_acpi::Device> request) -> void {
+  fuchsia_hardware_acpi::Service::InstanceHandler handler({
+    .device = [this](fidl::ServerEnd<fuchsia_hardware_acpi::Device> request) -> void {
         AcpiDeviceServer::BindDeviceClient(server_, dispatcher(), std::move(request));
-      });
-  if (result.is_error()) {
-    return result.take_error();
-  }
+      }
+  });
 
-  result = context().outgoing()->AddService<fuchsia_hardware_acpi::Service>(std::move(handler));
+  auto result = context().outgoing()->AddService<fuchsia_hardware_acpi::Service>(std::move(handler));
   if (result.is_error()) {
     FDF_SLOG(ERROR, "Failed to add service.", KV("status", result.status_string()));
     return result.take_error();
diff --git a/src/acpi_multiply/driver/acpi_multiply.cc b/src/acpi_multiply/driver/acpi_multiply.cc
index 4bfe4b9..a7f263b 100644
--- a/src/acpi_multiply/driver/acpi_multiply.cc
+++ b/src/acpi_multiply/driver/acpi_multiply.cc
@@ -34,17 +34,14 @@
 
   // Serve the examples.acpi.multiply/Device protocol to clients through the
   // examples.acpi.multiply/Service wrapper.
-  component::ServiceInstanceHandler handler;
-  examples_acpi_multiply::Service::Handler service(&handler);
-
-  auto result =
-      service.add_device([this](fidl::ServerEnd<examples_acpi_multiply::Device> request) -> void {
+  examples_acpi_multiply::Service::InstanceHandler handler({
+    .device = [this](fidl::ServerEnd<examples_acpi_multiply::Device> request) -> void {
         AcpiMultiplyServer::BindDeviceClient(&logger(), dispatcher(), multiplier_,
                                              std::move(request));
-      });
-  ZX_ASSERT(result.is_ok());
+      }
+  });
 
-  result = context().outgoing()->AddService<examples_acpi_multiply::Service>(std::move(handler));
+  auto result = context().outgoing()->AddService<examples_acpi_multiply::Service>(std::move(handler));
   if (result.is_error()) {
     FDF_SLOG(ERROR, "Failed to add service.", KV("status", result.status_string()));
     return result.take_error();
diff --git a/src/bind_library/parent/BUILD.bazel b/src/bind_library/parent/BUILD.bazel
index 3c96d3e..ce729c8 100644
--- a/src/bind_library/parent/BUILD.bazel
+++ b/src/bind_library/parent/BUILD.bazel
@@ -28,7 +28,6 @@
         # This is a C++ lib from an SDK FIDL based bind library.
         "@fuchsia_sdk//fidl/fuchsia.device.fs:fuchsia.device.fs_bindlib_cc",
         "@fuchsia_sdk//pkg/driver_component_cpp",
-        "@fuchsia_sdk//pkg/sys_component_cpp",
     ],
 )
 #[END parent_driver]
diff --git a/src/bind_library/parent/parent-driver.cc b/src/bind_library/parent/parent-driver.cc
index 8aa6302..01a59d7 100644
--- a/src/bind_library/parent/parent-driver.cc
+++ b/src/bind_library/parent/parent-driver.cc
@@ -18,15 +18,13 @@
 
   // Add gizmo examples_gizmo::Service to outgoing.
   {
-    component::ServiceInstanceHandler handler;
-    examples_gizmo::Service::Handler service(&handler);
-    auto result = service.add_testing(
-        [this](fidl::ServerEnd<examples_gizmo::TestingProtocol> server_end) -> void {
+    examples_gizmo::Service::InstanceHandler handler({
+      .testing = [this](fidl::ServerEnd<examples_gizmo::TestingProtocol> server_end) -> void {
           GizmoServer::BindDeviceClient(gizmo_server_, dispatcher(), std::move(server_end));
-        });
-    ZX_ASSERT(result.is_ok());
+        }
+    });
 
-    result = context().outgoing()->AddService<examples_gizmo::Service>(std::move(handler));
+    auto result = context().outgoing()->AddService<examples_gizmo::Service>(std::move(handler));
     if (result.is_error()) {
       FDF_SLOG(ERROR, "Failed to add service", KV("status", result.status_string()));
       return result.take_error();
diff --git a/src/composite_sample/driver/BUILD.bazel b/src/composite_sample/driver/BUILD.bazel
index 401f3e2..8a977ac 100644
--- a/src/composite_sample/driver/BUILD.bazel
+++ b/src/composite_sample/driver/BUILD.bazel
@@ -31,7 +31,6 @@
         "@fuchsia_sdk//fidl/zx:zx_cc",
         "@fuchsia_sdk//pkg/driver_component_cpp",
         "@fuchsia_sdk//pkg/fidl_cpp_wire",
-        "@fuchsia_sdk//pkg/sys_component_cpp",
         "@fuchsia_sdk//pkg/zx",
     ],
 )
diff --git a/src/i2c_temperature/controller/i2c_controller.cc b/src/i2c_temperature/controller/i2c_controller.cc
index 914d4d0..e97a959 100644
--- a/src/i2c_temperature/controller/i2c_controller.cc
+++ b/src/i2c_temperature/controller/i2c_controller.cc
@@ -16,16 +16,12 @@
 
   // Serve the fuchsia.hardware.i2c/Device protocol to clients through the
   // fuchsia.hardware.i2c/Service wrapper.
-  component::ServiceInstanceHandler handler;
-  fuchsia_hardware_i2c::Service::Handler service(&handler);
-  auto result =
-      service.add_device([this](fidl::ServerEnd<fuchsia_hardware_i2c::Device> request) -> void {
+  fuchsia_hardware_i2c::Service::InstanceHandler handler({
+    .device = [this](fidl::ServerEnd<fuchsia_hardware_i2c::Device> request) -> void {
         I2cDeviceServer::BindDeviceClient(i2c_server_, dispatcher(), std::move(request));
-      });
-  if (result.is_error()) {
-    return result.take_error();
-  }
-  result = context().outgoing()->AddService<fuchsia_hardware_i2c::Service>(std::move(handler));
+      }
+  });
+  auto result = context().outgoing()->AddService<fuchsia_hardware_i2c::Service>(std::move(handler));
   if (result.is_error()) {
     FDF_SLOG(ERROR, "Failed to add service", KV("status", result.status_string()));
     return result.take_error();
diff --git a/src/i2c_temperature/driver/i2c_temperature.cc b/src/i2c_temperature/driver/i2c_temperature.cc
index bc94c04..e2f1f6b 100644
--- a/src/i2c_temperature/driver/i2c_temperature.cc
+++ b/src/i2c_temperature/driver/i2c_temperature.cc
@@ -21,17 +21,14 @@
 
   // Serve the examples.i2c.temperature/Device protocol to clients through the
   // examples.i2c.temperature/Service wrapper.
-  component::ServiceInstanceHandler handler;
-  examples_i2c_temperature::Service::Handler service(&handler);
-
-  auto result =
-      service.add_device([this](fidl::ServerEnd<examples_i2c_temperature::Device> request) -> void {
+  examples_i2c_temperature::Service::InstanceHandler handler({
+    .device = [this](fidl::ServerEnd<examples_i2c_temperature::Device> request) -> void {
         I2cTemperatureServer::BindDeviceClient(dispatcher(), &logger(), i2c_channel_,
                                                std::move(request));
-      });
-  ZX_ASSERT(result.is_ok());
+      }
+  });
 
-  result = context().outgoing()->AddService<examples_i2c_temperature::Service>(std::move(handler));
+  auto result = context().outgoing()->AddService<examples_i2c_temperature::Service>(std::move(handler));
   if (result.is_error()) {
     FDF_SLOG(ERROR, "Failed to add service", KV("status", result.status_string()));
     return result.take_error();
diff --git a/src/qemu_edu/drivers/qemu_edu.cc b/src/qemu_edu/drivers/qemu_edu.cc
index b368039..fe1209b 100644
--- a/src/qemu_edu/drivers/qemu_edu.cc
+++ b/src/qemu_edu/drivers/qemu_edu.cc
@@ -67,16 +67,13 @@
 
   // [START serve_outgoing]
   // Serve the examples.qemuedu/Service capability.
-  component::ServiceInstanceHandler handler;
-  examples_qemuedu::Service::Handler service(&handler);
-
-  auto result =
-      service.add_device([this](fidl::ServerEnd<examples_qemuedu::Device> request) -> void {
+  examples_qemuedu::Service::InstanceHandler handler({
+    .device = [this](fidl::ServerEnd<examples_qemuedu::Device> request) -> void {
         QemuEduServer::BindDeviceClient(&logger(), dispatcher(), device_, std::move(request));
-      });
-  ZX_ASSERT(result.is_ok());
+      }
+  });
 
-  result = context().outgoing()->AddService<examples_qemuedu::Service>(std::move(handler));
+  auto result = context().outgoing()->AddService<examples_qemuedu::Service>(std::move(handler));
   if (result.is_error()) {
     FDF_SLOG(ERROR, "Failed to add Device service", KV("status", result.status_string()));
     return result.take_error();