[svn] commit: r265 - in /branches/f2f200910/src/bin: msgq/msgbuf.c parkinglot/Makefile.am parkinglot/ccsession.cc parkinglot/main.cc parkinglot/parkinglot.cc parkinglot/parkinglot.h parkinglot/zoneset.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Oct 30 22:37:13 UTC 2009
Author: each
Date: Fri Oct 30 22:37:13 2009
New Revision: 265
Log:
parkinglot now works with command channel
Modified:
branches/f2f200910/src/bin/msgq/msgbuf.c
branches/f2f200910/src/bin/parkinglot/Makefile.am
branches/f2f200910/src/bin/parkinglot/ccsession.cc
branches/f2f200910/src/bin/parkinglot/main.cc
branches/f2f200910/src/bin/parkinglot/parkinglot.cc
branches/f2f200910/src/bin/parkinglot/parkinglot.h
branches/f2f200910/src/bin/parkinglot/zoneset.h
Modified: branches/f2f200910/src/bin/msgq/msgbuf.c
==============================================================================
--- branches/f2f200910/src/bin/msgq/msgbuf.c (original)
+++ branches/f2f200910/src/bin/msgq/msgbuf.c Fri Oct 30 22:37:13 2009
@@ -25,6 +25,7 @@
#include <isc/util.h>
#include "msgbuf.h"
+#include "cc.h"
msgbuf_t *
msgbuf_create(isc_mem_t *mctx, unsigned int length)
Modified: branches/f2f200910/src/bin/parkinglot/Makefile.am
==============================================================================
--- branches/f2f200910/src/bin/parkinglot/Makefile.am (original)
+++ branches/f2f200910/src/bin/parkinglot/Makefile.am Fri Oct 30 22:37:13 2009
@@ -1,5 +1,5 @@
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_srcdir)/ext
bin_PROGRAMS = parkinglot
-parkinglot_SOURCES = common.cc common.h main.cc zoneset.h parkinglot.cc parkinglot.h
+parkinglot_SOURCES = common.cc common.h zoneset.h parkinglot.cc parkinglot.h ccsession.cc ccsession.h main.cc
parkinglot_LDADD = $(top_srcdir)/src/lib/dns/libdns.a $(top_srcdir)/src/lib/cc/cpp/libcc.a
Modified: branches/f2f200910/src/bin/parkinglot/ccsession.cc
==============================================================================
--- branches/f2f200910/src/bin/parkinglot/ccsession.cc (original)
+++ branches/f2f200910/src/bin/parkinglot/ccsession.cc Fri Oct 30 22:37:13 2009
@@ -15,48 +15,46 @@
// $Id$
#include <stdexcept>
+#include <stdlib.h>
#include <string.h>
+
+#include <iostream>
#include <cc/cpp/data.h>
#include <cc/cpp/session.h>
-using std::string;
+#include "common.h"
+#include "ccsession.h"
-class SessionManager {
-public:
- SessionManager();
-private:
- ISC::CC::Session session_;
-};
+using namespace std;
-SessionManager::SessionManager() :
- session_(ISC::CC::Session())
-{
+CommandSession::CommandSession() : session_(ISC::CC::Session()) {
try {
session_.establish();
session_.subscribe("ParkingLot");
session_.subscribe("Boss");
} catch (...) {
- throw std::runtime_error("SessionManager: failed to open sessions");
+ throw std::runtime_error("CommandSession: failed to open sessions");
}
}
-std::pair<string, string>
-getCommand(ISC::CC::Session& session)
-{
- ISC::Data::ElementPtr ep, routing, data;
+std::pair<std::string, std::string>
+CommandSession::getCommand() {
+ ISC::Data::ElementPtr cmd, routing, data, ep;
+ string s;
- session.group_recvmsg(routing, data, false);
- ep = data->get("zone_added");
+ session_.group_recvmsg(routing, data, false);
+ cmd = data->get("command");
+
+ ep = cmd->get(0);
+ s = ep->string_value();
+ if (s == "addzone" || s == "delzone") {
+ return std::pair<string, string>(s, cmd->get(1)->string_value());
+ }
+
if (ep != NULL) {
- return std::pair<string, string>("zone_added", ep->string_value());
+ return std::pair<string, string>(s, "");
}
- ep = data->get("zone_deleted");
- if (ep != NULL) {
- return std::pair<string, string>("zone_deleted", ep->string_value());
- }
- ep = data->get("shutdown");
- if (ep != NULL) {
- return std::pair<string, string>("shutdown", "");
- }
+
+ return std::pair<string, string>("unknown", "");
}
Modified: branches/f2f200910/src/bin/parkinglot/main.cc
==============================================================================
--- branches/f2f200910/src/bin/parkinglot/main.cc (original)
+++ branches/f2f200910/src/bin/parkinglot/main.cc Fri Oct 30 22:37:13 2009
@@ -32,6 +32,7 @@
#include "zoneset.h"
#include "parkinglot.h"
+#include "ccsession.h"
#include "common.h"
@@ -69,17 +70,15 @@
ParkingLot plot(port);
// initialize command channel
- ISC::CC::Session session;
- session.establish();
- session.subscribe("parkinglot");
+ CommandSession cs;
// main server loop
fd_set fds;
int ps = plot.getSocket();
- int ss = session.getSocket();
+ int ss = cs.getSocket();
int nfds = max(ps, ss) + 1;
- cout << "server running" << endl;
+ cout << "Server started." << endl;
while (true) {
FD_ZERO(&fds);
FD_SET(ps, &fds);
@@ -89,8 +88,13 @@
if (n < 0)
throw FatalError("select error");
- if (n != 0 && FD_ISSET(ps, &fds))
+ if (FD_ISSET(ps, &fds))
plot.processMessage();
+
+ if (FD_ISSET(ss, &fds)) {
+ pair<string,string> cmd = cs.getCommand();
+ plot.command(cmd);
+ }
}
return (0);
Modified: branches/f2f200910/src/bin/parkinglot/parkinglot.cc
==============================================================================
--- branches/f2f200910/src/bin/parkinglot/parkinglot.cc (original)
+++ branches/f2f200910/src/bin/parkinglot/parkinglot.cc Fri Oct 30 22:37:13 2009
@@ -156,3 +156,13 @@
msg.getBuffer().sendTo(s, *sa, sa_len);
}
}
+
+void
+ParkingLot::command(pair<string,string> cmd) {
+ if (cmd.first == "addzone")
+ zones.serve(cmd.second);
+ else if (cmd.first == "delzone")
+ zones.forget(cmd.second);
+ else if (cmd.first == "shutdown")
+ exit(0);
+}
Modified: branches/f2f200910/src/bin/parkinglot/parkinglot.h
==============================================================================
--- branches/f2f200910/src/bin/parkinglot/parkinglot.h (original)
+++ branches/f2f200910/src/bin/parkinglot/parkinglot.h Fri Oct 30 22:37:13 2009
@@ -25,6 +25,7 @@
virtual ~ParkingLot() {};
int getSocket() { return(sock); }
void processMessage();
+ void command(std::pair<std::string,std::string>);
private:
isc::dns::Rdata::RdataPtr ns1, ns2, ns3, a, aaaa, soa;
Modified: branches/f2f200910/src/bin/parkinglot/zoneset.h
==============================================================================
--- branches/f2f200910/src/bin/parkinglot/zoneset.h (original)
+++ branches/f2f200910/src/bin/parkinglot/zoneset.h Fri Oct 30 22:37:13 2009
@@ -22,6 +22,7 @@
class ZoneSet : std::set<std::string> {
public:
void serve(std::string s) { this->insert(s); }
+ void forget(std::string s) { this->erase(s); }
bool contains(std::string s) {
return (this->find(s) != this->end());
}
More information about the bind10-changes
mailing list