00001 /*******************************************************************\ 00002 00003 SESAME project software license 00004 00005 Copyright (C) 2002 University of Amsterdam 00006 00007 This program is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License 00009 as published by the Free Software Foundation; either version 2 00010 of the License, or (at your option) any later version. 00011 00012 This program 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 program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00020 02111-1307, USA. 00021 00022 For information regarding the SESAME software project see 00023 http://sesamesim.sourceforge.net or email 00024 jcofflan@users.sourceforge.net 00025 00026 \*******************************************************************/ 00027 00028 #ifndef PNCONNECTION_H 00029 #define PNCONNECTION_H 00030 00031 #include "datablockclass.h" 00032 00033 #include <ymlconnection.h> 00034 #include <BasicUtils/BasicCondition.h> 00035 #include <BasicUtils/BasicException.h> 00036 00037 #include <pthread.h> 00038 #include <iostream> 00039 #include <list> 00040 00041 // Forward declarations 00042 class ProcessLoader; 00043 class YMLPort; 00044 00046 00054 class PNConnection : public BasicCondition, public YMLConnection { 00055 // Attributes 00056 private: 00057 std::list<DataBlockClass *> dataQueue; 00058 unsigned int dataQueueSize; 00059 00060 ProcessLoader *reader; 00061 ProcessLoader *writer; 00062 YMLPort *readerPort; 00063 YMLPort *writerPort; 00064 00067 unsigned int sizeLimit; 00068 00070 int numReads; 00071 00073 int numWrites; 00074 00075 // Operations 00076 public: 00077 PNConnection(); 00078 ~PNConnection(); 00079 00080 DataBlockClass *read(); 00081 void write(DataBlockClass *data); 00082 int getNumReads() {return numReads;} 00083 int getNumWrites() {return numWrites;} 00084 00085 00087 void clear() {lock(); dataQueue.clear(); dataQueueSize = 0; unlock();} 00088 bool isEmpty(); 00089 unsigned int getSize(); 00090 00091 ProcessLoader *getWriter() {return writer;} 00092 ProcessLoader *getReader() {return reader;} 00093 void setReader(ProcessLoader *reader, YMLPort *port) 00094 {ASSERT_OR_THROW("NULL parameter", reader && port); 00095 this->reader = reader; readerPort = port;} 00096 void setWriter(ProcessLoader *writer, YMLPort *port) 00097 {ASSERT_OR_THROW("NULL parameter", writer && port); 00098 this->writer = writer; writerPort = port;} 00099 YMLPort *getReaderPort() {return readerPort;} 00100 YMLPort *getWriterPort() {return writerPort;} 00101 }; 00102 00103 std::ostream &operator<<(std::ostream &stream, PNConnection &c); 00104 #endif 00105