]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/arducontrol.h
Use a common implementation for the three different queues
[r2c2.git] / source / libr2c2 / arducontrol.h
index 69311f8280fecbb94ce0671b636a0ec4bf9fcf0d..c9a88aa56f4c30f068bda6fc40c9f673337d2284 100644 (file)
@@ -188,6 +188,18 @@ private:
                PendingCommand(Accessory &, Accessory::Command, unsigned = 0);
        };
 
+       template<typename T>
+       class Queue
+       {
+       private:
+               std::list<T> items;
+               Msp::Mutex mutex;
+
+       public:
+               void push(const T &);
+               bool pop(T &);
+       };
+
        class Task
        {
        protected:
@@ -263,8 +275,7 @@ private:
                unsigned size;
                unsigned bits;
                unsigned misses;
-               std::list<MfxInfo> queue;
-               Msp::Mutex mutex;
+               Queue<MfxInfo> queue;
 
        public:
                MfxSearchTask(ArduControl &);
@@ -272,9 +283,6 @@ private:
                virtual bool get_work(PendingCommand &);
                virtual void process_reply(const char *, unsigned);
 
-       private:
-               void push_info(const MfxInfo &);
-       public:
                bool pop_info(MfxInfo &);
        };
 
@@ -314,12 +322,12 @@ private:
        AccessoryPtrList accessory_queue;
        Accessory *active_accessory;
        Msp::Time::TimeStamp off_timeout;
-       std::list<PendingCommand> command_queue;
-       std::list<Tag> completed_commands;
 
        SensorMap sensors;
 
        Msp::Mutex mutex;
+       Queue<PendingCommand> command_queue;
+       Queue<Tag> completed_commands;
        RefreshTask refresh;
        S88Task s88;
        MfxAnnounceTask mfx_announce;
@@ -374,12 +382,6 @@ public:
 
        virtual void tick();
        virtual void flush();
-
-private:
-       void push_command(const PendingCommand &);
-       bool pop_command(PendingCommand &);
-       void push_completed_tag(const Tag &);
-       Tag pop_completed_tag();
 };
 
 } // namespace R2C2