zenoh_shm/api/protocol_implementations/posix/
posix_shm_client.rs

1//
2// Copyright (c) 2023 ZettaScale Technology
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8//
9// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10//
11// Contributors:
12//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
13//
14
15use std::sync::Arc;
16
17use zenoh_result::ZResult;
18
19use super::posix_shm_segment::PosixShmSegment;
20use crate::api::{
21    client::{shm_client::ShmClient, shm_segment::ShmSegment},
22    common::{
23        types::{ProtocolID, SegmentID},
24        with_id::WithProtocolID,
25    },
26    protocol_implementations::posix::protocol_id::POSIX_PROTOCOL_ID,
27};
28
29/// Client factory implementation for particular shared memory protocol
30#[zenoh_macros::unstable_doc]
31#[derive(Debug)]
32pub struct PosixShmClient;
33
34impl WithProtocolID for PosixShmClient {
35    fn id(&self) -> ProtocolID {
36        POSIX_PROTOCOL_ID
37    }
38}
39
40impl ShmClient for PosixShmClient {
41    /// Attach to particular shared memory segment
42    #[zenoh_macros::unstable_doc]
43    fn attach(&self, segment: SegmentID) -> ZResult<Arc<dyn ShmSegment>> {
44        Ok(Arc::new(PosixShmSegment::open(segment)?))
45    }
46}