Commit 04cf72b3 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

supported statistics in an ad hoc manner


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/f2f200910@275 e5f2f494-b856-4b98-b285-d166d9295462
parent 30ab8873
......@@ -28,6 +28,9 @@
using namespace std;
using ISC::Data::Element;
using ISC::Data::ElementPtr;
CommandSession::CommandSession() :
session_(ISC::CC::Session())
{
......@@ -35,6 +38,7 @@ CommandSession::CommandSession() :
session_.establish();
session_.subscribe("ParkingLot");
session_.subscribe("Boss");
session_.subscribe("statistics");
} catch (...) {
throw std::runtime_error("SessionManager: failed to open sessions");
}
......@@ -47,44 +51,40 @@ CommandSession::getSocket()
}
std::pair<std::string, std::string>
CommandSession::getCommand() {
ISC::Data::ElementPtr cmd, routing, data, ep;
CommandSession::getCommand(int counter) {
ElementPtr cmd, routing, data, ep;
string s;
session_.group_recvmsg(routing, data, false);
cmd = data->get("command");
string channel = routing->get("group")->string_value();
if (cmd != NULL) {
ep = cmd->get(0);
if (ep != NULL) {
s = ep->string_value();
if (s == "addzone" || s == "delzone") {
return std::pair<string, string>(s,
cmd->get(1)->string_value());
if (channel == "statistics") {
cmd = data->get("command");
if (cmd != NULL && cmd->string_value() == "getstat") {
struct timeval now;
ElementPtr resp = Element::create(std::map<std::string,
ElementPtr>());
gettimeofday(&now, NULL);
resp->set("sent", Element::create(now.tv_sec +
(double)now.tv_usec /
1000000));
resp->set("counter", Element::create(counter));
session_.group_sendmsg(resp, "statistics");
}
} else {
cmd = data->get("command");
if (cmd != NULL) {
ep = cmd->get(0);
if (ep != NULL) {
s = ep->string_value();
if (s == "addzone" || s == "delzone") {
return std::pair<string, string>(s,
cmd->get(1)->string_value());
}
return std::pair<string, string>(s, "");
}
return std::pair<string, string>(s, "");
}
}
return std::pair<string, string>("unknown", "");
}
#ifdef samplecode
void
handleStatRequest()
{
ISC::Data::ElementPtr ep, routing, data;
session.group_recvmsg(routing, data, false);
ep = data->get("command");
if (ep != NULL && ep->string_value() == "getstat") {
struct timeval now;
ElementPtr resp = Element::create(std::map<std::string, ElementPtr>());
gettimeofday(&now, NULL);
resp->set("sent", Element::create(now.tv_sec +
(double)now.tv_usec / 1000000));
resp->set("counter", Element::create(++counter));
session.group_sendmsg(resp, "statistics");
}
}
#endif
......@@ -25,7 +25,7 @@ class CommandSession {
public:
CommandSession();
int getSocket();
std::pair<std::string, std::string> getCommand();
std::pair<std::string, std::string> getCommand(int counter);
private:
ISC::CC::Session session_;
};
......
......@@ -77,6 +77,7 @@ main(int argc, char* argv[]) {
int ps = plot.getSocket();
int ss = cs.getSocket();
int nfds = max(ps, ss) + 1;
int counter = 0;
cout << "Server started." << endl;
while (true) {
......@@ -88,11 +89,13 @@ main(int argc, char* argv[]) {
if (n < 0)
throw FatalError("select error");
if (FD_ISSET(ps, &fds))
if (FD_ISSET(ps, &fds)) {
++counter;
plot.processMessage();
}
if (FD_ISSET(ss, &fds)) {
pair<string,string> cmd = cs.getCommand();
pair<string,string> cmd = cs.getCommand(counter);
plot.command(cmd);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment