blob: 3f42d2152ad681b4327225cef3ef67be43ada776 [file] [log] [blame]
Roman Khassrafc3234542015-08-03 16:17:46 +02001/* -*- c++ -*- */
2/* @file
Piotr Krysika6268a52017-08-23 16:02:19 +02003 * @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com>
Roman Khassrafc3234542015-08-03 16:17:46 +02004 * @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>
28#include "message_file_sink_impl.h"
29#include <stdio.h>
30
31namespace gr {
32 namespace gsm {
33
34 message_file_sink::sptr
35 message_file_sink::make(const std::string &filename)
36 {
37 return gnuradio::get_initial_sptr
38 (new message_file_sink_impl(filename));
39 }
40
41 /*
42 * The private constructor
43 */
44 message_file_sink_impl::message_file_sink_impl(const std::string &filename)
45 : gr::block("message_file_sink",
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"));
Vadim Yanitskiya1169202021-05-03 19:00:43 +020051 set_msg_handler(pmt::mp("in"), boost::bind(&message_file_sink_impl::process_message, this, boost::placeholders::_1));
Roman Khassrafc3234542015-08-03 16:17:46 +020052 }
53
54 /*
55 * Our virtual destructor.
56 */
57 message_file_sink_impl::~message_file_sink_impl()
58 {
59 if (d_output_file.is_open())
60 {
61 d_output_file.close();
62 }
63 }
64
65 void message_file_sink_impl::process_message(pmt::pmt_t msg)
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