commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r11501 - in gnuradio/branches/features/msg-passing: co


From: jcorgan
Subject: [Commit-gnuradio] r11501 - in gnuradio/branches/features/msg-passing: config gruel/src/include/gruel gruel/src/lib gruel/src/lib/msg
Date: Sun, 26 Jul 2009 17:34:05 -0600 (MDT)

Author: jcorgan
Date: 2009-07-26 17:34:05 -0600 (Sun, 26 Jul 2009)
New Revision: 11501

Added:
   gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_accepter.h
   
gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_accepter_msgq.h
   gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_queue.h
   gnuradio/branches/features/msg-passing/gruel/src/lib/msg/
   gnuradio/branches/features/msg-passing/gruel/src/lib/msg/Makefile.am
   gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_accepter.cc
   gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_accepter_msgq.cc
   gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_queue.cc
Modified:
   gnuradio/branches/features/msg-passing/config/grc_gruel.m4
   gnuradio/branches/features/msg-passing/gruel/src/include/gruel/Makefile.am
   gnuradio/branches/features/msg-passing/gruel/src/lib/Makefile.am
Log:
Adds basic message classes to libgruel.

General concept copied over from mblock:

 - gruel::msg_accepter
   Abstract class that accepts pmt's via operator()

 - gruel::msg_accepter_msgq
   Concrete class that accepts pmt's and stashes them
   into a queue.

 - gruel::msg_queue
   Thread safe linear queue of pmt's, similar to gr.message_queue,
   with blocking inserts and blocking or non-blocking reads.



Modified: gnuradio/branches/features/msg-passing/config/grc_gruel.m4
===================================================================
--- gnuradio/branches/features/msg-passing/config/grc_gruel.m4  2009-07-26 
20:29:47 UTC (rev 11500)
+++ gnuradio/branches/features/msg-passing/config/grc_gruel.m4  2009-07-26 
23:34:05 UTC (rev 11501)
@@ -43,6 +43,7 @@
        gruel/src/include/gruel/inet.h \
         gruel/src/lib/Makefile \
        gruel/src/lib/pmt/Makefile \
+       gruel/src/lib/msg/Makefile \
        gruel/src/scheme/Makefile \
        gruel/src/scheme/gnuradio/Makefile \
     ])

Modified: 
gnuradio/branches/features/msg-passing/gruel/src/include/gruel/Makefile.am
===================================================================
--- gnuradio/branches/features/msg-passing/gruel/src/include/gruel/Makefile.am  
2009-07-26 20:29:47 UTC (rev 11500)
+++ gnuradio/branches/features/msg-passing/gruel/src/include/gruel/Makefile.am  
2009-07-26 23:34:05 UTC (rev 11501)
@@ -28,6 +28,9 @@
 
 gruelinclude_HEADERS = \
        $(BUILT_SOURCES) \
+       msg_accepter.h \
+       msg_accepter_msgq.h \
+       msg_queue.h \
        pmt.h \
        pmt_pool.h \
        pmt_serial_tags.h \

Added: 
gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_accepter.h
===================================================================
--- 
gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_accepter.h   
                            (rev 0)
+++ 
gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_accepter.h   
    2009-07-26 23:34:05 UTC (rev 11501)
@@ -0,0 +1,42 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_MSG_ACCEPTER_H
+#define INCLUDED_MSG_ACCEPTER_H
+
+#include <gruel/pmt.h>
+
+namespace gruel {
+
+  /*!
+   * \brief Virtual base class that accepts messages
+   */
+  class msg_accepter
+  {
+  public:
+    msg_accepter() {};
+    virtual ~msg_accepter();
+
+    virtual void operator()(pmt::pmt_t msg) = 0;
+  };
+
+} /* namespace gruel */
+
+#endif /* INCLUDED_MSG_ACCEPTER_H */

Added: 
gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_accepter_msgq.h
===================================================================
--- 
gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_accepter_msgq.h
                          (rev 0)
+++ 
gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_accepter_msgq.h
  2009-07-26 23:34:05 UTC (rev 11501)
