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
// Copyright (c) 2023 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
//! Traits that provide modifyable memory which can be accessed by multiple processes
//! identified by a name.
//!
//! A [`DynamicStorage`] has to fulfill the following contract:
//! * zero sized names are not valid
//! * **unique:** multiple [`DynamicStorage`]s with the same cannot be created
//! * non-existing [`DynamicStorage`]s cannot be opened
//!
//! The contract is verified by the corresponding unit tests. Every [`DynamicStorage`] must
//! pass the test.
//!
//! **Important:** It is not the task of the [`DynamicStorage`] to ensure a thread-safe access to
//! the underlying object. If the [`DynamicStorage`] is used in an inter-process environment every
//! access must be considered as a concurrent access!
//!
//! # Example
//!
//! ```
//! use iceoryx2_bb_system_types::file_name::FileName;
//! use iceoryx2_bb_container::semantic_string::SemanticString;
//! use iceoryx2_cal::dynamic_storage::*;
//! use iceoryx2_cal::named_concept::*;
//! use std::sync::atomic::{AtomicU64, Ordering};
//!
//! // the following two functions can be implemented in different processes
//! fn process_one<Storage: DynamicStorage<AtomicU64>>() {
//! let storage_name = FileName::new(b"myStorageName").unwrap();
//! let mut storage = Storage::Builder::new(&storage_name)
//! .create(AtomicU64::new(873)).unwrap();
//!
//! println!("Created storage {}", storage.name());
//! storage.get().store(991, Ordering::Relaxed);
//! }
//!
//! fn process_two<Storage: DynamicStorage<AtomicU64>>() {
//! let storage_name = FileName::new(b"myStorageName").unwrap();
//! let mut storage = Storage::Builder::new(&storage_name)
//! .open().unwrap();
//!
//! println!("Opened storage {}", storage.name());
//! println!("Current value {}", storage.get().swap(1001, Ordering::Relaxed));
//! }
//! ```
use Debug;
use BumpAllocator;
use TEMP_DIRECTORY;
use FileName;
use Path;
use crate;
/// The default suffix of every dynamic storage
pub const DEFAULT_SUFFIX: FileName = unsafe ;
/// The default prefix of every dynamic storage
pub const DEFAULT_PREFIX: FileName = unsafe ;
/// The default path hint for every dynamic storage
pub const DEFAULT_PATH_HINT: Path = TEMP_DIRECTORY;
/// Describes failures when creating a new [`DynamicStorage`]
/// Describes failures when opening a new [`DynamicStorage`]
/// Builder for the [`DynamicStorage`]. T is not allowed to implement the [`Drop`] trait.
/// Is being built by the [`DynamicStorageBuilder`]. The [`DynamicStorage`] trait shall provide
/// inter-process access to a modifyable piece of memory identified by some name.