blob: aaeadfd0e32ef424f78977bd792abc95e80c3a6d [file] [log] [blame]
// 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 <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 <samples/sdk/examples/fidl/cpp/fidl.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 samples::sdk::examples::fidl::GreetingService {
public:
void Greet(std::unique_ptr<samples::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<samples::sdk::examples::fidl::GreetingService> binding(&impl);
fidl::InterfaceRequestHandler<samples::sdk::examples::fidl::GreetingService> handler =
[&](fidl::InterfaceRequest<samples::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();
}