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
00011 class
MessageQueue : public AutoSignaling<
BufferedTransformation>
00012 {
00013
public:
00014
MessageQueue(
unsigned int nodeSize=256);
00015
00016
void IsolatedInitialize(
const NameValuePairs ¶meters)
00017 {m_queue.IsolatedInitialize(parameters); m_lengths.assign(1, 0U); m_messageCounts.assign(1, 0U);}
00018
unsigned int Put2(
const byte *begin,
unsigned int 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
unsigned long MaxRetrievable()
const
00034
{
return m_lengths.front();}
00035
bool AnyRetrievable()
const
00036
{
return m_lengths.front() > 0;}
00037
00038
unsigned int TransferTo2(BufferedTransformation &target,
unsigned long &transferBytes,
const std::string &channel=NULL_CHANNEL,
bool blocking=
true);
00039
unsigned int CopyRangeTo2(BufferedTransformation &target,
unsigned long &begin,
unsigned long end=ULONG_MAX,
const std::string &channel=NULL_CHANNEL,
bool blocking=
true)
const;
00040
00041
unsigned long TotalBytesRetrievable()
const
00042
{
return m_queue.MaxRetrievable();}
00043
unsigned int NumberOfMessages()
const
00044
{
return 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 m_messageCounts.size()-1;}
00051
00052
unsigned int CopyMessagesTo(BufferedTransformation &target,
unsigned int count=UINT_MAX,
const std::string &channel=NULL_CHANNEL)
const;
00053
00054
const byte * Spy(
unsigned int &contiguousSize)
const;
00055
00056
void swap(
MessageQueue &rhs);
00057
00058
private:
00059
ByteQueue m_queue;
00060 std::deque<unsigned long> m_lengths, m_messageCounts;
00061 };
00062
00063
00064
00065 class EqualityComparisonFilter :
public Unflushable<Multichannel<Filter> >
00066 {
00067
public:
00068
struct MismatchDetected :
public Exception {MismatchDetected() :
Exception(DATA_INTEGRITY_CHECK_FAILED,
"EqualityComparisonFilter: did not receive the same data on two channels") {}};
00069
00070
00071 EqualityComparisonFilter(
BufferedTransformation *attachment=NULL,
bool throwIfNotEqual=
true,
const std::string &firstChannel=
"0",
const std::string &secondChannel=
"1")
00072 : Unflushable<Multichannel<
Filter> >(attachment), m_throwIfNotEqual(throwIfNotEqual), m_mismatchDetected(false)
00073 , m_firstChannel(firstChannel), m_secondChannel(secondChannel) {}
00074
00075
unsigned int ChannelPut2(
const std::string &channel,
const byte *begin,
unsigned int length,
int messageEnd,
bool blocking);
00076
00077
void ChannelInitialize(
const std::string &channel,
const NameValuePairs ¶meters=g_nullNameValuePairs,
int propagation=-1);
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 NAMESPACE_BEGIN(std)
00092 template<> inline
void swap(CryptoPP::
MessageQueue &a, CryptoPP::
MessageQueue &b)
00093 {
00094 a.swap(b);
00095 }
00096 NAMESPACE_END
00097
00098
#endif