|
10 | 10 | //
|
11 | 11 | // SPDX-License-Identifier: Apache-2.0 OR MIT
|
12 | 12 |
|
13 |
| -#![warn(missing_docs)] |
14 |
| - |
15 |
| -//! # iceoryx2-services-discovery |
16 |
| -//! |
17 |
| -//! A service for discovery and monitoring of other iceoryx2 services. |
18 |
| -//! |
19 |
| -//! This crate provides utilities for discovering, tracking, and monitoring services |
20 |
| -//! in an iceoryx2 system. It enables applications to detect when services become |
21 |
| -//! available or unavailable, and to react to these changes. |
22 |
| -//! |
23 |
| -//! ## Features |
24 |
| -//! |
25 |
| -//! - **Service Tracking**: Track the availability of services in the system |
26 |
| -//! - **Service Monitoring**: Monitor services and receive notifications when they appear or disappear |
27 |
| -//! |
28 |
| -//! ## Usage Examples |
29 |
| -//! |
30 |
| -//! ### Tracking Services |
31 |
| -//! |
32 |
| -//! ```rust |
33 |
| -//! use iceoryx2::config::Config; |
34 |
| -//! use iceoryx2_discovery::service::Tracker; |
35 |
| -//! use iceoryx2::service::YourServiceType; |
36 |
| -//! |
37 |
| -//! // Create a new tracker for your service type |
38 |
| -//! let mut tracker = Tracker::<YourServiceType>::new(); |
39 |
| -//! |
40 |
| -//! // Sync with the system to discover services |
41 |
| -//! let (added_services, removed_services) = tracker.sync(&Config::global_config()); |
42 |
| -//! |
43 |
| -//! // Process newly discovered services |
44 |
| -//! for service_id in added_services { |
45 |
| -//! if let Some(service_details) = tracker.get(&service_id) { |
46 |
| -//! println!("Discovered service: {:?}", service_details.static_details.name()); |
47 |
| -//! } |
48 |
| -//! } |
49 |
| -//! ``` |
50 |
| -//! |
51 |
| -//! ### Monitoring Services |
| 13 | +//! # Discovery Services |
52 | 14 | //!
|
53 |
| -//! ```rust |
54 |
| -//! use iceoryx2_discovery::service::Monitor; |
55 |
| -//! use iceoryx2::service::YourServiceType; |
| 15 | +//! The `iceoryx2-services-discovery` crate provides discovery services for the components |
| 16 | +//! of an iceoryx2 system. These services enable other applications built on iceoryx2 to |
| 17 | +//! get informed of the presense of these components. |
56 | 18 | //!
|
57 |
| -//! // Create a new service monitor |
58 |
| -//! let mut monitor = Monitor::<YourServiceType>::new(); |
59 |
| -//! |
60 |
| -//! // Periodically call spin() to detect and publish service changes |
61 |
| -//! loop { |
62 |
| -//! monitor.spin(); |
63 |
| -//! std::thread::sleep(std::time::Duration::from_secs(1)); |
64 |
| -//! } |
65 |
| -//! ``` |
66 |
| -//! |
67 |
| -//! ### Subscribing to Service Discovery Events |
68 |
| -//! |
69 |
| -//! ```rust |
70 |
| -//! use iceoryx2::config::Config; |
71 |
| -//! use iceoryx2::node::{Node, NodeBuilder}; |
72 |
| -//! use iceoryx2::port::subscriber::Subscriber; |
73 |
| -//! use iceoryx2::prelude::ServiceName; |
74 |
| -//! use iceoryx2_discovery::service::DiscoveryEvent; |
75 |
| -//! use iceoryx2::service::YourServiceType; |
76 |
| -//! |
77 |
| -//! // Create a node |
78 |
| -//! let node = NodeBuilder::new() |
79 |
| -//! .config(Config::global_config()) |
80 |
| -//! .create::<YourServiceType>() |
81 |
| -//! .expect("Failed to create node"); |
82 |
| -//! |
83 |
| -//! // Create a subscriber for discovery events |
84 |
| -//! let service_name = ServiceName::new("iox2://monitor/services") |
85 |
| -//! .expect("Failed to create service name"); |
86 |
| -//! |
87 |
| -//! let publish_subscribe = node |
88 |
| -//! .service_builder(&service_name) |
89 |
| -//! .publish_subscribe::<DiscoveryEvent>() |
90 |
| -//! .create() |
91 |
| -//! .expect("Failed to create publish-subscribe service"); |
92 |
| -//! |
93 |
| -//! let subscriber = publish_subscribe |
94 |
| -//! .subscriber_builder() |
95 |
| -//! .create() |
96 |
| -//! .expect("Failed to create subscriber"); |
97 |
| -//! |
98 |
| -//! // Process discovery events |
99 |
| -//! while let Some(event) = subscriber.receive() { |
100 |
| -//! match event.payload() { |
101 |
| -//! DiscoveryEvent::Added(config) => println!("Service added: {:?}", config.name()), |
102 |
| -//! DiscoveryEvent::Removed(config) => println!("Service removed: {:?}", config.name()), |
103 |
| -//! } |
104 |
| -//! } |
105 |
| -//! ``` |
106 |
| -//! |
107 |
| -//! ## Integration with iceoryx2 |
108 |
| -//! |
109 |
| -//! This crate is designed to work seamlessly with the core iceoryx2 library and provides |
110 |
| -//! a higher-level API for service discovery. It builds upon the service management |
111 |
| -//! capabilities of iceoryx2 to provide a more convenient interface for tracking and |
112 |
| -//! monitoring services. |
113 | 19 |
|
114 |
| -/// Utilities for service discovery and monitoring |
115 |
| -pub mod service; |
| 20 | +#![warn(missing_docs)] |
| 21 | + |
| 22 | +/// Discovery and tracking of services in an iceoryx2 system |
| 23 | +pub mod service_discovery; |
0 commit comments