summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src/lib')
-rw-r--r--gnuradio-core/src/lib/CMakeLists.txt31
-rw-r--r--gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc24
-rw-r--r--gnuradio-core/src/lib/gengen/gr_vector_sink_X.cc.t11
-rw-r--r--gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t2
-rw-r--r--gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t1
-rw-r--r--gnuradio-core/src/lib/gengen/gr_vector_source_X.cc.t67
-rw-r--r--gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t11
-rw-r--r--gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t6
-rw-r--r--gnuradio-core/src/lib/gnuradio-core.rc.in55
-rw-r--r--gnuradio-core/src/lib/io/gr_message_sink.cc70
-rw-r--r--gnuradio-core/src/lib/io/gr_message_sink.h27
-rw-r--r--gnuradio-core/src/lib/io/gr_message_sink.i7
-rw-r--r--gnuradio-core/src/lib/io/gr_message_source.cc45
-rw-r--r--gnuradio-core/src/lib/io/gr_message_source.h12
-rw-r--r--gnuradio-core/src/lib/io/gr_message_source.i4
-rw-r--r--gnuradio-core/src/lib/io/gr_pdu.h13
-rw-r--r--gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc8
-rw-r--r--gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc8
-rw-r--r--gnuradio-core/src/lib/runtime/CMakeLists.txt8
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block.cc49
-rw-r--r--gnuradio-core/src/lib/runtime/gr_block.h6
-rw-r--r--gnuradio-core/src/lib/runtime/gr_logger.cc204
-rw-r--r--gnuradio-core/src/lib/runtime/gr_logger.h564
-rw-r--r--gnuradio-core/src/lib/runtime/gr_logger.i109
-rw-r--r--gnuradio-core/src/lib/runtime/gr_tagged_stream_block.cc144
-rw-r--r--gnuradio-core/src/lib/runtime/gr_tagged_stream_block.h138
-rw-r--r--gnuradio-core/src/lib/runtime/gr_tagged_stream_block.i30
-rw-r--r--gnuradio-core/src/lib/runtime/qa_gr_logger.cc52
-rw-r--r--gnuradio-core/src/lib/runtime/qa_gr_logger.h42
-rw-r--r--gnuradio-core/src/lib/runtime/qa_runtime.cc2
-rw-r--r--gnuradio-core/src/lib/runtime/runtime.i4
-rw-r--r--gnuradio-core/src/lib/swig/CMakeLists.txt12
-rw-r--r--gnuradio-core/src/lib/swig/gnuradio.i5
-rw-r--r--gnuradio-core/src/lib/swig/gnuradio_swig_bug_workaround.h1
34 files changed, 1688 insertions, 84 deletions
diff --git a/gnuradio-core/src/lib/CMakeLists.txt b/gnuradio-core/src/lib/CMakeLists.txt
index 89a1bad88b..da6de8ed1b 100644
--- a/gnuradio-core/src/lib/CMakeLists.txt
+++ b/gnuradio-core/src/lib/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Free Software Foundation, Inc.
+# Copyright 2010-2011,2013 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -39,6 +39,21 @@ list(APPEND gnuradio_core_sources bug_work_around_6.cc)
list(APPEND test_gnuradio_core_sources bug_work_around_6.cc)
########################################################################
+# Set up Windows DLL resource files
+########################################################################
+
+IF(MSVC)
+ include(${CMAKE_SOURCE_DIR}/cmake/Modules/GrVersion.cmake)
+
+ configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/gnuradio-core.rc.in
+ ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-core.rc
+ @ONLY)
+
+ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-core.rc)
+ENDIF(MSVC)
+
+########################################################################
# Setup the include and linker paths
########################################################################
include_directories(
@@ -54,13 +69,25 @@ link_directories(
${FFTW3F_LIBRARY_DIRS}
)
+include_directories(${LOG4CPP_INCLUDE_DIRS})
+link_directories(${LOG4CPP_LIBRARY_DIRS})
+
########################################################################
# Setup library
########################################################################
+
+# Only use if log4cpp is installed
+# Define ENABLE_GR_LOG so .h and .cc files can turn actual
+# logging and insert dummy functions.
+#if(LOG4CPP_FOUND)
+# add_definitions(-DENABLE_GR_LOG)
+#endif(LOG4CPP_FOUND)
+
list(APPEND gnuradio_core_libs
gruel
${Boost_LIBRARIES}
${FFTW3F_LIBRARIES}
+ ${LOG4CPP_LIBRARIES}
)
if(FFTW3F_THREADS_LIBRARIES)
@@ -101,6 +128,6 @@ include_directories(${CPPUNIT_INCLUDE_DIRS})
link_directories(${CPPUNIT_LIBRARY_DIRS})
add_library(test-gnuradio-core SHARED ${test_gnuradio_core_sources})
-target_link_libraries(test-gnuradio-core gnuradio-core ${CPPUNIT_LIBRARIES} ${Boost_LIBRARIES})
+target_link_libraries(test-gnuradio-core gnuradio-core ${CPPUNIT_LIBRARIES} ${Boost_LIBRARIES} ${LOG4CPP_LIBRARIES})
endif(ENABLE_TESTING)
diff --git a/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc b/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc
index 97b8106994..95e17123c8 100644
--- a/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc
+++ b/gnuradio-core/src/lib/filter/gr_fir_sysconfig_x86.cc
@@ -48,6 +48,7 @@
// #include <gr_fir_sss_mmx.h>
// #include <gr_fir_sss_sse2.h>
+
#include <iostream>
using std::cerr;
@@ -207,7 +208,7 @@ gr_fir_sysconfig_x86::create_gr_fir_fcc (const std::vector<gr_complex> &taps)
if (gr_cpu::has_3dnow ()){
if (first){
- cerr << ">>> gr_fir_fcc: using 3DNow!\n";
+ cerr << ">>> gr_fir_fcc: gr_fir_fcc: using 3DNow!\n";
first = false;
}
return make_gr_fir_fcc_3dnow (taps);
@@ -215,7 +216,7 @@ gr_fir_sysconfig_x86::create_gr_fir_fcc (const std::vector<gr_complex> &taps)
if (gr_cpu::has_sse ()){
if (first){
- cerr << ">>> gr_fir_fcc: using SSE\n";
+ cerr << ">>> gr_fir_fcc: gr_fir_fcc: using SSE\n";
first = false;
}
return make_gr_fir_fcc_sse (taps);
@@ -326,19 +327,26 @@ gr_fir_sysconfig_x86::create_gr_fir_sss (const std::vector<short> &taps)
{
// FIXME -- probably want to figure out best answer for Athlon and code
// add code to select it here...
+ static bool first = true;
if (gr_cpu::has_sse2 ()){
- cerr << ">>> gr_fir_sss: using SSE2\n";
- return make_gr_fir_sss_sse2 (taps);
+ if(first) {
+ cerr << ">>> gr_fir_sss: using SSE2\n";
+ return make_gr_fir_sss_sse2 (taps);
+ }
}
if (gr_cpu::has_mmx ()){
- cerr << ">>> gr_fir_sss: using MMX\n";
- return make_gr_fir_sss_mmx (taps);
+ if(first) {
+ cerr << ">>> gr_fir_sss: using MMX\n";
+ return make_gr_fir_sss_mmx (taps);
+ }
}
- cerr << ">>> gr_fir_sss: handing off to parent class\n";
- return gr_fir_sysconfig_generic::create_gr_fir_sss (taps);
+ if(first) {
+ cerr << ">>> gr_fir_sss: handing off to parent class\n";
+ return gr_fir_sysconfig_generic::create_gr_fir_sss (taps);
+ }
}
#endif
diff --git a/gnuradio-core/src/lib/gengen/gr_vector_sink_X.cc.t b/gnuradio-core/src/lib/gengen/gr_vector_sink_X.cc.t
index a9e3a0a3ea..2b8207c027 100644
--- a/gnuradio-core/src/lib/gengen/gr_vector_sink_X.cc.t
+++ b/gnuradio-core/src/lib/gengen/gr_vector_sink_X.cc.t
@@ -28,6 +28,7 @@
#include <@NAME@.h>
#include <algorithm>
#include <gr_io_signature.h>
+#include <iostream>
@NAME@::@NAME@ (int vlen)
@@ -46,7 +47,9 @@ int
@TYPE@ *iptr = (@TYPE@ *) input_items[0];
for (int i = 0; i < noutput_items * d_vlen; i++)
d_data.push_back (iptr[i]);
-
+ std::vector<gr_tag_t> tags;
+ get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0) + noutput_items);
+ d_tags.insert(d_tags.end(), tags.begin(), tags.end());
return noutput_items;
}
@@ -62,3 +65,9 @@ std::vector<@TYPE@>
{
return d_data;
}
+
+std::vector<gr_tag_t>
+@NAME@::tags () const
+{
+ return d_tags;
+}
diff --git a/gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t b/gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t
index b9126dc7b2..b7de1d101c 100644
--- a/gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t
+++ b/gnuradio-core/src/lib/gengen/gr_vector_sink_X.h.t
@@ -43,6 +43,7 @@ gr_make_@BASE_NAME@ (int vlen = 1);
class GR_CORE_API @NAME@ : public gr_sync_block {
friend GR_CORE_API @NAME@_sptr gr_make_@BASE_NAME@ (int vlen);
std::vector<@TYPE@> d_data;
+ std::vector<gr_tag_t> d_tags;
int d_vlen;
@NAME@ (int vlen);
@@ -54,6 +55,7 @@ class GR_CORE_API @NAME@ : public gr_sync_block {
void reset() {d_data.clear();}
void clear() {reset(); } // deprecated
std::vector<@TYPE@> data () const;
+ std::vector<gr_tag_t> tags () const;
};
#endif
diff --git a/gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t b/gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t
index d4a9409114..ee0ebf378b 100644
--- a/gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t
+++ b/gnuradio-core/src/lib/gengen/gr_vector_sink_X.i.t
@@ -35,5 +35,6 @@ class @NAME@ : public gr_sync_block {
void clear(); // deprecated
void reset();
std::vector<@TYPE@> data () const;
+ std::vector<gr_tag_t> tags () const;
};
diff --git a/gnuradio-core/src/lib/gengen/gr_vector_source_X.cc.t b/gnuradio-core/src/lib/gengen/gr_vector_source_X.cc.t
index 9f68f9cf14..19272ee24b 100644
--- a/gnuradio-core/src/lib/gengen/gr_vector_source_X.cc.t
+++ b/gnuradio-core/src/lib/gengen/gr_vector_source_X.cc.t
@@ -30,20 +30,39 @@
#include <gr_io_signature.h>
#include <stdexcept>
-
-@NAME@::@NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen)
+@NAME@::@NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen, const std::vector<gr_tag_t> &tags)
: gr_sync_block ("@BASE_NAME@",
gr_make_io_signature (0, 0, 0),
gr_make_io_signature (1, 1, sizeof (@TYPE@) * vlen)),
d_data (data),
d_repeat (repeat),
d_offset (0),
- d_vlen (vlen)
+ d_vlen (vlen),
+ d_tags (tags),
+ d_tagpos (0)
{
+ if (tags.size() == 0) {
+ d_settags = 0;
+ } else {
+ d_settags = 1;
+ set_output_multiple(data.size() / vlen);
+ }
if ((data.size() % vlen) != 0)
throw std::invalid_argument("data length must be a multiple of vlen");
}
+void
+@NAME@::set_data (const std::vector<@TYPE@> &data, const std::vector<gr_tag_t> &tags){
+ d_data = data;
+ d_tags = tags;
+ rewind();
+ if (tags.size() == 0) {
+ d_settags = false;
+ } else {
+ d_settags = true;
+ }
+}
+
int
@NAME@::work (int noutput_items,
gr_vector_const_void_star &input_items,
@@ -54,36 +73,52 @@ int
if (d_repeat){
unsigned int size = d_data.size ();
unsigned int offset = d_offset;
-
if (size == 0)
return -1;
- for (int i = 0; i < noutput_items*d_vlen; i++){
- optr[i] = d_data[offset++];
- if (offset >= size)
- offset = 0;
+ if (d_settags) {
+ int n_outputitems_per_vector = d_data.size() / d_vlen;
+ for (int i = 0; i < noutput_items; i += n_outputitems_per_vector) {
+ // FIXME do proper vector copy
+ memcpy((void *) optr, (const void *) &d_data[0], size * sizeof (@TYPE@));
+ optr += size;
+ for (unsigned t = 0; t < d_tags.size(); t++) {
+ add_item_tag(0, nitems_written(0)+i+d_tags[t].offset, d_tags[t].key, d_tags[t].value);
+ }
+ }
+ } else {
+ for (int i = 0; i < noutput_items*d_vlen; i++){
+ optr[i] = d_data[offset++];
+ if (offset >= size) {
+ offset = 0;
+ }
+ }
}
+
+
d_offset = offset;
return noutput_items;
- }
-
- else {
+ } else {
if (d_offset >= d_data.size ())
return -1; // Done!
unsigned n = std::min ((unsigned) d_data.size () - d_offset,
- (unsigned) noutput_items*d_vlen);
- for (unsigned i = 0; i < n; i++)
+ (unsigned) noutput_items*d_vlen);
+ for (unsigned i = 0; i < n; i++) {
optr[i] = d_data[d_offset + i];
-
+ }
+ for (unsigned t = 0; t < d_tags.size(); t++) {
+ if ((d_tags[t].offset >= d_offset) && (d_tags[t].offset < d_offset+n))
+ add_item_tag(0, d_tags[t].offset, d_tags[t].key, d_tags[t].value);
+ }
d_offset += n;
return n/d_vlen;
}
}
@NAME@_sptr
-gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen)
+gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen, const std::vector<gr_tag_t> &tags)
{
- return gnuradio::get_initial_sptr(new @NAME@ (data, repeat, vlen));
+ return gnuradio::get_initial_sptr(new @NAME@ (data, repeat, vlen, tags));
}
diff --git a/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t b/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t
index fe02c1346f..041cc47a45 100644
--- a/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t
+++ b/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t
@@ -38,24 +38,27 @@ typedef boost::shared_ptr<@NAME@> @NAME@_sptr;
class @NAME@ : public gr_sync_block {
friend GR_CORE_API @NAME@_sptr
- gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen);
+ gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen, const std::vector<gr_tag_t> &tags);
std::vector<@TYPE@> d_data;
bool d_repeat;
unsigned int d_offset;
int d_vlen;
+ bool d_settags;
+ std::vector<gr_tag_t> d_tags;
+ unsigned int d_tagpos;
- @NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen);
+ @NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen, const std::vector<gr_tag_t> &tags);
public:
void rewind() {d_offset=0;}
virtual int work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
- void set_data(const std::vector<@TYPE@> &data){ d_data = data; rewind(); }
+ void set_data(const std::vector<@TYPE@> &data, const std::vector<gr_tag_t> &tags = std::vector<gr_tag_t>());
};
GR_CORE_API @NAME@_sptr
-gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat = false, int vlen = 1);
+gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat = false, int vlen = 1, const std::vector<gr_tag_t> &tags = std::vector<gr_tag_t>());
#endif
diff --git a/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t b/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t
index 4986c68a35..1f1479f947 100644
--- a/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t
+++ b/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t
@@ -25,13 +25,13 @@
GR_SWIG_BLOCK_MAGIC(gr,@BASE_NAME@);
@NAME@_sptr
-gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat = false, int vlen = 1)
+gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat = false, int vlen = 1, const std::vector<gr_tag_t> &tags=std::vector<gr_tag_t>())
throw(std::invalid_argument);
class @NAME@ : public gr_sync_block {
public:
void rewind();
- void set_data(const std::vector<@TYPE@> &data);
+ void set_data(const std::vector<@TYPE@> &data, const std::vector<gr_tag_t> &tags = std::vector<gr_tag_t>());
private:
- @NAME@ (const std::vector<@TYPE@> &data, int vlen);
+ @NAME@ (const std::vector<@TYPE@> &data, bool repeat, int vlen, const std::vector<gr_tag_t> &tags);
};
diff --git a/gnuradio-core/src/lib/gnuradio-core.rc.in b/gnuradio-core/src/lib/gnuradio-core.rc.in
new file mode 100644
index 0000000000..a5579ce4ed
--- /dev/null
+++ b/gnuradio-core/src/lib/gnuradio-core.rc.in
@@ -0,0 +1,55 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013 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 <afxres.h>
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION @MAJOR_VERSION@,@API_COMPAT@,@RC_MINOR_VERSION@,@RC_MAINT_VERSION@
+ PRODUCTVERSION @MAJOR_VERSION@,@API_COMPAT@,@RC_MINOR_VERSION@,@RC_MAINT_VERSION@
+ FILEFLAGSMASK 0x3fL
+#ifndef NDEBUG
+ FILEFLAGS 0x0L
+#else
+ FILEFLAGS 0x1L
+#endif
+ FILEOS VOS__WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE VFT2_DRV_INSTALLABLE
+ BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "FileDescription", "gnuradio-core"
+ VALUE "FileVersion", "@VERSION@"
+ VALUE "InternalName", "gnuradio-core.dll"
+ VALUE "LegalCopyright", "Licensed under GPLv3 or any later version"
+ VALUE "OriginalFilename", "gnuradio-core.dll"
+ VALUE "ProductName", "gnuradio-core"
+ VALUE "ProductVersion", "@VERSION@"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+ END
diff --git a/gnuradio-core/src/lib/io/gr_message_sink.cc b/gnuradio-core/src/lib/io/gr_message_sink.cc
index ae0b5c7649..3816f5da48 100644
--- a/gnuradio-core/src/lib/io/gr_message_sink.cc
+++ b/gnuradio-core/src/lib/io/gr_message_sink.cc
@@ -34,7 +34,6 @@
#include <stdexcept>
#include <string.h>
-
// public constructor that returns a shared_ptr
gr_message_sink_sptr
@@ -42,12 +41,25 @@ gr_make_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block)
{
return gnuradio::get_initial_sptr(new gr_message_sink(itemsize, msgq, dont_block));
}
+gr_message_sink_sptr
+gr_make_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block, const std::string& lengthtagname)
+{
+ return gnuradio::get_initial_sptr(new gr_message_sink(itemsize, msgq, dont_block, lengthtagname));
+}
gr_message_sink::gr_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block)
: gr_sync_block("message_sink",
gr_make_io_signature(1, 1, itemsize),
gr_make_io_signature(0, 0, 0)),
- d_itemsize(itemsize), d_msgq(msgq), d_dont_block(dont_block)
+ d_itemsize(itemsize), d_msgq(msgq), d_dont_block(dont_block), d_tags(false), d_items_read(0)
+{
+}
+
+gr_message_sink::gr_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block, const std::string& lengthtagname)
+ : gr_sync_block("message_sink",
+ gr_make_io_signature(1, 1, itemsize),
+ gr_make_io_signature(0, 0, 0)),
+ d_itemsize(itemsize), d_msgq(msgq), d_dont_block(dont_block), d_tags(true), d_lengthtagname(lengthtagname), d_items_read(0)
{
}
@@ -62,18 +74,46 @@ gr_message_sink::work(int noutput_items,
{
const char *in = (const char *) input_items[0];
- // if we'd block, drop the data on the floor and say everything is OK
- if (d_dont_block && d_msgq->full_p())
- return noutput_items;
+ if (d_tags) {
+ long packet_length = 0;
+ std::vector<gr_tag_t> tags;
+ this->get_tags_in_range(tags, 0, d_items_read, d_items_read+1);
+ //const size_t ninput_items = noutput_items; //assumption for sync block, this can change
+ for (unsigned int i = 0; i < tags.size(); i++) {
+ if (pmt::pmt_symbol_to_string(tags[i].key) == d_lengthtagname) {
+ packet_length = pmt::pmt_to_long(tags[i].value);
+ }
+ }
+ assert(packet_length != 0);
- // build a message to hold whatever we've got
- gr_message_sptr msg = gr_make_message(0, // msg type
- d_itemsize, // arg1 for other end
- noutput_items, // arg2 for other end (redundant)
- noutput_items * d_itemsize); // len of msg
- memcpy(msg->msg(), in, noutput_items * d_itemsize);
-
- d_msgq->handle(msg); // send it
-
- return noutput_items;
+ // FIXME run this multiple times if input_items >= N * packet_length
+ if (noutput_items >= packet_length ) {
+ // If the message queue is full we drop the packet.
+ if (!d_msgq->full_p()) {
+ gr_message_sptr msg = gr_make_message(0, // msg type
+ d_itemsize, // arg1 for other end
+ packet_length, // arg2 for other end (redundant)
+ packet_length * d_itemsize); // len of msg
+ memcpy(msg->msg(), in, packet_length * d_itemsize);
+ d_msgq->handle(msg); // send it
+ }
+ d_items_read += packet_length;
+ return packet_length;
+ } else {
+ return 0;
+ }
+ } else {
+ // If the queue if full we drop all the data we got.
+ if (!d_msgq->full_p()) {
+ // build a message to hold whatever we've got
+ gr_message_sptr msg = gr_make_message(0, // msg type
+ d_itemsize, // arg1 for other end
+ noutput_items, // arg2 for other end (redundant)
+ noutput_items * d_itemsize); // len of msg
+ memcpy(msg->msg(), in, noutput_items * d_itemsize);
+
+ d_msgq->handle(msg); // send it
+ }
+ return noutput_items;
+ }
}
diff --git a/gnuradio-core/src/lib/io/gr_message_sink.h b/gnuradio-core/src/lib/io/gr_message_sink.h
index 84005694a1..2db84cff44 100644
--- a/gnuradio-core/src/lib/io/gr_message_sink.h
+++ b/gnuradio-core/src/lib/io/gr_message_sink.h
@@ -27,13 +27,23 @@
#include <gr_sync_block.h>
#include <gr_message.h>
#include <gr_msg_queue.h>
+#include <string>
class gr_message_sink;
typedef boost::shared_ptr<gr_message_sink> gr_message_sink_sptr;
-GR_CORE_API gr_message_sink_sptr gr_make_message_sink (size_t itemsize,
- gr_msg_queue_sptr msgq,
- bool dont_block);
+GR_CORE_API gr_message_sink_sptr gr_make_message_sink (
+ size_t itemsize,
+ gr_msg_queue_sptr msgq,
+ bool dont_block
+);
+
+GR_CORE_API gr_message_sink_sptr gr_make_message_sink (
+ size_t itemsize,
+ gr_msg_queue_sptr msgq,
+ bool dont_block,
+ const std::string& lengthtagname
+);
/*!
* \brief Gather received items into messages and insert into msgq
@@ -45,12 +55,21 @@ class GR_CORE_API gr_message_sink : public gr_sync_block
size_t d_itemsize;
gr_msg_queue_sptr d_msgq;
bool d_dont_block;
+ bool d_tags;
+ std::string d_lengthtagname;
+ uint64_t d_items_read;
friend GR_CORE_API gr_message_sink_sptr
- gr_make_message_sink(size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block);
+ gr_make_message_sink(size_t itemsize, gr_msg_queue_sptr msgq,
+ bool dont_block);
+ friend GR_CORE_API gr_message_sink_sptr
+ gr_make_message_sink(size_t itemsize, gr_msg_queue_sptr msgq,
+ bool dont_block, const std::string& lengthtagname);
protected:
gr_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block);
+ gr_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block,
+ const std::string& lengthtagname);
public:
~gr_message_sink ();
diff --git a/gnuradio-core/src/lib/io/gr_message_sink.i b/gnuradio-core/src/lib/io/gr_message_sink.i
index 8415cbd66d..b22eff18c0 100644
--- a/gnuradio-core/src/lib/io/gr_message_sink.i
+++ b/gnuradio-core/src/lib/io/gr_message_sink.i
@@ -22,14 +22,21 @@
GR_SWIG_BLOCK_MAGIC(gr,message_sink);
+#include <string>
+
gr_message_sink_sptr gr_make_message_sink (size_t itemsize,
gr_msg_queue_sptr msgq,
bool dont_block);
+gr_message_sink_sptr gr_make_message_sink (size_t itemsize,
+ gr_msg_queue_sptr msgq,
+ bool dont_block,
+ const std::string& lengthtagname);
class gr_message_sink : public gr_sync_block
{
protected:
gr_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block);
+ gr_message_sink (size_t itemsize, gr_msg_queue_sptr msgq, bool dont_block, const std::string& lengthtagname);
public:
~gr_message_sink ();
diff --git a/gnuradio-core/src/lib/io/gr_message_source.cc b/gnuradio-core/src/lib/io/gr_message_source.cc
index fb3da89a8b..0b79bb526b 100644
--- a/gnuradio-core/src/lib/io/gr_message_source.cc
+++ b/gnuradio-core/src/lib/io/gr_message_source.cc
@@ -36,7 +36,6 @@
// public constructor that returns a shared_ptr
-
gr_message_source_sptr
gr_make_message_source(size_t itemsize, int msgq_limit)
{
@@ -50,11 +49,19 @@ gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq)
return gnuradio::get_initial_sptr(new gr_message_source(itemsize, msgq));
}
+// public constructor that takes existing message queue and adds messages length tags.
+gr_message_source_sptr
+gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq, const std::string& lengthtagname)
+{
+ return gnuradio::get_initial_sptr(new gr_message_source(itemsize, msgq, lengthtagname));
+}
+
gr_message_source::gr_message_source (size_t itemsize, int msgq_limit)
: gr_sync_block("message_source",
gr_make_io_signature(0, 0, 0),
gr_make_io_signature(1, 1, itemsize)),
- d_itemsize(itemsize), d_msgq(gr_make_msg_queue(msgq_limit)), d_msg_offset(0), d_eof(false)
+ d_itemsize(itemsize), d_msgq(gr_make_msg_queue(msgq_limit)), d_msg_offset(0), d_eof(false),
+ d_tags(false)
{
}
@@ -62,11 +69,19 @@ gr_message_source::gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq)
: gr_sync_block("message_source",
gr_make_io_signature(0, 0, 0),
gr_make_io_signature(1, 1, itemsize)),
- d_itemsize(itemsize), d_msgq(msgq), d_msg_offset(0), d_eof(false)
+ d_itemsize(itemsize), d_msgq(msgq), d_msg_offset(0), d_eof(false), d_tags(false)
{
}
gr_message_source::~gr_message_source()
+{}
+
+gr_message_source::gr_message_source(size_t itemsize, gr_msg_queue_sptr msgq, const std::string& lengthtagname)
+ : gr_sync_block("message_source",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(1, 1, itemsize)),
+ d_itemsize(itemsize), d_msgq(msgq), d_msg_offset(0), d_eof(false),
+ d_tags(true), d_lengthtagname(lengthtagname)
{
}
@@ -86,15 +101,21 @@ gr_message_source::work(int noutput_items,
int mm = std::min(noutput_items - nn, (int)((d_msg->length() - d_msg_offset) / d_itemsize));
memcpy (out, &(d_msg->msg()[d_msg_offset]), mm * d_itemsize);
+ if (d_tags && (d_msg_offset == 0)) {
+ const uint64_t offset = this->nitems_written(0) + nn;
+ pmt::pmt_t key = pmt::pmt_string_to_symbol(d_lengthtagname);
+ pmt::pmt_t value = pmt::pmt_from_long(d_msg->length());
+ this->add_item_tag(0, offset, key, value);
+ }
nn += mm;
out += mm * d_itemsize;
d_msg_offset += mm * d_itemsize;
assert(d_msg_offset <= d_msg->length());
if (d_msg_offset == d_msg->length()){
- if (d_msg->type() == 1) // type == 1 sets EOF
- d_eof = true;
- d_msg.reset();
+ if (d_msg->type() == 1) // type == 1 sets EOF
+ d_eof = true;
+ d_msg.reset();
}
}
else {
@@ -102,17 +123,17 @@ gr_message_source::work(int noutput_items,
// No current message
//
if (d_msgq->empty_p() && nn > 0){ // no more messages in the queue, return what we've got
- break;
+ break;
}
-
+
if (d_eof)
- return -1;
-
+ return -1;
+
d_msg = d_msgq->delete_head(); // block, waiting for a message
d_msg_offset = 0;
-
+
if ((d_msg->length() % d_itemsize) != 0)
- throw std::runtime_error("msg length is not a multiple of d_itemsize");
+ throw std::runtime_error("msg length is not a multiple of d_itemsize");
}
}
diff --git a/gnuradio-core/src/lib/io/gr_message_source.h b/gnuradio-core/src/lib/io/gr_message_source.h
index c510d1775f..1828475987 100644
--- a/gnuradio-core/src/lib/io/gr_message_source.h
+++ b/gnuradio-core/src/lib/io/gr_message_source.h
@@ -33,6 +33,8 @@ typedef boost::shared_ptr<gr_message_source> gr_message_source_sptr;
GR_CORE_API gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0);
GR_CORE_API gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq);
+GR_CORE_API gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq,
+ const std::string& lengthtagname);
/*!
* \brief Turn received messages into a stream
@@ -46,15 +48,21 @@ class GR_CORE_API gr_message_source : public gr_sync_block
gr_message_sptr d_msg;
unsigned d_msg_offset;
bool d_eof;
+ bool d_tags;
+ // FIXME: Is this adequate tagname length.
+ std::string d_lengthtagname;
friend GR_CORE_API gr_message_source_sptr
- gr_make_message_source(size_t itemsize, int msgq_limit);
+ gr_make_message_source(size_t itemsize, int msgq_limit);
friend GR_CORE_API gr_message_source_sptr
- gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq);
+ gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq);
+ friend GR_CORE_API gr_message_source_sptr
+ gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq, const std::string& lengthtagname);
protected:
gr_message_source (size_t itemsize, int msgq_limit);
gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq);
+ gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq, const std::string& lengthtagname);
public:
~gr_message_source ();
diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i
index 9ee9157e8c..bb1ddfcc31 100644
--- a/gnuradio-core/src/lib/io/gr_message_source.i
+++ b/gnuradio-core/src/lib/io/gr_message_source.i
@@ -22,14 +22,18 @@
GR_SWIG_BLOCK_MAGIC(gr,message_source);
+#include <string>
+
gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0);
gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq);
+gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq, const std::string& lengthtagname);
class gr_message_source : public gr_sync_block
{
protected:
gr_message_source (size_t itemsize, int msgq_limit);
gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq);
+ gr_message_source (size_t itemsize, gr_msg_queue_sptr msgq, const std::string& lengthtagname);
public:
~gr_message_source ();
diff --git a/gnuradio-core/src/lib/io/gr_pdu.h b/gnuradio-core/src/lib/io/gr_pdu.h
index a5ae87db7f..53058ccb6c 100644
--- a/gnuradio-core/src/lib/io/gr_pdu.h
+++ b/gnuradio-core/src/lib/io/gr_pdu.h
@@ -23,17 +23,18 @@
#ifndef GR_PDU_H
#define GR_PDU_H
+#include <gr_core_api.h>
#include <gr_complex.h>
#include <gruel/pmt.h>
-#define pdu_port_id pmt::mp("pdus")
-#define pdu_length_tag pmt::mp("pdu_length")
+#define PDU_PORT_ID pmt::mp("pdus")
+#define PDU_LENGTH_TAG pmt::mp("pdu_length")
enum gr_pdu_vector_type { pdu_byte, pdu_float, pdu_complex };
-size_t gr_pdu_itemsize(gr_pdu_vector_type type);
-bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v);
-pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items);
-gr_pdu_vector_type type_from_pmt(pmt::pmt_t vector);
+GR_CORE_API size_t gr_pdu_itemsize(gr_pdu_vector_type type);
+GR_CORE_API bool gr_pdu_type_matches(gr_pdu_vector_type type, pmt::pmt_t v);
+GR_CORE_API pmt::pmt_t gr_pdu_make_vector(gr_pdu_vector_type type, const uint8_t* buf, size_t items);
+GR_CORE_API gr_pdu_vector_type type_from_pmt(pmt::pmt_t vector);
#endif
diff --git a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc
index 5c319dc39d..a702b66a2b 100644
--- a/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc
+++ b/gnuradio-core/src/lib/io/gr_pdu_to_tagged_stream.cc
@@ -49,7 +49,7 @@ gr_pdu_to_tagged_stream::gr_pdu_to_tagged_stream (gr_pdu_vector_type t)
gr_make_io_signature(1, 1, gr_pdu_itemsize(t))),
d_vectortype(t), d_itemsize(gr_pdu_itemsize(t))
{
- message_port_register_in(pdu_port_id);
+ message_port_register_in(PDU_PORT_ID);
}
gr_pdu_to_tagged_stream::~gr_pdu_to_tagged_stream()
@@ -77,8 +77,8 @@ gr_pdu_to_tagged_stream::work(int noutput_items,
if(noutput_items > 0){
// grab a message if one exists
- //pmt::pmt_t msg( delete_head_nowait( pdu_port_id ) );
- pmt::pmt_t msg( delete_head_blocking( pdu_port_id ) );
+ //pmt::pmt_t msg( delete_head_nowait( PDU_PORT_ID ) );
+ pmt::pmt_t msg( delete_head_blocking( PDU_PORT_ID ) );
if(msg.get() == NULL ){
return nout;
}
@@ -99,7 +99,7 @@ gr_pdu_to_tagged_stream::work(int noutput_items,
uint64_t offset = nitems_written(0) + nout;
// add a tag for pdu length
- add_item_tag(0, offset, pdu_length_tag, pmt::pmt_from_long( pmt::pmt_length(vect) ), pmt::mp(alias()));
+ add_item_tag(0, offset, PDU_LENGTH_TAG, pmt::pmt_from_long( pmt::pmt_length(vect) ), pmt::mp(alias()));
// if we recieved metadata add it as tags
if( !pmt_eq(meta, pmt::PMT_NIL) ){
diff --git a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc
index 8211b7672d..1b869edfab 100644
--- a/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc
+++ b/gnuradio-core/src/lib/io/gr_tagged_stream_to_pdu.cc
@@ -49,7 +49,7 @@ gr_tagged_stream_to_pdu::gr_tagged_stream_to_pdu (gr_pdu_vector_type t)
d_vectortype(t), d_itemsize(gr_pdu_itemsize(t)), d_inpdu(false),
d_pdu_meta(pmt::PMT_NIL), d_pdu_vector(pmt::PMT_NIL)
{
- message_port_register_out(pdu_port_id);
+ message_port_register_out(PDU_PORT_ID);
}
gr_tagged_stream_to_pdu::~gr_tagged_stream_to_pdu()
@@ -70,7 +70,7 @@ gr_tagged_stream_to_pdu::work(int noutput_items,
get_tags_in_range(d_tags, 0, abs_N, abs_N+1);
bool found_length_tag(false);
for(d_tags_itr = d_tags.begin(); (d_tags_itr != d_tags.end()) && (!found_length_tag); d_tags_itr++){
- if( pmt::pmt_equal( (*d_tags_itr).key, pdu_length_tag ) ){
+ if( pmt::pmt_equal( (*d_tags_itr).key, PDU_LENGTH_TAG ) ){
if( (*d_tags_itr).offset != abs_N ){
throw std::runtime_error("expected next pdu length tag on a different item...");
}
@@ -91,7 +91,7 @@ gr_tagged_stream_to_pdu::work(int noutput_items,
// copy any tags in this range into our meta object
get_tags_in_range(d_tags, 0, abs_N, abs_N+ncopy);
for(d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++){
- if( ! pmt_equal( (*d_tags_itr).key, pdu_length_tag ) ){
+ if( ! pmt_equal( (*d_tags_itr).key, PDU_LENGTH_TAG ) ){
d_pdu_meta = pmt_dict_add(d_pdu_meta, (*d_tags_itr).key, (*d_tags_itr).value);
}
}
@@ -127,7 +127,7 @@ void gr_tagged_stream_to_pdu::send_message(){
}
pmt::pmt_t msg = pmt::pmt_cons( d_pdu_meta, d_pdu_vector );
- message_port_pub( pdu_port_id, msg );
+ message_port_pub( PDU_PORT_ID, msg );
d_pdu_meta = pmt::PMT_NIL;
d_pdu_vector = pmt::PMT_NIL;
diff --git a/gnuradio-core/src/lib/runtime/CMakeLists.txt b/gnuradio-core/src/lib/runtime/CMakeLists.txt
index 70938a0f17..80db1e7e7e 100644
--- a/gnuradio-core/src/lib/runtime/CMakeLists.txt
+++ b/gnuradio-core/src/lib/runtime/CMakeLists.txt
@@ -62,6 +62,7 @@ list(APPEND gnuradio_core_sources
${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_local_sighandler.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/gr_logger.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_message.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.cc
@@ -78,6 +79,7 @@ list(APPEND gnuradio_core_sources
${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_decimator.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_interpolator.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_sys_paths.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/gr_tagged_stream_block.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block_impl.cc
${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_detail.cc
@@ -105,6 +107,7 @@ list(APPEND test_gnuradio_core_sources
${CMAKE_CURRENT_SOURCE_DIR}/qa_block_tags.cc
${CMAKE_CURRENT_SOURCE_DIR}/qa_runtime.cc
${CMAKE_CURRENT_SOURCE_DIR}/qa_set_msg_handler.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr_logger.cc
)
########################################################################
@@ -126,6 +129,7 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_local_sighandler.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/gr_logger.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_message.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_accepter.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.h
@@ -143,6 +147,7 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_block.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_decimator.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_interpolator.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/gr_tagged_stream_block.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block_impl.h
${CMAKE_CURRENT_SOURCE_DIR}/gr_tpb_detail.h
@@ -170,6 +175,7 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/gr_dispatcher.i
${CMAKE_CURRENT_SOURCE_DIR}/gr_error_handler.i
${CMAKE_CURRENT_SOURCE_DIR}/gr_io_signature.i
+ ${CMAKE_CURRENT_SOURCE_DIR}/gr_logger.i
${CMAKE_CURRENT_SOURCE_DIR}/gr_message.i
${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_handler.i
${CMAKE_CURRENT_SOURCE_DIR}/gr_msg_queue.i
@@ -178,10 +184,12 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_block.i
${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_decimator.i
${CMAKE_CURRENT_SOURCE_DIR}/gr_sync_interpolator.i
+ ${CMAKE_CURRENT_SOURCE_DIR}/gr_tagged_stream_block.i
${CMAKE_CURRENT_SOURCE_DIR}/gr_tags.i
${CMAKE_CURRENT_SOURCE_DIR}/gr_top_block.i
${CMAKE_CURRENT_SOURCE_DIR}/runtime.i
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig
COMPONENT "core_swig"
)
+
endif(ENABLE_PYTHON)
diff --git a/gnuradio-core/src/lib/runtime/gr_block.cc b/gnuradio-core/src/lib/runtime/gr_block.cc
index 54d2676203..4950e8666c 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.cc
+++ b/gnuradio-core/src/lib/runtime/gr_block.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2004,2009,2010 Free Software Foundation, Inc.
+ * Copyright 2004,2009,2010,2013 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -29,6 +29,7 @@
#include <stdexcept>
#include <iostream>
#include <gr_block_registry.h>
+#include <gr_prefs.h>
gr_block::gr_block (const std::string &name,
gr_io_signature_sptr input_signature,
@@ -49,6 +50,52 @@ gr_block::gr_block (const std::string &name,
d_min_output_buffer(std::max(output_signature->max_streams(),1), -1)
{
global_block_registry.register_primitive(alias(), this);
+
+#ifdef ENABLE_GR_LOG
+#ifdef HAVE_LOG4CPP
+ gr_prefs *p = gr_prefs::singleton();
+ std::string config_file = p->get_string("LOG", "log_config", "");
+ std::string log_level = p->get_string("LOG", "log_level", "off");
+ std::string log_file = p->get_string("LOG", "log_file", "");
+ std::string debug_level = p->get_string("LOG", "debug_level", "off");
+ std::string debug_file = p->get_string("LOG", "debug_file", "");
+
+ GR_CONFIG_LOGGER(config_file);
+
+ GR_LOG_GETLOGGER(LOG, "gr_log." + alias());
+ GR_LOG_SET_LEVEL(LOG, log_level);
+ if(log_file.size() > 0) {
+ if(log_file == "stdout") {
+ GR_LOG_ADD_CONSOLE_APPENDER(LOG, "cout","gr::log :%p: %c{1} - %m%n");
+ }
+ else if(log_file == "stderr") {
+ GR_LOG_ADD_CONSOLE_APPENDER(LOG, "cerr","gr::log :%p: %c{1} - %m%n");
+ }
+ else {
+ GR_LOG_ADD_FILE_APPENDER(LOG, log_file , true,"%r :%p: %c{1} - %m%n");
+ }
+ }
+ d_logger = LOG;
+
+ GR_LOG_GETLOGGER(DLOG, "gr_log_debug." + alias());
+ GR_LOG_SET_LEVEL(DLOG, debug_level);
+ if(debug_file.size() > 0) {
+ if(debug_file == "stdout") {
+ GR_LOG_ADD_CONSOLE_APPENDER(DLOG, "cout","gr::debug :%p: %c{1} - %m%n");
+ }
+ else if(debug_file == "stderr") {
+ GR_LOG_ADD_CONSOLE_APPENDER(DLOG, "cerr", "gr::debug :%p: %c{1} - %m%n");
+ }
+ else {
+ GR_LOG_ADD_FILE_APPENDER(DLOG, debug_file, true, "%r :%p: %c{1} - %m%n");
+ }
+ }
+ d_debug_logger = DLOG;
+#endif /* HAVE_LOG4CPP */
+#else /* ENABLE_GR_LOG */
+ d_logger = NULL;
+ d_debug_logger = NULL;
+#endif /* ENABLE_GR_LOG */
}
gr_block::~gr_block ()
diff --git a/gnuradio-core/src/lib/runtime/gr_block.h b/gnuradio-core/src/lib/runtime/gr_block.h
index 0783e86848..e4b30267e6 100644
--- a/gnuradio-core/src/lib/runtime/gr_block.h
+++ b/gnuradio-core/src/lib/runtime/gr_block.h
@@ -26,6 +26,7 @@
#include <gr_core_api.h>
#include <gr_basic_block.h>
#include <gr_tags.h>
+#include <gr_logger.h>
/*!
* \brief The abstract base class for all 'terminal' processing blocks.
@@ -616,6 +617,11 @@ class GR_CORE_API gr_block : public gr_basic_block {
*/
gruel::mutex d_setlock;
+ /*! Used by blocks to access the logger system.
+ */
+ gr_logger_ptr d_logger;
+ gr_logger_ptr d_debug_logger;
+
// These are really only for internal use, but leaving them public avoids
// having to work up an ever-varying list of friend GR_CORE_APIs
diff --git a/gnuradio-core/src/lib/runtime/gr_logger.cc b/gnuradio-core/src/lib/runtime/gr_logger.cc
new file mode 100644
index 0000000000..530c66f964
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_logger.cc
@@ -0,0 +1,204 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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.
+ */
+
+/*******************************************************************************
+* Author: Mark Plett
+* Description:
+* The gr_log module wraps the log4cpp library for logging in gnuradio.
+*******************************************************************************/
+
+//#ifdef HAVE_CONFIG_H
+//#include "config.h"
+//#endif
+
+#include <gr_logger.h>
+#include <stdexcept>
+#include <algorithm>
+
+#ifdef ENABLE_GR_LOG
+#ifdef HAVE_LOG4CPP
+
+bool gr_logger_configured(false);
+
+void
+logger_load_config(const std::string &config_filename)
+{
+ if(!gr_logger_configured){
+ gr_logger_configured = true;
+ if(config_filename.size() != 0) {
+ try
+ {
+ log4cpp::PropertyConfigurator::configure(config_filename);
+ }
+ catch( log4cpp::ConfigureFailure &e )
+ {
+ std::cout << "Logger config failed :" << e.what() << std::endl;
+ }
+ };
+ };
+}
+
+void
+logger_load_config_and_watch(const std::string &config_filename,
+ unsigned int watch_period)
+{
+// NOTE:: NEEDS CODE TO WATCH FILE HERE
+ if(!gr_logger_configured){
+ gr_logger_configured = true;
+ if(config_filename.size() != 0) {
+ try
+ {
+ log4cpp::PropertyConfigurator::configure(config_filename);
+ }
+ catch( log4cpp::ConfigureFailure &e )
+ {
+ std::cout << "Logger config failed :" << e.what() << std::endl;
+ }
+ };
+ };
+}
+
+void
+logger_reset_config(void){
+ std::vector<log4cpp::Category*> *loggers = log4cpp::Category::getCurrentCategories();
+ std::vector<log4cpp::Category*>::iterator logger = loggers->begin();
+// We can't destroy categories but we can neuter them by removing all appenders.
+ for (;logger!=loggers->end();logger++){
+ (*logger)->removeAllAppenders();
+ };
+}
+
+void
+logger_set_level(gr_logger_ptr logger, const std::string &level)
+{
+ std::string nocase = level;
+ std::transform(level.begin(), level.end(), nocase.begin(), ::tolower);
+
+ if(nocase == "off" || nocase == "notset")
+ logger_set_level(logger, log4cpp::Priority::NOTSET);
+ else if(nocase == "debug")
+ logger_set_level(logger, log4cpp::Priority::DEBUG);
+ else if(nocase == "info")
+ logger_set_level(logger, log4cpp::Priority::INFO);
+ else if(nocase == "notice")
+ logger_set_level(logger, log4cpp::Priority::NOTICE);
+ else if(nocase == "warn")
+ logger_set_level(logger, log4cpp::Priority::WARN);
+ else if(nocase == "error")
+ logger_set_level(logger, log4cpp::Priority::ERROR);
+ else if(nocase == "crit")
+ logger_set_level(logger, log4cpp::Priority::CRIT);
+ else if(nocase == "alert")
+ logger_set_level(logger, log4cpp::Priority::ALERT);
+ else if(nocase=="fatal")
+ logger_set_level(logger, log4cpp::Priority::FATAL);
+ else if(nocase == "all" || nocase == "emerg")
+ logger_set_level(logger, log4cpp::Priority::EMERG);
+ else
+ throw std::runtime_error("logger_set_level: Bad level type.\n");
+}
+
+void
+logger_set_level(gr_logger_ptr logger, log4cpp::Priority::Value level)
+{
+ logger->setPriority(level);
+}
+
+void
+logger_get_level(gr_logger_ptr logger, std::string &level)
+{
+ log4cpp::Priority::Value levelPtr = logger->getPriority();
+ if(levelPtr == log4cpp::Priority::NOTSET) level = "noset";
+ if(levelPtr == log4cpp::Priority::DEBUG) level = "debug";
+ if(levelPtr == log4cpp::Priority::INFO) level = "info";
+ if(levelPtr == log4cpp::Priority::NOTICE) level = "notice";
+ if(levelPtr == log4cpp::Priority::WARN) level = "warn";
+ if(levelPtr == log4cpp::Priority::ERROR) level = "error";
+ if(levelPtr == log4cpp::Priority::CRIT) level = "crit";
+ if(levelPtr == log4cpp::Priority::ALERT) level = "alert";
+ if(levelPtr == log4cpp::Priority::FATAL) level = "fatal";
+ if(levelPtr == log4cpp::Priority::EMERG) level = "emerg";
+};
+
+void
+logger_get_level(gr_logger_ptr logger,log4cpp::Priority::Value level)
+{
+ level = logger->getPriority();
+}
+
+void
+logger_add_console_appender(gr_logger_ptr logger,std::string target,std::string pattern)
+{
+
+ log4cpp::PatternLayout* layout = new log4cpp::PatternLayout();
+ log4cpp::Appender* app;
+ if(target=="cout")
+ app = new log4cpp::OstreamAppender("ConsoleAppender::",&std::cout);
+ else
+ app = new log4cpp::OstreamAppender("ConsoleAppender::",&std::cerr);
+
+ layout->setConversionPattern(pattern);
+ app->setLayout(layout);
+ logger->setAppender(app);
+
+}
+
+void
+logger_add_file_appender(gr_logger_ptr logger,std::string filename,bool append,std::string pattern)
+{
+
+ log4cpp::PatternLayout* layout = new log4cpp::PatternLayout();
+ log4cpp::Appender* app = new
+ log4cpp::FileAppender("FileAppender::"+filename,
+ filename);
+ layout->setConversionPattern(pattern);
+ app->setLayout(layout);
+ logger->setAppender(app);
+
+}
+
+void
+logger_add_rollingfile_appender(gr_logger_ptr logger,std::string filename,
+ size_t filesize,int bkup_index,bool append,mode_t mode,std::string pattern)
+{
+ log4cpp::PatternLayout* layout = new log4cpp::PatternLayout();
+ log4cpp::Appender* app = new
+ log4cpp::RollingFileAppender("RollFileAppender::"+filename,filename,filesize,bkup_index,append,mode);
+ layout->setConversionPattern(pattern);
+ app->setLayout(layout);
+ logger->setAppender(app);
+}
+
+void
+logger_get_logger_names(std::vector<std::string>& names){
+ std::vector<log4cpp::Category*> *loggers = log4cpp::Category::getCurrentCategories();
+ std::vector<log4cpp::Category*>::iterator logger = loggers->begin();
+
+ names.clear();
+ for (;logger!=loggers->end();logger++){
+ names.push_back((*logger)->getName());
+ };
+
+}
+
+#endif /* HAVE_LOG4CPP */
+#endif /* ENABLE_GR_LOGGER */
diff --git a/gnuradio-core/src/lib/runtime/gr_logger.h b/gnuradio-core/src/lib/runtime/gr_logger.h
new file mode 100644
index 0000000000..2ccd498822
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_logger.h
@@ -0,0 +1,564 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012-2013 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.
+ */
+
+/*******************************************************************************
+* Author: Mark Plett
+* Description:
+* The gr_logger module wraps the log4cpp library for logging in gnuradio
+*******************************************************************************/
+
+#ifndef INCLUDED_GR_LOGGER_H
+#define INCLUDED_GR_LOGGER_H
+
+/*!
+* \file gr_logger.h
+* \ingroup logging
+* \brief GNURADIO logging wrapper for log4cpp library (C++ port of log4j)
+*
+*/
+
+#ifndef ENABLE_GR_LOG
+#include "config.h"
+//#define GR_LOG_CONFIG_H
+#endif
+
+#include <gr_core_api.h>
+#include <assert.h>
+#include <iostream>
+
+//#ifndef ENABLE_GR_LOG
+//#define ENABLE_GR_LOG 1
+//#endif
+//#ifndef HAVE_LOG4CPP
+//#define HAVE_LOG4CPP 2
+//#endif
+
+#ifdef ENABLE_GR_LOG
+
+// We have three configurations... first logging to stdout/stderr
+#ifndef HAVE_LOG4CPP
+//#warning GR logging Enabled and using std::cout
+
+typedef std::string gr_logger_ptr;
+
+#define GR_LOG_DECLARE_LOGPTR(logger)
+#define GR_LOG_ASSIGN_LOGPTR(logger,name)
+#define GR_CONFIG_LOGGER(config)
+#define GR_CONFIG_AND_WATCH_LOGGER(config,period)
+#define GR_LOG_GETLOGGER(logger, name)
+#define GR_SET_LEVEL(name, level)
+#define GR_LOG_SET_LEVEL(logger, level)
+#define GR_GET_LEVEL(name, level)
+#define GR_LOG_GET_LEVEL(logger, level)
+#define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
+#define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
+#define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
+#define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
+#define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
+#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
+#define GR_GET_LOGGER_NAMES(names)
+#define GR_RESET_CONFIGURATION()
+#define GR_DEBUG(name, msg) std::cout<<"DEBUG: "<<msg<<std::endl
+#define GR_INFO(name, msg) std::cout<<"INFO: "<<msg<<std::endl
+#define GR_NOTICE(name, msg) std::cout<<"NOTICE: "<<msg<<std::endl
+#define GR_WARN(name, msg) std::cerr<<"WARN: "<<msg<<std::endl
+#define GR_ERROR(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
+#define GR_ALERT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
+#define GR_CRIT(name, msg) std::cerr<<"ERROR: "<<msg<<std::endl
+#define GR_FATAL(name, msg) std::cerr<<"FATAL: "<<msg<<std::endl
+#define GR_EMERG(name, msg) std::cerr<<"EMERG: "<<msg<<std::endl
+#define GR_ERRORIF(name, cond, msg) if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl
+#define GR_ASSERT(name, cond, msg) if(!(cond)) std::cerr<<"ERROR: "<<msg<<std::endl; assert(cond)
+#define GR_LOG_DEBUG(logger, msg) std::cout<<"DEBUG: "<<msg<<std::endl
+#define GR_LOG_INFO(logger, msg) std::cout<<"INFO: "<<msg<<std::endl
+#define GR_LOG_NOTICE(logger, msg) std::cout<<"NOTICE: "<<msg<<std::endl
+#define GR_LOG_WARN(logger, msg) std::cerr<<"WARN: "<<msg<<std::endl
+#define GR_LOG_ERROR(logger, msg) std::cerr<<"ERROR: "<<msg<<std::endl
+#define GR_LOG_ALERT(logger, msg) std::cerr<<"ALERT: "<<msg<<std::endl
+#define GR_LOG_CRIT(logger, msg) std::cerr<<"CRIT: "<<msg<<std::endl
+#define GR_LOG_FATAL(logger, msg) std::cerr<<"FATAL: "<<msg<<std::endl
+#define GR_LOG_EMERG(logger, msg) std::cerr<<"EMERG: "<<msg<<std::endl
+#define GR_LOG_ERRORIF(logger, cond, msg) if((cond)) std::cerr<<"ERROR: "<<msg<<std::endl
+#define GR_LOG_ASSERT(logger, cond, msg) std::cerr<<"ERROR: "<<msg<<std::endl; assert(cond)
+
+#else /* HAVE_LOG4CPP */
+// Second configuration...logging to log4cpp
+
+#include <log4cpp/Category.hh>
+#include <log4cpp/PropertyConfigurator.hh>
+#include <log4cpp/FileAppender.hh>
+#include <log4cpp/RollingFileAppender.hh>
+#include <log4cpp/OstreamAppender.hh>
+#include <log4cpp/PatternLayout.hh>
+
+/*!
+ * \brief GR_LOG macros
+ * \ingroup logging
+ *
+ * These macros wrap the standard LOG4CPP_LEVEL macros. The availablie macros
+ * are:
+ * GR_LOG_DEBUG
+ * GR_LOG_INFO
+ * GR_LOG_WARN
+ * GR_LOG_TRACE
+ * GR_LOG_ERROR
+ * GR_LOG_ALERT
+ * GR_LOG_CRIT
+ * GR_LOG_FATAL
+ * GR_LOG_EMERG
+ */
+typedef log4cpp::Category* gr_logger_ptr;
+
+/* Macros for Programmatic Configuration */
+#define GR_LOG_DECLARE_LOGPTR(logger) \
+ gr_logger_ptr logger;
+
+#define GR_LOG_ASSIGN_LOGPTR(logger,name) \
+ logger = gr_logger::getLogger(name);
+
+#define GR_CONFIG_LOGGER(config) \
+ logger_load_config(config)
+
+#define GR_CONFIG_AND_WATCH_LOGGER(config,period) \
+ logger_load_config_and_watch(config,period)
+
+#define GR_LOG_GETLOGGER(logger, name) \
+ gr_logger_ptr logger = gr_logger::getLogger(name);
+
+#define GR_SET_LEVEL(name, level){ \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ logger_set_level(logger,level);}
+
+#define GR_LOG_SET_LEVEL(logger, level) \
+ logger_set_level(logger, level);
+
+#define GR_GET_LEVEL(name, level){ \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ logger_get_level(logger,level);}
+
+#define GR_LOG_GET_LEVEL(logger, level) \
+ logger_get_level(logger,level);
+
+#define GR_ADD_CONSOLE_APPENDER(name,target,pattern){\
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ logger_add_console_appender(logger,target,pattern);}
+
+#define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern){\
+ logger_add_console_appender(logger,target,pattern);}
+
+#define GR_ADD_FILE_APPENDER(name,filename,append,pattern){\
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ logger_add_file_appender(logger,filename,append,pattern);}
+
+#define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern){\
+ logger_add_file_appender(logger,filename,append,pattern);}
+
+#define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern){\
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
+
+#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern){\
+ logger_add_rollingfile_appender(logger,filename,filesize,bkup_index,append,mode,pattern);}
+
+#define GR_GET_LOGGER_NAMES(names){ \
+ logger_get_logger_names(names);}
+
+#define GR_RESET_CONFIGURATION(){ \
+ logger_reset_config();}
+
+/* Logger name referenced macros */
+#define GR_DEBUG(name, msg) { \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger<< log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
+
+#define GR_INFO(name, msg) { \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger<< log4cpp::Priority::INFO << msg << log4cpp::eol;}
+
+#define GR_NOTICE(name, msg) { \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger << log4cpp::Priority::NOTICE << msg;}
+
+#define GR_WARN(name, msg) { \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger<< log4cpp::Priority::WARN << msg << log4cpp::eol;}
+
+#define GR_ERROR(name, msg) { \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;}
+
+#define GR_CRIT(name, msg) { \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger<< log4cpp::Priority::CRIT << msg << log4cpp::eol;}
+
+#define GR_ALERT(name, msg) { \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger<< log4cpp::Priority::ALERT << msg << log4cpp::eol;}
+
+#define GR_FATAL(name, msg) { \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger<< log4cpp::Priority::FATAL << msg << log4cpp::eol;}
+
+#define GR_EMERG(name, msg) { \
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;}
+
+#define GR_ERRORIF(name, cond, msg) { \
+if((cond)){\
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;};\
+};
+
+#define GR_ASSERT(name, cond, msg) { \
+if((!cond)){\
+ gr_logger_ptr logger = gr_logger::getLogger(name);\
+ *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;};\
+ assert(0);\
+};
+
+/* LoggerPtr Referenced Macros */
+#define GR_LOG_DEBUG(logger, msg) { \
+ *logger << log4cpp::Priority::DEBUG << msg << log4cpp::eol;}
+
+#define GR_LOG_INFO(logger, msg) { \
+ *logger << log4cpp::Priority::INFO << msg << log4cpp::eol;}
+
+#define GR_LOG_NOTICE(logger, msg) { \
+ *logger << log4cpp::Priority::NOTICE << msg << log4cpp::eol;}
+
+#define GR_LOG_WARN(logger, msg) { \
+ *logger << log4cpp::Priority::WARN << msg << log4cpp::eol;}
+
+#define GR_LOG_ERROR(logger, msg) { \
+ *logger << log4cpp::Priority::ERROR << msg << log4cpp::eol;}
+
+#define GR_LOG_CRIT(logger, msg) { \
+ *logger << log4cpp::Priority::CRIT << msg << log4cpp::eol;}
+
+#define GR_LOG_ALERT(logger, msg) { \
+ *logger << log4cpp::Priority::ALERT << msg << log4cpp::eol;}
+
+#define GR_LOG_FATAL(logger, msg) { \
+ *logger << log4cpp::Priority::FATAL << msg << log4cpp::eol;}
+
+#define GR_LOG_EMERG(logger, msg) { \
+ *logger << log4cpp::Priority::EMERG << msg << log4cpp::eol;}
+
+#define GR_LOG_ERRORIF(logger,cond, msg) { \
+if((!cond)){\
+ *logger<< log4cpp::Priority::ERROR << msg << log4cpp::eol;};\
+ assert(0);\
+};
+
+#define GR_LOG_ASSERT(logger, cond, msg) { \
+if((!cond)){\
+ *logger<< log4cpp::Priority::EMERG << msg << log4cpp::eol;};\
+ assert(0);\
+};
+
+/*!
+ * \brief Load logger's configuration file.
+ *
+ * Initialize the GNU Radio logger by loading the configuration file
+ * \p config_filename.
+ *
+ * \param config_filename The configuration file. Set to "" for the
+ * basic logger that outputs to the console.
+ */
+GR_CORE_API void logger_load_config(const std::string &config_filename="");
+
+
+GR_CORE_API void logger_load_config_and_watch(const std::string &config_filename,
+ unsigned int watch_period);
+
+GR_CORE_API void logger_reset_config(void);
+
+/*!
+ * \brief Set the logger's output level.
+ *
+ * Sets the level of the logger. This takes a string that is
+ * translated to the standard levels and can be (case insensitive):
+ *
+ * \li off , notset
+ * \li debug
+ * \li info
+ * \li notice
+ * \li warn
+ * \li error
+ * \li crit
+ * \li alert
+ * \li fatal
+ * \li emerg
+ *
+ * \param logger the logger to set the level of.
+ * \param level string to set the level to.
+ */
+GR_CORE_API void logger_set_level(gr_logger_ptr logger, const std::string &level);
+
+/*!
+ * \brief Set the logger's output level.
+ *
+ * Sets the level of the logger. This takes the actual Log4cpp::Priority
+ * data type, which can be:
+ *
+ * \li log4cpp::Priority::NOTSET
+ * \li log4cpp::Priority::DEBUG
+ * \li log4cpp::Priority::INFO
+ * \li log4cpp::Priority::NOTICE
+ * \li log4cpp::Priority::WARN
+ * \li log4cpp::Priority::ERROR
+ * \li log4cpp::Priority::CRIT
+ * \li log4cpp::Priority::ALERT
+ * \li log4cpp::Priority::FATAL
+ * \li log4cpp::Priority::EMERG
+ *
+ * \param logger the logger to set the level of.
+ * \param level new logger level of type Log4cpp::Priority
+ */
+void logger_set_level(gr_logger_ptr logger, log4cpp::Priority::Value level);
+
+
+/*!
+ * \brief Get the logger's output level.
+ *
+ * Gets the level of the logger. This returns a string that
+ * corresponds to the standard levels and can be (case insensitive):
+ *
+ * \li notset
+ * \li debug
+ * \li info
+ * \li notice
+ * \li warn
+ * \li error
+ * \li crit
+ * \li alert
+ * \li fatal
+ * \li emerg
+ *
+ * \param logger the logger to get the level of.
+ * \param level string to get the level into.
+ */
+GR_CORE_API void logger_get_level(gr_logger_ptr logger, std::string &level);
+
+/*!
+ * \brief Get the logger's output level.
+ *
+ * Gets the level of the logger. This returns the actual Log4cpp::Level
+ * data type, which can be:
+ *
+ * \li log4cpp::Priority::NOTSET
+ * \li log4cpp::Priority::DEBUG
+ * \li log4cpp::Priority::INFO
+ * \li log4cpp::Priority::NOTICE
+ * \li log4cpp::Priority::WARN
+ * \li log4cpp::Priority::ERROR
+ * \li log4cpp::Priority::CRIT
+ * \li log4cpp::Priority::ALERT
+ * \li log4cpp::Priority::FATAL
+ * \li log4cpp::Priority::EMERG
+ *
+ * \param logger the logger to get the level of.
+ * \param level of the logger.
+ */
+GR_CORE_API void logger_get_level(gr_logger_ptr logger, log4cpp::Priority::Value &level);
+
+GR_CORE_API void logger_add_console_appender(gr_logger_ptr logger,std::string target,std::string pattern);
+
+GR_CORE_API void logger_add_file_appender(gr_logger_ptr logger,std::string filename,bool append,std::string pattern);
+
+GR_CORE_API void logger_add_rollingfile_appender(gr_logger_ptr logger,std::string filename,
+ size_t filesize,int bkup_index,bool append,mode_t mode,std::string pattern);
+
+GR_CORE_API void logger_get_logger_names(std::vector<std::string>& names);
+
+/*!
+ * \brief instantiate (configure) logger.
+ * \ingroup logging
+ *
+ */
+class gr_logger
+{
+ public:
+ /*!
+ * \brief contructor take log configuration file and configures loggers.
+ */
+ gr_logger(std::string config_filename)
+ {
+ // Load configuration file
+ logger_load_config(config_filename);
+ };
+
+ /*!
+ * \brief contructor take log configuration file and watchtime and configures
+ */
+ gr_logger(std::string config_filename, int watchPeriodSec)
+ {
+ // Load configuration file
+ logger_load_config_and_watch(config_filename,watchPeriodSec);
+
+ };
+
+ static gr_logger_ptr getLogger(std::string name)
+ {
+ if(log4cpp::Category::exists(name)){
+ gr_logger_ptr logger = &log4cpp::Category::getInstance(name);
+ return logger;
+ }
+ else
+ {
+ gr_logger_ptr logger = &log4cpp::Category::getInstance(name);
+ logger->setPriority(log4cpp::Priority::NOTSET);
+ return logger;
+ };
+ };
+
+ // Wrappers for logging macros
+ /*! \brief inline function, wrapper to set the logger level */
+ void set_level(std::string name,std::string level){GR_SET_LEVEL(name,level);}
+
+ /*! \brief inline function, wrapper to get the logger level */
+ void get_level(std::string name,std::string &level){GR_GET_LEVEL(name,level);}
+
+ /*! \brief inline function, wrapper for DEBUG message */
+ void debug(std::string name,std::string msg){GR_DEBUG(name,msg);};
+
+ /*! \brief inline function, wrapper for INFO message */
+ void info(std::string name,std::string msg){GR_INFO(name,msg);};
+
+ /*! \brief inline function, wrapper for NOTICE message */
+ void notice(std::string name,std::string msg){GR_NOTICE(name,msg);};
+
+ /*! \brief inline function, wrapper for WARN message */
+ void warn(std::string name,std::string msg){GR_WARN(name,msg);};
+
+ /*! \brief inline function, wrapper for ERROR message */
+ void error(std::string name,std::string msg){GR_ERROR(name,msg);};
+
+ /*! \brief inline function, wrapper for CRIT message */
+ void crit(std::string name,std::string msg){GR_CRIT(name,msg);};
+
+ /*! \brief inline function, wrapper for ALERT message */
+ void alert(std::string name,std::string msg){GR_ALERT(name,msg);};
+
+ /*! \brief inline function, wrapper for FATAL message */
+ void fatal(std::string name,std::string msg){GR_FATAL(name,msg);};
+
+ /*! \brief inline function, wrapper for EMERG message */
+ void emerg(std::string name,std::string msg){GR_EMERG(name,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
+ void errorIF(std::string name,bool cond,std::string msg){GR_ERRORIF(name,cond,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
+ void gr_assert(std::string name,bool cond,std::string msg){GR_ASSERT(name,cond,msg);};
+
+ // Wrappers for Logger Pointer referenced functions
+ /*! \brief inline function, wrapper to set the logger level */
+ void set_log_level(gr_logger_ptr logger,std::string level){GR_LOG_SET_LEVEL(logger,level);}
+
+ /*! \brief inline function, wrapper to get the logger level */
+ void get_log_level(gr_logger_ptr logger,std::string &level){GR_LOG_GET_LEVEL(logger,level);}
+
+ /*! \brief inline function, wrapper for LOG4CPP_DEBUG for DEBUG message */
+ void log_debug(gr_logger_ptr logger,std::string msg){GR_LOG_DEBUG(logger,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_INFO for INFO message */
+ void log_info(gr_logger_ptr logger,std::string msg){GR_LOG_INFO(logger,msg);};
+
+ /*! \brief inline function, wrapper for NOTICE message */
+ void log_notice(gr_logger_ptr logger,std::string msg){GR_LOG_NOTICE(logger,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_WARN for WARN message */
+ void log_warn(gr_logger_ptr logger,std::string msg){GR_LOG_WARN(logger,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_ERROR for ERROR message */
+ void log_error(gr_logger_ptr logger,std::string msg){GR_LOG_ERROR(logger,msg);};
+
+ /*! \brief inline function, wrapper for NOTICE message */
+ void log_crit(gr_logger_ptr logger,std::string msg){GR_LOG_CRIT(logger,msg);};
+
+ /*! \brief inline function, wrapper for ALERT message */
+ void log_alert(gr_logger_ptr logger,std::string msg){GR_LOG_ALERT(logger,msg);};
+
+ /*! \brief inline function, wrapper for FATAL message */
+ void log_fatal(gr_logger_ptr logger,std::string msg){GR_LOG_FATAL(logger,msg);};
+
+ /*! \brief inline function, wrapper for EMERG message */
+ void log_emerg(gr_logger_ptr logger,std::string msg){GR_LOG_EMERG(logger,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
+ void log_errorIF(gr_logger_ptr logger,bool cond,std::string msg){GR_LOG_ERRORIF(logger,cond,msg);};
+
+ /*! \brief inline function, wrapper for LOG4CPP_ASSERT for conditional ERROR message */
+ void log_assert(gr_logger_ptr logger,bool cond,std::string msg){GR_LOG_ASSERT(logger,cond,msg);};
+};
+
+
+#endif /* HAVE_LOG4CPP */
+
+// If Logger disable do nothing
+#else /* ENABLE_GR_LOG */
+
+typedef void* gr_logger_ptr;
+
+#define GR_LOG_DECLARE_LOGPTR(logger)
+#define GR_LOG_ASSIGN_LOGPTR(logger,name)
+#define GR_CONFIG_LOGGER(config)
+#define GR_CONFIG_AND_WATCH_LOGGER(config,period)
+#define GR_LOG_GETLOGGER(logger, name)
+#define GR_SET_LEVEL(name, level)
+#define GR_LOG_SET_LEVEL(logger, level)
+#define GR_GET_LEVEL(name, level)
+#define GR_LOG_GET_LEVEL(logger, level)
+#define GR_ADD_CONSOLE_APPENDER(logger,target,pattern)
+#define GR_LOG_ADD_CONSOLE_APPENDER(logger,target,pattern)
+#define GR_ADD_FILE_APPENDER(name,filename,append,pattern)
+#define GR_LOG_ADD_FILE_APPENDER(logger,filename,append,pattern)
+#define GR_ADD_ROLLINGFILE_APPENDER(name,filename,filesize,bkup_index,append,mode,pattern)
+#define GR_LOG_ADD_ROLLINGFILE_APPENDER(logger,filename,filesize,bkup_index,append,mode,pattern)
+#define GR_GET_LOGGER_NAMES(names)
+#define GR_RESET_CONFIGURATION()
+#define GR_DEBUG(name, msg)
+#define GR_INFO(name, msg)
+#define GR_NOTICE(name, msg)
+#define GR_WARN(name, msg)
+#define GR_ERROR(name, msg)
+#define GR_ALERT(name, msg)
+#define GR_CRIT(name, msg)
+#define GR_FATAL(name, msg)
+#define GR_EMERG(name, msg)
+#define GR_ERRORIF(name, cond, msg)
+#define GR_ASSERT(name, cond, msg)
+#define GR_LOG_DEBUG(logger, msg)
+#define GR_LOG_INFO(logger, msg)
+#define GR_LOG_NOTICE(logger, msg)
+#define GR_LOG_WARN(logger, msg)
+#define GR_LOG_ERROR(logger, msg)
+#define GR_LOG_ALERT(logger, msg)
+#define GR_LOG_CRIT(logger, msg)
+#define GR_LOG_FATAL(logger, msg)
+#define GR_LOG_EMERG(logger, msg)
+#define GR_LOG_ERRORIF(logger, cond, msg)
+#define GR_LOG_ASSERT(logger, cond, msg)
+
+#endif /* ENABLE_GR_LOG */
+#endif /* INCLUDED_GR_LOGGER_H */
diff --git a/gnuradio-core/src/lib/runtime/gr_logger.i b/gnuradio-core/src/lib/runtime/gr_logger.i
new file mode 100644
index 0000000000..70e50e02b3
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_logger.i
@@ -0,0 +1,109 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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.
+ */
+
+/*******************************************************************************
+* Copyright 2011 Johns Hopkins University Applied Physics Lab
+* Author: Mark Plett
+* Description:
+* SWIG interface generator file for gr_logger module. gr_logger wraps log4cpp logging
+* for gnuradio.
+*******************************************************************************/
+
+%feature("autodoc", "1"); // generate python docstrings
+
+%include "exception.i"
+%import "gnuradio.i" // the common stuff
+
+%{
+#include "gnuradio_swig_bug_workaround.h" // mandatory bug fix
+#include <stdexcept>
+%}
+
+//-----------------------------------
+
+#ifdef ENABLE_GR_LOG
+#ifdef HAVE_LOG4CPP
+
+%{
+// The .h files
+#include <gr_logger.h>
+#include <log4cpp/Category.hh>
+%}
+
+namespace log4cpp{
+class LoggerPtr {
+public:
+ ~LoggerPtr();
+};
+};
+void logger_load_config(const std::string &config_filename);
+void logger_set_level(log4cpp::LoggerPtr logger, const std::string &level);
+
+%rename(log) gr_logger;
+
+class gr_logger
+{
+private:
+
+public:
+ //gr_logger(std::string config_filename);
+ gr_logger(std::string config_filename,int watchPeriodSec);
+ void set_level(std::string name,std::string level);
+ void get_level(std::string name,std::string &level);
+ void add_console_appender(std::string name,std::string target,std::string pattern);
+ void add_file_appender(std::string name,std::string filename,bool append,std::string patter);
+ void add_rollingfile_appender(std::string name,std::string filename,size_t filesize,int bkup_indx,bool append,mode_t mode,std::string pattern);
+
+ void notice(std::string name,std::string msg);
+ void debug(std::string name,std::string msg);
+ void info(std::string name,std::string msg);
+ void warn(std::string name,std::string msg);
+ void error(std::string name,std::string msg);
+ void emerg(std::string name,std::string msg);
+ void crit(std::string name,std::string msg);
+ void errorIF(std::string name,bool cond,std::string msg);
+ void gr_assert(std::string name,bool cond,std::string msg);
+
+ static gr_logger_ptr getLogger(std::string name);
+
+ void log_set_level(gr_logger_ptr logger,std::string level);
+ void log_get_level(gr_logger_ptr logger,std::string &level);
+ void log_add_console_appender(gr_logger_ptr logger,std::string target,std::string pattern);
+ void log_add_file_appender(gr_logger_ptr logger,std::string filename,bool append,std::string pattern);
+ void log_add_rollingfile_appender(gr_logger_ptr logger,std::string filename,size_t filesize,int bkup_index,bool append,mode_t mode,std::string pattern);
+
+ void log_notice(gr_logger_ptr logger,std::string msg);
+ void log_debug(gr_logger_ptr logger,std::string msg);
+ void log_info(gr_logger_ptr logger,std::string msg);
+ void log_warn(gr_logger_ptr logger,std::string msg);
+ void log_error(gr_logger_ptr logger,std::string msg);
+ void log_crit(gr_logger_ptr logger,std::string msg);
+ void log_emerg(gr_logger_ptr logger,std::string msg);
+ void log_errorIF(gr_logger_ptr logger,bool cond,std::string msg);
+ void log_assert(gr_logger_ptr logger,bool cond,std::string msg);
+
+ void get_logger_names(std::vector<std::string>& names);
+ void reset_configuration();
+
+};
+
+#endif /* HAVE_LOG4CPP */
+#endif /* ENABLE_GR_LOG */
diff --git a/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.cc b/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.cc
new file mode 100644
index 0000000000..3c4a75fd37
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.cc
@@ -0,0 +1,144 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013 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 <gr_tagged_stream_block.h>
+
+gr_tagged_stream_block::gr_tagged_stream_block (const std::string &name,
+ gr_io_signature_sptr input_signature,
+ gr_io_signature_sptr output_signature,
+ const std::string &length_tag_key)
+ : gr_block(name, input_signature, output_signature),
+ d_length_tag_key(pmt::pmt_string_to_symbol(length_tag_key)),
+ d_n_input_items_reqd(input_signature->min_streams(), 0),
+ d_length_tag_key_str(length_tag_key)
+{
+}
+
+
+// This is evil hackery: We trick the scheduler into creating the right number of input items
+void
+gr_tagged_stream_block::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ unsigned ninputs = ninput_items_required.size();
+ for (unsigned i = 0; i < ninputs; i++) {
+ if (i < d_n_input_items_reqd.size() && d_n_input_items_reqd[i] != 0) {
+ ninput_items_required[i] = d_n_input_items_reqd[i];
+ } else {
+ // If there's no item, there's no tag--so there must at least be one!
+ ninput_items_required[i] = std::max(1, (int) std::floor((double) noutput_items / relative_rate() + 0.5));
+ }
+ }
+}
+
+
+void
+gr_tagged_stream_block::parse_length_tags(
+ const std::vector<std::vector<gr_tag_t> > &tags,
+ gr_vector_int &n_input_items_reqd
+){
+ for (unsigned i = 0; i < tags.size(); i++) {
+ for (unsigned k = 0; k < tags[i].size(); k++) {
+ if (tags[i][k].key == d_length_tag_key) {
+ n_input_items_reqd[i] = pmt::pmt_to_long(tags[i][k].value);
+ remove_item_tag(i, tags[i][k]);
+ }
+ }
+ }
+}
+
+
+int
+gr_tagged_stream_block::calculate_output_stream_length(const gr_vector_int &ninput_items)
+{
+ int noutput_items = *std::max_element(ninput_items.begin(), ninput_items.end());
+ return (int) std::floor(relative_rate() * noutput_items + 0.5);
+}
+
+
+void
+gr_tagged_stream_block::update_length_tags(int n_produced, int n_ports)
+{
+ for (int i = 0; i < n_ports; i++) {
+ add_item_tag(i, nitems_written(i),
+ d_length_tag_key,
+ pmt::pmt_from_long(n_produced)
+ );
+ }
+ return;
+}
+
+
+int
+gr_tagged_stream_block::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ if (d_length_tag_key_str.empty()) {
+ return work(noutput_items, ninput_items, input_items, output_items);
+ }
+
+ if (d_n_input_items_reqd[0] == 0) { // Otherwise, it's already set from a previous call
+ std::vector<std::vector<gr_tag_t> > tags(input_items.size(), std::vector<gr_tag_t>());
+ for (unsigned i = 0; i < input_items.size(); i++) {
+ get_tags_in_range(tags[i], i, nitems_read(i), nitems_read(i)+1);
+ }
+ d_n_input_items_reqd.assign(input_items.size(), -1);
+ parse_length_tags(tags, d_n_input_items_reqd);
+ }
+ for (unsigned i = 0; i < input_items.size(); i++) {
+ if (d_n_input_items_reqd[i] == -1) {
+ throw std::runtime_error("Missing length tag.");
+ }
+ if (d_n_input_items_reqd[i] > ninput_items[i]) {
+ return 0;
+ }
+ }
+
+ int min_output_size = calculate_output_stream_length(d_n_input_items_reqd);
+ if (noutput_items < min_output_size) {
+ set_min_noutput_items(min_output_size);
+ return 0;
+ }
+ set_min_noutput_items(1);
+
+ // WORK CALLED HERE //
+ int n_produced = work(noutput_items, d_n_input_items_reqd, input_items, output_items);
+ //////////////////////
+
+ if (n_produced == WORK_DONE) {
+ return n_produced;
+ }
+ for (int i = 0; i < (int) d_n_input_items_reqd.size(); i++) {
+ consume(i, d_n_input_items_reqd[i]);
+ }
+ update_length_tags(n_produced, output_items.size());
+
+ d_n_input_items_reqd.assign(input_items.size(), 0);
+
+ return n_produced;
+}
+
diff --git a/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.h b/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.h
new file mode 100644
index 0000000000..a9d396c06f
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.h
@@ -0,0 +1,138 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013 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_GR_TAGGED_STREAM_BLOCK_H
+#define INCLUDED_GR_TAGGED_STREAM_BLOCK_H
+
+#include <gr_core_api.h>
+#include <gr_block.h>
+
+/*!
+ * \brief Block that operates on PDUs in form of tagged streams
+ * \ingroup base_blk
+ *
+ * Override work to provide the signal processing implementation.
+ */
+class GR_CORE_API gr_tagged_stream_block : public gr_block
+{
+ private:
+ pmt::pmt_t d_length_tag_key; //! This is the key for the tag that stores the PDU length
+ gr_vector_int d_n_input_items_reqd; //! How many input items do I need to process the next PDU?
+
+ protected:
+ std::string d_length_tag_key_str;
+ gr_tagged_stream_block (void){} //allows pure virtual interface sub-classes
+ gr_tagged_stream_block (const std::string &name,
+ gr_io_signature_sptr input_signature,
+ gr_io_signature_sptr output_signature,
+ const std::string &length_tag_key);
+
+ /* \brief Parse all tags on the first sample of a PDU, return the number of items per input
+ * and prune the length tags.
+ *
+ * In most cases, you don't need to override this, unless the number of items read
+ * is not directly coded in one single tag.
+ *
+ * Default behaviour:
+ * - Go through all input ports
+ * - On every input port, search for the tag with the key specified in \p length_tag_key
+ * - Copy that value as an int to the corresponding position in \p n_input_items_reqd
+ * - Remove the length tag.
+ *
+ * \param[in] tags All the tags found on the first item of every input port.
+ * \param[out] n_input_items_reqd Number of items which will be read from every input
+ */
+ virtual void parse_length_tags(
+ const std::vector<std::vector<gr_tag_t> > &tags,
+ gr_vector_int &n_input_items_reqd
+ );
+
+ /* \brief Calculate the number of output items.
+ *
+ * This is basically the inverse function to forecast(): Given a number of input
+ * items, it returns the maximum number of output items.
+ *
+ * You most likely need to override this function, unless your block is a sync
+ * block or integer interpolator/decimator.
+ *
+ */
+ virtual int calculate_output_stream_length(const gr_vector_int &ninput_items);
+
+ /* \brief Set the new length tags on the output stream
+ *
+ * Default behaviour: Set a tag with key \p length_tag_key and
+ * the number of produced items on every output port.
+ *
+ * For anything else, override this.
+ *
+ * \param n_produced Length of the new PDU
+ * \param n_ports Number of output ports
+ */
+ virtual void update_length_tags(int n_produced, int n_ports);
+
+ public:
+
+ /* \brief Don't override this.
+ */
+ void /* final */ forecast (int noutput_items, gr_vector_int &ninput_items_required);
+
+ /* - Reads the number of input items from the tags using parse_length_tags()
+ * - Checks there's enough data on the input and output buffers
+ * - If not, inform the scheduler and do nothing
+ * - Calls work() with the exact number of items per PDU
+ * - Updates the tags using update_length_tags()
+ */
+ int general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ /*!
+ * \brief Just like gr_block::general_work, but makes sure the input is valid
+ *
+ * The user must override work to define the signal processing code.
+ * Check the documentation for general_work() to see what happens here.
+ *
+ * Like gr_sync_block, this calls consume() for you (it consumes ninput_items[i]
+ * items from the i-th port).
+ *
+ * A note on tag propagation: The PDU length tags are handled by other functions,
+ * but all other tags are handled just as in any other \p gr_block. So, most likely,
+ * you either set the tag propagation policy to TPP_DONT and handle the tag
+ * propagation manually, or you propagate tags through the scheduler and don't
+ * do anything here.
+ *
+ * \param noutput_items The size of the writable output buffer
+ * \param ninput_items The exact size of the items on every input for this particular PDU.
+ * These will be consumed if a length tag key is provided!
+ * \param input_items See gr_block
+ * \param output_items See gr_block
+ */
+ virtual int work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items) = 0;
+
+};
+
+#endif /* INCLUDED_GR_TAGGED_STREAM_BLOCK_H */
+
diff --git a/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.i b/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.i
new file mode 100644
index 0000000000..9fc803dca1
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/gr_tagged_stream_block.i
@@ -0,0 +1,30 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013 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.
+ */
+class gr_tagged_stream_block : public gr_block
+{
+ protected:
+ gr_tagged_stream_block (const std::string &name,
+ gr_io_signature_sptr input_signature,
+ gr_io_signature_sptr output_signature,
+ const std::string &length_tag_key);
+};
+
diff --git a/gnuradio-core/src/lib/runtime/qa_gr_logger.cc b/gnuradio-core/src/lib/runtime/qa_gr_logger.cc
new file mode 100644
index 0000000000..a8e4a1d766
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/qa_gr_logger.cc
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2012 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.
+ */
+
+/*
+ * This class gathers together all the test cases for the example
+ * directory into a single test suite. As you create new test cases,
+ * add them here.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <qa_gr_logger.h>
+#include <gr_logger.h>
+
+void
+qa_gr_logger::t1()
+{
+#ifdef ENABLE_GR_LOG
+ // This doesn't really test anything, more just
+ // making sure nothing's gone horribly wrong.
+
+ GR_LOG_GETLOGGER(LOG,"main");
+ GR_ADD_CONSOLE_APPENDER("main","cout","%d{%H:%M:%S} : %m%n");
+ GR_LOG_NOTICE(LOG,"test from c++ NOTICE");
+ GR_LOG_DEBUG(LOG,"test from c++ DEBUG");
+ GR_LOG_INFO(LOG,"test from c++ INFO");
+ GR_LOG_WARN(LOG,"test from c++ WARN");
+ GR_LOG_ERROR(LOG,"test from c++ ERROR");
+ GR_LOG_FATAL(LOG,"test from c++ FATAL");
+ CPPUNIT_ASSERT(true);
+#endif
+}
diff --git a/gnuradio-core/src/lib/runtime/qa_gr_logger.h b/gnuradio-core/src/lib/runtime/qa_gr_logger.h
new file mode 100644
index 0000000000..b0d3711523
--- /dev/null
+++ b/gnuradio-core/src/lib/runtime/qa_gr_logger.h
@@ -0,0 +1,42 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 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 Example 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 Example Public License for more details.
+ *
+ * You should have received a copy of the GNU Example 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_QA_GR_LOG_H
+#define INCLUDED_QA_GR_LOG_H
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestSuite.h>
+
+//! collect all the tests for the example directory
+
+class qa_gr_logger : public CppUnit::TestCase {
+ public:
+ CPPUNIT_TEST_SUITE(qa_gr_logger);
+ CPPUNIT_TEST(t1);
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+ void t1();
+
+};
+
+#endif /* INCLUDED_QA_GR_LOG_H */
diff --git a/gnuradio-core/src/lib/runtime/qa_runtime.cc b/gnuradio-core/src/lib/runtime/qa_runtime.cc
index 5e62c79915..62c95ef5c4 100644
--- a/gnuradio-core/src/lib/runtime/qa_runtime.cc
+++ b/gnuradio-core/src/lib/runtime/qa_runtime.cc
@@ -34,6 +34,7 @@
#include <qa_gr_io_signature.h>
#include <qa_gr_block.h>
#include <qa_gr_flowgraph.h>
+#include <qa_gr_logger.h>
#include <qa_gr_top_block.h>
#include <qa_gr_hier_block2.h>
#include <qa_gr_hier_block2_derived.h>
@@ -50,6 +51,7 @@ qa_runtime::suite ()
s->addTest (qa_gr_io_signature::suite ());
s->addTest (qa_gr_block::suite ());
s->addTest (qa_gr_flowgraph::suite ());
+ s->addTest (qa_gr_logger::suite ());
s->addTest (qa_gr_top_block::suite ());
s->addTest (qa_gr_hier_block2::suite ());
s->addTest (qa_gr_hier_block2_derived::suite ());
diff --git a/gnuradio-core/src/lib/runtime/runtime.i b/gnuradio-core/src/lib/runtime/runtime.i
index 8e35df8342..dd7b095547 100644
--- a/gnuradio-core/src/lib/runtime/runtime.i
+++ b/gnuradio-core/src/lib/runtime/runtime.i
@@ -39,7 +39,9 @@
#include <gr_sync_block.h>
#include <gr_sync_decimator.h>
#include <gr_sync_interpolator.h>
+#include <gr_tagged_stream_block.h>
#include <gr_top_block.h>
+#include <gr_logger.h>
%}
%constant int sizeof_char = sizeof(char);
@@ -66,4 +68,6 @@
%include <gr_sync_block.i>
%include <gr_sync_decimator.i>
%include <gr_sync_interpolator.i>
+%include <gr_tagged_stream_block.i>
%include <gr_top_block.i>
+%include <gr_logger.i>
diff --git a/gnuradio-core/src/lib/swig/CMakeLists.txt b/gnuradio-core/src/lib/swig/CMakeLists.txt
index d8a64cc0f6..2c89494e78 100644
--- a/gnuradio-core/src/lib/swig/CMakeLists.txt
+++ b/gnuradio-core/src/lib/swig/CMakeLists.txt
@@ -25,9 +25,19 @@ set(GR_SWIG_INCLUDE_DIRS
${CMAKE_CURRENT_BINARY_DIR}
${GNURADIO_CORE_SWIG_INCLUDE_DIRS}
${GRUEL_INCLUDE_DIRS}
+ ${LOG4CPP_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
-set(GR_SWIG_LIBRARIES gnuradio-core)
+set(GR_SWIG_LIBRARIES
+ gnuradio-core
+ ${LOG4CPP_LIBRARIES}
+)
+
+# Only use if log4cpp is installed
+# Define ENABLE_GR_LOG for the .i file to ignore it.
+if(ENABLE_GR_LOG)
+ SET(GR_SWIG_FLAGS "-DENABLE_GR_LOG")
+endif(ENABLE_GR_LOG)
link_directories(${Boost_LIBRARY_DIRS})
diff --git a/gnuradio-core/src/lib/swig/gnuradio.i b/gnuradio-core/src/lib/swig/gnuradio.i
index 3a421ad5d6..4378e6aad2 100644
--- a/gnuradio-core/src/lib/swig/gnuradio.i
+++ b/gnuradio-core/src/lib/swig/gnuradio.i
@@ -38,6 +38,7 @@
#include <gr_types.h>
#include <stddef.h> // size_t
#include <complex>
+#include <string.h>
%}
%feature("autodoc","1");
@@ -48,6 +49,7 @@
%include <std_vector.i>
%include <stl.i>
%include <std_except.i>
+%include <std_string.i>
typedef std::complex<float> gr_complex;
typedef std::complex<double> gr_complexd;
@@ -64,7 +66,8 @@ namespace std {
%template() vector<int>;
%template() vector<float>;
%template() vector<double>;
- // %template() std::complex<float>;
+ %template() vector<std::string>;
+ %template() vector<gr_tag_t>;
%template() vector< std::complex<float> >;
%template() vector< std::vector< unsigned char > >;
diff --git a/gnuradio-core/src/lib/swig/gnuradio_swig_bug_workaround.h b/gnuradio-core/src/lib/swig/gnuradio_swig_bug_workaround.h
index 1994f06609..bbbabaf07b 100644
--- a/gnuradio-core/src/lib/swig/gnuradio_swig_bug_workaround.h
+++ b/gnuradio-core/src/lib/swig/gnuradio_swig_bug_workaround.h
@@ -40,6 +40,7 @@ class gr_msg_queue;
class gr_sync_block;
class gr_sync_decimator;
class gr_sync_interpolator;
+class gr_tagged_stream_block;
class gr_top_block;
#endif /* INCLUDED_GNURADIO_SWIG_BUG_WORKAROUND_H */