µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::posix::file_lockable< T, L > Class Template Reference

#include <file.h>

+ Inheritance diagram for os::posix::file_lockable< T, L >:

Public Types

using lockable_type = L
 
using value_type = T
 
Types & Constants
enum class  type : type_t {
  unknown = 0 ,
  not_set = 1 << 0 ,
  char_device = 1 << 1 ,
  block_device = 1 << 2 ,
  tty = 1 << 3 ,
  file = 1 << 4 ,
  socket = 1 << 5
}
 
using type_t = unsigned int
 

Public Member Functions

Constructors & Destructor
 file_lockable (file_system &fs, lockable_type &locker)
 
virtual ~file_lockable () override
 
Public Member Functions
virtual int close (void) override
 
virtual ssize_t read (void *buf, std::size_t nbyte) override
 
virtual ssize_t write (const void *buf, std::size_t nbyte) override
 
virtual ssize_t writev (const iovec *iov, int iovcnt) override
 
virtual int vfcntl (int cmd, std::va_list args) override
 
virtual int fstat (struct stat *buf) override
 
virtual off_t lseek (off_t offset, int whence) override
 
virtual int ftruncate (off_t length) override
 
virtual int fsync (void) override
 
value_typeimpl (void) const
 
Public Member Functions
virtual int fstatvfs (struct statvfs *buf)
 
class file_systemget_file_system (void)
 
Public Member Functions
int fcntl (int cmd,...)
 
int isatty (void)
 
type_t get_type (void) const
 
file_descriptor_t file_descriptor (void) const
 
bool is_opened (void)
 

Protected Member Functions

Private Member Functions
void file_descriptor (file_descriptor_t fildes)
 
void clear_file_descriptor (void)
 
ioalloc_file_descriptor (void)
 

Detailed Description

template<typename T, typename L>
class os::posix::file_lockable< T, L >

Definition at line 354 of file file.h.

Member Typedef Documentation

◆ lockable_type

template<typename T , typename L >
using os::posix::file_lockable< T, L >::lockable_type = L

Definition at line 360 of file file.h.

◆ type_t

using os::posix::io::type_t = unsigned int
inherited

Definition at line 125 of file io.h.

◆ value_type

template<typename T , typename L >
using os::posix::file_lockable< T, L >::value_type = T

Definition at line 359 of file file.h.

Member Enumeration Documentation

◆ type

enum class os::posix::io::type : type_t
stronginherited
Enumerator
unknown 
not_set 
char_device 
block_device 
tty 
file 
socket 

Definition at line 126 of file io.h.

127 {
128 unknown = 0,
129 not_set = 1 << 0,
130 char_device = 1 << 1,
131 block_device = 1 << 2,
132 tty = 1 << 3,
133 file = 1 << 4,
134 socket = 1 << 5
135 };

Constructor & Destructor Documentation

◆ file_lockable()

template<typename T , typename L >
os::posix::file_lockable< T, L >::file_lockable ( file_system fs,
lockable_type locker 
)

Definition at line 533 of file file.h.

535 : file{ impl_instance_ }, //
536 impl_instance_{ fs }, //
537 locker_ (locker)
538 {
539#if defined(OS_TRACE_POSIX_IO_FILE)
540 trace::printf ("file_lockable::%s()=@%p\n", __func__, this);
541#endif
542 }
file(file_impl &impl)
Definition file.cpp:37
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59

References os::trace::printf().

◆ ~file_lockable()

template<typename T , typename L >
os::posix::file_lockable< T, L >::~file_lockable
overridevirtual

Definition at line 550 of file file.h.

551 {
552#if defined(OS_TRACE_POSIX_IO_FILE)
553 trace::printf ("file_lockable::%s() @%p\n", __func__, this);
554#endif
555 }

References os::trace::printf().

Member Function Documentation

◆ alloc_file_descriptor()

io * os::posix::io::alloc_file_descriptor ( void  )
protectedinherited

Definition at line 189 of file io.cpp.

