From f2bf6fbb5617f0d26654821fb1eb30bc2a1c16a2 Mon Sep 17 00:00:00 2001
From: Martin Braun <martin.braun@kit.edu>
Date: Mon, 7 Jan 2013 15:54:56 +0100
Subject: core: added operator == for tags

---
 gnuradio-core/src/lib/runtime/gr_tags.h | 5 +++++
 1 file changed, 5 insertions(+)

(limited to 'gnuradio-core/src')

diff --git a/gnuradio-core/src/lib/runtime/gr_tags.h b/gnuradio-core/src/lib/runtime/gr_tags.h
index 8bffcd0fe5..a9ca902352 100644
--- a/gnuradio-core/src/lib/runtime/gr_tags.h
+++ b/gnuradio-core/src/lib/runtime/gr_tags.h
@@ -45,6 +45,11 @@ struct GR_CORE_API gr_tag_t{
     ){
         return x.offset < y.offset;
     }
+
+    inline bool operator == (const gr_tag_t &t) const
+    {
+      return (t.key == key) && (t.value == value) && (t.srcid == srcid) && (t.offset == offset);
+    }
 };
 
 #endif /*INCLUDED_GR_TAGS_H*/
-- 
cgit v1.2.3


From f676197e6dd2a638f294e350654e32d3ffc45af8 Mon Sep 17 00:00:00 2001
From: Martin Braun <martin.braun@kit.edu>
Date: Mon, 7 Jan 2013 17:10:20 +0100
Subject: core: added remove_tag_item()

---
 gnuradio-core/src/lib/runtime/gr_block.cc        |  7 +++++
 gnuradio-core/src/lib/runtime/gr_block.h         | 36 ++++++++++++++++++++++++
 gnuradio-core/src/lib/runtime/gr_block_detail.cc | 12 ++++++++
 gnuradio-core/src/lib/runtime/gr_block_detail.h  | 13 +++++++--
 gnuradio-core/src/lib/runtime/gr_buffer.cc       | 12 ++++++++
 gnuradio-core/src/lib/runtime/gr_buffer.h        |  9 ++++++
 6 files changed, 87 insertions(+), 2 deletions(-)

(limited to 'gnuradio-core/src')

diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc
index 43aebf0bfd..5ba30955f9 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.cc
+++ b/gnuradio-core/src/lib/runtime/gr_block.cc
@@ -186,6 +186,13 @@ gr_block::add_item_tag(unsigned int which_output,
   d_detail->add_item_tag(which_output, tag);
 }
 
