SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Public Attributes | Private Attributes | List of all members
leansdr::file_reader< T > Struct Template Reference

#include <generic.h>

+ Inheritance diagram for leansdr::file_reader< T >:
+ Collaboration diagram for leansdr::file_reader< T >:

Public Member Functions

 file_reader (scheduler *sch, int _fdin, pipebuf< T > &_out)
 
void run ()
 
void set_realtime (T &_filler)
 
- Public Member Functions inherited from leansdr::runnable
 runnable (scheduler *_sch, const char *name)
 
- Public Member Functions inherited from leansdr::runnable_common
 runnable_common (const char *_name)
 
virtual ~runnable_common ()
 
virtual void shutdown ()
 

Public Attributes

bool loop
 
- Public Attributes inherited from leansdr::runnable_common
const char * name
 

Private Attributes

T * filler
 
int fdin
 
pipewriter< T > out
 

Additional Inherited Members

- Protected Attributes inherited from leansdr::runnable
schedulersch
 

Detailed Description

template<typename T>
struct leansdr::file_reader< T >

Definition at line 44 of file generic.h.

Constructor & Destructor Documentation

◆ file_reader()

template<typename T >
leansdr::file_reader< T >::file_reader ( scheduler sch,
int  _fdin,
pipebuf< T > &  _out 
)
inline

Definition at line 46 of file generic.h.

47  : runnable(sch, _out.name),
48  loop(false),
49  filler(NULL),
50  fdin(_fdin), out(_out)
51  {
52  }
runnable(scheduler *_sch, const char *name)
Definition: framework.h:193
scheduler * sch
Definition: framework.h:199
pipewriter< T > out
Definition: generic.h:113

Member Function Documentation

◆ run()

template<typename T >
void leansdr::file_reader< T >::run ( )
inlinevirtual

Reimplemented from leansdr::runnable_common.

Definition at line 53 of file generic.h.

References leansdr::scheduler::debug, leansdr::fatal(), leansdr::file_reader< T >::fdin, leansdr::file_reader< T >::filler, leansdr::file_reader< T >::loop, leansdr::runnable_common::name, leansdr::file_reader< T >::out, and leansdr::runnable::sch.

54  {
55  size_t size = out.writable() * sizeof(T);
56  if (!size)
57  return;
58 
59  again:
60  ssize_t nr = read(fdin, out.wr(), size);
61  if (nr < 0 && errno == EWOULDBLOCK)
62  {
63  if (filler)
64  {
65  if (sch->debug)
66  fprintf(stderr, "U");
67  out.write(*filler);
68  }
69  return;
70  }
71  if (nr < 0)
72  fatal("read(file_reader)");
73  if (!nr)
74  {
75  if (!loop)
76  return;
77  if (sch->debug)
78  fprintf(stderr, "%s looping\n", name);
79  off_t res = lseek(fdin, 0, SEEK_SET);
80  if (res == (off_t)-1)
81  fatal("lseek");
82  goto again;
83  }
84 
85  // Always stop at element boundary (may block)
86  size_t partial = nr % sizeof(T);
87  size_t remain = partial ? sizeof(T) - partial : 0;
88  while (remain)
89  {
90  if (sch->debug)
91  fprintf(stderr, "+");
92  ssize_t nr2 = read(fdin, (char *)out.wr() + nr, remain);
93  if (nr2 <= 0)
94  fatal("partial read");
95  nr += nr2;
96  remain -= nr2;
97  }
98 
99  out.written(nr / sizeof(T));
100  }
void fatal(const char *s)
Definition: framework.cpp:6
scheduler * sch
Definition: framework.h:199
pipewriter< T > out
Definition: generic.h:113
+ Here is the call graph for this function:

◆ set_realtime()

template<typename T >
void leansdr::file_reader< T >::set_realtime ( T &  _filler)
inline

Definition at line 102 of file generic.h.

References leansdr::fatal(), leansdr::file_reader< T >::fdin, and leansdr::file_reader< T >::filler.

103  {
104  int flags = fcntl(fdin, F_GETFL);
105  if (fcntl(fdin, F_SETFL, flags | O_NONBLOCK))
106  fatal("fcntl");
107  filler = new T(_filler);
108  }
void fatal(const char *s)
Definition: framework.cpp:6
+ Here is the call graph for this function:

Member Data Documentation

◆ fdin

template<typename T >
int leansdr::file_reader< T >::fdin
private

◆ filler

template<typename T >
T* leansdr::file_reader< T >::filler
private

◆ loop

template<typename T >
bool leansdr::file_reader< T >::loop

Definition at line 101 of file generic.h.

Referenced by leansdr::file_reader< T >::run().

◆ out

template<typename T >
pipewriter<T> leansdr::file_reader< T >::out
private

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