27 virtual bool method() = 0;
30 struct ConcreteA : InterfaceA {
31 bool method()
final {
return true; }
35 virtual bool method() = 0;
38 struct ConcreteB : InterfaceB {
39 bool method()
final {
return false; }
43 [[nodiscard]]
virtual bool method()
const = 0;
46 struct ConcreteC : InterfaceC {
47 [[nodiscard]]
bool method()
const final {
return false; }
54 ConcreteC
const serviceC;
55 ref.registerService(ServiceRegistryHelpers::handleForService<InterfaceA>(&serviceA));
56 ref.registerService(ServiceRegistryHelpers::handleForService<InterfaceB>(&serviceB));
57 ref.registerService(ServiceRegistryHelpers::handleForService<InterfaceC const>(&serviceC));
58 REQUIRE(registry.
get<InterfaceA>(ServiceRegistry::globalDeviceSalt()).method() ==
true);
59 REQUIRE(registry.
get<InterfaceB>(ServiceRegistry::globalDeviceSalt()).method() ==
false);
60 REQUIRE(registry.
get<InterfaceC
const>(ServiceRegistry::globalDeviceSalt()).method() ==
false);
61 REQUIRE(registry.
active<InterfaceA>(ServiceRegistry::globalDeviceSalt()) ==
true);
62 REQUIRE(registry.
active<InterfaceB>(ServiceRegistry::globalDeviceSalt()) ==
true);
63 REQUIRE(registry.
active<InterfaceC>(ServiceRegistry::globalDeviceSalt()) ==
false);
64 REQUIRE_THROWS_AS(registry.
get<InterfaceA
const>(ServiceRegistry::globalDeviceSalt()),
RuntimeErrorRef);
65 REQUIRE_THROWS_AS(registry.
get<InterfaceC>(ServiceRegistry::globalDeviceSalt()),
RuntimeErrorRef);
106 registry.
registerService({TypeIdHelpers::uniqueId<DummyService>()}, &
t0, ServiceKind::Serial, salt_0);
108 auto tt0 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Serial));
109 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Serial));
110 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Serial));
111 REQUIRE(tt0->threadId == 0);
112 REQUIRE(tt1->threadId == 0);
113 REQUIRE(tt2->threadId == 0);
123 registry.
registerService({TypeIdHelpers::uniqueId<DummyService>()}, &
t0, ServiceKind::Global, salt_0);
125 auto tt0 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Serial));
126 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Serial));
127 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Serial));
128 REQUIRE(tt0->threadId == 0);
129 REQUIRE(tt1->threadId == 0);
130 REQUIRE(tt2->threadId == 0);
139 fair::mq::ProgOptions options;
141 .uniqueId = CommonServices::simpleServiceId<DummyService>(),
147 .configure = CommonServices::noConfiguration(),
148 .kind = ServiceKind::Global};
157 registry.
registerService({TypeIdHelpers::uniqueId<DummyService>()},
nullptr, ServiceKind::Global, salt_1);
159 INFO(error_from_ref(e).what);
163 auto tt0 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Global));
164 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Global));
165 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Global));
166 REQUIRE(tt0->threadId == 1);
167 REQUIRE(tt1->threadId == 1);
168 REQUIRE(tt2->threadId == 1);
182 .uniqueId = CommonServices::simpleServiceId<DummyService>(),
183 .init = CommonServices::simpleServiceInit<DummyService, DummyService>(),
184 .configure = CommonServices::noConfiguration(),
185 .kind = ServiceKind::Stream};
188 fair::mq::ProgOptions options;
198 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Stream));
199 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Stream));
200 auto tt3 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_3, ServiceKind::Stream));
201 REQUIRE(tt1->threadId == 1);
202 REQUIRE(tt2->threadId == 2);
203 REQUIRE(tt3->threadId == 3);
205 REQUIRE_THROWS_AS(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1_1, ServiceKind::Stream),
RuntimeErrorRef);
208 REQUIRE_THROWS_AS(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Stream),
RuntimeErrorRef);
212 REQUIRE(tt2_dp1->threadId == 2);
214 REQUIRE_THROWS_AS(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1_1, ServiceKind::Stream),
RuntimeErrorRef);
223 .uniqueId = CommonServices::simpleServiceId<DummyService>(),
224 .init = CommonServices::simpleServiceInit<DummyService, DummyService>(),
225 .configure = CommonServices::noConfiguration(),
226 .kind = ServiceKind::Stream};
229 fair::mq::ProgOptions options;
237 constexpr short STREAMS = 32;
238 std::vector<DummyService> services(STREAMS);
239 for (
short i = 0;
i < STREAMS; ++
i) {
240 services[
i].threadId =
i + 1;
243 for (
short i = 0;
i < STREAMS; ++
i) {
246 REQUIRE_NOTHROW(registry.
registerService({TypeIdHelpers::uniqueId<DummyService>()}, &services[
i], ServiceKind::Stream,
252 for (
short i = 0;
i < STREAMS; ++
i) {
254 registry.
get({TypeIdHelpers::uniqueId<DummyService>()},
256 REQUIRE(found !=
nullptr);
257 CHECK(found->threadId ==
i + 1);
287 auto overrides = ServiceSpecHelpers::parseOverrides(
"foo:enable,bar:disable");
288 REQUIRE(overrides.size() == 2);
289 REQUIRE(overrides[0].
name ==
"foo");
290 REQUIRE(overrides[0].
active ==
true);
291 REQUIRE(overrides[1].
name ==
"bar");
292 REQUIRE(overrides[1].
active ==
false);
294 auto overrides2 = ServiceSpecHelpers::parseOverrides(
"foo:enable");
295 REQUIRE(overrides2.size() == 1);
296 REQUIRE(overrides[0].
name ==
"foo");
297 REQUIRE(overrides[0].
active ==
true);
299 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:enabledisabl"), std::runtime_error);
300 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo"), std::runtime_error);
301 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:"), std::runtime_error);
302 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:a,"), std::runtime_error);
303 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:,"), std::runtime_error);
304 REQUIRE(ServiceSpecHelpers::parseOverrides(
"").
size() == 0);
305 REQUIRE(ServiceSpecHelpers::parseOverrides(
nullptr).
size() == 0);
307 auto overrides3 = ServiceSpecHelpers::parseOverrides(
"foo:disable,bar:enable,baz:enable");
309 {.name =
"foo", .active =
true},
310 {.name =
"bar", .active =
false},
312 REQUIRE(overrides3.size() == 3);
313 auto services = ServiceSpecHelpers::filterDisabled(originalServices, overrides3);
314 REQUIRE(services.size() == 1);
315 REQUIRE(services[0].
name ==
"bar");
316 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