Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
HubDeviceSelect< HFlow, ReadFlow > Class Template Reference

HubPort that connects a select-aware device to a strongly typed Hub. More...

#include <HubDeviceSelect.hxx>

Inheritance diagram for HubDeviceSelect< HFlow, ReadFlow >:
FdHubPortService Atomic FdHubPortInterface Service Destructable

Classes

class  WriteFlow
 State flow implementing select-aware fd writes. More...
 

Public Member Functions

 HubDeviceSelect (HFlow *hub, const char *path, Notifiable *on_error=nullptr)
 Creates a select-aware hub port for the device specified by ‘path’.
 
 HubDeviceSelect (HFlow *hub, int fd, Notifiable *on_error=nullptr)
 Creates a select-aware hub port for the opened device specified by ‘fd’.
 
virtual ~HubDeviceSelect ()
 If the barrier has not been called yet, will notify it inline.
 
HFlow * hub ()
 
HFlow::port_type * write_port ()
 
void unregister_write_port ()
 Removes the current write port from the registry of the source hub.
 
bool write_done ()
 
- Public Member Functions inherited from FdHubPortInterface
int fd ()
 
- Public Member Functions inherited from Service
 Service (ExecutorBase *e)
 Constructor.
 
 ~Service ()
 Destructor.
 
ExecutorBaseexecutor ()
 

Protected Types

typedef StateFlow< typename HFlow::buffer_type, QList< 1 > > WriteFlowBase
 Base stateflow for the WriteFlow.
 

Protected Member Functions

void report_write_error () override
 The assumption here is that the write flow still has entries in its queue that need to be removed.
 
void report_read_error () override
 Callback from the ReadFlow when the read call has seen an error.
 
void close_fd ()
 
- Protected Member Functions inherited from FdHubPortService
 FdHubPortService (ExecutorBase *exec, int fd)
 Constructor.
 
- Protected Member Functions inherited from FdHubPortInterface
 FdHubPortInterface (int fd)
 

Protected Attributes

HFlow * hub_
 Hub whose data we are trying to send.
 
ReadFlow readFlow_
 StateFlow for reading data from the fd. Woken when data arrives.
 
WriteFlow writeFlow_
 StateFlow for writing data to the fd.
 
bool isRegistered_
 True when the write flow is registered in the hub.
 
- Protected Attributes inherited from FdHubPortService
BarrierNotifiable barrier_
 This notifiable will be called (if not NULL) upon read or write error.
 
- Protected Attributes inherited from FdHubPortInterface
int fd_ {-1}
 The device file descriptor.
 

Additional Inherited Members

- Private Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Detailed Description

template<class HFlow, class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
class HubDeviceSelect< HFlow, ReadFlow >

HubPort that connects a select-aware device to a strongly typed Hub.

The device is given by either the path to the device or the fd to an opened device instance or socket. The device will be put to nonblocking mode and all processing will be performed in the executor of the hub, by using ExecutorBase::select(). No additional threads are started.

Reads and writes will be performed in the units defined by the type of the hub: for string-typed hubs in 64 bytes units; for hubs of specific structures (such as CAN frame, dcc Packets or dcc Feedback structures) in the units ofthe size of the structure.

Definition at line 298 of file HubDeviceSelect.hxx.

Member Typedef Documentation

◆ WriteFlowBase

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
typedef StateFlow<typename HFlow::buffer_type, QList<1> > HubDeviceSelect< HFlow, ReadFlow >::WriteFlowBase
protected

Base stateflow for the WriteFlow.

Definition at line 413 of file HubDeviceSelect.hxx.

Constructor & Destructor Documentation

◆ HubDeviceSelect() [1/2]

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
HubDeviceSelect< HFlow, ReadFlow >::HubDeviceSelect ( HFlow *  hub,
const char *  path,
Notifiable on_error = nullptr 
)
inline

Creates a select-aware hub port for the device specified by ‘path’.

