Find file
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (44 sloc) 1.23 KB
#pragma once
#include <boost/thread.hpp>
#include <string>
#include <list>
#include <sstream>
class UpdateListener {
public:
class Delegate {
public:
virtual bool quitRequested() = 0;
virtual void onMoved(int64_t transaction_id, const std::string& oldPath, const std::string& newPath) = 0;
virtual void onStored(int64_t transaction_id, const std::string& path) = 0;
};
UpdateListener(const std::string& server, Delegate& delegate)
: mServer(server)
, mDelegate(delegate)
{ }
UpdateListener(const UpdateListener& o)
: mServer(o.mServer)
, mDelegate(o.mDelegate)
, mLatestKnownTransaction(o.mLatestKnownTransaction)
, mCurrentHeaders()
, mCurrentData()
{ }
UpdateListener& operator=(const UpdateListener& o) {
mServer=o.mServer;
mDelegate=o.mDelegate;
mLatestKnownTransaction=o.mLatestKnownTransaction;
mCurrentHeaders.clear();
mCurrentData.clear();
return *this;
}
~UpdateListener();
void operator()();
void onDataReceived(const uint8_t* data, size_t length);
void onNewHeaderReceived(const std::string& line);
void parseUpdateLine(const std::string& line);
private:
std::string mServer;
Delegate& mDelegate;
int64_t mLatestKnownTransaction;
std::list<std::string> mCurrentHeaders;
std::stringstream mCurrentData;
};