@@ -0,0 +1,48 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_MSG_ACCEPTER_MSGQ_H
+#define INCLUDED_MSG_ACCEPTER_MSGQ_H
+
+#include <gruel/msg_accepter.h>
+#include <gruel/msg_queue.h>
+
+namespace gruel {
+
+  /*!
+   * \brief Concrete class that accepts messages and inserts them into a 
message queue.
+   */
+  class msg_accepter_msgq : public msg_accepter 
+  {
+    msg_queue_sptr d_msgq;
+    
+  public:
+    msg_accepter_msgq(msg_queue_sptr msgq);
+    ~msg_accepter_msgq();
+
+    void operator()(pmt::pmt_t msg);
+
+    msg_queue_sptr msgq() const { return d_msgq; }
+  };
+
+} /* namespace gruel */
+
+#endif /* INCLUDED_MSG_ACCEPTER_MSGQ_H */

Added: 
gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_queue.h
===================================================================
--- gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_queue.h  
                        (rev 0)
+++ gnuradio/branches/features/msg-passing/gruel/src/include/gruel/msg_queue.h  
2009-07-26 23:34:05 UTC (rev 11501)
@@ -0,0 +1,90 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef INCLUDED_MSG_QUEUE_H
+#define INCLUDED_MSG_QUEUE_H
+
+#include <gruel/thread.h>
+#include <gruel/pmt.h>
+#include <deque>
+
+namespace gruel {
+
+  class msg_queue;
+  typedef boost::shared_ptr<msg_queue> msg_queue_sptr;
+
+  msg_queue_sptr make_msg_queue(unsigned int limit=0);
+
+  /*!
+   * \brief thread-safe message queue
+   */
+  class msg_queue {
+
+    gruel::mutex              d_mutex;
+    gruel::condition_variable d_not_empty;
+    gruel::condition_variable d_not_full;
+    unsigned int             d_limit;    // max # of messages in queue.  0 -> 
unbounded
+
+    std::deque<pmt::pmt_t>    d_msgs;
+
+  public:
+    msg_queue(unsigned int limit);
+    ~msg_queue();
+
+    /*!
+     * \brief Insert message at tail of queue.
+     * \param msg message
+     *
+     * Block if queue if full.
+     */
+    void insert_tail(pmt::pmt_t msg);
+
+    /*!
+     * \brief Delete message from head of queue and return it.
+     * Block if no message is available.
+     */
+    pmt::pmt_t delete_head();
+    
+    /*!
+     * \brief If there's a message in the q, delete it and return it.
+     * If no message is available, return pmt_t().
+     */
+    pmt::pmt_t delete_head_nowait();
+    
+    //! Delete all messages from the queue
+    void flush();
+
+    //! is the queue empty?
+    bool empty_p() const { return d_msgs.empty(); }
+  
+    //! is the queue full?
+    bool full_p() const { return d_limit != 0 && count() >= d_limit; }
+  
+    //! return number of messages in queue
+    unsigned int count() const { return d_msgs.size(); }
+
+    //! return limit on number of message in queue.  0 -> unbounded
+    unsigned int limit() const { return d_limit; }
+  };
+
+} /* namespace gruel */
+
+#endif /* INCLUDED_MSG_QUEUE_H */

Modified: gnuradio/branches/features/msg-passing/gruel/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/features/msg-passing/gruel/src/lib/Makefile.am    
2009-07-26 20:29:47 UTC (rev 11500)
+++ gnuradio/branches/features/msg-passing/gruel/src/lib/Makefile.am    
2009-07-26 23:34:05 UTC (rev 11501)
@@ -21,7 +21,7 @@
 
 include $(top_srcdir)/Makefile.common
 
-SUBDIRS = pmt
+SUBDIRS = pmt msg
 
 AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) 
$(GRUEL_INCLUDES) $(WITH_INCLUDES)
 
@@ -33,6 +33,7 @@
 # ----------------------------------------------------------------
 
 PMT_LIB = pmt/libpmt.la
+MSG_LIB = msg/libmsg.la
 
 # These are the source files that go into the gruel shared library
 libgruel_la_SOURCES =                  \
@@ -44,6 +45,5 @@
 libgruel_la_LIBADD =                   \
        $(BOOST_THREAD_LIB)             \
        $(PMT_LIB)                      \
+       $(MSG_LIB)                      \
        -lstdc++
-
-


Property changes on: gnuradio/branches/features/msg-passing/gruel/src/lib/msg
___________________________________________________________________
Added: svn:ignore
   + Makefile
