YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ShmemOutputStream.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_SHMEM_SHMEMOUTPUTSTREAM_H
8#define YARP_SHMEM_SHMEMOUTPUTSTREAM_H
9
10#include "ShmemPlatform.h"
11#include "ShmemTypes.h"
12
13#include <yarp/os/Bytes.h>
14
15#include <memory>
16#include <vector>
17
18
20{
21public:
24
25 bool isOk() const;
26 bool open(int port, int size = SHMEM_DEFAULT_SIZE);
27 bool write(const yarp::os::Bytes& b);
28 void close();
29
30protected:
31 bool Resize(int newsize);
32 void unlinkAll();
33
34 bool m_bOpen;
35
37 int m_Port;
38
39 // Protects the shared buffer. A semaphore (used as a binary mutex) is
40 // used instead of a mutex, since it can be released by any thread.
42
43 // Signalled by the writer when new data is available. It must be a
44 // semaphore and not a mutex, since it is released by a different
45 // process (and thread) than the one waiting on it.
47
48 std::unique_ptr<shmem::SharedMemory> m_pMap;
49 // Segments replaced by a resize, kept alive until the reader has mapped
50 // the new segment (on Windows a segment is destroyed when the last handle
51 // is closed).
52 std::vector<std::unique_ptr<shmem::SharedMemory>> m_OldMaps;
53 char* m_pData;
55};
56
57#endif // YARP_SHMEM_SHMEMOUTPUTSTREAM_H
#define SHMEM_DEFAULT_SIZE
Definition ShmemTypes.h:10
bool write(const yarp::os::Bytes &b)
bool open(int port, int size=4096)
shmem::NamedSemaphore m_WaitDataSem
shmem::NamedSemaphore m_AccessMutex
std::vector< std::unique_ptr< shmem::SharedMemory > > m_OldMaps
ShmemHeader_t * m_pHeader
std::unique_ptr< shmem::SharedMemory > m_pMap
A named inter-process semaphore.
A simple abstraction for a block of bytes.
Definition Bytes.h:24