Skip to content

Commit 39cd3b7

Browse files
committed
[#674] Move internal service check logic to ServiceName
1 parent 70ef0b6 commit 39cd3b7

File tree

11 files changed

+27
-96
lines changed

11 files changed

+27
-96
lines changed

BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ filegroup(
177177
"//benchmarks/publish-subscribe:all_srcs",
178178
"//benchmarks/queue:all_srcs",
179179
"//benchmarks/request-response:all_srcs",
180-
"//iceoryx2-services/common:all_srcs",
181180
"//iceoryx2-services/discovery:all_srcs",
182181
"//iceoryx2:all_srcs",
183182
"//iceoryx2-bb/container:all_srcs",

Cargo.lock

-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ members = [
2222
"iceoryx2-pal/posix/",
2323
"iceoryx2-pal/configuration/",
2424

25-
"iceoryx2-services/common",
2625
"iceoryx2-services/discovery",
2726

2827
"iceoryx2-cli",
@@ -77,7 +76,6 @@ iceoryx2-ffi-macros = { version = "0.5.0", path = "iceoryx2-ffi/ffi-macros" }
7776

7877
iceoryx2 = { version = "0.5.0", path = "iceoryx2/" }
7978

80-
iceoryx2-services-common = { version = "0.5.0", path = "iceoryx2-services/common"}
8179
iceoryx2-services-discovery = { version = "0.5.0", path = "iceoryx2-services/discovery"}
8280

8381
iceoryx2-cli = { version = "0.5.0", path = "iceoryx2_cli/"}

WORKSPACE.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ maybe(
9090
"//:benchmarks/queue/Cargo.toml",
9191
"//:benchmarks/request-response/Cargo.toml",
9292
"//:examples/Cargo.toml",
93-
"//:iceoryx2-services/common/Cargo.toml",
9493
"//:iceoryx2-services/discovery/Cargo.toml",
9594
"//:iceoryx2/Cargo.toml",
9695
"//:iceoryx2-bb/container/Cargo.toml",

iceoryx2-services/common/BUILD.bazel

-25
This file was deleted.

iceoryx2-services/common/Cargo.toml

-20
This file was deleted.

iceoryx2-services/common/src/lib.rs

-35
This file was deleted.

iceoryx2-services/discovery/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ rust_library(
2424
srcs = glob(["src/**/*.rs"]),
2525
deps = [
2626
"//iceoryx2:iceoryx2",
27-
"//iceoryx2-services/common:iceoryx2-services-common",
2827
"@crate_index//:once_cell",
2928
"@crate_index//:serde",
3029
"@crate_index//:serde_json",

iceoryx2-services/discovery/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ path = "src/lib.rs"
1717

1818
[dependencies]
1919
iceoryx2 = { workspace = true }
20-
iceoryx2-services-common = { workspace = true }
2120
once_cell = { workspace = true }
2221
serde = { workspace = true }
2322
serde_json = { workspace = true }

iceoryx2-services/discovery/src/service_discovery/service.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use iceoryx2::{
1818
prelude::{AllocationStrategy, ServiceName},
1919
service::{static_config::StaticConfig, Service as ServiceType, ServiceDetails},
2020
};
21-
use iceoryx2_services_common::{is_internal_service, INTERNAL_SERVICE_PREFIX};
2221

2322
use once_cell::sync::Lazy;
2423

@@ -290,7 +289,7 @@ impl<S: ServiceType> Service<S> {
290289
for id in &added_ids {
291290
if let Some(service) = self.tracker.get(id) {
292291
if !self.discovery_config.include_internal
293-
&& is_internal_service(service.static_details.name())
292+
&& ServiceName::is_internal(service.static_details.name())
294293
{
295294
continue;
296295
}
@@ -302,7 +301,7 @@ impl<S: ServiceType> Service<S> {
302301

303302
for service in &removed_services {
304303
if !self.discovery_config.include_internal
305-
&& is_internal_service(service.static_details.name())
304+
&& ServiceName::is_internal(service.static_details.name())
306305
{
307306
continue;
308307
}
@@ -358,7 +357,7 @@ impl<S: ServiceType> Service<S> {
358357
///
359358
pub fn service_name() -> &'static ServiceName {
360359
static SERVICE_NAME_INSTANCE: Lazy<ServiceName> = Lazy::new(|| {
361-
ServiceName::new(&(INTERNAL_SERVICE_PREFIX.to_owned() + SERVICE_DISCOVERY_SERVICE_NAME))
360+
ServiceName::__internal_new(SERVICE_DISCOVERY_SERVICE_NAME)
362361
.expect("shouldn't occur: invalid service name for service discovery service")
363362
});
364363

iceoryx2/src/service/service_name.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,33 @@
2525
use iceoryx2_bb_container::semantic_string::SemanticStringError;
2626
use serde::{de::Visitor, Deserialize, Serialize};
2727

28+
/// Prefix used to identify internal iceoryx2 services.
29+
///
30+
/// This prefix is used to distinguish between user-defined services and internal
31+
/// iceoryx2 services. Services with this prefix are considered internal and are
32+
/// managed by the iceoryx2 system.
33+
pub const INTERNAL_SERVICE_PREFIX: &str = "iox2://";
34+
2835
/// The name of a [`Service`](crate::service::Service).
2936
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
3037
pub struct ServiceName {
3138
value: String,
3239
}
3340

3441
impl ServiceName {
35-
/// Creates a new [`ServiceName`]. The name is not allowed to be empty.
42+
/// Creates a new [`ServiceName`].
43+
///
44+
/// The name is not allowed to be empty nor be prefixed with "iox2://".
3645
pub fn new(name: &str) -> Result<Self, SemanticStringError> {
46+
if Self::is_internal(name) {
47+
return Err(SemanticStringError::InvalidContent);
48+
}
49+
50+
Self::__internal_new(name)
51+
}
52+
53+
#[doc(hidden)]
54+
pub fn __internal_new(name: &str) -> Result<Self, SemanticStringError> {
3755
if name.is_empty() {
3856
return Err(SemanticStringError::InvalidContent);
3957
}
@@ -45,6 +63,11 @@ impl ServiceName {
4563
pub fn as_str(&self) -> &str {
4664
&self.value
4765
}
66+
67+
/// Checks if a service is an internal iceoryx2 service.
68+
pub fn is_internal(name: &str) -> bool {
69+
name.starts_with(INTERNAL_SERVICE_PREFIX)
70+
}
4871
}
4972

5073
impl core::fmt::Display for ServiceName {

0 commit comments

Comments
 (0)