+void
+gr_block::remove_item_tag(unsigned int which_input,
+		       const gr_tag_t &tag)
+{
+  d_detail->remove_item_tag(which_input, tag);
+}
+
 void
 gr_block::get_tags_in_range(std::vector<gr_tag_t> &v,
 			    unsigned int which_output,
diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h
index 57e3fda90a..7a70bdaf09 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.h
+++ b/gnuradio-core/src/lib/runtime/gr_block.h
@@ -415,6 +415,42 @@ class GR_CORE_API gr_block : public gr_basic_block {
    */
   void add_item_tag(unsigned int which_output, const gr_tag_t &tag);
 
+  /*!
+   * \brief  Removes a tag from the given input buffer.
+   *
+   * \param which_input an integer of which input stream to remove the tag from
+   * \param abs_offset   a uint64 number of the absolute item number
+   *                     assicated with the tag. Can get from nitems_written.
+   * \param key          the tag key as a PMT symbol
+   * \param value        any PMT holding any value for the given key
+   * \param srcid        optional source ID specifier; defaults to PMT_F
+   *
+   * If no such tag is found, does nothing.
+   */
+  inline void remove_item_tag(unsigned int which_input,
+		    uint64_t abs_offset,
+		    const pmt::pmt_t &key,
+		    const pmt::pmt_t &value,
+		    const pmt::pmt_t &srcid=pmt::PMT_F)
+  {
+      gr_tag_t tag;
+      tag.offset = abs_offset;
+      tag.key = key;
+      tag.value = value;
+      tag.srcid = srcid;
+      this->remove_item_tag(which_input, tag);
+  }
+
+ /*!
+   * \brief  Removes a tag from the given input buffer.
+   *
+   * If no such tag is found, does nothing.
+   *
+   * \param which_input an integer of which input stream to remove the tag from
+   * \param tag the tag object to remove
+   */
+  void remove_item_tag(unsigned int which_input, const gr_tag_t &tag);
+
   /*!
    * \brief Given a [start,end), returns a vector of all tags in the range.
    *
diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.cc b/gnuradio-core/src/lib/runtime/gr_block_detail.cc
index 337c9518ef..c65493473c 100644
--- a/gnuradio-core/src/lib/runtime/gr_block_detail.cc
+++ b/gnuradio-core/src/lib/runtime/gr_block_detail.cc
@@ -155,6 +155,18 @@ gr_block_detail::add_item_tag(unsigned int which_output, const gr_tag_t &tag)
   }
 }
 
+void
+gr_block_detail::remove_item_tag(unsigned int which_input, const gr_tag_t &tag)
+{
+  if(!pmt_is_symbol(tag.key)) {
+    throw pmt_wrong_type("gr_block_detail::add_item_tag key", tag.key);
+  }
+  else {
+    // Add tag to gr_buffer's deque tags
+    d_input[which_input]->buffer()->remove_item_tag(tag);
+  }
+}
+
 void
 gr_block_detail::get_tags_in_range(std::vector<gr_tag_t> &v,
 				   unsigned int which_input,
diff --git a/gnuradio-core/src/lib/runtime/gr_block_detail.h b/gnuradio-core/src/lib/runtime/gr_block_detail.h
index 16d9f4d42e..af00ea7c79 100644
--- a/gnuradio-core/src/lib/runtime/gr_block_detail.h
+++ b/gnuradio-core/src/lib/runtime/gr_block_detail.h
@@ -95,8 +95,7 @@ class GR_CORE_API gr_block_detail {
   /*!
    * \brief  Adds a new tag to the given output stream.
    *
-   * This takes the input parameters and builds a PMT tuple
-   * from it. It then calls gr_buffer::add_item_tag(pmt::pmt_t t),
+   * Calls gr_buffer::add_item_tag(),
    * which appends the tag onto its deque.
    *
    * \param which_output  an integer of which output stream to attach the tag
@@ -104,6 +103,16 @@ class GR_CORE_API gr_block_detail {
    */
   void add_item_tag(unsigned int which_output, const gr_tag_t &tag);
 
+  /*!
+   * \brief  Removes a tag from the given input stream.
+   *
+   * Calls gr_buffer::remove_item_tag(), which removes the tag from its deque.
+   *
+   * \param which_input  an integer of which input stream to remove the tag from
+   * \param tag the tag object to add
+   */
+  void remove_item_tag(unsigned int which_input, const gr_tag_t &tag);
+
   /*!
    * \brief Given a [start,end), returns a vector of all tags in the range.
    *
diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc
index b923ca57a6..369959d65f 100644
--- a/gnuradio-core/src/lib/runtime/gr_buffer.cc
+++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc
@@ -233,6 +233,18 @@ gr_buffer::add_item_tag(const gr_tag_t &tag)
   d_item_tags.push_back(tag);
 }
 
+void
+gr_buffer::remove_item_tag(const gr_tag_t &tag)
+{
+  gruel::scoped_lock guard(*mutex());
+  for (std::deque<gr_tag_t>::iterator it = d_item_tags.begin(); it != d_item_tags.end(); ++it) {
+    if (*it == tag) {
+      d_item_tags.erase(it);
+      break;
+    }
+  }
+}
+
 void
 gr_buffer::prune_tags(uint64_t max_time)
 {
diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h
index 67d48fb2dd..28ea977269 100644
--- a/gnuradio-core/src/lib/runtime/gr_buffer.h
+++ b/gnuradio-core/src/lib/runtime/gr_buffer.h
@@ -102,6 +102,15 @@ class GR_CORE_API gr_buffer {
    */
   void add_item_tag(const gr_tag_t &tag);
 
+  /*!
+   * \brief  Removes an existing tag from the buffer.
+   *
+   * If no such tag is found, does nothing.
+   *
+   * \param tag        the tag that needs to be removed
+   */
+  void remove_item_tag(const gr_tag_t &tag);
+
   /*!
    * \brief  Removes all tags before \p max_time from buffer
    *
-- 
cgit v1.2.3