26 virtual bool method() = 0;
29 struct ConcreteA : InterfaceA {
30 bool method()
final {
return true; }
34 virtual bool method() = 0;
37 struct ConcreteB : InterfaceB {
38 bool method()
final {
return false; }
42 [[nodiscard]]
virtual bool method()
const = 0;
45 struct ConcreteC : InterfaceC {
46 [[nodiscard]]
bool method()
const final {
return false; }
53 ConcreteC
const serviceC;
54 ref.registerService(ServiceRegistryHelpers::handleForService<InterfaceA>(&serviceA));
55 ref.registerService(ServiceRegistryHelpers::handleForService<InterfaceB>(&serviceB));
56 ref.registerService(ServiceRegistryHelpers::handleForService<InterfaceC const>(&serviceC));
57 REQUIRE(registry.
get<InterfaceA>(ServiceRegistry::globalDeviceSalt()).method() ==
true);
58 REQUIRE(registry.
get<InterfaceB>(ServiceRegistry::globalDeviceSalt()).method() ==
false);
59 REQUIRE(registry.
get<InterfaceC
const>(ServiceRegistry::globalDeviceSalt()).method() ==
false);
60 REQUIRE(registry.
active<InterfaceA>(ServiceRegistry::globalDeviceSalt()) ==
true);
61 REQUIRE(registry.
active<InterfaceB>(ServiceRegistry::globalDeviceSalt()) ==
true);
62 REQUIRE(registry.
active<InterfaceC>(ServiceRegistry::globalDeviceSalt()) ==
false);
63 REQUIRE_THROWS_AS(registry.
get<InterfaceA
const>(ServiceRegistry::globalDeviceSalt()),
RuntimeErrorRef);
64 REQUIRE_THROWS_AS(registry.
get<InterfaceC>(ServiceRegistry::globalDeviceSalt()),
RuntimeErrorRef);
105 registry.
registerService({TypeIdHelpers::uniqueId<DummyService>()}, &
t0, ServiceKind::Serial, salt_0);
107 auto tt0 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Serial));
108 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Serial));
109 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Serial));
110 REQUIRE(tt0->threadId == 0);
111 REQUIRE(tt1->threadId == 0);
112 REQUIRE(tt2->threadId == 0);
122 registry.
registerService({TypeIdHelpers::uniqueId<DummyService>()}, &
t0, ServiceKind::Global, salt_0);
124 auto tt0 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Serial));
125 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Serial));
126 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Serial));
127 REQUIRE(tt0->threadId == 0);
128 REQUIRE(tt1->threadId == 0);
129 REQUIRE(tt2->threadId == 0);
138 fair::mq::ProgOptions options;
140 .uniqueId = CommonServices::simpleServiceId<DummyService>(),
146 .configure = CommonServices::noConfiguration(),
147 .kind = ServiceKind::Global};
156 registry.
registerService({TypeIdHelpers::uniqueId<DummyService>()},
nullptr, ServiceKind::Global, salt_1);
158 INFO(error_from_ref(e).what);
162 auto tt0 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Global));
163 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Global));
164 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Global));
165 REQUIRE(tt0->threadId == 1);
166 REQUIRE(tt1->threadId == 1);
167 REQUIRE(tt2->threadId == 1);
181 .uniqueId = CommonServices::simpleServiceId<DummyService>(),
182 .init = CommonServices::simpleServiceInit<DummyService, DummyService>(),
183 .configure = CommonServices::noConfiguration(),
184 .kind = ServiceKind::Stream};
187 fair::mq::ProgOptions options;
197 auto tt1 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1, ServiceKind::Stream));
198 auto tt2 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_2, ServiceKind::Stream));
199 auto tt3 =
reinterpret_cast<DummyService*
>(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_3, ServiceKind::Stream));
200 REQUIRE(tt1->threadId == 1);
201 REQUIRE(tt2->threadId == 2);
202 REQUIRE(tt3->threadId == 3);
204 REQUIRE_THROWS_AS(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1_1, ServiceKind::Stream),
RuntimeErrorRef);
207 REQUIRE_THROWS_AS(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_0, ServiceKind::Stream),
RuntimeErrorRef);
211 REQUIRE(tt2_dp1->threadId == 2);
213 REQUIRE_THROWS_AS(registry.
get({TypeIdHelpers::uniqueId<DummyService>()}, salt_1_1, ServiceKind::Stream),
RuntimeErrorRef);
242 auto overrides = ServiceSpecHelpers::parseOverrides(
"foo:enable,bar:disable");
243 REQUIRE(overrides.size() == 2);
244 REQUIRE(overrides[0].
name ==
"foo");
245 REQUIRE(overrides[0].
active ==
true);
246 REQUIRE(overrides[1].
name ==
"bar");
247 REQUIRE(overrides[1].
active ==
false);
249 auto overrides2 = ServiceSpecHelpers::parseOverrides(
"foo:enable");
250 REQUIRE(overrides2.size() == 1);
251 REQUIRE(overrides[0].
name ==
"foo");
252 REQUIRE(overrides[0].
active ==
true);
254 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:enabledisabl"), std::runtime_error);
255 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo"), std::runtime_error);
256 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:"), std::runtime_error);
257 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:a,"), std::runtime_error);
258 REQUIRE_THROWS_AS(ServiceSpecHelpers::parseOverrides(
"foo:,"), std::runtime_error);
259 REQUIRE(ServiceSpecHelpers::parseOverrides(
"").
size() == 0);
260 REQUIRE(ServiceSpecHelpers::parseOverrides(
nullptr).
size() == 0);
262 auto overrides3 = ServiceSpecHelpers::parseOverrides(
"foo:disable,bar:enable,baz:enable");
264 {.name =
"foo", .active =
true},
265 {.name =
"bar", .active =
false},
267 REQUIRE(overrides3.size() == 3);
268 auto services = ServiceSpecHelpers::filterDisabled(originalServices, overrides3);
269 REQUIRE(services.size() == 1);
270 REQUIRE(services[0].
name ==
"bar");
271 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