]> git.tdb.fi Git - r2c2.git/commitdiff
Turn ArduControl command_queue into a Task
authorMikko Rasa <tdb@tdb.fi>
Mon, 16 Feb 2015 00:17:03 +0000 (02:17 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 16 Feb 2015 00:19:45 +0000 (02:19 +0200)
It seems that I was thinking of this back in d5d8ee8, but left it
unfinished probably because it was simpler to use a Queue directly.  Now
some upcoming task management improvements call for it to be a Task.

source/libr2c2/arducontrol.cpp
source/libr2c2/arducontrol.h

index 6d75c7542dd0490fb3cde74b8b2e771560636eb1..4acfc60e0e761a0c5aaa7d4c260a0023988a8034 100644 (file)
@@ -702,6 +702,17 @@ bool ArduControl::Queue<T>::empty() const
 }
 
 
+bool ArduControl::CommandQueueTask::get_work(PendingCommand &cmd)
+{
+       return queue.pop(cmd);
+}
+
+void ArduControl::CommandQueueTask::push(const PendingCommand &cmd)
+{
+       queue.push(cmd);
+}
+
+
 ArduControl::RefreshTask::RefreshTask():
        next(cycle.end()),
        round(0),
@@ -1035,6 +1046,7 @@ ArduControl::ControlThread::ControlThread(ArduControl &c):
        control(c),
        done(false)
 {
+       tasks.push_back(&control.command_queue);
        tasks.push_back(&control.monitor);
        tasks.push_back(&control.mfx_announce);
        tasks.push_back(&control.mfx_search);
@@ -1156,9 +1168,6 @@ void ArduControl::ControlThread::init_baud_rate()
 
 bool ArduControl::ControlThread::get_work(PendingCommand &cmd)
 {
-       if(control.command_queue.pop(cmd))
-               return true;
-
        for(vector<Task *>::iterator i=tasks.begin(); i!=tasks.end(); ++i)
                if((*i)->get_work(cmd))
                        return true;
index ad14e2d4239a5182f6223b70ae3f7bea9ac88ab3..4373a84f707713e6b7d80c1e927875719b6cad0a 100644 (file)
@@ -241,6 +241,9 @@ private:
 
        public:
                virtual bool get_work(PendingCommand &);
+
+               void push(const PendingCommand &);
+               bool empty() const { return queue.empty(); }
        };
 
        class RefreshTask: public Task
@@ -387,7 +390,7 @@ private:
        SensorMap sensors;
 
        Msp::Time::TimeDelta command_timeout;
-       Queue<PendingCommand> command_queue;
+       CommandQueueTask command_queue;
        Queue<Tag> completed_commands;
        RefreshTask refresh;
        S88Task s88;