| // Copyright 2022 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/sdk/examples/fidl/cpp/fidl.h> |
| #include <lib/async-loop/cpp/loop.h> |
| #include <lib/async-loop/default.h> |
| #include <lib/fidl/cpp/binding.h> |
| #include <lib/sys/cpp/component_context.h> |
| #include <stdio.h> |
| |
| // This GreetingService implementation echoes back the Greeting sent in calls |
| // to Greet. This is provided to facilitate testing. |
| class GreetingServiceImpl : public fuchsia::sdk::examples::fidl::GreetingService { |
| public: |
| void Greet(std::unique_ptr<fuchsia::sdk::examples::fidl::Greeting> value, |
| GreetCallback callback) override { |
| callback(std::move(value)); |
| } |
| }; |
| |
| int main(int argc, const char** argv) { |
| async::Loop loop(&kAsyncLoopConfigAttachToCurrentThread); |
| |
| GreetingServiceImpl impl; |
| fidl::Binding<fuchsia::sdk::examples::fidl::GreetingService> binding(&impl); |
| fidl::InterfaceRequestHandler<fuchsia::sdk::examples::fidl::GreetingService> handler = |
| [&](fidl::InterfaceRequest<fuchsia::sdk::examples::fidl::GreetingService> request) { |
| binding.Bind(std::move(request)); |
| }; |
| auto context = sys::ComponentContext::CreateAndServeOutgoingDirectory(); |
| context->outgoing()->AddPublicService(std::move(handler)); |
| |
| printf("Running GreetingService server\n"); |
| return loop.Run(); |
| } |