summaryrefslogtreecommitdiff
path: root/gruel/src
diff options
context:
space:
mode:
Diffstat (limited to 'gruel/src')
-rw-r--r--gruel/src/include/gruel/msg_accepter.h3
-rw-r--r--gruel/src/include/gruel/pmt.h19
-rw-r--r--gruel/src/lib/pmt/pmt.cc33
-rw-r--r--gruel/src/lib/pmt/qa_pmt_prims.cc31
-rw-r--r--gruel/src/lib/pmt/qa_pmt_prims.h2
5 files changed, 87 insertions, 1 deletions
diff --git a/gruel/src/include/gruel/msg_accepter.h b/gruel/src/include/gruel/msg_accepter.h
index 3afd6dde0..70ac846f5 100644
--- a/gruel/src/include/gruel/msg_accepter.h
+++ b/gruel/src/include/gruel/msg_accepter.h
@@ -22,6 +22,7 @@
#define INCLUDED_GRUEL_MSG_ACCEPTER_H
#include <gruel/pmt.h>
+#include <boost/shared_ptr.hpp>
namespace gruel {
@@ -44,6 +45,8 @@ namespace gruel {
virtual void post(pmt::pmt_t msg) = 0;
};
+ typedef boost::shared_ptr<msg_accepter> msg_accepter_sptr;
+
} /* namespace gruel */
#endif /* INCLUDED_GRUEL_MSG_ACCEPTER_H */
diff --git a/gruel/src/include/gruel/pmt.h b/gruel/src/include/gruel/pmt.h
index 240359301..b1cb29f7c 100644
--- a/gruel/src/include/gruel/pmt.h
+++ b/gruel/src/include/gruel/pmt.h
@@ -24,6 +24,7 @@
#define INCLUDED_PMT_H
#include <boost/intrusive_ptr.hpp>
+#include <boost/shared_ptr.hpp>
#include <boost/any.hpp>
#include <complex>
#include <string>
@@ -31,6 +32,10 @@
#include <iosfwd>
#include <stdexcept>
+namespace gruel {
+ class msg_accepter;
+};
+
/*!
* This file defines a polymorphic type and the operations on it.
*
@@ -484,6 +489,20 @@ void pmt_any_set(pmt_t obj, const boost::any &any);
/*
* ------------------------------------------------------------------------
+ * msg_accepter -- pmt representation of gruel::msg_accepter
+ * ------------------------------------------------------------------------
+ */
+//! Return true if \p obj is a msg_accepter
+bool pmt_is_msg_accepter(const pmt_t &obj);
+
+//! make a msg_accepter
+pmt_t pmt_make_msg_accepter(boost::shared_ptr<gruel::msg_accepter> ma);
+
+//! Return underlying msg_accepter
+boost::shared_ptr<gruel::msg_accepter> pmt_msg_accepter_ref(const pmt_t &obj);
+
+/*
+ * ------------------------------------------------------------------------
* General functions
* ------------------------------------------------------------------------
*/
diff --git a/gruel/src/lib/pmt/pmt.cc b/gruel/src/lib/pmt/pmt.cc
index f0e3c30a2..5301529b2 100644
--- a/gruel/src/lib/pmt/pmt.cc
+++ b/gruel/src/lib/pmt/pmt.cc
@@ -26,8 +26,9 @@
#include <vector>
#include <gruel/pmt.h>
#include "pmt_int.h"
-#include <stdio.h>
+#include <gruel/msg_accepter.h>
#include <gruel/pmt_pool.h>
+#include <stdio.h>
#include <string.h>
namespace pmt {
@@ -882,6 +883,36 @@ pmt_any_set(pmt_t obj, const boost::any &any)
}
////////////////////////////////////////////////////////////////////////////
+// msg_accepter -- built from "any"
+////////////////////////////////////////////////////////////////////////////
+
+bool
+pmt_is_msg_accepter(const pmt_t &obj)
+{
+ if (!pmt_is_any(obj))
+ return false;
+
+ boost::any r = pmt_any_ref(obj);
+ return boost::any_cast<gruel::msg_accepter_sptr>(&r) != 0;
+}
+
+//! make a msg_accepter
+pmt_t
+pmt_make_msg_accepter(gruel::msg_accepter_sptr ma)
+{
+ return pmt_make_any(ma);
+}
+
+//! Return underlying msg_accepter
+gruel::msg_accepter_sptr
+pmt_msg_accepter_ref(const pmt_t &obj)
+{
+ return boost::any_cast<gruel::msg_accepter_sptr>(pmt_any_ref(obj));
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////
// General Functions
////////////////////////////////////////////////////////////////////////////
diff --git a/gruel/src/lib/pmt/qa_pmt_prims.cc b/gruel/src/lib/pmt/qa_pmt_prims.cc
index 899674bbb..2c66b8fdb 100644
--- a/gruel/src/lib/pmt/qa_pmt_prims.cc
+++ b/gruel/src/lib/pmt/qa_pmt_prims.cc
@@ -23,6 +23,7 @@
#include <qa_pmt_prims.h>
#include <cppunit/TestAssert.h>
#include <gruel/pmt.h>
+#include <gruel/msg_accepter.h>
#include <stdio.h>
#include <sstream>
@@ -453,6 +454,36 @@ qa_pmt_prims::test_any()
// ------------------------------------------------------------------------
+class qa_pmt_msg_accepter_nop : public gruel::msg_accepter {
+public:
+ qa_pmt_msg_accepter_nop();
+ ~qa_pmt_msg_accepter_nop();
+ void post(pmt_t) { };
+};
+
+qa_pmt_msg_accepter_nop::~qa_pmt_msg_accepter_nop(){}
+
+void
+qa_pmt_prims::test_msg_accepter()
+{
+ pmt_t sym = pmt_intern("my-symbol");
+
+ boost::any a0;
+ a0 = std::string("Hello!");
+ pmt_t p0 = pmt_make_any(a0);
+
+ gruel::msg_accepter_sptr ma0 = gruel::msg_accepter_sptr(new qa_pmt_msg_accepter_nop());
+ pmt_t p1 = pmt_make_msg_accepter(ma0);
+
+ CPPUNIT_ASSERT_EQUAL(ma0.get(), pmt_msg_accepter_ref(p1).get());
+
+ CPPUNIT_ASSERT_THROW(pmt_msg_accepter_ref(sym), pmt_wrong_type);
+ CPPUNIT_ASSERT_THROW(pmt_msg_accepter_ref(p0), pmt_wrong_type); // FIXME
+
+}
+
+// ------------------------------------------------------------------------
+
void
qa_pmt_prims::test_serialize()
{
diff --git a/gruel/src/lib/pmt/qa_pmt_prims.h b/gruel/src/lib/pmt/qa_pmt_prims.h
index 2fe473c43..fd6f70c8e 100644
--- a/gruel/src/lib/pmt/qa_pmt_prims.h
+++ b/gruel/src/lib/pmt/qa_pmt_prims.h
@@ -40,6 +40,7 @@ class qa_pmt_prims : public CppUnit::TestCase {
CPPUNIT_TEST(test_misc);
CPPUNIT_TEST(test_dict);
CPPUNIT_TEST(test_any);
+ CPPUNIT_TEST(test_msg_accepter);
CPPUNIT_TEST(test_io);
CPPUNIT_TEST(test_lists);
CPPUNIT_TEST(test_serialize);
@@ -59,6 +60,7 @@ class qa_pmt_prims : public CppUnit::TestCase {
void test_misc();
void test_dict();
void test_any();
+ void test_msg_accepter();
void test_io();
void test_lists();
void test_serialize();