- Main Page
- Namespaces
- Classes
- Files

# mqueue.h

    00001 #ifndef CRYPTOPP_MQUEUE_H
    00002 #define CRYPTOPP_MQUEUE_H
    00003
    00004 #include "queue.h"
    00005 #include "filters.h"
    00006 #include <deque>
    00007
    00008 NAMESPACE_BEGIN(CryptoPP)
    00009
    00010 //! Message Queue
    00011 class CRYPTOPP_DLL MessageQueue : public AutoSignaling<BufferedTransformation>
    00012 {
    00013 public:
    00014         MessageQueue(unsigned int nodeSize=256);
    00015
    00016         void IsolatedInitialize(const NameValuePairs &parameters)
    00017                 {m_queue.IsolatedInitialize(parameters); m_lengths.assign(1, 0U); m_messageCounts.assign(1, 0U);}
    00018         size_t Put2(const byte *begin, size_t length, int messageEnd, bool blocking)
    00019         {
    00020                 m_queue.Put(begin, length);
    00021                 m_lengths.back() += length;
    00022                 if (messageEnd)
    00023                 {
    00024                         m_lengths.push_back(0);
    00025                         m_messageCounts.back()++;
    00026                 }
    00027                 return 0;
    00028         }
    00029         bool IsolatedFlush(bool hardFlush, bool blocking) {return false;}
    00030         bool IsolatedMessageSeriesEnd(bool blocking)
    00031                 {m_messageCounts.push_back(0); return false;}
    00032
    00033         lword MaxRetrievable() const
    00034                 {return m_lengths.front();}
    00035         bool AnyRetrievable() const
    00036                 {return m_lengths.front() > 0;}
    00037
    00038         size_t TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true);
    00039         size_t CopyRangeTo2(BufferedTransformation &target, lword &begin, lword end=LWORD_MAX, const std::string &channel=DEFAULT_CHANNEL, bool blocking=true) const;
    00040
    00041         lword TotalBytesRetrievable() const
    00042                 {return m_queue.MaxRetrievable();}
    00043         unsigned int NumberOfMessages() const
    00044                 {return (unsigned int)m_lengths.size()-1;}
    00045         bool GetNextMessage();
    00046
    00047         unsigned int NumberOfMessagesInThisSeries() const
    00048                 {return m_messageCounts[0];}
    00049         unsigned int NumberOfMessageSeries() const
    00050                 {return (unsigned int)m_messageCounts.size()-1;}
    00051
    00052         unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=DEFAULT_CHANNEL) const;
    00053
    00054         const byte * Spy(size_t &contiguousSize) const;
    00055
    00056         void swap(MessageQueue &rhs);
    00057
    00058 private:
    00059         ByteQueue m_queue;
    00060         std::deque<lword> m_lengths;
    00061         std::deque<unsigned int> m_messageCounts;
    00062 };
    00063
    00064
    00065 //! A filter that checks messages on two channels for equality
    00066 class CRYPTOPP_DLL EqualityComparisonFilter : public Unflushable<Multichannel<Filter> >
    00067 {
    00068 public:
    00069         struct MismatchDetected : public Exception {MismatchDetected() : Exception(DATA_INTEGRITY_CHECK_FAILED, "EqualityComparisonFilter: did not receive the same data on two channels") {}};
    00070
    00071         /*! if throwIfNotEqual is false, this filter will output a '\\0' byte when it detects a mismatch, '\\1' otherwise */
    00072         EqualityComparisonFilter(BufferedTransformation *attachment=NULL, bool throwIfNotEqual=true, const std::string &firstChannel="0", const std::string &secondChannel="1")
    00073                 : m_throwIfNotEqual(throwIfNotEqual), m_mismatchDetected(false)
    00074                 , m_firstChannel(firstChannel), m_secondChannel(secondChannel)
    00075                 {Detach(attachment);}
    00076
    00077         size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
    00078         bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
    00079
    00080 private:
    00081         unsigned int MapChannel(const std::string &channel) const;
    00082         bool HandleMismatchDetected(bool blocking);
    00083
    00084         bool m_throwIfNotEqual, m_mismatchDetected;
    00085         std::string m_firstChannel, m_secondChannel;
    00086         MessageQueue m_q[2];
    00087 };
    00088
    00089 NAMESPACE_END
    00090
    00091 #ifndef __BORLANDC__
    00092 NAMESPACE_BEGIN(std)
    00093 template<> inline void swap(CryptoPP::MessageQueue &a, CryptoPP::MessageQueue &b)
    00094 {
    00095         a.swap(b);
    00096 }
    00097 NAMESPACE_END
    00098 #endif
    00099
    00100 #endif