monotone

monotone Mtn Source Tree

Root/cryptopp/mqueue.h

1#ifndef CRYPTOPP_MQUEUE_H
2#define CRYPTOPP_MQUEUE_H
3
4#include "queue.h"
5#include "filters.h"
6#include <deque>
7
8NAMESPACE_BEGIN(CryptoPP)
9
10//! Message Queue
11class MessageQueue : public AutoSignaling<BufferedTransformation>
12{
13public:
14MessageQueue(unsigned int nodeSize=256);
15
16void IsolatedInitialize(const NameValuePairs &parameters)
17{m_queue.IsolatedInitialize(parameters); m_lengths.assign(1, 0U); m_messageCounts.assign(1, 0U);}
18unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking)
19{
20m_queue.Put(begin, length);
21m_lengths.back() += length;
22if (messageEnd)
23{
24m_lengths.push_back(0);
25m_messageCounts.back()++;
26}
27return 0;
28}
29bool IsolatedFlush(bool hardFlush, bool blocking) {return false;}
30bool IsolatedMessageSeriesEnd(bool blocking)
31{m_messageCounts.push_back(0); return false;}
32
33unsigned long MaxRetrievable() const
34{return m_lengths.front();}
35bool AnyRetrievable() const
36{return m_lengths.front() > 0;}
37
38unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true);
39unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const;
40
41unsigned long TotalBytesRetrievable() const
42{return m_queue.MaxRetrievable();}
43unsigned int NumberOfMessages() const
44{return m_lengths.size()-1;}
45bool GetNextMessage();
46
47unsigned int NumberOfMessagesInThisSeries() const
48{return m_messageCounts[0];}
49unsigned int NumberOfMessageSeries() const
50{return m_messageCounts.size()-1;}
51
52unsigned int CopyMessagesTo(BufferedTransformation &target, unsigned int count=UINT_MAX, const std::string &channel=NULL_CHANNEL) const;
53
54const byte * Spy(unsigned int &contiguousSize) const;
55
56void swap(MessageQueue &rhs);
57
58private:
59ByteQueue m_queue;
60std::deque<unsigned long> m_lengths, m_messageCounts;
61};
62
63
64//! A filter that checks messages on two channels for equality
65class EqualityComparisonFilter : public Unflushable<Multichannel<Filter> >
66{
67public:
68struct MismatchDetected : public Exception {MismatchDetected() : Exception(DATA_INTEGRITY_CHECK_FAILED, "EqualityComparisonFilter: did not receive the same data on two channels") {}};
69
70/*! if throwIfNotEqual is false, this filter will output a '\0' byte when it detects a mismatch, '\1' otherwise */
71EqualityComparisonFilter(BufferedTransformation *attachment=NULL, bool throwIfNotEqual=true, const std::string &firstChannel="0", const std::string &secondChannel="1")
72: Unflushable<Multichannel<Filter> >(attachment), m_throwIfNotEqual(throwIfNotEqual), m_mismatchDetected(false)
73, m_firstChannel(firstChannel), m_secondChannel(secondChannel) {}
74
75unsigned int ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking);
76
77void ChannelInitialize(const std::string &channel, const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1);
78bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
79
80private:
81unsigned int MapChannel(const std::string &channel) const;
82bool HandleMismatchDetected(bool blocking);
83
84bool m_throwIfNotEqual, m_mismatchDetected;
85std::string m_firstChannel, m_secondChannel;
86MessageQueue m_q[2];
87};
88
89NAMESPACE_END
90
91NAMESPACE_BEGIN(std)
92template<> inline void swap(CryptoPP::MessageQueue &a, CryptoPP::MessageQueue &b)
93{
94a.swap(b);
95}
96NAMESPACE_END
97
98#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status