1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-07 16:00:35 +00:00

Code cleaning

git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@271 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
Carles Fernandez 2012-11-01 16:39:06 +00:00
parent e659ca96b2
commit 268b4ab566

View File

@ -9,7 +9,7 @@
* *
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
* *
* Copyright (C) 2010-2011 (see AUTHORS file for a list of contributors) * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
* *
* GNSS-SDR is a software defined Global Navigation * GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver * Satellite Systems receiver
@ -56,6 +56,7 @@ ControlThread::ControlThread()
init(); init();
} }
ControlThread::ControlThread(ConfigurationInterface *configuration) ControlThread::ControlThread(ConfigurationInterface *configuration)
{ {
configuration_ = configuration; configuration_ = configuration;
@ -63,6 +64,8 @@ ControlThread::ControlThread(ConfigurationInterface *configuration)
init(); init();
} }
ControlThread::~ControlThread() ControlThread::~ControlThread()
{ {
delete flowgraph_; delete flowgraph_;
@ -70,6 +73,8 @@ ControlThread::~ControlThread()
delete control_message_factory_; delete control_message_factory_;
} }
/* /*
* Runs the control thread that manages the receiver control plane * Runs the control thread that manages the receiver control plane
* *
@ -81,7 +86,7 @@ ControlThread::~ControlThread()
*/ */
void ControlThread::run() void ControlThread::run()
{ {
// Connect the flowgraph
flowgraph_->connect(); flowgraph_->connect();
if (flowgraph_->connected()) if (flowgraph_->connected())
{ {
@ -92,7 +97,7 @@ void ControlThread::run()
LOG_AT_LEVEL(ERROR) << "Unable to connect flowgraph"; LOG_AT_LEVEL(ERROR) << "Unable to connect flowgraph";
return; return;
} }
// Start the flowgraph
flowgraph_->start(); flowgraph_->start();
if (flowgraph_->running()) if (flowgraph_->running())
{ {
@ -103,7 +108,6 @@ void ControlThread::run()
LOG_AT_LEVEL(ERROR) << "Unable to start flowgraph"; LOG_AT_LEVEL(ERROR) << "Unable to start flowgraph";
return; return;
} }
// start the keyboard_listener thread // start the keyboard_listener thread
keyboard_thread_ = boost::thread(&ControlThread::keyboard_listener, this); keyboard_thread_ = boost::thread(&ControlThread::keyboard_listener, this);
@ -114,25 +118,25 @@ void ControlThread::run()
read_control_messages(); read_control_messages();
if (control_messages_ != 0) process_control_messages(); if (control_messages_ != 0) process_control_messages();
} }
keyboard_thread_.join(); keyboard_thread_.join();
flowgraph_->stop(); flowgraph_->stop();
LOG_AT_LEVEL(INFO) << "Flowgraph stopped"; LOG_AT_LEVEL(INFO) << "Flowgraph stopped";
} }
void ControlThread::set_control_queue(gr_msg_queue_sptr control_queue) void ControlThread::set_control_queue(gr_msg_queue_sptr control_queue)
{ {
if (flowgraph_->running()) if (flowgraph_->running())
{ {
LOG_AT_LEVEL(WARNING) LOG_AT_LEVEL(WARNING) << "Unable to set control queue while flowgraph is running";
<< "Unable to set control queue while flowgraph is running";
return; return;
} }
control_queue_ = control_queue; control_queue_ = control_queue;
} }
void ControlThread::init() void ControlThread::init()
{ {
// Instantiates a control queue, a GNSS flowgraph, and a control message factory // Instantiates a control queue, a GNSS flowgraph, and a control message factory
@ -144,9 +148,10 @@ void ControlThread::init()
applied_actions_ = 0; applied_actions_ = 0;
} }
void ControlThread::read_control_messages() void ControlThread::read_control_messages()
{ {
DLOG(INFO) << "Reading control messages from queue"; DLOG(INFO) << "Reading control messages from queue";
gr_message_sptr queue_message = control_queue_->delete_head(); gr_message_sptr queue_message = control_queue_->delete_head();
if (queue_message != 0) if (queue_message != 0)
@ -160,11 +165,11 @@ void ControlThread::read_control_messages()
} }
} }
// Apply the corresponding control actions // Apply the corresponding control actions
// TODO: May be it is better to move the apply_action state machine to the control_thread // TODO: May be it is better to move the apply_action state machine to the control_thread
void ControlThread::process_control_messages() void ControlThread::process_control_messages()
{ {
for (unsigned int i = 0; i < control_messages_->size(); i++) for (unsigned int i = 0; i < control_messages_->size(); i++)
{ {
if (stop_) break; if (stop_) break;
@ -177,17 +182,16 @@ void ControlThread::process_control_messages()
flowgraph_->apply_action(control_messages_->at(i)->who, flowgraph_->apply_action(control_messages_->at(i)->who,
control_messages_->at(i)->what); control_messages_->at(i)->what);
} }
delete control_messages_->at(i); delete control_messages_->at(i);
processed_control_messages_++; processed_control_messages_++;
} }
control_messages_->clear(); control_messages_->clear();
delete control_messages_; delete control_messages_;
DLOG(INFO) << "Processed all control messages"; DLOG(INFO) << "Processed all control messages";
} }
void ControlThread::apply_action(unsigned int what) void ControlThread::apply_action(unsigned int what)
{ {
@ -201,29 +205,28 @@ void ControlThread::apply_action(unsigned int what)
default: default:
DLOG(INFO) << "Unrecognized action."; DLOG(INFO) << "Unrecognized action.";
} }
} }
void ControlThread::keyboard_listener() void ControlThread::keyboard_listener()
{ {
bool read_keys=true; bool read_keys = true;
char c; char c;
//std::cout<<"Keystroke reader start!"<<std::endl; while(read_keys)
while(read_keys) {
{ c = std::cin.get();
c= std::cin.get(); if (c =='q')
//std::cout<<"Keystroke received: "<<c<<std::endl; {
if (c=='q') std::cout << "Quit keystroke order received, stopping GNSS-SDR !!" << std::endl;
{ ControlMessageFactory* cmf = new ControlMessageFactory();
std::cout<<"Quit keystroke order received, stopping GNSS-SDR !!"<<std::endl; if (control_queue_ != gr_msg_queue_sptr())
ControlMessageFactory* cmf = new ControlMessageFactory(); {
if (control_queue_ != gr_msg_queue_sptr()) { control_queue_->handle(cmf->GetQueueMessage(200, 0));
control_queue_->handle(cmf->GetQueueMessage(200, 0)); }
} delete cmf;
delete cmf; read_keys = false;
read_keys=false; }
} }
}
} }