GNU Radio 3.6.5 C++ API

file_meta_source_impl.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2012 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_BLOCKS_FILE_META_SOURCE_IMPL_H
00024 #define INCLUDED_BLOCKS_FILE_META_SOURCE_IMPL_H
00025 
00026 #include <blocks/file_meta_source.h>
00027 #include <gr_tags.h>
00028 #include <gruel/pmt.h>
00029 #include <gruel/thread.h>
00030 
00031 #include <blocks/file_meta_sink.h>
00032 
00033 using namespace pmt;
00034 
00035 namespace gr {
00036   namespace blocks {
00037 
00038     class file_meta_source_impl : public file_meta_source
00039     {
00040     private:
00041       enum meta_state_t {
00042         STATE_INLINE=0,
00043         STATE_DETACHED
00044       };
00045 
00046       size_t d_itemsize;
00047       double d_samp_rate;
00048       pmt_t d_time_stamp;
00049       size_t d_seg_size;
00050       bool d_updated;
00051       bool d_repeat;
00052 
00053       gruel::mutex d_mutex;
00054       FILE *d_new_fp, *d_new_hdr_fp;
00055       FILE *d_fp, *d_hdr_fp;
00056       meta_state_t d_state;
00057 
00058       std::vector<gr_tag_t> d_tags;
00059 
00060     protected:
00061       bool _open(FILE **fp, const char *filename);
00062       bool read_header(pmt_t &hdr, pmt_t &extras);
00063       void parse_header(pmt_t hdr, uint64_t offset,
00064                         std::vector<gr_tag_t> &tags);
00065       void parse_extras(pmt_t extras, uint64_t offset,
00066                         std::vector<gr_tag_t> &tags);
00067 
00068     public:
00069       file_meta_source_impl(const std::string &filename,
00070                             bool repeat=false,
00071                             bool detached_header=false,
00072                             const std::string &hdr_filename="");
00073 
00074       ~file_meta_source_impl();
00075 
00076       bool open(const std::string &filename,
00077                 const std::string &hdr_filename="");
00078       void close();
00079       void do_update();
00080 
00081       int work(int noutput_items,
00082                gr_vector_const_void_star &input_items,
00083                gr_vector_void_star &output_items);
00084     };
00085 
00086   } /* namespace blocks */
00087 } /* namespace gr */
00088 
00089 #endif /* INCLUDED_BLOCKS_FILE_META_SOURCE_IMPL_H */