From: Michal 'vorner' Vaner Date: Tue, 21 May 2013 13:58:03 +0000 (+0200) Subject: [2930] Sending notifications, C++ version X-Git-Tag: bind10-1.2.0beta1-release~431^2~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f3cd2b49392a4883751e2dbce2d8677e46d1f167;p=thirdparty%2Fkea.git [2930] Sending notifications, C++ version --- diff --git a/src/lib/cc/proto_defs.cc b/src/lib/cc/proto_defs.cc index 8f7fb91d9d..9ecaf7a767 100644 --- a/src/lib/cc/proto_defs.cc +++ b/src/lib/cc/proto_defs.cc @@ -43,6 +43,8 @@ const char* const CC_COMMAND_STOP = "stop"; // The wildcards of some headers const char* const CC_TO_WILDCARD = "*"; const char* const CC_INSTANCE_WILDCARD = "*"; +// Prefixes for groups +const char* const CC_GROUP_NOTIFICATION_PREFIX = "notifications/"; // Reply codes const int CC_REPLY_NO_RECPT = -1; const int CC_REPLY_SUCCESS = 0; diff --git a/src/lib/config/ccsession.cc b/src/lib/config/ccsession.cc index d094ab9bf6..85c9a01389 100644 --- a/src/lib/config/ccsession.cc +++ b/src/lib/config/ccsession.cc @@ -884,5 +884,21 @@ ModuleCCSession::rpcCall(const std::string &command, const std::string &group, } } +void +ModuleCCSession::notify(const std::string &group, const std::string &name, + const ConstElementPtr ¶ms) +{ + const ElementPtr message(Element::createMap()); + const ElementPtr notification(Element::createList()); + notification->add(Element::create(name)); + if (params) { + notification->add(params); + } + message->set("notification", notification); + groupSendMsg(message, isc::cc::CC_GROUP_NOTIFICATION_PREFIX + group, + isc::cc::CC_INSTANCE_WILDCARD, + isc::cc::CC_TO_WILDCARD, false); +} + } } diff --git a/src/lib/config/tests/ccsession_unittests.cc b/src/lib/config/tests/ccsession_unittests.cc index c11cd24163..ffc5434977 100644 --- a/src/lib/config/tests/ccsession_unittests.cc +++ b/src/lib/config/tests/ccsession_unittests.cc @@ -117,6 +117,28 @@ TEST_F(CCSessionTest, rpcNoRecpt) { RPCRecipientMissing); } +// Test sending a notification +TEST_F(CCSessionTest, notify) { + ModuleCCSession mccs(ccspecfile("spec1.spec"), session, NULL, NULL, false, + false); + mccs.notify("group", "event", el("{\"param\": true}")); + const ConstElementPtr notification(el( + "[" + " \"notifications/group\"," + " \"*\"," + " {" + " \"notification\": [" + " \"event\", {" + " \"param\": true" + " }" + " ]" + " }," + " -1" + "]")); + EXPECT_TRUE(notification->equals(*session.getMsgQueue()->get(1))) << + session.getMsgQueue()->get(1)->toWire(); +} + TEST_F(CCSessionTest, createAnswer) { ConstElementPtr answer; answer = createAnswer();