diff --git a/ircddb/IRCMessageQueue.cpp b/ircddb/IRCMessageQueue.cpp
index 315a559..7d80397 100644
--- a/ircddb/IRCMessageQueue.cpp
+++ b/ircddb/IRCMessageQueue.cpp
@@ -1,114 +1,86 @@
-#include "IRCMessageQueue.h"
+/*
+CIRCDDB - ircDDB client library in C++
+
+Based on code by:
+Copyright (C) 2010 Michael Dirska, DL1BFF (dl1bff@mdx.de)
+
+Completely rewritten by:
+Copyright (c) 2017 by Thomas A. Early N7TAE
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
+#include "IRCMessageQueue.h"
IRCMessageQueue::IRCMessageQueue()
{
- eof = false;
- first = NULL;
- last = NULL;
-
+ m_eof = false;
}
IRCMessageQueue::~IRCMessageQueue()
{
- while (messageAvailable()) {
- IRCMessage * m = getMessage();
-
- delete m;
+ accessMutex.lock();
+ while (! m_queue.empty()) {
+ delete m_queue.front();
+ m_queue.pop();
}
+ accessMutex.unlock();
}
-
bool IRCMessageQueue::isEOF()
{
- return eof;
+ return m_eof;
}
-
void IRCMessageQueue::signalEOF()
{
- eof = true;
+ m_eof = true;
}
-
bool IRCMessageQueue::messageAvailable()
{
- accessMutex.lock();
-
- IRCMessageQueueItem *m = first;
-
- accessMutex.unlock();
-
- return (m != NULL);
+ accessMutex.lock();
+ bool retv = ! m_queue.empty();
+ accessMutex.unlock();
+ return retv;
}
-
-IRCMessage * IRCMessageQueue::peekFirst()
+IRCMessage *IRCMessageQueue::peekFirst()
{
accessMutex.lock();
-
- IRCMessageQueueItem * k = first;
-
+ IRCMessage *msg = m_queue.empty() ? NULL : m_queue.front();
accessMutex.unlock();
-
- if ( k == NULL ) {
- return NULL;
- }
-
- return k->msg;
+ return msg;
}
-
-IRCMessage * IRCMessageQueue::getMessage()
+IRCMessage *IRCMessageQueue::getMessage()
{
accessMutex.lock();
-
- IRCMessageQueueItem * k;
-
- if (first == NULL) {
- return NULL;
- }
-
- k = first;
-
- first = k -> next;
-
- if (k -> next == NULL) {
- last = NULL;
- } else {
- k -> next -> prev = NULL;
- }
-
-
- IRCMessage * msg = k -> msg;
-
- delete k;
-
+ IRCMessage *msg = m_queue.empty() ? NULL : m_queue.front();
+ if (msg)
+ m_queue.pop();
accessMutex.unlock();
-
return msg;
}
-
-void IRCMessageQueue::putMessage( IRCMessage * m )
+void IRCMessageQueue::putMessage(IRCMessage *m)
{
accessMutex.lock();
+ m_queue.push(m);
+ accessMutex.unlock();
+}
- //printf("IRCMessageQueue::putMessage\n");
-
- IRCMessageQueueItem * k = new IRCMessageQueueItem(m);
-
- k -> prev = last;
- k -> next = NULL;
-
- if (last == NULL) {
- first = k;
- } else {
- last -> next = k;
- }
- last = k;
- accessMutex.unlock();
-}
diff --git a/ircddb/IRCMessageQueue.h b/ircddb/IRCMessageQueue.h
index 50e2351..f0edd76 100644
--- a/ircddb/IRCMessageQueue.h
+++ b/ircddb/IRCMessageQueue.h
@@ -1,53 +1,49 @@
-#pragma once
+/*
+CIRCDDB - ircDDB client library in C++
-#include
+Based on original code by:
+Copyright (C) 2010 Michael Dirska, DL1BFF (dl1bff@mdx.de)
-#include "IRCMessage.h"
+Completely rewritten by:
+Copyright (c) 2017 by Thomas A. Early N7TAE
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
-class IRCMessageQueueItem
-{
-public:
- IRCMessageQueueItem( IRCMessage * m ) {
- msg = m;
- }
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
- ~IRCMessageQueueItem() {
- }
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
- IRCMessage * msg;
+#pragma once
- IRCMessageQueueItem * prev;
- IRCMessageQueueItem * next;
-};
+#include
+#include
+#include "IRCMessage.h"
class IRCMessageQueue
{
public:
IRCMessageQueue();
-
~IRCMessageQueue();
bool isEOF();
-
void signalEOF();
-
bool messageAvailable();
-
- IRCMessage * getMessage();
-
- IRCMessage * peekFirst();
-
- void putMessage ( IRCMessage * m );
+ IRCMessage *getMessage();
+ IRCMessage *peekFirst();
+ void putMessage(IRCMessage *m);
private:
-
- bool eof;
-
- IRCMessageQueueItem * first;
- IRCMessageQueueItem * last;
-
+ bool m_eof;
std::mutex accessMutex;
-
+ std::queue m_queue;
};
+