Makefile.in
.deps
.libs


Added: gnuradio/branches/features/msg-passing/gruel/src/lib/msg/Makefile.am
===================================================================
--- gnuradio/branches/features/msg-passing/gruel/src/lib/msg/Makefile.am        
                        (rev 0)
+++ gnuradio/branches/features/msg-passing/gruel/src/lib/msg/Makefile.am        
2009-07-26 23:34:05 UTC (rev 11501)
@@ -0,0 +1,32 @@
+#
+# Copyright 2009 Free Software Foundation, Inc.
+# 
+# This file is part of GNU Radio
+# 
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+# 
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+
+include $(top_srcdir)/Makefile.common
+
+AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(GRUEL_INCLUDES) $(WITH_INCLUDES)
+
+noinst_LTLIBRARIES = libmsg.la
+
+libmsg_la_SOURCES = \
+       msg_accepter.cc \
+       msg_accepter_msgq.cc \
+       msg_queue.cc
+

Added: gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_accepter.cc
===================================================================
--- gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_accepter.cc    
                        (rev 0)
+++ gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_accepter.cc    
2009-07-26 23:34:05 UTC (rev 11501)
@@ -0,0 +1,36 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gruel/msg_accepter.h>
+
+namespace gruel {
+
+  msg_accepter::~msg_accepter()
+  {
+    // NOP, required as virtual destructor
+  }
+
+} /* namespace gruel */

Added: 
gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_accepter_msgq.cc
===================================================================
--- 
gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_accepter_msgq.cc   
                            (rev 0)
+++ 
gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_accepter_msgq.cc   
    2009-07-26 23:34:05 UTC (rev 11501)
@@ -0,0 +1,48 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gruel/msg_accepter_msgq.h>
+
+using namespace pmt;
+
+namespace gruel {
+
+  msg_accepter_msgq::msg_accepter_msgq(msg_queue_sptr msgq)
+    : d_msgq(msgq)
+  {
+  }
+
+  msg_accepter_msgq::~msg_accepter_msgq()
+  {
+    // NOP, required as virtual destructor
+  }
+
+  void
+  msg_accepter_msgq::operator()(pmt_t msg)
+  {
+    d_msgq->insert_tail(msg);
+  }
+
+} /* namespace gruel */

Added: gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_queue.cc
===================================================================
--- gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_queue.cc       
                        (rev 0)
+++ gnuradio/branches/features/msg-passing/gruel/src/lib/msg/msg_queue.cc       
2009-07-26 23:34:05 UTC (rev 11501)
@@ -0,0 +1,98 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gruel/msg_queue.h>
+#include <stdexcept>
+
+using namespace pmt;
+
+namespace gruel {
+
+  msg_queue_sptr
+  make_msg_queue(unsigned int limit)
+  {
+    return msg_queue_sptr(new msg_queue(limit));
+  }
+  
+  msg_queue::msg_queue(unsigned int limit)
+    : d_limit(limit)
+  {
+  }
+  
+  msg_queue::~msg_queue()
+  {
+    flush();
+  }
+
+  void
+  msg_queue::insert_tail(pmt_t msg)
+  {
+    gruel::scoped_lock guard(d_mutex);
+
+    while (full_p())
+      d_not_full.wait(guard);
+
+    d_msgs.push_back(msg);
+    d_not_empty.notify_one();
+  }
+
+  pmt_t
+  msg_queue::delete_head()
+  {
+    gruel::scoped_lock guard(d_mutex);
+
+    while (empty_p())
+      d_not_empty.wait(guard);
+
+    pmt_t m(d_msgs.front());
+    d_msgs.pop_front();
+    d_not_full.notify_one();
+    return m;
+  }
+
+  pmt_t
+  msg_queue::delete_head_nowait()
+  {
+    gruel::scoped_lock guard(d_mutex);
+
+    if (empty_p())
+      return pmt_t();
+       
+    pmt_t m(d_msgs.front());
+    d_msgs.pop_front();
+    d_not_full.notify_one();
+
+    return m;
+  }
+
+  void
+  msg_queue::flush()
+  {
+    while (delete_head_nowait() != pmt_t())
+      ;
+  }
+
+} /* namespace gruel */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]