#include "../shared/CommandDispatcher.h" #include "../shared/ThreadMonitor.h" #include "../shared/ReplyToClient.h" #include "Ping.h" // Conceivably this could have been a lot more generic. These two values // could have been inputs, and we could create multiple listeners. However, // if the need should ever arise, it would make more sense for the client’s // ping command to take one or more arguments. We’d always listen for ping, // and the argument would say what to report. static const std::string listenFor = "ping"; static const std::string reportAs = "ping"; class PingListener : private RequestListener { private: void newRequest(Request *request); public: PingListener(); }; void PingListener::newRequest(Request *request) { ThreadMonitor::find().increment(reportAs); if (ExternalRequest *r = dynamic_cast< ExternalRequest * >(request)) { if (r->getProperty("response") == "1") { addToOutputQueue(request->getSocketInfo(), "", r->getResponseMessageId()); } } delete request; } PingListener::PingListener() { CommandDispatcher::getInstance()-> listenForCommand(listenFor, this, 0, false, true); } static PingListener *pingListener; void initPing() { if (!pingListener) { pingListener = new PingListener(); } }