00001 // vim:shiftwidth=4 sts=4 00002 // 00003 // ConnectionList - this class is simply a mutex-protected list of Connections 00004 // used by both the <yet-to-be-named-MasterProcController> and the BiDirConn 00005 // classes as a list of things it needs to manage and/or interact with. 00006 // 00007 // $Id$ 00008 00009 // ***** BEGIN LICENSE BLOCK ***** 00010 // Version: MPL 1.1/GPL 2.0/LGPL 2.1 00011 // 00012 // The contents of this file are subject to the Mozilla Public License 00013 // Version 1.1 (the "License"); you may not use this file except in 00014 // compliance with the License. You may obtain a copy of the License at 00015 // http://www.mozilla.org/MPL/ 00016 // 00017 // Software distributed under the License is distributed on an "AS IS" 00018 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00019 // the License for the specific language governing rights and limitations 00020 // under the License. 00021 // 00022 // The Original Code is the consmgr network/serial-line monitoring package. 00023 // 00024 // The Initial Developer of the Original Code is Chris P. Ross. 00025 // Portions created by the Initial Developer are Copyright (C) 2000-2008 00026 // the Initial Developer. All Rights Reserved. 00027 // 00028 // Contributor(s): 00029 // 00030 // Alternatively, the contents of this file may be used under the terms of 00031 // either the GNU General Public License Version 2 or later (the "GPL"), or 00032 // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 00033 // in which case the provisions of the GPL or the LGPL are applicable instead 00034 // of those above. If you wish to allow use of your version of this file only 00035 // under the terms of either the GPL or the LGPL, and not to allow others to 00036 // use your version of this file under the terms of the MPL, indicate your 00037 // decision by deleting the provisions above and replace them with the notice 00038 // and other provisions required by the GPL or the LGPL. If you do not delete 00039 // the provisions above, a recipient may use your version of this file under 00040 // the terms of any one of the MPL, the GPL or the LGPL. 00041 // 00042 // ***** END LICENSE BLOCK ***** 00043 00044 #include "consmgr.h" 00045 #include "connlist.h" 00046 00047 ConnectionList::ConnectionList(void) 00048 { 00049 int ret; 00050 00051 ret = pthread_mutex_init(&mutex, NULL); 00052 PTHREAD_CHECK_AND_THROW(ret, "mutex_init(ConnectionList::mutex)"); 00053 return; 00054 } 00055 00056 ConnectionList::~ConnectionList(void) 00057 { 00058 int ret; 00059 00060 ret = pthread_mutex_destroy(&mutex); 00061 PTHREAD_CHECK_AND_THROW(ret, "mutex_destroy(ConnectionList::mutex)"); 00062 return; 00063 } 00064 00065 void 00066 ConnectionList::add(const Connection *conn) 00067 { 00068 int ret; 00069 00070 ret = pthread_mutex_lock(&mutex); 00071 PTHREAD_CHECK_AND_THROW(ret, "mutex_lock(ConnectionList::mutex)"); 00072 00073 clog << "Adding " << conn << " to connection list..." << endl; 00074 list.push_back(const_cast<Connection*>(conn)); 00075 00076 ret = pthread_mutex_unlock(&mutex); 00077 PTHREAD_CHECK_AND_THROW(ret, "mutex_unlock(ConnectionList::mutex)"); 00078 return; 00079 } 00080 00081 void 00082 ConnectionList::remove(const Connection *conn) 00083 { 00084 int ret; 00085 00086 ret = pthread_mutex_lock(&mutex); 00087 PTHREAD_CHECK_AND_THROW(ret, "mutex_lock(ConnectionList::mutex)"); 00088 00089 clog << "Adding " << conn << " to connection list..." << endl; 00090 list.remove(const_cast<Connection*>(conn)); 00091 00092 ret = pthread_mutex_unlock(&mutex); 00093 PTHREAD_CHECK_AND_THROW(ret, "mutex_unlock(ConnectionList::mutex)"); 00094 return; 00095 } 00096