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
#define SHMEM_DEFAULT_SIZE
Definition: ShmemTypes.h:13
ACE_SOCK_Stream * m_pSock
yarp::conf::ssize_t read(yarp::os::Bytes &b)
ACE_Shared_Memory * m_pMap
ACE_Process_Mutex * m_pWaitDataMutex
ShmemHeader_t * m_pHeader
bool open(int port, ACE_SOCK_Stream *pSock, int size=4096)
std::mutex m_ReadSerializerMutex
ACE_Process_Mutex * m_pAccessMutex
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
::ssize_t ssize_t
Definition: numeric.h:60