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);
148 virtual DescriptorHandle ReadDescriptor()
const = 0;
155 return ReadDescriptor() != INVALID_DESCRIPTOR;
163 virtual void PerformRead() = 0;
178 virtual DescriptorHandle WriteDescriptor()
const = 0;
185 return WriteDescriptor() != INVALID_DESCRIPTOR;
193 virtual void PerformWrite() = 0;
232 m_on_write = on_write;
260 DescriptorHandle m_handle;
299 virtual ssize_t Send(
const uint8_t *buffer,
unsigned int size);
311 virtual ssize_t Send(
IOQueue *data);
322 virtual int Receive(uint8_t *buffer,
324 unsigned int &data_read);
333 return SetNonBlocking(ReadDescriptor());
336 virtual bool Close() = 0;
342 int DataRemaining()
const;
347 bool IsClosed()
const;
357 m_on_close = on_close;
370 OnCloseCallback *on_close = m_on_close;
378 static bool SetNonBlocking(DescriptorHandle fd);
381 virtual bool IsSocket()
const = 0;
386 bool SetNoSigPipe(DescriptorHandle fd);
389 OnCloseCallback *m_on_close;
424 bool IsSocket()
const {
return false; }
427 DescriptorHandle m_handle_pair[2];
471 bool IsSocket()
const {
return false; }
474 DescriptorHandle m_in_pair[2];
475 DescriptorHandle m_out_pair[2];
479 DescriptorHandle out_pair[2],
493 m_handle = INVALID_DESCRIPTOR;
525 bool IsSocket()
const {
return true; }
528 DescriptorHandle m_handle;
556 bool IsSocket()
const {
return false; }
559 DescriptorHandle m_handle;
567 #endif // INCLUDE_OLA_IO_DESCRIPTOR_H_ A 0 arg, single use callback that returns void.
Definition: Callback.h:157
DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition: Descriptor.h:458
DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition: Descriptor.h:409
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
int ToFD(const DescriptorHandle &handle)
Definition: Descriptor.cpp:125
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
virtual bool SetReadNonBlocking()
Enable on non-blocking reads..
Definition: Descriptor.h:332
DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition: Descriptor.h:548
std::ostream & operator<<(std::ostream &out, const DmxBuffer &data)
Stream operator to allow DmxBuffer to be output to stdout.
Definition: DmxBuffer.cpp:402
DescriptorHandle WriteDescriptor() const
Returns the write descriptor for this socket.
Definition: Descriptor.h:511
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
A descriptor that uses unix pipes.
Definition: Descriptor.h:439
A unix domain socket pair.
Definition: Descriptor.h:489
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:256
A loopback descriptor.
Definition: Descriptor.h:398
Represents a file descriptor that supports reading data.
Definition: Descriptor.h:140
DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition: Descriptor.h:408
Allows a FD created by a library to be used with the SelectServer.
Definition: Descriptor.h:247
DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition: Descriptor.h:457
void SetOnData(ola::Callback0< void > *on_read)
Set the callback to be run when data is available for reading.
Definition: Descriptor.h:218
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Comparison operator for UnmanagedFileDescriptor.
Definition: Descriptor.h:270
OnCloseCallback * TransferOnClose()
Take ownership of the on_close callback.
Definition: Descriptor.h:369
bool ValidReadDescriptor() const
Check if this file descriptor is valid.
Definition: Descriptor.h:154
DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition: Descriptor.h:547
DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition: Descriptor.h:510
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
DescriptorHandle ReadDescriptor() const
Returns the read descriptor for this socket.
Definition: Descriptor.h:255