GNU Radio 3.4.2 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2008,2009 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License along 00018 * with this program; if not, write to the Free Software Foundation, Inc., 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00020 */ 00021 #ifndef INCLUDED_THREAD_BODY_WRAPPER_H 00022 #define INCLUDED_THREAD_BODY_WRAPPER_H 00023 00024 #include <gruel/thread.h> 00025 #include <exception> 00026 #include <iostream> 00027 00028 namespace gruel 00029 { 00030 00031 void mask_signals(); 00032 00033 template <class F> 00034 class thread_body_wrapper 00035 { 00036 F d_f; 00037 std::string d_name; 00038 00039 public: 00040 00041 explicit thread_body_wrapper(F f, const std::string &name="") 00042 : d_f(f), d_name(name) {} 00043 00044 void operator()() 00045 { 00046 mask_signals(); 00047 00048 try { 00049 d_f(); 00050 } 00051 catch(boost::thread_interrupted const &) 00052 { 00053 } 00054 catch(std::exception const &e) 00055 { 00056 std::cerr << "thread[" << d_name << "]: " 00057 << e.what() << std::endl; 00058 } 00059 catch(...) 00060 { 00061 std::cerr << "thread[" << d_name << "]: " 00062 << "caught unrecognized exception\n"; 00063 } 00064 } 00065 }; 00066 } 00067 00068 #endif /* INCLUDED_THREAD_BODY_WRAPPER_H */