YARP
Yet Another Robot Platform
ShmemOutputStream.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_SHMEM_SHMEMOUTPUTSTREAM_H
11 #define YARP_SHMEM_SHMEMOUTPUTSTREAM_H
12 
13 
14 #include "ShmemTypes.h"
15 
16 #include <yarp/os/OutputStream.h>
17 #include <yarp/os/Semaphore.h>
18 #include <yarp/os/Thread.h>
19 #include <yarp/os/Time.h>
20 
21 #include <ace/config.h>
22 #include <ace/Mutex.h>
23 #include <ace/Process_Mutex.h>
24 #include <ace/SOCK_Stream.h>
25 #include <ace/SOCK_Acceptor.h>
26 #include <ace/SOCK_Connector.h>
27 #include <ace/Log_Msg.h>
28 #if defined(ACE_LACKS_SYSV_SHMEM)
29 #include <ace/Shared_Memory_MM.h>
30 #else
31 #include <ace/Shared_Memory_SV.h>
32 #endif
33 // In one the ACE headers there is a definition of "main" for WIN32
34 # ifdef main
35 # undef main
36 # endif
37 
38 
40 {
41 public:
44 
45  bool isOk() const;
46  bool open(int port, int size = SHMEM_DEFAULT_SIZE);
47  bool write(const yarp::os::Bytes& b);
48  void close();
49 
50 protected:
51  bool Resize(int newsize);
52 
53  bool m_bOpen;
54 
56  int m_Port;
57 
58 #if defined(_ACE_USE_SV_SEM)
59  ACE_Mutex* m_pAccessMutex;
60  ACE_Mutex* m_pWaitDataMutex;
61 #else
62  ACE_Process_Mutex* m_pAccessMutex;
63  ACE_Process_Mutex* m_pWaitDataMutex;
64 #endif
65 
66  ACE_Shared_Memory* m_pMap;
67  char* m_pData;
69 };
70 
71 #endif // YARP_SHMEM_SHMEMOUTPUTSTREAM_H
ShmemOutputStreamImpl::write
bool write(const yarp::os::Bytes &b)
Definition: ShmemOutputStream.cpp:187
OutputStream.h
ShmemOutputStreamImpl::m_ResizeNum
int m_ResizeNum
Definition: ShmemOutputStream.h:55
ShmemOutputStreamImpl::close
void close()
Definition: ShmemOutputStream.cpp:232
ShmemOutputStreamImpl::m_pWaitDataMutex
ACE_Process_Mutex * m_pWaitDataMutex
Definition: ShmemOutputStream.h:63
SHMEM_DEFAULT_SIZE
#define SHMEM_DEFAULT_SIZE
Definition: ShmemTypes.h:13
ShmemHeader_t
Definition: ShmemTypes.h:16
ShmemOutputStreamImpl::m_pData
char * m_pData
Definition: ShmemOutputStream.h:67
ShmemOutputStreamImpl::open
bool open(int port, int size=4096)
Definition: ShmemOutputStream.cpp:45
ShmemOutputStreamImpl::m_bOpen
bool m_bOpen
Definition: ShmemOutputStream.h:53
ShmemOutputStreamImpl
Definition: ShmemOutputStream.h:40
ShmemOutputStreamImpl::Resize
bool Resize(int newsize)
Definition: ShmemOutputStream.cpp:112
ShmemOutputStreamImpl::isOk
bool isOk() const
Definition: ShmemOutputStream.cpp:40
ShmemOutputStreamImpl::~ShmemOutputStreamImpl
~ShmemOutputStreamImpl()
Definition: ShmemOutputStream.cpp:35
Thread.h
Semaphore.h
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
ShmemOutputStreamImpl::m_pHeader
ShmemHeader_t * m_pHeader
Definition: ShmemOutputStream.h:68
ShmemOutputStreamImpl::m_pAccessMutex
ACE_Process_Mutex * m_pAccessMutex
Definition: ShmemOutputStream.h:62
ShmemOutputStreamImpl::ShmemOutputStreamImpl
ShmemOutputStreamImpl()
Definition: ShmemOutputStream.cpp:23
Time.h
ShmemOutputStreamImpl::m_pMap
ACE_Shared_Memory * m_pMap
Definition: ShmemOutputStream.h:66
ShmemTypes.h
ShmemOutputStreamImpl::m_Port
int m_Port
Definition: ShmemOutputStream.h:56