YARP
Yet Another Robot Platform
ShmemInputStream.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_SHMEMINPUTSTREAM_H
11 #define YARP_SHMEM_SHMEMINPUTSTREAM_H
12 
13 #include "ShmemTypes.h"
14 
15 #include <yarp/os/InputStream.h>
16 #include <yarp/os/Thread.h>
17 #include <yarp/os/Time.h>
18 
19 #include <mutex>
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 
39 
41 {
42 public:
45 
46  bool isOk() const;
47  bool open(int port, ACE_SOCK_Stream* pSock, int size = SHMEM_DEFAULT_SIZE);
49  void close();
50 
51 protected:
52  int read(char* data, int len);
53  bool Resize();
54  bool m_bOpen;
55 
57  int m_Port;
58 
59 #if defined(_ACE_USE_SV_SEM)
60  ACE_Mutex* m_pAccessMutex;
61  ACE_Mutex* m_pWaitDataMutex;
62 #else
63  ACE_Process_Mutex* m_pAccessMutex;
64  ACE_Process_Mutex* m_pWaitDataMutex;
65 #endif
66 
68 
69  ACE_Shared_Memory* m_pMap;
70  char* m_pData;
72 
73  ACE_SOCK_Stream* m_pSock;
74 };
75 
76 #endif
ShmemInputStreamImpl::m_pAccessMutex
ACE_Process_Mutex * m_pAccessMutex
Definition: ShmemInputStream.h:63
ShmemInputStreamImpl::read
yarp::conf::ssize_t read(yarp::os::Bytes &b)
Definition: ShmemInputStream.cpp:196
ShmemInputStreamImpl::m_pSock
ACE_SOCK_Stream * m_pSock
Definition: ShmemInputStream.h:73
SHMEM_DEFAULT_SIZE
#define SHMEM_DEFAULT_SIZE
Definition: ShmemTypes.h:13
ShmemHeader_t
Definition: ShmemTypes.h:16
ShmemInputStreamImpl
Definition: ShmemInputStream.h:41
ShmemInputStreamImpl::Resize
bool Resize()
Definition: ShmemInputStream.cpp:106
ShmemInputStreamImpl::close
void close()
Definition: ShmemInputStream.cpp:233
ShmemInputStreamImpl::isOk
bool isOk() const
Definition: ShmemInputStream.cpp:42
ShmemInputStreamImpl::m_pData
char * m_pData
Definition: ShmemInputStream.h:70
yarp::conf::ssize_t
::ssize_t ssize_t
Definition: numeric.h:60
Thread.h
ShmemInputStreamImpl::open
bool open(int port, ACE_SOCK_Stream *pSock, int size=4096)
Definition: ShmemInputStream.cpp:47
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
ShmemInputStreamImpl::m_pMap
ACE_Shared_Memory * m_pMap
Definition: ShmemInputStream.h:69
ShmemInputStreamImpl::m_ReadSerializerMutex
std::mutex m_ReadSerializerMutex
Definition: ShmemInputStream.h:67
ShmemInputStreamImpl::m_pWaitDataMutex
ACE_Process_Mutex * m_pWaitDataMutex
Definition: ShmemInputStream.h:64
ShmemInputStreamImpl::m_ResizeNum
int m_ResizeNum
Definition: ShmemInputStream.h:56
ShmemInputStreamImpl::m_pHeader
ShmemHeader_t * m_pHeader
Definition: ShmemInputStream.h:71
ShmemInputStreamImpl::m_bOpen
bool m_bOpen
Definition: ShmemInputStream.h:54
InputStream.h
Time.h
ShmemInputStreamImpl::~ShmemInputStreamImpl
~ShmemInputStreamImpl()
Definition: ShmemInputStream.cpp:37
ShmemTypes.h
ShmemInputStreamImpl::ShmemInputStreamImpl
ShmemInputStreamImpl()
Definition: ShmemInputStream.cpp:24
ShmemInputStreamImpl::m_Port
int m_Port
Definition: ShmemInputStream.h:57