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
#define SHMEM_DEFAULT_SIZE
Definition: ShmemTypes.h:13
bool write(const yarp::os::Bytes &b)
bool open(int port, int size=4096)
bool Resize(int newsize)
ACE_Process_Mutex * m_pWaitDataMutex
ACE_Process_Mutex * m_pAccessMutex
ShmemHeader_t * m_pHeader
ACE_Shared_Memory * m_pMap
A simple abstraction for a block of bytes.
Definition: Bytes.h:28