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 // ObjectQueue.h: interface for the ObjectQueue class. 00024 // 00025 ////////////////////////////////////////////////////////////////////// 00026 00027 #if !defined(AFX_OBJECTQUEUE_H__49E44B86_BFB0_463A_BB0A_998CA086D94B__INCLUDED_) 00028 #define AFX_OBJECTQUEUE_H__49E44B86_BFB0_463A_BB0A_998CA086D94B__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 "ObjectDictionary.h" 00037 #include "JSemaphore.h" 00038 #include "Queue.h" 00039 00040 namespace cmlabs { 00041 00042 class ObjectQueue : public Object 00043 { 00044 public: 00045 ObjectQueue(); 00046 virtual ~ObjectQueue(); 00047 00048 bool unitTest(); 00049 00050 Object* clone() const {return NULL;} 00051 bool isEmpty(); 00052 int getCount(); 00053 bool removeAll(); 00054 ObjectCollection* retrieveAll(); 00055 00056 //! Add and return newly created id 00057 JString add(Object* obj); 00058 JString add(JString id, Object* obj); 00059 //! Get total size of payload 00060 virtual unsigned long getPayloadSize() const; 00061 00062 //! use to block until Queue is no longer empty 00063 JString waitForNewEntryID(long ms); 00064 bool waitForNewEntryToAppear(long ms); 00065 Object* waitForNewEntry(long ms); 00066 Object* waitForNewEntry(JString id, long ms); 00067 Object* retrieveEntry(JString id); 00068 Object* retrieveEntry(int pos); 00069 Object* viewEntry(JString id); 00070 Object* viewEntry(int pos); 00071 00072 // *************************************************************** 00073 // Binary Functions 00074 // *************************************************************** 00075 00076 //! Get the size of binary data chunk, -1 for all chunks 00077 long getBinarySize(int chunk); 00078 //! Get the number of data chunks 00079 int getBinaryChunkCount(); 00080 //! Write binary data to buffer at chunk number 'chunk' 00081 long toBinaryBuffer(int chunk, char* buffer, int maxlen); 00082 //! Set the data after separate reception 00083 bool fromBinaryBuffer(int chunk, char* buffer, long len); 00084 00085 ObjectDictionary* dict; 00086 00087 protected: 00088 00089 JMutex mutex; 00090 JSemaphore sem; 00091 00092 }; 00093 00094 } // namespace cmlabs 00095 00096 #endif // !defined(AFX_OBJECTQUEUE_H__49E44B86_BFB0_463A_BB0A_998CA086D94B__INCLUDED_)