00001 /***************************** License ********************************** 00002 00003 Copyright (C) 2008 by Communicative Machines 00004 http://www.cmlabs.com All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 ************************************************************************/ 00021 00022 00023 // Queue.h: interface for the Queue class. 00024 // 00025 ////////////////////////////////////////////////////////////////////// 00026 00027 #if !defined(AFX_QUEUE_H__BD4FC98D_2207_460D_9D2D_CB0E36E84650__INCLUDED_) 00028 #define AFX_QUEUE_H__BD4FC98D_2207_460D_9D2D_CB0E36E84650__INCLUDED_ 00029 00030 #if _MSC_VER > 1000 00031 #pragma once 00032 #endif // _MSC_VER > 1000 00033 00034 // #include <thread.h> 00035 // #include "Object.h" 00036 #include "Dictionary.h" 00037 #include "JSemaphore.h" 00038 00039 namespace cmlabs { 00040 00041 class Queue : public Object 00042 { 00043 public: 00044 Queue(); 00045 virtual ~Queue(); 00046 00047 bool unitTest(); 00048 00049 Object* clone() const {return NULL;} 00050 bool isEmpty(); 00051 int getCount(); 00052 bool removeAll(); 00053 //! Get total size of payload 00054 virtual unsigned long getPayloadSize() const; 00055 00056 //! Add and return newly created id 00057 JString add(JString str); 00058 JString add(JString id, JString str); 00059 00060 //! use to block until Queue is no longer empty 00061 JString waitForNewEntryID(long ms); 00062 JString waitForNewEntry(JString id, long ms); 00063 JString waitForNewEntry(long ms); 00064 00065 JString retrieveEntry(JString id); 00066 JString retrieveEntry(int pos); 00067 JString viewEntry(JString id); 00068 JString viewEntry(int pos); 00069 00070 protected: 00071 00072 Dictionary* dict; 00073 JMutex mutex; 00074 JSemaphore sem; 00075 00076 }; 00077 00078 } // namespace cmlabs 00079 00080 #endif // !defined(AFX_QUEUE_H__BD4FC98D_2207_460D_9D2D_CB0E36E84650__INCLUDED_)