21 #ifndef INCLUDE_OLA_IO_DESCRIPTOR_H_
22 #define INCLUDE_OLA_IO_DESCRIPTOR_H_
28 #include <ola/io/IOQueue.h>
79 GENERIC_DESCRIPTOR = 0,
85 struct DescriptorHandle {
92 DescriptorType m_type;
96 uint8_t* m_async_data;
98 uint32_t* m_async_data_size;
103 bool AllocAsyncBuffer();
104 void FreeAsyncBuffer();
106 bool IsValid()
const;
109 void* ToHandle(
const DescriptorHandle &handle);
111 static DescriptorHandle INVALID_DESCRIPTOR;
112 static const uint32_t ASYNC_DATA_BUFFER_SIZE = 1024;
113 bool operator!=(
const DescriptorHandle &lhs,
const DescriptorHandle &rhs);
114 bool operator==(
const DescriptorHandle &lhs,
const DescriptorHandle &rhs);
115 bool operator<(
const DescriptorHandle &lhs,
const DescriptorHandle &rhs);
116 std::ostream&
operator<<(std::ostream &stream,
const DescriptorHandle &data);
118 typedef int DescriptorHandle;
119 static DescriptorHandle INVALID_DESCRIPTOR = -1;
131 int ToFD(
const DescriptorHandle& handle);
232 m_on_write = on_write;
260 DescriptorHandle m_handle;
299 virtual ssize_t
Send(
const uint8_t *buffer,
unsigned int size);
322 virtual int Receive(uint8_t *buffer,
324 unsigned int &data_read);
336 virtual bool Close() = 0;
357 m_on_close = on_close;
370 OnCloseCallback *on_close = m_on_close;
381 virtual bool IsSocket()
const = 0;
389 OnCloseCallback *m_on_close;
424 bool IsSocket()
const {
return false; }
427 DescriptorHandle m_handle_pair[2];
430 DISALLOW_COPY_AND_ASSIGN(LoopbackDescriptor);
471 bool IsSocket()
const {
return false; }
474 DescriptorHandle m_in_pair[2];
475 DescriptorHandle m_out_pair[2];
476 PipeDescriptor *m_other_end;
478 PipeDescriptor(DescriptorHandle in_pair[2],
479 DescriptorHandle out_pair[2],
480 PipeDescriptor *other_end);
483 DISALLOW_COPY_AND_ASSIGN(PipeDescriptor);
493 m_handle = INVALID_DESCRIPTOR;
525 bool IsSocket()
const {
return true; }
528 DescriptorHandle m_handle;
529 UnixSocket *m_other_end;
530 UnixSocket(
int socket, UnixSocket *other_end);
532 DISALLOW_COPY_AND_ASSIGN(UnixSocket);
556 bool IsSocket()
const {
return false; }
559 DescriptorHandle m_handle;
567 #endif // INCLUDE_OLA_IO_DESCRIPTOR_H_
virtual void PerformRead()=0
Called when there is data available on the descriptor.
A 0 arg, single use callback that returns void.
Definition: Callback.h:157
int ToFD(const DescriptorHandle &handle)
Definition: Descriptor.cpp:125
bool Init()
Setup this loopback descriptor.
Definition: Descriptor.cpp:505
bool CloseClient()
Close the write portion of the loopback descriptor.
Definition: Descriptor.cpp:540
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
virtual bool SetReadNonBlocking()
Enable on non-blocking reads..
Definition: Descriptor.h:332
bool CloseClient()
Close the write portion of this UnixSocket.
Definition: Descriptor.cpp:691
DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition: Descriptor.h:510
DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition: Descriptor.h:457
bool CloseClient()
Close the write portion of this PipeDescriptor.
Definition: Descriptor.cpp:622
bool SetNoSigPipe(DescriptorHandle fd)
Disable SIGPIPE for this descriptor.
Definition: Descriptor.cpp:267
bool IsClosed() const
Check if the descriptor is closed.
Definition: Descriptor.cpp:493
DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition: Descriptor.h:458
std::ostream & operator<<(std::ostream &out, const DmxBuffer &data)
Stream operator to allow DmxBuffer to be output to stdout.
Definition: DmxBuffer.cpp:402
virtual void PerformWrite()=0
Called when the descriptor can be written to.
A file descriptor that supports both read & write.
Definition: Descriptor.h:200
void SetOnClose(OnCloseCallback *on_close)
Set the callback to be run when the descriptor is closed.
Definition: Descriptor.h:354
void SetOnWritable(ola::Callback0< void > *on_write)
Set the callback to be run when the descriptor can be written to.
Definition: Descriptor.h:229
bool Init()
Initialize the PipeDescriptor.
Definition: Descriptor.cpp:562
virtual DescriptorHandle ReadDescriptor() const =0
Returns the read descriptor for this socket.
A descriptor that uses unix pipes.
Definition: Descriptor.h:439
DeviceDescriptor(int fd)
Create a new DeviceDescriptor.
Definition: Descriptor.cpp:712
DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition: Descriptor.h:511
static bool SetNonBlocking(DescriptorHandle fd)
Set a DescriptorHandle to non-blocking mode.
Definition: Descriptor.cpp:246
int DataRemaining() const
Find out how much data is left to read.
Definition: Descriptor.cpp:289
DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition: Descriptor.h:547
A unix domain socket pair.
Definition: Descriptor.h:489
DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition: Descriptor.h:408
bool ValidWriteDescriptor() const
Check if this file descriptor is valid.
Definition: Descriptor.h:184
DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition: Descriptor.h:409
PipeDescriptor * OppositeEnd()
Fetch the other end of the PipeDescriptor.
Definition: Descriptor.cpp:588
A loopback descriptor.
Definition: Descriptor.h:398
void PerformRead()
Called when there is data available on the descriptor.
Definition: Descriptor.cpp:212
Represents a file descriptor that supports reading data.
Definition: Descriptor.h:140
UnmanagedFileDescriptor(int fd)
Create a new UnmanagedFileDescriptor.
Definition: Descriptor.cpp:232
DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition: Descriptor.h:256
Allows a FD created by a library to be used with the SelectServer.
Definition: Descriptor.h:247
void PerformWrite()
Called when the descriptor can be written to.
Definition: Descriptor.cpp:221
void SetOnData(ola::Callback0< void > *on_read)
Set the callback to be run when data is available for reading.
Definition: Descriptor.h:218
virtual DescriptorHandle WriteDescriptor() const =0
Returns the write descriptor for this socket.
bool Close()
Close this UnixSocket.
Definition: Descriptor.cpp:678
virtual ssize_t Send(const uint8_t *buffer, unsigned int size)
Write a buffer to the descriptor.
Definition: Descriptor.cpp:318
bool Init()
Initialize the UnixSocket.
Definition: Descriptor.cpp:649
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition: Descriptor.h:548
Comparison operator for UnmanagedFileDescriptor.
Definition: Descriptor.h:270
OnCloseCallback * TransferOnClose()
Take ownership of the on_close callback.
Definition: Descriptor.h:369
bool Close()
Close the loopback descriptor.
Definition: Descriptor.cpp:518
UnixSocket * OppositeEnd()
Fetch the other end of the unix socket.
Definition: Descriptor.cpp:671
bool Close()
Close this DeviceDescriptor.
Definition: Descriptor.cpp:721
Represents a file descriptor that supports writing data.
Definition: Descriptor.h:170
A descriptor which represents a connection to a device.
Definition: Descriptor.h:538
bool Close()
Close this PipeDescriptor.
Definition: Descriptor.cpp:600
DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition: Descriptor.h:255
bool ValidReadDescriptor() const
Check if this file descriptor is valid.
Definition: Descriptor.h:154
virtual int Receive(uint8_t *buffer, unsigned int size, unsigned int &data_read)
Read data from this descriptor.
Definition: Descriptor.cpp:422