#ifndef NETWORK_DEPENDENCIES_POST_BOX_H #define NETWORK_DEPENDENCIES_POST_BOX_H ///////////////////////////////////// // Created by Pontus Fransson 2013 // ///////////////////////////////////// #include "IPostBox.h" #include #include "../../Misc/Thread/OysterMutex.h" namespace Oyster { namespace Network { template class PostBox : public IPostBox { public: PostBox(); virtual ~PostBox(); virtual void PostMessage(T& message); virtual void FetchMessage(T& message); virtual bool IsFull(); private: std::queue messages; OysterMutex mutex; }; //Implementation of PostBox template PostBox::PostBox() { } template PostBox::~PostBox() { } template void PostBox::PostMessage(T& message) { mutex.LockMutex(); messages.push(message); mutex.UnlockMutex(); } template void PostBox::FetchMessage(T& message) { mutex.LockMutex(); if(IsFull()) { message = messages.front(); messages.pop(); } mutex.UnlockMutex(); } template bool PostBox::IsFull() { return !messages.empty(); } } } #endif