Files
Library/tests/package/ServiceOnly/main.cpp

37 lines
925 B
C++

#include <Void/Service/Registry.hpp>
#include <Void/Service/Service.hpp>
#include <Void/Service/Types.hpp>
#include <memory>
#include <string_view>
namespace
{
struct ICounter {
virtual ~ICounter() = default;
virtual int value() const = 0;
};
struct Counter final : Void::Service::IManagedService, ICounter {
std::string_view service_name() const override { return "counter"; }
int value() const override { return 42; }
};
} // namespace
int main()
{
Void::Service::ServiceRegistry reg;
Void::Service::ProviderSet set;
set.add<ICounter>("counter", std::make_shared<Counter>());
auto ep = reg.start_and_publish(std::move(set));
if (!ep) {
return 1;
}
auto handle = reg.acquire<ICounter>();
if (!handle || (*handle)->value() != 42 || handle->generation() != *ep) {
return 2;
}
auto report = reg.close_and_join();
return report && !report->clean() ? 0 : 3; // handle still held until return
}