190 {
191#if defined(OS_TRACE_POSIX_IO_IO)
192 trace::printf ("io::%s() @%p\n", __func__, this);
193#endif
194
196 if (fd < 0)
197 {
198 // If allocation failed, close this object.
199 impl ().do_close ();
201 return nullptr;
202 }
203
204#if defined(OS_TRACE_POSIX_IO_IO)
205 trace::printf ("io::%s() @%p fd=%d\n", __func__, this, fd);
206#endif
207
208 // Return a valid pointer to an object derived from `io`.
209 return this;
210 }
virtual int do_close(void)=0
io_impl & impl(void) const
Definition io.h:464
void clear_file_descriptor(void)
Definition io.h:446

References os::posix::file_descriptors_manager::allocate(), os::posix::io::clear_file_descriptor(), os::posix::io_impl::do_close(), os::posix::io::impl(), and os::trace::printf().

Referenced by os::posix::socket::accept(), os::posix::socket(), os::posix::device::vopen(), and os::posix::file_system::vopen().

◆ clear_file_descriptor()

void os::posix::io::clear_file_descriptor ( void  )
inlineprotectedinherited

Definition at line 446 of file io.h.

447 {
448 file_descriptor_ = no_file_descriptor;
449 }
constexpr file_descriptor_t no_file_descriptor
Definition types.h:44

References os::posix::no_file_descriptor.

Referenced by os::posix::io::alloc_file_descriptor().

◆ close()

template<typename T , typename L >
int os::posix::file_lockable< T, L >::close ( void  )
overridevirtual

Reimplemented from os::posix::file.

Definition at line 562 of file file.h.

563 {
564 std::lock_guard<L> lock{ locker_ };
565
566 return file::close ();
567 }
virtual int close(void) override
Definition file.cpp:54
port::scheduler::state_t lock(void)

References os::posix::file::close().

◆ fcntl()

int os::posix::io::fcntl ( int  cmd,
  ... 
)
inherited

Definition at line 363 of file io.cpp.

364 {
365 // Forward to the variadic version of the function.
366 std::va_list args;
367 va_start (args, cmd);
368 int ret = vfcntl (cmd, args);
369 va_end (args);
370
371 return ret;
372 }
virtual int vfcntl(int cmd, std::va_list args)
Definition io.cpp:380

References os::posix::io::vfcntl().

◆ file_descriptor() [1/2]

void os::posix::io::file_descriptor ( file_descriptor_t  fildes)
inlineprotectedinherited

Definition at line 440 of file io.h.

441 {
442 file_descriptor_ = fildes;
443 }

◆ file_descriptor() [2/2]

file_descriptor_t os::posix::io::file_descriptor ( void  ) const
inlineinherited

Definition at line 452 of file io.h.

453 {
454 return file_descriptor_;
455 }

Referenced by os::posix::file_descriptors_manager::allocate(), os::posix::file_descriptors_manager::assign(), os::posix::device::vopen(), and os::posix::vopen().

◆ fstat()

template<typename T , typename L >
int os::posix::file_lockable< T, L >::fstat ( struct stat buf)
overridevirtual

Reimplemented from os::posix::io.

Definition at line 612 of file file.h.

613 {
614 std::lock_guard<L> lock{ locker_ };
615
616 return file::fstat (buf);
617 }
virtual int fstat(struct stat *buf)
Definition io.cpp:416

References os::posix::io::fstat().

◆ fstatvfs()

int os::posix::file::fstatvfs ( struct statvfs buf)
virtualinherited

Definition at line 104 of file file.cpp.

105 {
106#if defined(OS_TRACE_POSIX_IO_FILE)
107 trace::printf ("file::%s(%p) @%p\n", __func__, buf, this);
108#endif
109
110 errno = 0;
111
112 // Execute the file system code. Might be locked there.
113 return get_file_system ().statvfs (buf);
114 }
virtual int statvfs(struct statvfs *buf)
class file_system & get_file_system(void)
Definition file.h:478

References os::posix::file::get_file_system(), os::trace::printf(), and os::posix::file_system::statvfs().

◆ fsync()

template<typename T , typename L >
int os::posix::file_lockable< T, L >::fsync ( void  )
overridevirtual

Reimplemented from os::posix::file.

Definition at line 640 of file file.h.

641 {
642 std::lock_guard<L> lock{ locker_ };
643
644 return file::fsync ();
645 }
virtual int fsync(void)
Definition file.cpp:91

References os::posix::file::fsync().

◆ ftruncate()

template<typename T , typename L >
int os::posix::file_lockable< T, L >::ftruncate ( off_t  length)
overridevirtual

