YARP
Yet Another Robot Platform
ShmemHybridStream.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_SHMEMHYBRIDSTREAM_H
11 #define YARP_SHMEM_SHMEMHYBRIDSTREAM_H
12 
13 #include <yarp/os/InputStream.h>
14 #include <yarp/os/NetType.h>
15 #include <yarp/os/OutputStream.h>
16 #include <yarp/os/TwoWayStream.h>
17 
18 #include "ShmemInputStream.h"
19 #include "ShmemOutputStream.h"
20 
21 
26  public yarp::os::InputStream,
28 {
29 public:
31  virtual ~ShmemHybridStream();
32 
33  int open(const yarp::os::Contact& yarp_address, bool sender);
34  int accept();
35 
36  void close() override;
37  void interrupt() override;
38 
40  void write(const yarp::os::Bytes& b) override;
41 
44 
45  // TwoWayStrem implementation
48  bool isOk() const override;
49 
50  void reset() override;
51 
52  void beginPacket() override;
53  void endPacket() override;
54 
55  const yarp::os::Contact& getLocalAddress() const override;
56  const yarp::os::Contact& getRemoteAddress() const override;
57 
58 private:
59  enum
60  {
61  CONNECT = 0,
62  ACKNOWLEDGE,
63  READ,
64  WRITE,
65  CLOSE,
66  WAKE_UP_MF,
67  RESIZE
68  };
69 
70  // DATA
71  bool m_bLinked;
72 
73  yarp::os::Contact m_LocalAddress;
74  yarp::os::Contact m_RemoteAddress;
75  ACE_SOCK_Stream m_SockStream;
76  ACE_SOCK_Acceptor m_Acceptor;
77 
80 
81  // FUNCTIONS
82  int connect(const ACE_INET_Addr& ace_address);
83 };
84 
85 #endif // YARP_SHMEM_SHMEMHYBRIDSTREAM_H
yarp::os::TwoWayStream
A stream which can be asked to perform bidirectional communication.
Definition: TwoWayStream.h:29
ShmemHybridStream::beginPacket
void beginPacket() override
Mark the beginning of a logical packet.
Definition: ShmemHybridStream.cpp:206
ShmemHybridStream::interrupt
void interrupt() override
Interrupt the stream.
Definition: ShmemHybridStream.cpp:163
ShmemHybridStream
A stream abstraction for shared memory communication.
Definition: ShmemHybridStream.h:28
ShmemHybridStream::ShmemHybridStream
ShmemHybridStream()
Definition: ShmemHybridStream.cpp:13
yarp::os::OutputStream::write
virtual void write(char ch)
Write a single byte to the stream.
Definition: OutputStream.cpp:17
yarp::os::OutputStream
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:25
OutputStream.h
ShmemHybridStream::getOutputStream
yarp::os::OutputStream & getOutputStream() override
Get an OutputStream to write to.
Definition: ShmemHybridStream.cpp:190
ShmemHybridStream::getLocalAddress
const yarp::os::Contact & getLocalAddress() const override
Get the address of the local side of the stream.
Definition: ShmemHybridStream.cpp:214
ShmemOutputStream.h
TwoWayStream.h
ShmemHybridStream::isOk
bool isOk() const override
Check if the stream is ok or in an error state.
Definition: ShmemHybridStream.cpp:195
NetType.h
ShmemHybridStream::accept
int accept()
Definition: ShmemHybridStream.cpp:52
ShmemInputStreamImpl
Definition: ShmemInputStream.h:41
ShmemHybridStream::close
void close() override
Terminate the stream.
Definition: ShmemHybridStream.cpp:156
ShmemOutputStreamImpl
Definition: ShmemOutputStream.h:40
ShmemHybridStream::endPacket
void endPacket() override
Mark the end of a logical packet (see beginPacket).
Definition: ShmemHybridStream.cpp:210
yarp::conf::ssize_t
::ssize_t ssize_t
Definition: numeric.h:60
yarp::os::Bytes
A simple abstraction for a block of bytes.
Definition: Bytes.h:28
ShmemHybridStream::~ShmemHybridStream
virtual ~ShmemHybridStream()
Definition: ShmemHybridStream.cpp:18
yarp::os::InputStream::read
virtual int read()
Read and return a single byte.
Definition: InputStream.cpp:23
yarp::os::Contact
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
InputStream.h
ShmemHybridStream::write
void write(const yarp::os::Bytes &b) override
Write a block of bytes to the stream.
Definition: ShmemHybridStream.cpp:169
ShmemInputStream.h
yarp::os::InputStream
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:29
ShmemHybridStream::reset
void reset() override
Reset the stream.
Definition: ShmemHybridStream.cpp:200
ShmemHybridStream::getRemoteAddress
const yarp::os::Contact & getRemoteAddress() const override
Get the address of the remote side of the stream.
Definition: ShmemHybridStream.cpp:219
ShmemHybridStream::getInputStream
yarp::os::InputStream & getInputStream() override
Get an InputStream to read from.
Definition: ShmemHybridStream.cpp:185
ShmemHybridStream::open
int open(const yarp::os::Contact &yarp_address, bool sender)
Definition: ShmemHybridStream.cpp:23