diff --git a/stepmania/src/crypto51/mqueue.cpp b/stepmania/src/crypto51/mqueue.cpp index 2bac976c8f..b24bc0752d 100644 --- a/stepmania/src/crypto51/mqueue.cpp +++ b/stepmania/src/crypto51/mqueue.cpp @@ -68,115 +68,4 @@ const byte * MessageQueue::Spy(unsigned int &contiguousSize) const // ************************************************************* -unsigned int EqualityComparisonFilter::MapChannel(const std::string &channel) const -{ - if (channel == m_firstChannel) - return 0; - else if (channel == m_secondChannel) - return 1; - else - return 2; -} - -unsigned int EqualityComparisonFilter::ChannelPut2(const std::string &channel, const byte *inString, unsigned int length, int messageEnd, bool blocking) -{ - if (!blocking) - throw BlockingInputOnly("EqualityComparisonFilter"); - - unsigned int i = MapChannel(channel); - - if (i == 2) - return Output(3, inString, length, messageEnd, blocking, channel); - else if (m_mismatchDetected) - return 0; - else - { - MessageQueue &q1 = m_q[i], &q2 = m_q[1-i]; - - if (q2.AnyMessages() && q2.MaxRetrievable() < length) - goto mismatch; - - while (length > 0 && q2.AnyRetrievable()) - { - unsigned int len = length; - const byte *data = q2.Spy(len); - len = STDMIN(len, length); - if (memcmp(inString, data, len) != 0) - goto mismatch; - inString += len; - length -= len; - q2.Skip(len); - } - - q1.Put(inString, length); - - if (messageEnd) - { - if (q2.AnyRetrievable()) - goto mismatch; - else if (q2.AnyMessages()) - q2.GetNextMessage(); - else if (q2.NumberOfMessageSeries() > 0) - goto mismatch; - else - q1.MessageEnd(); - } - - return 0; - -mismatch: - return HandleMismatchDetected(blocking); - } -} - -void EqualityComparisonFilter::ChannelInitialize(const std::string &channel, const NameValuePairs ¶meters, int propagation) -{ - unsigned int i = MapChannel(channel); - - if (i == 2) - PropagateInitialize(parameters, propagation, channel); - else - { - m_q[i].Initialize(); - m_mismatchDetected = false; - } -} - -bool EqualityComparisonFilter::ChannelMessageSeriesEnd(const std::string &channel, int propagation, bool blocking) -{ - unsigned int i = MapChannel(channel); - - if (i == 2) - { - OutputMessageSeriesEnd(4, propagation, blocking, channel); - return false; - } - else if (m_mismatchDetected) - return false; - else - { - MessageQueue &q1 = m_q[i], &q2 = m_q[1-i]; - - if (q2.AnyRetrievable() || q2.AnyMessages()) - goto mismatch; - else if (q2.NumberOfMessageSeries() > 0) - return Output(2, (const byte *)"\1", 1, 0, blocking) != 0; - else - q1.MessageSeriesEnd(); - - return false; - -mismatch: - return HandleMismatchDetected(blocking); - } -} - -bool EqualityComparisonFilter::HandleMismatchDetected(bool blocking) -{ - m_mismatchDetected = true; - if (m_throwIfNotEqual) - throw MismatchDetected(); - return Output(1, (const byte *)"\0", 1, 0, blocking) != 0; -} - NAMESPACE_END diff --git a/stepmania/src/crypto51/mqueue.h b/stepmania/src/crypto51/mqueue.h index edc701a75e..eed93122d9 100644 --- a/stepmania/src/crypto51/mqueue.h +++ b/stepmania/src/crypto51/mqueue.h @@ -61,31 +61,6 @@ private: }; -//! A filter that checks messages on two channels for equality -class EqualityComparisonFilter : public Unflushable > -{ -public: - struct MismatchDetected : public Exception {MismatchDetected() : Exception(DATA_INTEGRITY_CHECK_FAILED, "EqualityComparisonFilter: did not receive the same data on two channels") {}}; - - /*! if throwIfNotEqual is false, this filter will output a '\0' byte when it detects a mismatch, '\1' otherwise */ - EqualityComparisonFilter(BufferedTransformation *attachment=NULL, bool throwIfNotEqual=true, const std::string &firstChannel="0", const std::string &secondChannel="1") - : Unflushable >(attachment), m_throwIfNotEqual(throwIfNotEqual), m_mismatchDetected(false) - , m_firstChannel(firstChannel), m_secondChannel(secondChannel) {} - - unsigned int ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking); - - void ChannelInitialize(const std::string &channel, const NameValuePairs ¶meters=g_nullNameValuePairs, int propagation=-1); - bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true); - -private: - unsigned int MapChannel(const std::string &channel) const; - bool HandleMismatchDetected(bool blocking); - - bool m_throwIfNotEqual, m_mismatchDetected; - std::string m_firstChannel, m_secondChannel; - MessageQueue m_q[2]; -}; - NAMESPACE_END NAMESPACE_BEGIN(std)