2010-10-31 07:23:53 +00:00
|
|
|
#ifndef D_MOCK_DHT_MESSAGE_DISPATCHER_H
|
|
|
|
#define D_MOCK_DHT_MESSAGE_DISPATCHER_H
|
2008-02-11 12:32:46 +00:00
|
|
|
|
|
|
|
#include "DHTMessageDispatcher.h"
|
|
|
|
#include "DHTMessageCallback.h"
|
|
|
|
#include "DHTMessage.h"
|
|
|
|
#include "DHTConstants.h"
|
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class MockDHTMessageDispatcher : public DHTMessageDispatcher {
|
2008-02-11 12:32:46 +00:00
|
|
|
public:
|
2013-07-02 13:58:20 +00:00
|
|
|
struct Entry {
|
|
|
|
std::unique_ptr<DHTMessage> message_;
|
2015-06-07 17:03:31 +00:00
|
|
|
std::chrono::seconds timeout_;
|
2013-07-02 13:58:20 +00:00
|
|
|
std::unique_ptr<DHTMessageCallback> callback_;
|
|
|
|
|
2015-06-07 17:03:31 +00:00
|
|
|
Entry(std::unique_ptr<DHTMessage> message, std::chrono::seconds timeout,
|
2013-07-02 13:58:20 +00:00
|
|
|
std::unique_ptr<DHTMessageCallback> callback)
|
2015-12-27 09:39:47 +00:00
|
|
|
: message_{std::move(message)},
|
|
|
|
timeout_{std::move(timeout)},
|
|
|
|
callback_{std::move(callback)}
|
|
|
|
{
|
|
|
|
}
|
2008-02-11 12:32:46 +00:00
|
|
|
};
|
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
std::deque<Entry> messageQueue_;
|
2008-02-11 12:32:46 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
MockDHTMessageDispatcher() {}
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual void addMessageToQueue(
|
|
|
|
std::unique_ptr<DHTMessage> message, std::chrono::seconds timeout,
|
|
|
|
std::unique_ptr<DHTMessageCallback>
|
|
|
|
callback = std::unique_ptr<DHTMessageCallback>{}) CXX11_OVERRIDE
|
2008-02-11 12:32:46 +00:00
|
|
|
{
|
2015-12-27 09:39:47 +00:00
|
|
|
messageQueue_.push_back(
|
|
|
|
Entry(std::move(message), std::move(timeout), std::move(callback)));
|
2008-02-11 12:32:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
virtual void addMessageToQueue(
|
|
|
|
std::unique_ptr<DHTMessage> message,
|
|
|
|
std::unique_ptr<DHTMessageCallback>
|
|
|
|
callback = std::unique_ptr<DHTMessageCallback>{}) CXX11_OVERRIDE
|
2008-02-11 12:32:46 +00:00
|
|
|
{
|
2015-12-27 09:39:47 +00:00
|
|
|
messageQueue_.push_back(
|
|
|
|
Entry(std::move(message), DHT_MESSAGE_TIMEOUT, std::move(callback)));
|
2008-02-11 12:32:46 +00:00
|
|
|
}
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2013-07-06 09:15:09 +00:00
|
|
|
virtual void sendMessages() CXX11_OVERRIDE {}
|
2008-02-11 12:32:46 +00:00
|
|
|
|
2013-07-06 09:15:09 +00:00
|
|
|
virtual size_t countMessageInQueue() const CXX11_OVERRIDE
|
2008-02-11 12:32:46 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return messageQueue_.size();
|
2008-02-11 12:32:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace aria2
|
|
|
|
|
2010-10-31 07:23:53 +00:00
|
|
|
#endif // D_MOCK_DHT_MESSAGE_DISPATCHER_H
|