00001 /* 00002 * Copyright (C) 2006, Jose Renato Santos. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 */ 00017 00018 /////////////////////////////////////////////////////////////////////////////// 00019 // msgqueue.h -- singely linked fifo queue for router messages 00020 /////////////////////////////////////////////////////////////////////////////// 00021 00022 #ifndef __MSGQUEUE_H_ 00023 #define __MSGQUEUE_H_ 00024 00025 #include "rioqueue.h" 00026 #include "riofreelist.h" 00027 00028 #include "msgrouterstorage.h" 00029 00030 // queue element structure 00031 00032 struct StrMsg { 00033 StrMsg* linkf; 00034 MsgRSS Msg; 00035 }; 00036 00037 /////////////////////////////////////////////////////////////////////////////// 00038 class CMsgQueue { 00039 public: 00040 void Put(StrMsg *Element); // Put element on queue 00041 StrMsg* Get() ; // wait for available element and get 00042 // first element on queue 00043 void Signal(); // If there is a thread waiting 00044 // for an element unblock thread 00045 // making Get() return NULL 00046 private: 00047 RioQueue m_Queue; 00048 }; 00049 00050 /////////////////////////////////////////////////////////////////////////////// 00051 class CMsgManager { 00052 public: 00053 CMsgManager(); 00054 ~CMsgManager(); 00055 int Initialize(const unsigned int nMsg); 00056 void Free(StrMsg* Msg); // Return message to free list 00057 StrMsg* New(); // Wait for available free message 00058 // slot and get it when available 00059 private: 00060 CRioFreeList m_FreeList; 00061 StrMsg* m_Msg; 00062 }; 00063 00064 #endif //_MSGQUEUE_H__ 00065