[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 35/50: controlport: cleanup
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 35/50: controlport: cleanup |
Date: |
Wed, 15 Apr 2015 21:07:56 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 6a5daf4f9942d0536a4507e2389e1a68f877465a
Author: Nate Goergen <address@hidden>
Date: Sat Mar 7 15:53:16 2015 -0600
controlport: cleanup
---
.../include/gnuradio/thrift_application_base.h | 87 +++++++++++-----------
.../controlport/thrift/rpcserver_booter_thrift.cc | 53 ++++++-------
.../controlport/thrift/thrift_application_base.cc | 21 ------
3 files changed, 65 insertions(+), 96 deletions(-)
diff --git a/gnuradio-runtime/include/gnuradio/thrift_application_base.h
b/gnuradio-runtime/include/gnuradio/thrift_application_base.h
index c7a57d5..dac5d58 100644
--- a/gnuradio-runtime/include/gnuradio/thrift_application_base.h
+++ b/gnuradio-runtime/include/gnuradio/thrift_application_base.h
@@ -29,37 +29,27 @@
#include <boost/date_time/posix_time/posix_time.hpp>
namespace {
- static const unsigned int THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS(600);
+ static const unsigned int THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS(200);
};
namespace apache { namespace thrift { namespace server { class TServer; } } }
-class GR_RUNTIME_API thrift_application_common
+template<typename TserverClass>
+class thrift_application_base_impl
{
- public:
- template<typename TserverBase, typename TserverClass> friend class
thrift_application_base;
- static boost::shared_ptr<thrift_application_common> Instance();
- ~thrift_application_common() {;}
- static int d_reacquire_attributes;
-
- protected:
- static bool d_main_called;
- static bool d_have_thrift_config;
- static std::string d_endpointStr;
- static boost::shared_ptr<gr::thread::thread> d_thread;
-
- apache::thrift::server::TServer* d_thriftserver;
-
- thrift_application_common() {;}
+public:
+ thrift_application_base_impl() :
+ d_application_initilized(false)
+ {
- int run(int, char*[]);
+ }
+ bool d_application_initilized;
};
template<typename TserverBase, typename TserverClass>
class thrift_application_base
{
public:
- boost::shared_ptr<thrift_application_common> d_application;
thrift_application_base(TserverClass* _this);
~thrift_application_base();
@@ -67,41 +57,51 @@ public:
static const std::vector<std::string> endpoints();
protected:
- bool have_thrift_config() { return d_application->d_have_thrift_config; }
void set_endpoint(const std::string& endpoint);
- //this one is the key... overwrite in templated/inherited variants
virtual TserverBase* i_impl() = 0;
static TserverClass* d_this;
apache::thrift::server::TServer* d_thriftserver;
+ static const unsigned int d_default_max_init_attempts;
static const unsigned int d_default_thrift_port;
static const unsigned int d_default_num_thrift_threads;
gr::logger_ptr d_logger, d_debug_logger;
private:
+ static std::auto_ptr<thrift_application_base_impl<TserverClass> > p_impl;
gr::thread::mutex d_lock;
- bool d_is_running;
+ bool d_thirft_is_running;
+
+ static std::string d_endpointStr;
+ static boost::shared_ptr<gr::thread::thread> d_start_thrift_thread;
void start_thrift();
bool application_started();
- int run(int, char*[]);
-
- static void kickoff();
+ static void start_application();
};
template<typename TserverBase, typename TserverClass>
TserverClass* thrift_application_base<TserverBase, TserverClass>::d_this(0);
+template<typename TserverBase, typename TserverClass>
+boost::shared_ptr<gr::thread::thread>
+ thrift_application_base<TserverBase, TserverClass>::d_start_thrift_thread;
+
+template<typename TserverBase, typename TserverClass>
+std::string
+ thrift_application_base<TserverBase, TserverClass>::d_endpointStr("");
template<typename TserverBase, typename TserverClass>
thrift_application_base<TserverBase,
TserverClass>::thrift_application_base(TserverClass* _this)
+ : d_lock(),
+ d_thirft_is_running(false)
{
gr::configure_default_loggers(d_logger, d_debug_logger, "controlport");
d_this = _this;
@@ -109,37 +109,38 @@ thrift_application_base<TserverBase,
TserverClass>::thrift_application_base(Tser
}
template<typename TserverBase, typename TserverClass>
-void thrift_application_base<TserverBase, TserverClass>::kickoff()
+void thrift_application_base<TserverBase, TserverClass>::start_application()
{
- //std::cerr << "thrift_application_base: kickoff" << std::endl;
+ //std::cerr << "thrift_application_base: start_application" << std::endl;
- static bool run_once = false;
-
- if(!run_once) {
- thrift_application_common::d_thread = boost::shared_ptr<gr::thread::thread>
+ if(!p_impl->d_application_initilized) {
+ d_start_thrift_thread = boost::shared_ptr<gr::thread::thread>
(new
gr::thread::thread(boost::bind(&thrift_application_base::start_thrift,
d_this)));
- int iter = 0;
- while(!d_this->application_started()) {
+ bool app_started(false);
+ for(unsigned int attempts(0); (!app_started && attempts <
d_default_max_init_attempts); ++attempts) {
boost::this_thread::sleep(boost::posix_time::milliseconds(THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS));
- if(!d_this->application_started())
+
+ app_started = d_this->application_started();
+
+ if(app_started) {
std::cerr << "@";
- if(iter++ > 100) {
- std::cerr << "thrift_application_base::c(), timeout waiting to port
number might have failed?" << std::endl;
- break;
}
}
- run_once = true;
+ if(!app_started) {
+ std::cerr << "thrift_application_base::c(), timeout waiting to port
number might have failed?" << std::endl;
+ }
+
+ p_impl->d_application_initilized = true;
}
}
-
template<typename TserverBase, typename TserverClass>
const std::vector<std::string> thrift_application_base<TserverBase,
TserverClass>::endpoints()
{
std::vector<std::string> ep;
- ep.push_back(d_this->d_application->d_endpointStr);
+ ep.push_back(d_this->d_endpointStr);
return ep;
}
@@ -147,14 +148,14 @@ template<typename TserverBase, typename TserverClass>
void thrift_application_base<TserverBase, TserverClass>::set_endpoint(const
std::string& endpoint)
{
gr::thread::scoped_lock guard(d_lock);
- d_application->d_endpointStr = endpoint;
+ d_endpointStr = endpoint;
}
template<typename TserverBase, typename TserverClass>
TserverBase* thrift_application_base<TserverBase, TserverClass>::i()
{
- if(!d_this->application_started()) {
- kickoff();
+ if(!p_impl->d_application_initilized) {
+ start_application();
}
return d_this->i_impl();
}
diff --git a/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
b/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
index 874df5b..f033b61 100644
--- a/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
+++ b/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
@@ -59,51 +59,40 @@ rpcserver_booter_thrift::endpoints()
GNURadio::ControlPortIf>::endpoints();
}
-template<typename TserverBase, typename TserverClass>
-const unsigned int thrift_application_base<TserverBase,
TserverClass>::d_default_thrift_port(0U);
+<class rpcserver_base, class rpcserver_booter_thrift>
+const unsigned int thrift_application_base<rpcserver_base,
rpcserver_booter_thrift>::d_default_max_init_attempts(100U);
-template<typename TserverBase, typename TserverClass>
-const unsigned int thrift_application_base<TserverBase,
TserverClass>::d_default_num_thrift_threads(10U);
+template<class rpcserver_base, class rpcserver_booter_thrift>
+const unsigned int thrift_application_base<rpcserver_base,
rpcserver_booter_thrift>::d_default_thrift_port(0U);
-template<typename TserverBase, typename TserverClass>
-thrift_application_base<TserverBase, TserverClass>::~thrift_application_base()
+template<class rpcserver_base, class rpcserver_booter_thrift>
+const unsigned int thrift_application_base<rpcserver_base,
rpcserver_booter_thrift>::d_default_num_thrift_threads(10U);
+
+template<class rpcserver_base, class rpcserver_booter_thrift>
+thrift_application_base<rpcserver_base,
rpcserver_booter_thrift>::~thrift_application_base()
{
GR_LOG_DEBUG(d_debug_logger, "thrift_application_base: shutdown");
- if(d_is_running) {
+ if(d_thirft_is_running) {
d_thriftserver->stop();
- d_is_running = false;
+ d_thirft_is_running = false;
}
}
-template<typename TserverBase, typename TserverClass>
-void thrift_application_base<TserverBase, TserverClass>::start_thrift()
+template<class rpcserver_base, class rpcserver_booter_thrift>
+void thrift_application_base<rpcserver_base,
rpcserver_booter_thrift>::start_thrift()
{
- //char* argv[2];
- //argv[0] = (char*)"";
- //
- //std::string conffile = gr::prefs::singleton()->get_string("ControlPort",
"config", "");
- //
- //if(conffile.size() > 0) {
- // std::stringstream thriftconf;
- // d_have_thrift_config = true;
- // d_main_called = true;
- // thriftconf << conffile;
- // main(0, argv, thriftconf.str().c_str());
- //}
- //else {
- // d_have_thrift_config = false;
- // d_main_called = true;
- // main(0, argv);
- //}
-
d_thriftserver->serve();
}
+template<class rpcserver_base, class rpcserver_booter_thrift>
+std::auto_ptr<thrift_application_base_impl<rpcserver_booter_thrift> >
+ thrift_application_base<rpcserver_base, rpcserver_booter_thrift>::p_impl(
+ new thrift_application_base_impl<rpcserver_booter_thrift>());
-template<typename TserverBase, typename TserverClass>
-bool thrift_application_base<TserverBase, TserverClass>::application_started()
+template<class rpcserver_base, typename rpcserver_booter_thrift>
+bool thrift_application_base<rpcserver_base,
rpcserver_booter_thrift>::application_started()
{
- if (d_is_running) return true;
+ if (d_thirft_is_running) return true;
bool result(false);
// Define the endpoint
@@ -123,7 +112,7 @@ bool thrift_application_base<TserverBase,
TserverClass>::application_started()
set_endpoint(endpoint);
GR_LOG_INFO(d_logger, "Apache Thrift: " + endpoint);
- d_is_running = true;
+ d_thirft_is_running = true;
result = true;
}
diff --git a/gnuradio-runtime/lib/controlport/thrift/thrift_application_base.cc
b/gnuradio-runtime/lib/controlport/thrift/thrift_application_base.cc
index 2f7ff3b..45d4b20 100644
--- a/gnuradio-runtime/lib/controlport/thrift/thrift_application_base.cc
+++ b/gnuradio-runtime/lib/controlport/thrift/thrift_application_base.cc
@@ -21,25 +21,4 @@
*/
#include <gnuradio/thrift_application_base.h>
-#include <thrift/server/TServer.h>
-int thrift_application_common::d_reacquire_attributes(0);
-bool thrift_application_common::d_main_called(false);
-bool thrift_application_common::d_have_thrift_config(false);
-boost::shared_ptr<boost::thread> thrift_application_common::d_thread;
-std::string thrift_application_common::d_endpointStr("");
-
-boost::shared_ptr<thrift_application_common>
-thrift_application_common::Instance()
-{
- static boost::shared_ptr<thrift_application_common>
- instance(new thrift_application_common());
- return instance;
-}
-
-int
-thrift_application_common::run(int, char**)
-{
- d_thriftserver->serve();
- return EXIT_SUCCESS;
-}
- [Commit-gnuradio] [gnuradio] 23/50: controlport: cleaning up and using logger to display endpoint., (continued)
- [Commit-gnuradio] [gnuradio] 23/50: controlport: cleaning up and using logger to display endpoint., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 34/50: controlport: replacement of nanosleep() with boost::sleep() in startup thread. Fix of merge error in booter_thrift., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 28/50: controlport: more cleaning up., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 31/50: controlport: moving the logger call that publishes Thrift's endpoint to i_impl()., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 24/50: controlport: adding performance and controlport monitor GRC blocks., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 29/50: controlport: changing the default port number on the Thrift interface to zero., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 21/50: controlport: Adds ability to configure Thrift through a config file, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 30/50: controlport: ephemeral / unused port number selection by OS working., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 13/50: controlport: using threaded server for multiple connections., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 39/50: controlport: documentation cleanup, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 35/50: controlport: cleanup,
git <=
- [Commit-gnuradio] [gnuradio] 33/50: controlport: more cleanup and conveniences, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 11/50: controlport: more work on the translation layer; properties and setting parameters in gr-ctrlport-monitor now working., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 45/50: controlport: ensure proper ctrlport shutdown., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 08/50: controlport: adding abstraction layer for the controlport backends; support thrift currently., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 25/50: controlport: fixing up some issues; generate thrift sources into thrift subdir., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 16/50: controlport: switching rpcpmtconverter::to_pmt() to To_PMT singleton, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 40/50: controlport: documentation cleanup, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 10/50: controlport: more cleanup of python code to help generalize the interface, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 38/50: controlport: cleanup, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 41/50: controlport: cmake fixes to FindThrift for when thrift is not installed., git, 2015/04/16