28 virtual bool method() = 0;
31 struct ConcreteA : InterfaceA {
32 bool method()
final {
return true; }
36 virtual bool method() = 0;
39 struct ConcreteB : InterfaceB {
40 bool method()
final {
return false; }
44 [[nodiscard]]
virtual bool method()
const = 0;
47 struct ConcreteC : InterfaceC {
48 [[nodiscard]]
bool method()
const final {
return false; }
55 ConcreteC
const serviceC;
56 ref.registerService(ServiceRegistryHelpers::handleForService<InterfaceA>(&serviceA));
57 ref.registerService(ServiceRegistryHelpers::handleForService<InterfaceB>(&serviceB));
58 ref.registerService(ServiceRegistryHelpers::handleForService<InterfaceC const>(&serviceC));
59 REQUIRE(registry.
get<InterfaceA>(ServiceRegistry::globalDeviceSalt()).method() ==
true);
60 REQUIRE(registry.
get<InterfaceB>(ServiceRegistry::globalDeviceSalt()).method() ==
false);
61 REQUIRE(registry.
get<InterfaceC
const>(ServiceRegistry::globalDeviceSalt()).method() ==
false);
62 REQUIRE(registry.
active<InterfaceA>(ServiceRegistry::globalDeviceSalt()) ==
true);
63 REQUIRE(registry.
active<InterfaceB>(ServiceRegistry::globalDeviceSalt()) ==
true);
64 REQUIRE(registry.
active<InterfaceC>(ServiceRegistry::globalDeviceSalt()) ==
false);
65 REQUIRE_THROWS_AS(registry.
get<InterfaceA
const>(ServiceRegistry::globalDeviceSalt()),
RuntimeErrorRef);
66 REQUIRE_THROWS_AS(registry.
get<InterfaceC>(ServiceRegistry::globalDeviceSalt()),
RuntimeErrorRef);
107 registry.
registerService({TypeIdHelpers::uniqueId<DummyService>()}, &
t0, ServiceKind::Serial, salt_0);
109 auto tt0 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Serial));
110 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Serial));
111 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Serial));
112 REQUIRE(tt0->threadId == 0);
113 REQUIRE(tt1->threadId == 0);
114 REQUIRE(tt2->threadId == 0);
124 registry.
registerService({TypeIdHelpers::uniqueId<DummyService>()}, &
t0, ServiceKind::Global, salt_0);
126 auto tt0 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Serial));
127 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Serial));
128 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Serial));
129 REQUIRE(tt0->threadId == 0);
130 REQUIRE(tt1->threadId == 0);
131 REQUIRE(tt2->threadId == 0);
140 fair::mq::ProgOptions options;
142 .uniqueId = CommonServices::simpleServiceId<DummyService>(),
148 .configure = CommonServices::noConfiguration(),
149 .kind = ServiceKind::Global};
158 registry.
registerService({TypeIdHelpers::uniqueId<DummyService>()},
nullptr, ServiceKind::Global, salt_1);
160 INFO(error_from_ref(e).what);
164 auto tt0 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Global));
165 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Global));
166 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Global));
167 REQUIRE(tt0->threadId == 1);
168 REQUIRE(tt1->threadId == 1);
169 REQUIRE(tt2->threadId == 1);
183 .uniqueId = CommonServices::simpleServiceId<DummyService>(),
184 .init = CommonServices::simpleServiceInit<DummyService, DummyService>(),
185 .configure = CommonServices::noConfiguration(),
186 .kind = ServiceKind::Stream};
189 fair::mq::ProgOptions options;
199 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Stream));
200 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Stream));
201 auto tt3 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_3, ServiceKind::Stream));
202 REQUIRE(tt1->threadId == 1);
203 REQUIRE(tt2->threadId == 2);
204 REQUIRE(tt3->threadId == 3);
206 REQUIRE_THROWS_AS(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1_1, ServiceKind::Stream),
RuntimeErrorRef);
209 REQUIRE_THROWS_AS(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Stream),
RuntimeErrorRef);
213 REQUIRE(tt2_dp1->threadId == 2);
215 REQUIRE_THROWS_AS(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1_1, ServiceKind::Stream),
RuntimeErrorRef);
244 auto overrides = ServiceSpecHelpers::parseOverrides(
"foo:enable,bar:disable");
245 REQUIRE(overrides.size() == 2);
246 REQUIRE(overrides[0].
name ==
"foo");
247 REQUIRE(overrides[0].
active ==
true);
248 REQUIRE(overrides[1].
name ==
"bar");
249 REQUIRE(overrides[1].
active ==
false);
251 auto overrides2 = ServiceSpecHelpers::parseOverrides(
"foo:enable");
252 REQUIRE(overrides2.size() == 1);
253 REQUIRE(overrides[0].
name ==
"foo");
254 REQUIRE(overrides[0].
active ==
true);
256 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:enabledisabl"), std::runtime_error);
257 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo"), std::runtime_error);
258 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:"), std::runtime_error);
259 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:a,"), std::runtime_error);
260 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:,"), std::runtime_error);
261 REQUIRE(ServiceSpecHelpers::parseOverrides(
"").
size() == 0);
262 REQUIRE(ServiceSpecHelpers::parseOverrides(
nullptr).
size() == 0);
264 auto overrides3 = ServiceSpecHelpers::parseOverrides(
"foo:disable,bar:enable,baz:enable");
266 {.name =
"foo", .active =
true},
267 {.name =
"bar", .active =
false},
269 REQUIRE(overrides3.size() == 3);
270 auto services = ServiceSpecHelpers::filterDisabled(originalServices, overrides3);
271 REQUIRE(services.size() == 1);
272 REQUIRE(services[0].
name ==
"bar");
273 REQUIRE(services[0].
active ==
true);
void registerService(ServiceTypeHash typeHash, void *service, ServiceKind kind, Salt salt, char const *name=nullptr, ServiceRegistry::SpecIndex specIndex=SpecIndex{-1}) const