Reimplemented from os::posix::file.

Definition at line 631 of file file.h.

632 {
633 std::lock_guard<L> lock{ locker_ };
634
635 return file::ftruncate (length);
636 }
virtual int ftruncate(off_t length)
Definition file.cpp:72

References os::posix::file::ftruncate().

◆ get_file_system()

file_system & os::posix::file::get_file_system ( void  )
inlineinherited

Definition at line 478 of file file.h.

479 {
480 return impl ().get_file_system ();
481 }
class file_system & get_file_system(void)
Definition file.h:492
file_impl & impl(void) const
Definition file.h:484

References os::posix::file_impl::get_file_system(), and os::posix::file::impl().

Referenced by os::posix::file::close(), and os::posix::file::fstatvfs().

◆ get_type()

io::type_t os::posix::io::get_type ( void  ) const
inlineinherited

Definition at line 434 of file io.h.

435 {
436 return type_;
437 }

Referenced by os::posix::file_descriptors_manager::socket().

◆ impl()

template<typename T , typename L >
file_lockable< T, L >::value_type & os::posix::file_lockable< T, L >::impl ( void  ) const

Definition at line 649 of file file.h.

650 {
651 return static_cast<value_type&> (impl_);
652 }

◆ is_opened()

bool os::posix::io::is_opened ( void  )
inlineinherited

Definition at line 458 of file io.h.

459 {
460 return impl ().do_is_opened ();
461 }
virtual bool do_is_opened(void)=0

References os::posix::io_impl::do_is_opened(), and os::posix::io::impl().

◆ isatty()

int os::posix::io::isatty ( void  )
inherited

Definition at line 406 of file io.cpp.

407 {
408 errno = 0;
409
410 // Execute the implementation specific code.
411 return impl ().do_isatty ();
412 }
virtual int do_isatty(void)
Definition io.cpp:532

References os::posix::io_impl::do_isatty(), and os::posix::io::impl().

◆ lseek()

template<typename T , typename L >
off_t os::posix::file_lockable< T, L >::lseek ( off_t  offset,
int  whence 
)
overridevirtual

Reimplemented from os::posix::io.

Definition at line 622 of file file.h.

623 {
624 std::lock_guard<L> lock{ locker_ };
625
626 return file::lseek (offset, whence);
627 }
virtual off_t lseek(off_t offset, int whence)
Definition io.cpp:447

References os::posix::io::lseek().

◆ read()

template<typename T , typename L >
ssize_t os::posix::file_lockable< T, L >::read ( void *  buf,
std::size_t  nbyte 
)
overridevirtual

Reimplemented from os::posix::io.

Definition at line 571 of file file.h.

572 {
573 std::lock_guard<L> lock{ locker_ };
574
575 return file::read (buf, nbyte);
576 }
virtual ssize_t read(void *buf, std::size_t nbyte)
Definition io.cpp:217

References os::posix::io::read().

◆ vfcntl()

template<typename T , typename L >
int os::posix::file_lockable< T, L >::vfcntl ( int  cmd,
std::va_list  args 
)
overridevirtual

Reimplemented from os::posix::io.

Definition at line 598 of file file.h.

599 {
600 std::lock_guard<L> lock{ locker_ };
601
602 return file::vfcntl (cmd, args);
603 }

References os::posix::io::vfcntl().

◆ write()

template<typename T , typename L >
ssize_t os::posix::file_lockable< T, L >::write ( const void *  buf,
std::size_t  nbyte 
)
overridevirtual

Reimplemented from os::posix::io.

Definition at line 580 of file file.h.

581 {
582 std::lock_guard<L> lock{ locker_ };
583
584 return file::write (buf, nbyte);
585 }
virtual ssize_t write(const void *buf, std::size_t nbyte)
Definition io.cpp:268

References os::posix::io::write().

◆ writev()

template<typename T , typename L >
ssize_t os::posix::file_lockable< T, L >::writev ( const iovec iov,
int  iovcnt 
)
overridevirtual

Reimplemented from os::posix::io.

Definition at line 589 of file file.h.

590 {
591 std::lock_guard<L> lock{ locker_ };
592
593 return file::writev (iov, iovcnt);
594 }
virtual ssize_t writev(const iovec *iov, int iovcnt)
Definition io.cpp:321

References os::posix::io::writev().


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