/// ----------------------------------------*- mode: C++; -*-- /// @file queuemanager.cpp /// queuemanager which records queues and message source IDs /// ---------------------------------------------------------- /// $Id: queuemanager.cpp 2774 2007-08-08 12:32:08Z bless $ /// $HeadURL: https://svn.ipv6.tm.uka.de/nsis/protlib/trunk/src/queuemanager.cpp $ // =========================================================== // // Copyright (C) 2005-2007, all rights reserved by // - Institute of Telematics, Universitaet Karlsruhe (TH) // // More information and contact: // https://projekte.tm.uka.de/trac/NSIS // // 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; version 2 of the License // // 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, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // // =========================================================== /** @ingroup queuemanager * */ #include #include "queuemanager.h" #include "logfile.h" namespace protlib { /** @addtogroup queuemanager Queue Manager * \ingroup fastqueue * @{ */ using namespace log; /***** class QueueManagerError *****/ QueueManagerError::QueueManagerError(error_t e) : err(e) {} const char* QueueManagerError::getstr() const { return errstr[err]; } const char* const QueueManagerError::errstr[] = { "Unable to create QueueManager.", "Cannot register FastQueue. No memory or registered queue more than once." }; // end errstr /***** class QueueManager *****/ /** Return QueueManager singleton. */ QueueManager* QueueManager::instance() { if (!inst) { // try to create singleton inst = new(nothrow) QueueManager(); if (!inst) { Log(INFO_LOG,LOG_NORMAL, "QueueManager" ,"Cannot created QueueManager singleton."); throw QueueManagerError(QueueManagerError::ERROR_NO_QUEUE_MANAGER); } else { Log(DEBUG_LOG,LOG_NORMAL, "QueueManager", "Just created QueueManager singleton."); } // end if not inst } // end if not inst return inst; } // end QueueManager /** * Delete the QueueManager singleton object. * * After a call to clear references to that object become invalid and must * be updated by a call to instance(). */ void QueueManager::clear() { if (inst) { QueueManager *tmp = inst; inst = 0; DLog("QueueManager", "Destroying QueueManager singleton ..."); delete tmp; } DLog("QueueManager", "The QueueManager singleton has been destroyed"); } /** * Register a queue. * * This registers a FastQueue for the given message source ID with the * QueueManager. * * The registered queue (and all its entries) is deleted as soon as the * QueueManager is deleted. Because of this, a queue may only be registered * once. * * @param fq pointer to an already allocated fastqueue * @param s message source ID */ void QueueManager::register_queue(FastQueue* fq, message::qaddr_t s) { pthread_mutex_lock(&mutex); // install_cleanup_mutex_lock(&mutex); // expand array if necessary if (((uint32)s)>=queue_arr.capacity()) { Log(DEBUG_LOG,LOG_NORMAL, "QueueManager", "expanding queue array from " << s << " to " << s+5); // get more memory queue_arr.reserve(s+5); while (queue_arr.size()get_name() << " has not been unregistered"); pthread_mutex_unlock(&mutex); pthread_mutex_destroy(&mutex); } //@} } // end namespace protlib