Browse Source

[1924] Use constants when building CC message in C++

Use the newly introduced constants in the group_sendmsg method. Other
methods still need to be ported, but leaving that to other ticket.
Michal 'vorner' Vaner 12 years ago
parent
commit
6dab65b159
3 changed files with 29 additions and 17 deletions
  1. 13 10
      src/lib/cc/session.cc
  2. 4 0
      src/lib/util/common_defs.cc
  3. 12 7
      src/lib/util/common_defs.h

+ 13 - 10
src/lib/cc/session.cc

@@ -30,6 +30,11 @@
 #include <asio/deadline_timer.hpp>
 #include <asio/system_error.hpp>
 
+#include <cc/data.h>
+#include <cc/session.h>
+
+#include <util/common_defs.h>
+
 #include <cstdio>
 #include <vector>
 #include <iostream>
@@ -44,9 +49,6 @@
 
 #include <exceptions/exceptions.h>
 
-#include <cc/data.h>
-#include <cc/session.h>
-
 using namespace std;
 using namespace isc::cc;
 using namespace isc::data;
@@ -480,13 +482,14 @@ Session::group_sendmsg(ConstElementPtr msg, std::string group,
     ElementPtr env = Element::createMap();
     long int nseq = ++impl_->sequence_;
 
-    env->set("type", Element::create("send"));
-    env->set("from", Element::create(impl_->lname_));
-    env->set("to", Element::create(to));
-    env->set("group", Element::create(group));
-    env->set("instance", Element::create(instance));
-    env->set("seq", Element::create(nseq));
-    env->set("want_answer", Element::create(want_answer));
+    env->set(isc::util::CC_HEADER_TYPE,
+             Element::create(isc::util::CC_COMMAND_SEND));
+    env->set(isc::util::CC_HEADER_FROM, Element::create(impl_->lname_));
+    env->set(isc::util::CC_HEADER_TO, Element::create(to));
+    env->set(isc::util::CC_HEADER_GROUP, Element::create(group));
+    env->set(isc::util::CC_HEADER_INSTANCE, Element::create(instance));
+    env->set(isc::util::CC_HEADER_SEQ, Element::create(nseq));
+    env->set(isc::util::CC_HEADER_WANT_ANSWER, Element::create(want_answer));
 
     sendmsg(env, msg);
     return (nseq);

+ 4 - 0
src/lib/util/common_defs.cc

@@ -22,6 +22,8 @@ namespace util {
 // keep the syntax here simple and check the generated file
 // (lib/python/isc/util/common_defs.py) is correct and sane.
 
+// The constants used in the CC protocol
+// First the header names
 const char* CC_HEADER_TYPE = "type";
 const char* CC_HEADER_FROM = "from";
 const char* CC_HEADER_TO = "to";
@@ -29,6 +31,8 @@ const char* CC_HEADER_GROUP = "group";
 const char* CC_HEADER_INSTANCE = "instance";
 const char* CC_HEADER_SEQ = "seq";
 const char* CC_HEADER_WANT_ANSWER = "want_answer";
+// The commands in the "type" header
+const char* CC_COMMAND_SEND = "send";
 
 }
 }

+ 12 - 7
src/lib/util/common_defs.h

@@ -26,15 +26,20 @@ namespace util {
 // one process to another. Since the names should be self-explanatory and
 // the variables here are used mostly to synchronize the same values across
 // multiple programs, separate documentation for each variable is not provided.
+//
+// \todo Generate this header from the .cc file too. It should be simple.
 
 // Constants used in the CC protocol (sent through MSGQ)
-extern const char* CC_HEADER_TYPE;
-extern const char* CC_HEADER_FROM;
-extern const char* CC_HEADER_TO;
-extern const char* CC_HEADER_GROUP;
-extern const char* CC_HEADER_INSTANCE;
-extern const char* CC_HEADER_SEQ;
-extern const char* CC_HEADER_WANT_ANSWER;
+// First the header names.
+extern const char* CC_HEADER_TYPE; // "type"
+extern const char* CC_HEADER_FROM; // "from"
+extern const char* CC_HEADER_TO; // "to"
+extern const char* CC_HEADER_GROUP; // "group"
+extern const char* CC_HEADER_INSTANCE; // "instance"
+extern const char* CC_HEADER_SEQ; // "seq"
+extern const char* CC_HEADER_WANT_ANSWER; // "want_answer"
+// Then the commands used in the CC_HEADER_TYPE header
+extern const char* CC_COMMAND_SEND; // "send"
 
 }
 }