Definition at line 303 of file HubDeviceSelect.hxx.

◆ HubDeviceSelect() [2/2]

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
HubDeviceSelect< HFlow, ReadFlow >::HubDeviceSelect ( HFlow *  hub,
int  fd,
Notifiable on_error = nullptr 
)
inline

Creates a select-aware hub port for the opened device specified by ‘fd’.

It can be a hardware device, socket or pipe.

Parameters
hubthe hub to open the port on
fdthe filedes to read/write data from/to.
on_errornotifiable that will be called when a write or read error is encountered.

Definition at line 327 of file HubDeviceSelect.hxx.

◆ ~HubDeviceSelect()

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
virtual HubDeviceSelect< HFlow, ReadFlow >::~HubDeviceSelect ( )
inlinevirtual

If the barrier has not been called yet, will notify it inline.

Definition at line 348 of file HubDeviceSelect.hxx.

Member Function Documentation

◆ close_fd()

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
void HubDeviceSelect< HFlow, ReadFlow >::close_fd ( )
inlineprotected

Definition at line 497 of file HubDeviceSelect.hxx.

◆ hub()

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
HFlow * HubDeviceSelect< HFlow, ReadFlow >::hub ( )
inline
Returns
parent hub flow.

Definition at line 371 of file HubDeviceSelect.hxx.

◆ report_read_error()

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
void HubDeviceSelect< HFlow, ReadFlow >::report_read_error ( )
inlineoverrideprotectedvirtual

Callback from the ReadFlow when the read call has seen an error.

The read count will already have been taken out of the barrier, and the read flow in terminated state.

Implements FdHubPortService.

Definition at line 491 of file HubDeviceSelect.hxx.

◆ report_write_error()

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
void HubDeviceSelect< HFlow, ReadFlow >::report_write_error ( )
inlineoverrideprotectedvirtual

The assumption here is that the write flow still has entries in its queue that need to be removed.

Implements FdHubPortService.

Definition at line 481 of file HubDeviceSelect.hxx.

◆ unregister_write_port()

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
void HubDeviceSelect< HFlow, ReadFlow >::unregister_write_port ( )
inline

Removes the current write port from the registry of the source hub.

Definition at line 383 of file HubDeviceSelect.hxx.

◆ write_done()

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
bool HubDeviceSelect< HFlow, ReadFlow >::write_done ( )
inline
Returns
true if there is no pending data to write. Can be used to check safe destruction.

Definition at line 406 of file HubDeviceSelect.hxx.

◆ write_port()

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
HFlow::port_type * HubDeviceSelect< HFlow, ReadFlow >::write_port ( )
inline
Returns
the write flow belonging to this device.

Definition at line 377 of file HubDeviceSelect.hxx.

Member Data Documentation

◆ hub_

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
HFlow* HubDeviceSelect< HFlow, ReadFlow >::hub_
protected

Hub whose data we are trying to send.

Definition at line 520 of file HubDeviceSelect.hxx.

◆ isRegistered_

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
bool HubDeviceSelect< HFlow, ReadFlow >::isRegistered_
protected

True when the write flow is registered in the hub.

Used to synchronize different and concurrent shutdown paths. Protected by Atomic this.

Definition at line 528 of file HubDeviceSelect.hxx.

◆ readFlow_

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
ReadFlow HubDeviceSelect< HFlow, ReadFlow >::readFlow_
protected

StateFlow for reading data from the fd. Woken when data arrives.

Definition at line 522 of file HubDeviceSelect.hxx.

◆ writeFlow_

template<class HFlow , class ReadFlow = HubDeviceSelectReadFlow<HFlow>>
WriteFlow HubDeviceSelect< HFlow, ReadFlow >::writeFlow_
protected

StateFlow for writing data to the fd.

Woken by data to send or the fd being writeable.

Definition at line 525 of file HubDeviceSelect.hxx.


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