SNode.C
Loading...
Searching...
No Matches
core::pipe::PipeSource Class Reference

#include <PipeSource.h>

Inheritance diagram for core::pipe::PipeSource:
Collaboration diagram for core::pipe::PipeSource:

Public Member Functions

 PipeSource (const PipeSource &)=delete
 
PipeSourceoperator= (const PipeSource &)=delete
 
 PipeSource (int fd)
 
 ~PipeSource () override
 
void send (const char *chunk, std::size_t chunkLen)
 
void send (const std::string &data)
 
void eof ()
 
void setOnError (const std::function< void(int)> &onError)
 
- Public Member Functions inherited from core::DescriptorEventReceiver
 DescriptorEventReceiver (const std::string &name, DescriptorEventPublisher &descriptorEventPublisher, const utils::Timeval &timeout=TIMEOUT::DISABLE)
 
int getRegisteredFd () const
 
bool isEnabled () const
 
bool isSuspended () const
 
void setTimeout (const utils::Timeval &timeout)
 
utils::Timeval getTimeout (const utils::Timeval &currentTime) const
 
void checkTimeout (const utils::Timeval &currentTime)
 
- Public Member Functions inherited from core::EventReceiver
 EventReceiver (const std::string &name)
 
 EventReceiver (EventReceiver &)=delete
 
 EventReceiver (EventReceiver &&)=delete
 
EventReceiveroperator= (EventReceiver &)=delete
 
EventReceiveroperator= (EventReceiver &&)=delete
 
virtual void destruct ()
 
void span ()
 
void relax ()
 
const std::string & getName () const
 

Protected Member Functions

void writeEvent () override
 
void unobservedEvent () override
 
- Protected Member Functions inherited from core::eventreceiver::WriteEventReceiver
 WriteEventReceiver (const std::string &name, const utils::Timeval &timeout)
 
virtual void writeTimeout ()
 
- Protected Member Functions inherited from core::DescriptorEventReceiver
bool enable (int fd)
 
void disable ()
 
void suspend ()
 
void resume ()
 
- Protected Member Functions inherited from core::Observer
void observed ()
 
void unObserved ()
 
 Observer ()=default
 
 Observer (Observer &)=delete
 
 Observer (Observer &&)=delete
 
virtual ~Observer ()
 
- Protected Member Functions inherited from core::EventReceiver
virtual ~EventReceiver ()=default
 
 EventReceiver (const std::string &name)
 
 EventReceiver (EventReceiver &)=delete
 
 EventReceiver (EventReceiver &&)=delete
 
EventReceiveroperator= (EventReceiver &)=delete
 
EventReceiveroperator= (EventReceiver &&)=delete
 
virtual void destruct ()
 
void span ()
 
void relax ()
 
const std::string & getName () const
 

Private Attributes

std::function< void(int errnum)> onError
 
std::vector< char > writeBuffer
 

Additional Inherited Members

- Static Public Member Functions inherited from core::EventReceiver
static void atNextTick (const std::function< void(void)> &callBack)
 
- Static Protected Member Functions inherited from core::EventReceiver
static void atNextTick (const std::function< void(void)> &callBack)
 

Detailed Description

Definition at line 58 of file PipeSource.h.

Constructor & Destructor Documentation

◆ PipeSource() [1/2]

core::pipe::PipeSource::PipeSource ( const PipeSource )
delete

◆ PipeSource() [2/2]

core::pipe::PipeSource::PipeSource ( int  fd)
explicit

Definition at line 60 of file PipeSource.cpp.

61 : core::eventreceiver::WriteEventReceiver("PipeSource fd = " + std::to_string(fd), 60) {
62 if (!WriteEventReceiver::enable(fd)) {
63 delete this;
64 } else {
65 WriteEventReceiver::suspend();
66 }
67 }

References core::DescriptorEventReceiver::enable(), core::DescriptorEventReceiver::suspend(), and core::eventreceiver::WriteEventReceiver::WriteEventReceiver().

Referenced by core::pipe::Pipe::Pipe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~PipeSource()

core::pipe::PipeSource::~PipeSource ( )
override

Definition at line 69 of file PipeSource.cpp.

69 {
71 }
int close(int fd)
Definition unistd.cpp:67

References core::DescriptorEventReceiver::getRegisteredFd().

Here is the call graph for this function:

Member Function Documentation

◆ eof()

void core::pipe::PipeSource::eof ( )

Definition at line 89 of file PipeSource.cpp.

89 {
90 WriteEventReceiver::disable();
91 }

References core::DescriptorEventReceiver::disable().

Here is the call graph for this function:

◆ operator=()

PipeSource & core::pipe::PipeSource::operator= ( const PipeSource )
delete

◆ send() [1/2]

void core::pipe::PipeSource::send ( const char *  chunk,
std::size_t  chunkLen 
)

Definition at line 77 of file PipeSource.cpp.

77 {
78 writeBuffer.insert(writeBuffer.end(), chunk, chunk + chunkLen);
79
80 if (WriteEventReceiver::isSuspended()) {
81 WriteEventReceiver::resume();
82 }
83 }
std::vector< char > writeBuffer
Definition PipeSource.h:80

References core::DescriptorEventReceiver::isSuspended(), core::DescriptorEventReceiver::resume(), and writeBuffer.

Referenced by main(), and send().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send() [2/2]

void core::pipe::PipeSource::send ( const std::string &  data)

Definition at line 85 of file PipeSource.cpp.

85 {
86 send(data.data(), data.size());
87 }
void send(const char *chunk, std::size_t chunkLen)

References send().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setOnError()

void core::pipe::PipeSource::setOnError ( const std::function< void(int)> &  onError)

Definition at line 73 of file PipeSource.cpp.

73 {
74 this->onError = onError;
75 }
std::function< void(int errnum)> onError
Definition PipeSource.h:78

References onError.

Referenced by main().

Here is the caller graph for this function:

◆ unobservedEvent()

void core::pipe::PipeSource::unobservedEvent ( )
overrideprotectedvirtual

Implements core::Observer.

Definition at line 112 of file PipeSource.cpp.

112 {
113 delete this;
114 }

◆ writeEvent()

void core::pipe::PipeSource::writeEvent ( )
overrideprotectedvirtual

Implements core::eventreceiver::WriteEventReceiver.

Definition at line 93 of file PipeSource.cpp.

93 {
94 const ssize_t ret = core::system::write(
96
97 if (ret > 0) {
98 writeBuffer.erase(writeBuffer.begin(), writeBuffer.begin() + ret);
99
100 if (writeBuffer.empty()) {
101 WriteEventReceiver::suspend();
102 }
103 } else if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
104 WriteEventReceiver::disable();
105
106 if (onError) {
107 onError(errno);
108 }
109 }
110 }
#define MAX_SEND_JUNKSIZE
ssize_t write(int fd, const void *buf, std::size_t count)
Definition unistd.cpp:62

References core::DescriptorEventReceiver::disable(), core::DescriptorEventReceiver::getRegisteredFd(), onError, core::DescriptorEventReceiver::suspend(), core::system::write(), and writeBuffer.

Here is the call graph for this function:

Member Data Documentation

◆ onError

std::function<void(int errnum)> core::pipe::PipeSource::onError
private

Definition at line 78 of file PipeSource.h.

Referenced by setOnError(), and writeEvent().

◆ writeBuffer

std::vector<char> core::pipe::PipeSource::writeBuffer
private

Definition at line 80 of file PipeSource.h.

Referenced by send(), and writeEvent().


The documentation for this class was generated from the following files: