Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Device Struct Reference

Device tab structure. More...

#include <Devtab.hxx>

Inheritance diagram for Device:
FileIO Node Null DccDecoder< Module > DeviceFile EEPROM I2C NonBlockNode Pic32mxCan Pipe RailcomDriverBase< HW > RailcomDriverBase< HW > RamDiskBase SPI Serial Socket TinyUsbCdc TivaDCC< HW > TivaFlash TivaNRZ< HW > TivaTestPacketSource< HW >

Classes

struct  SelectInfo
 Select wakeup information. More...
 

Public Member Functions

 Device (const char *name)
 Constructor.
 
virtual ~Device ()
 Destructor.
 

Static Public Member Functions

static int open (struct _reent *reent, const char *path, int flags, int mode)
 Open a file or device.
 
static int close (struct _reent *reent, int fd)
 Close a file or device.
 
static int stat (struct _reent *reent, const char *path, struct stat *stat)
 Get the status information of a file or device.
 
static int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, long long timeout)
 POSIX select().
 
static void select_clear ()
 Clears the current thread's select bits.
 
- Static Public Member Functions inherited from FileIO
static ssize_t read (struct _reent *reent, int fd, void *buf, size_t count)
 Read from a file or device.
 
static ssize_t write (struct _reent *reent, int fd, const void *buf, size_t count)
 Write to a file or device.
 
static _off_t lseek (struct _reent *reent, int fd, _off_t offset, int whence)
 Change the offset index of a file or device.
 
static int fstat (struct _reent *reent, int fd, struct stat *stat)
 Get the status information of a file or device.
 
static int ioctl (int fd, unsigned long int key, unsigned long data)
 Request and ioctl transaction.
 
static int fcntl (int fd, int cmd, unsigned long data)
 Manipulate a file descriptor.
 
static bool is_device (int fd)
 Test if the file descriptor belongs to a device.
 

Protected Member Functions

virtual mode_t get_mode ()
 Get the mode of the device.
 
- Protected Member Functions inherited from FileIO
 FileIO (const char *name)
 Constructor.
 
virtual ~FileIO ()
 Destructor.
 
virtual int open (File *file, const char *path, int flags, int mode)=0
 Open a file or device.
 
virtual int close (File *file)=0
 Close a file or device.
 
virtual ssize_t read (File *file, void *buf, size_t count)=0
 Read from a file or device.
 
virtual ssize_t write (File *file, const void *buf, size_t count)=0
 Write to a file or device.
 
virtual off_t lseek (File *f, off_t offset, int whence)
 Seek method.
 
virtual int fstat (File *file, struct stat *stat)=0
 Get the status information of a file or device.
 
virtual int ioctl (File *file, unsigned long int key, unsigned long data)
 Request an ioctl transaction.
 
virtual int fcntl (File *file, int cmd, unsigned long data)
 Manipulate a file descriptor.
 
virtual bool select (File *file, int mode)
 Device select method.
 

Static Protected Member Functions

static void select_insert (SelectInfo *info)
 Add client to list of clients needing woken.
 
static void select_wakeup (SelectInfo *info)
 Wakeup the list of clients needing woken.
 
static void select_wakeup_from_isr (SelectInfo *info, int *woken)
 Wakeup the list of clients needing woken.
 
- Static Protected Member Functions inherited from FileIO
static int fd_alloc (void)
 Allocate a free file descriptor.
 
static void fd_free (int fd)
 Free up a file descriptor.
 
static Filefile_lookup (int fd)
 Looks up a reference to a File corresponding to a given file descriptor.
 
static int fd_lookup (File *file)
 Looks up a file descriptor corresponding to a given File reference.
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (Device)
 

Private Attributes

Devicenext
 next device in linked list
 
Deviceprev
 previous device in linked list
 

Static Private Attributes

static Devicefirst = NULL
 first device in linked list
 

Friends

class DeviceBufferBase
 allow class DeviceBuffer access to select() related members.
 
class OSSelectWakeup
 allow class OSSelectWakeup access to select() related members.
 

Additional Inherited Members

- Protected Attributes inherited from FileIO
const char * name
 device name
 
- Static Protected Attributes inherited from FileIO
static const unsigned int numOpenFiles = 20
 
static File files []
 File descriptor pool.
 
static OSMutex mutex
 mutual exclusion for fileio
 

Detailed Description

Device tab structure.

Definition at line 431 of file Devtab.hxx.

Constructor & Destructor Documentation

◆ Device()

Device::Device ( const char *  name)

Constructor.

Parameters
namename of device in file system. Pointer must be valid throughout the entire lifetime.

Definition at line 52 of file Device.cxx.

◆ ~Device()

Device::~Device ( )
virtual

Destructor.

Definition at line 68 of file Device.cxx.

Member Function Documentation

◆ close()

int Device::close ( struct _reent *  reent,
int  fd 
)
static

Close a file or device.

Parameters
reentthread save reentrant structure
fdfile descriptor to close
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 134 of file Device.cxx.

◆ get_mode()

virtual mode_t Device::get_mode ( )
inlineprotectedvirtual

Get the mode of the device.

Returns
mode of device.

Reimplemented in Node.

Definition at line 506 of file Devtab.hxx.

◆ open()

int Device::open ( struct _reent *  reent,
const char *  path,
int  flags,
int  mode 
)
static

Open a file or device.

Parameters
reentthread save reentrant structure
pathfile or device name
flagsopen flags
modeopen mode, ignored in this implementation
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 93 of file Device.cxx.

◆ select()

int Device::select ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
long long  timeout 
)
static

POSIX select().

Parameters
nfdshighest numbered file descriptor in any of the three, sets plus 1
readfdsfd_set of file descritpors to pend on read active
writefdsfd_set of file descritpors to pend on write active
exceptfdsfd_set of file descritpors to pend on error active
timeouttimeout in nsec to wait, if 0, return immediately, if < 0 wait forever
Returns
on success, number of file descriptors in the three sets that are active, 0 on timeout, -1 with errno set appropriately upon error.

Definition at line 96 of file Select.cxx.

◆ select_clear()

void Device::select_clear ( )
static

Clears the current thread's select bits.

This is used by select and ::pselect to ensure the necessary atomicity.

Definition at line 78 of file Select.cxx.

◆ select_insert()

void Device::select_insert ( SelectInfo info)
staticprotected

Add client to list of clients needing woken.

Add client to list of clients needing woken,.

Parameters
infowakeup event instance
Todo:
do we need the critical lock here, or are we always already locked?

Definition at line 197 of file Select.cxx.

◆ select_wakeup()

void Device::select_wakeup ( SelectInfo info)
staticprotected

Wakeup the list of clients needing woken.

Wakeup the list of clients needing woken,.

Parameters
infowakeup event instance

Definition at line 210 of file Select.cxx.

◆ select_wakeup_from_isr()

void Device::select_wakeup_from_isr ( SelectInfo info,
int *  woken 
)
staticprotected

Wakeup the list of clients needing woken.

Wakeup the list of clients needing woken,.

from ISR context.

Parameters
infowakeup event instance
wokenis the task woken up
infowakeup event instance

Definition at line 224 of file Select.cxx.

◆ stat()

int Device::stat ( struct _reent *  reent,
const char *  path,
struct stat *  stat 
)
static

Get the status information of a file or device.

Parameters
reentthread save reentrant structure
pathfile or device name
statstructure to fill status info into
Returns
0 upon success, -1 upon failure with errno containing the cause

Definition at line 165 of file Device.cxx.

Friends And Related Symbol Documentation

◆ DeviceBufferBase

friend class DeviceBufferBase
friend

allow class DeviceBuffer access to select() related members.

Definition at line 528 of file Devtab.hxx.

◆ OSSelectWakeup

friend class OSSelectWakeup
friend

allow class OSSelectWakeup access to select() related members.

Definition at line 531 of file Devtab.hxx.

Member Data Documentation

◆ first

Device * Device::first = NULL
staticprivate

first device in linked list

Definition at line 535 of file Devtab.hxx.

◆ next

Device* Device::next
private

next device in linked list

Definition at line 538 of file Devtab.hxx.

◆ prev

Device* Device::prev
private

previous device in linked list

Definition at line 541 of file Devtab.hxx.


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