Roman Khassraf | cd5a48b | 2015-05-28 19:23:55 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* @file |
| 3 | * @author Roman Khassraf <rkhassraf@gmail.com> |
| 4 | * @section LICENSE |
| 5 | * |
| 6 | * Gr-gsm is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * Gr-gsm is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with gr-gsm; see the file COPYING. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H |
| 24 | #include "config.h" |
| 25 | #endif |
| 26 | |
| 27 | #include <gnuradio/io_signature.h> |
Roman Khassraf | 1c3419e | 2015-08-03 10:58:57 +0200 | [diff] [blame] | 28 | #include "burst_file_sink_impl.h" |
Roman Khassraf | cd5a48b | 2015-05-28 19:23:55 +0200 | [diff] [blame] | 29 | #include "stdio.h" |
| 30 | |
| 31 | namespace gr { |
| 32 | namespace gsm { |
| 33 | |
Roman Khassraf | 1c3419e | 2015-08-03 10:58:57 +0200 | [diff] [blame] | 34 | burst_file_sink::sptr |
| 35 | burst_file_sink::make(const std::string &filename) |
Roman Khassraf | cd5a48b | 2015-05-28 19:23:55 +0200 | [diff] [blame] | 36 | { |
| 37 | return gnuradio::get_initial_sptr |
Roman Khassraf | 1c3419e | 2015-08-03 10:58:57 +0200 | [diff] [blame] | 38 | (new burst_file_sink_impl(filename)); |
Roman Khassraf | cd5a48b | 2015-05-28 19:23:55 +0200 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /* |
| 42 | * The private constructor |
| 43 | */ |
Roman Khassraf | 1c3419e | 2015-08-03 10:58:57 +0200 | [diff] [blame] | 44 | burst_file_sink_impl::burst_file_sink_impl(const std::string &filename) |
| 45 | : gr::block("burst_file_sink", |
Roman Khassraf | cd5a48b | 2015-05-28 19:23:55 +0200 | [diff] [blame] | 46 | gr::io_signature::make(0, 0, 0), |
| 47 | gr::io_signature::make(0, 0, 0)), |
| 48 | d_output_file(filename.c_str(), std::ofstream::binary) |
| 49 | { |
| 50 | message_port_register_in(pmt::mp("in")); |
Roman Khassraf | 1c3419e | 2015-08-03 10:58:57 +0200 | [diff] [blame] | 51 | set_msg_handler(pmt::mp("in"), boost::bind(&burst_file_sink_impl::process_burst, this, _1)); |
Roman Khassraf | cd5a48b | 2015-05-28 19:23:55 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /* |
| 55 | * Our virtual destructor. |
| 56 | */ |
Roman Khassraf | 1c3419e | 2015-08-03 10:58:57 +0200 | [diff] [blame] | 57 | burst_file_sink_impl::~burst_file_sink_impl() |
Roman Khassraf | cd5a48b | 2015-05-28 19:23:55 +0200 | [diff] [blame] | 58 | { |
| 59 | if (d_output_file.is_open()) |
| 60 | { |
| 61 | d_output_file.close(); |
| 62 | } |
| 63 | } |
| 64 | |
Roman Khassraf | 1c3419e | 2015-08-03 10:58:57 +0200 | [diff] [blame] | 65 | void burst_file_sink_impl::process_burst(pmt::pmt_t msg) |
Roman Khassraf | cd5a48b | 2015-05-28 19:23:55 +0200 | [diff] [blame] | 66 | { |
| 67 | std::string s = pmt::serialize_str(msg); |
| 68 | const char *serialized = s.data(); |
| 69 | d_output_file.write(serialized, s.length()); |
| 70 | } |
| 71 | } /* namespace gsm */ |
| 72 | } /* namespace gr */ |
| 73 | |