1 /* -*- c++ -*- */
2 /*
3  * Copyright 2013 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include "pdu_remove_impl.h"
28 #include <gnuradio/blocks/pdu.h>
29 #include <gnuradio/io_signature.h>
30 
31 namespace gr {
32 namespace blocks {
33 
make(pmt::pmt_t k)34 pdu_remove::sptr pdu_remove::make(pmt::pmt_t k)
35 {
36     return gnuradio::get_initial_sptr(new pdu_remove_impl(k));
37 }
38 
pdu_remove_impl(pmt::pmt_t k)39 pdu_remove_impl::pdu_remove_impl(pmt::pmt_t k)
40     : block("pdu_remove", io_signature::make(0, 0, 0), io_signature::make(0, 0, 0)),
41       d_k(k)
42 {
43     message_port_register_out(pdu::pdu_port_id());
44     message_port_register_in(pdu::pdu_port_id());
45     set_msg_handler(pdu::pdu_port_id(),
46                     [this](pmt::pmt_t msg) { this->handle_msg(msg); });
47 }
48 
handle_msg(pmt::pmt_t pdu)49 void pdu_remove_impl::handle_msg(pmt::pmt_t pdu)
50 {
51     // add the field and publish
52     pmt::pmt_t meta = pmt::car(pdu);
53     if (pmt::is_null(meta)) {
54         meta = pmt::make_dict();
55     } else if (!pmt::is_dict(meta)) {
56         throw std::runtime_error("pdu_remove received non PDU input");
57     }
58     meta = pmt::dict_delete(meta, d_k);
59     message_port_pub(pdu::pdu_port_id(), pmt::cons(meta, pmt::cdr(pdu)));
60 }
61 
62 } /* namespace blocks */
63 } /* namespace gr */
64