GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
file_source.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012, 2018 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_BLOCKS_FILE_SOURCE_H
12 #define INCLUDED_BLOCKS_FILE_SOURCE_H
13 
14 #include <gnuradio/blocks/api.h>
15 #include <gnuradio/sync_block.h>
16 
17 namespace gr {
18 namespace blocks {
19 
20 /*!
21  * \brief Read stream from file
22  * \ingroup file_operators_blk
23  */
24 class BLOCKS_API file_source : virtual public sync_block
25 {
26 public:
27  // gr::blocks::file_source::sptr
28  typedef std::shared_ptr<file_source> sptr;
29 
30  /*!
31  * \brief Create a file source.
32  *
33  * Opens \p filename as a source of items into a flowgraph. The
34  * data is expected to be in binary format, item after item. The
35  * \p itemsize of the block determines the conversion from bits
36  * to items. The first \p offset items (default 0) will be
37  * skipped.
38  *
39  * If \p repeat is turned on, the file will repeat the file after
40  * it's reached the end.
41  *
42  * If \p len is non-zero, only items (offset, offset+len) will
43  * be produced.
44  *
45  * \param itemsize the size of each item in the file, in bytes
46  * \param filename name of the file to source from
47  * \param repeat repeat file from start
48  * \param offset begin this many items into file
49  * \param len produce only items (offset, offset+len)
50  */
51  static sptr make(size_t itemsize,
52  const char* filename,
53  bool repeat = false,
54  uint64_t offset = 0,
55  uint64_t len = 0);
56 
57  /*!
58  * \brief seek file to \p seek_point relative to \p whence
59  *
60  * \param seek_point sample offset in file
61  * \param whence one of SEEK_SET, SEEK_CUR, SEEK_END (man fseek)
62  */
63  virtual bool seek(int64_t seek_point, int whence) = 0;
64 
65  /*!
66  * \brief Opens a new file.
67  *
68  * \param filename name of the file to source from
69  * \param repeat repeat file from start
70  * \param offset begin this many items into file
71  * \param len produce only items [offset, offset+len)
72  */
73  virtual void
74  open(const char* filename, bool repeat, uint64_t offset = 0, uint64_t len = 0) = 0;
75 
76  /*!
77  * \brief Close the file handle.
78  */
79  virtual void close() = 0;
80 
81  /*!
82  * \brief Add a stream tag to the first sample of the file if true
83  */
84  virtual void set_begin_tag(pmt::pmt_t val) = 0;
85 };
86 
87 } /* namespace blocks */
88 } /* namespace gr */
89 
90 #endif /* INCLUDED_BLOCKS_FILE_SOURCE_H */
Read stream from file.
Definition: file_source.h:25
virtual bool seek(int64_t seek_point, int whence)=0
seek file to seek_point relative to whence
virtual void close()=0
Close the file handle.
virtual void open(const char *filename, bool repeat, uint64_t offset=0, uint64_t len=0)=0
Opens a new file.
static sptr make(size_t itemsize, const char *filename, bool repeat=false, uint64_t offset=0, uint64_t len=0)
Create a file source.
std::shared_ptr< file_source > sptr
Definition: file_source.h:28
virtual void set_begin_tag(pmt::pmt_t val)=0
Add a stream tag to the first sample of the file if true.
repeat each input repeat times
Definition: repeat.h:30
synchronous 1:1 input to output with history
Definition: sync_block.h:26
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:18
GR_RUNTIME_API size_t itemsize(types::vector_type type)
GNU Radio logging wrapper.
Definition: basic_block.h:29
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:83