Goby Underwater Autonomy Project
Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
|
00001 // copyright 2008, 2009 t. schneider tes@mit.edu 00002 // 00003 // this file is part of the Queue Library (libqueue), 00004 // the goby-acomms message queue manager. goby-acomms is a collection of 00005 // libraries for acoustic underwater networking 00006 // 00007 // This program 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 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // This software 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 00018 // along with this software. If not, see <http://www.gnu.org/licenses/>. 00019 00020 #ifndef Queue20080605H 00021 #define Queue20080605H 00022 00023 #include <iostream> 00024 #include <vector> 00025 #include <deque> 00026 #include <sstream> 00027 #include <bitset> 00028 #include <list> 00029 #include <string> 00030 #include <map> 00031 00032 #include <boost/algorithm/string.hpp> 00033 00034 #include "goby/util/time.h" 00035 #include "goby/util/string.h" 00036 00037 #include "goby/protobuf/queue.pb.h" 00038 #include "goby/acomms/acomms_helpers.h" 00039 00040 typedef std::list<goby::acomms::protobuf::ModemDataTransmission>::iterator messages_it; 00041 typedef std::multimap<unsigned, messages_it>::iterator waiting_for_ack_it; 00042 00043 namespace goby 00044 { 00045 namespace acomms 00046 { 00047 class Queue 00048 { 00049 public: 00050 00051 00052 Queue(const protobuf::QueueConfig cfg = protobuf::QueueConfig(), 00053 std::ostream* log = 0, 00054 int modem_id = 0); 00055 00056 bool push_message(const protobuf::ModemDataTransmission& data_msg); 00057 protobuf::ModemDataTransmission give_data(const protobuf::ModemDataRequest& request_msg); 00058 bool pop_message(unsigned frame); 00059 bool pop_message_ack(unsigned frame, protobuf::ModemDataTransmission* data_msg); 00060 void stream_for_pop(const protobuf::ModemDataTransmission& data_msg); 00061 00062 00063 std::vector<protobuf::ModemDataTransmission> expire(); 00064 00065 bool priority_values(double& priority, 00066 boost::posix_time::ptime& last_send_time, 00067 const protobuf::ModemDataRequest& request_msg, 00068 const protobuf::ModemDataTransmission& data_msg); 00069 00070 void clear_ack_queue() 00071 { waiting_for_ack_.clear(); } 00072 00073 void flush(); 00074 00075 size_t size() const 00076 { return messages_.size(); } 00077 00078 00079 boost::posix_time::ptime last_send_time() const 00080 { return last_send_time_; } 00081 00082 boost::posix_time::ptime newest_msg_time() const 00083 { 00084 return size() 00085 ? goby::util::as<boost::posix_time::ptime>(messages_.back().base().time()) 00086 : boost::posix_time::ptime(); 00087 } 00088 00089 const protobuf::QueueConfig cfg() const 00090 { return cfg_; } 00091 00092 std::string summary() const; 00093 00094 private: 00095 waiting_for_ack_it find_ack_value(messages_it it_to_find); 00096 messages_it next_message_it(); 00097 00098 private: 00099 const protobuf::QueueConfig cfg_; 00100 00101 boost::posix_time::ptime last_send_time_; 00102 00103 std::ostream* log_; 00104 00105 std::list<protobuf::ModemDataTransmission> messages_; 00106 00107 // map frame number onto messages list iterator 00108 // can have multiples in the same frame now 00109 std::multimap<unsigned, messages_it> waiting_for_ack_; 00110 00111 }; 00112 std::ostream & operator<< (std::ostream & os, const Queue & oq); 00113 } 00114 00115 } 00116 #endif