2 #ifndef TEMPLATE_QUEUE_H
3 #define TEMPLATE_QUEUE_H
10 #include <condition_variable>
25 std::unique_lock<std::mutex> mlock(
mutex_);
33 std::unique_lock<std::mutex> mlock(
mutex_);
40 std::unique_lock<std::mutex> mlock(
mutex_);
42 typename std::list<T>::iterator datagram_found;
43 while (
findFirstByKeyword(datagram_keywords, datagram_found) ==
false && (ret ==
true))
45 ret = (
cond_.wait_for(mlock, std::chrono::milliseconds(timeOutInMs)) == std::cv_status::no_timeout);
50 T
pop(
const std::vector<std::string>& datagram_keywords)
52 std::unique_lock<std::mutex> mlock(
mutex_);
53 typename std::list<T>::iterator datagram_found;
58 T item = *datagram_found;
59 queue_.erase(datagram_found);
66 std::unique_lock<std::mutex> mlock(
mutex_);
75 bool findFirstByKeyword(
const std::vector<std::string>& keywords,
typename std::list<T>::iterator & iter)
82 for( ; iter !=
queue_.end(); iter++)
84 std::vector<unsigned char>& datagram = iter->data();
85 uint32_t cola_b_start = 0x02020202;
86 uint8_t* datagram_keyword_start = 0;
87 int datagram_keyword_maxlen = (int)datagram.size();
88 int commandIdOffset = 1;
89 if(datagram.size() > 12 && memcmp(datagram.data(),&cola_b_start,
sizeof(cola_b_start)) == 0)
92 datagram_keyword_start = datagram.data() + 12;
93 datagram_keyword_maxlen -= 12;
95 else if(datagram.size() > 5)
98 datagram_keyword_start = datagram.data() + 5;
99 datagram_keyword_maxlen -= 5;
104 for(
int keyword_idx = 0; keyword_idx < keywords.size(); keyword_idx++)
106 const std::string&
keyword = keywords[keyword_idx];
107 if(
keyword.size() <= datagram_keyword_maxlen && memcmp(datagram_keyword_start,
keyword.data(),
keyword.size()) == 0)
116 std::string errorIdentifier =
"sFA";
117 if (datagram.size() >= (commandIdOffset + errorIdentifier.length()))
119 const char* errorIdentifierPtr = errorIdentifier.c_str();
120 const char* cmpPtr = (
const char *)(datagram.data() + commandIdOffset);
121 if (memcmp(cmpPtr, errorIdentifierPtr, errorIdentifier.length() )== 0)
123 ROS_DEBUG_STREAM(
"Queue::findFirstByKeyword(): error identifier sFA found in datagram");