1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Allows one process to monitor the state of another process. Can detect if the process is
//! [`State::Alive`], [`State::Dead`] or the existance with [`State::DoesNotExist`]. To activate
//! monitoring the process that shall be monitored must instantiate a [`MonitoringToken`]. As long
//! as the [`MonitoringToken`] is in scope the [`MonitoringMonitor`] will detect the process as
//! [`State::Alive`]. When the process crashes it will be detected as [`State::Dead`]. If the
//! process does not yet have instantiated a [`MonitoringMonitor`] the process is identified as
//! [`State::DoesNotExist`].
//!
//! # Example
//!
//! ```
//! use iceoryx2_cal::monitoring::*;
//!
//! fn monitored_process<M: Monitoring>() {
//! let token =
//! M::Builder::new(&FileName::new(b"unique_process_identifier").unwrap()).
//! token().unwrap();
//!
//! // keep the token in scope and do what a process shall do
//!
//! // process can no longer be monitored
//! drop(token);
//! }
//!
//! fn watching_process<M: Monitoring>() {
//! let monitor = M::Builder::new(&FileName::new(b"unique_process_identifier").unwrap()).
//! monitor().unwrap();
//!
//! match monitor.state().unwrap() {
//! State::Alive => println!("process is alive"),
//! State::Dead => println!("process is dead"),
//! State::DoesNotExist => println!("process does not exist"),
//! }
//! }
//!
//! fn cleaning_process<M: Monitoring>() {
//! let cleaner = match M::Builder::new(&FileName::new(b"unique_process_identifier")
//! .unwrap()).cleaner() {
//! Ok(cleaner) => cleaner,
//! Err(MonitoringCreateCleanerError::AlreadyOwnedByAnotherInstance) => {
//! // someone is already cleaning up for us - perfect :)
//! return;
//! }
//! Err(MonitoringCreateCleanerError::InstanceStillAlive) => {
//! // whoopsie, the monitored instance is not dead
//! return;
//! }
//! Err(e) => {
//! // usual error handling
//! return;
//! }
//! };
//!
//! // cleanup all stale resources of the dead process
//! drop(cleaner);
//! }
//! ```
use Debug;
pub use SemanticString;
pub use FileName;
pub use crate::;
/// Represents the state of a monitored process.
/// Represents the possible errors that can occur when a new [`MonitoringToken`] is created with
/// [`MonitoringBuilder::token()`].
/// Represents the possible errors that can occur when a new [`MonitoringCleaner`] is created with
/// [`MonitoringBuilder::cleaner()`].
/// Represents the possible errors that can occur when a new [`MonitoringMonitor`] is created with
/// [`MonitoringBuilder::monitor()`].
/// Represents the possible errors that can occur when the [`State`] is acquired via
/// [`MonitoringMonitor::state()`].
/// The token enables a process to be monitored by another process.
/// The cleaner owns the remains of a dead process and is the only one that is allowed to clean up
/// those resources.
/// The monitor allows to monitor another process that has instantiated a [`MonitoringToken`]
/// Creates either a [`MonitoringToken`] or instantiates a [`MonitoringMonitor`] that can monitor
/// the state of a token.
/// Concept that allows to monitor a process from within another process. The process must hereby
/// instantiate a [`MonitoringToken`] with [`MonitoringBuilder`] so that it can be monitored with
/// the [`MonitoringMonitor`].