[svn] commit: r869 - in /branches/jelte-configuration/src: bin/auth/main.cc bin/parkinglot/main.cc lib/config/cpp/ccsession.cc lib/config/cpp/ccsession.h lib/config/cpp/data_def.cc lib/config/cpp/data_def.h lib/config/cpp/data_def_unittests.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Feb 18 14:11:43 UTC 2010


Author: jelte
Date: Thu Feb 18 14:11:43 2010
New Revision: 869

Log:
sync cpp part with python part (similar functionality and function/class names)

Modified:
    branches/jelte-configuration/src/bin/auth/main.cc
    branches/jelte-configuration/src/bin/parkinglot/main.cc
    branches/jelte-configuration/src/lib/config/cpp/ccsession.cc
    branches/jelte-configuration/src/lib/config/cpp/ccsession.h
    branches/jelte-configuration/src/lib/config/cpp/data_def.cc
    branches/jelte-configuration/src/lib/config/cpp/data_def.h
    branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc

Modified: branches/jelte-configuration/src/bin/auth/main.cc
==============================================================================
--- branches/jelte-configuration/src/bin/auth/main.cc (original)
+++ branches/jelte-configuration/src/bin/auth/main.cc Thu Feb 18 14:11:43 2010
@@ -106,7 +106,7 @@
         } else {
             specfile = std::string(AUTH_SPECFILE_LOCATION);
         }
-        CommandSession cs = CommandSession(specfile,
+        ModuleCCSession cs = ModuleCCSession(specfile,
                                            my_config_handler,
                                            my_command_handler);
     

Modified: branches/jelte-configuration/src/bin/parkinglot/main.cc
==============================================================================
--- branches/jelte-configuration/src/bin/parkinglot/main.cc (original)
+++ branches/jelte-configuration/src/bin/parkinglot/main.cc Thu Feb 18 14:11:43 2010
@@ -110,7 +110,7 @@
         } else {
             specfile = std::string(PARKINGLOT_SPECFILE_LOCATION);
         }
-        CommandSession cs = CommandSession(specfile, my_config_handler, my_command_handler);
+        ModuleCCSession cs = ModuleCCSession(specfile, my_config_handler, my_command_handler);
     
         // main server loop
         fd_set fds;

Modified: branches/jelte-configuration/src/lib/config/cpp/ccsession.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/ccsession.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/ccsession.cc Thu Feb 18 14:11:43 2010
@@ -50,7 +50,7 @@
 using isc::data::ModuleSpecError;
 
 void
-CommandSession::read_data_definition(const std::string& filename) {
+ModuleCCSession::read_module_specification(const std::string& filename) {
     std::ifstream file;
 
     // this file should be declared in a @something@ directive
@@ -61,27 +61,27 @@
     }
 
     try {
-        data_definition_ = ModuleSpec(file, true);
+        module_specification_ = ModuleSpec(file, true);
     } catch (ParseError pe) {
-        cout << "Error parsing definition file: " << pe.what() << endl;
+        cout << "Error parsing module specification file: " << pe.what() << endl;
         exit(1);
     } catch (ModuleSpecError dde) {
-        cout << "Error reading definition file: " << dde.what() << endl;
+        cout << "Error reading module specification file: " << dde.what() << endl;
         exit(1);
     }
     file.close();
 }
 
-CommandSession::CommandSession(std::string spec_file_name,
+ModuleCCSession::ModuleCCSession(std::string spec_file_name,
                                isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config),
                                isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command)
                               ) throw (isc::cc::SessionError):
     session_(isc::cc::Session())
 {
-    read_data_definition(spec_file_name);
+    read_module_specification(spec_file_name);
     sleep(1);
 
-    module_name_ = data_definition_.getDefinition()->get("module_spec")->get("module_name")->stringValue();
+    module_name_ = module_specification_.getFullSpec()->get("module_spec")->get("module_name")->stringValue();
     config_handler_ = config_handler;
     command_handler_ = command_handler;
 
@@ -96,7 +96,7 @@
     //session_.subscribe("Boss", "*");
     //session_.subscribe("statistics", "*");
     // send the data specification
-    session_.group_sendmsg(data_definition_.getDefinition(), "ConfigManager");
+    session_.group_sendmsg(module_specification_.getFullSpec(), "ConfigManager");
     session_.group_recvmsg(env, answer, false);
     
     // get any stored configuration from the manager
@@ -116,13 +116,13 @@
 }
 
 int
-CommandSession::getSocket()
+ModuleCCSession::getSocket()
 {
     return (session_.getSocket());
 }
 
 int
-CommandSession::check_command()
+ModuleCCSession::check_command()
 {
     cout << "[XX] check for command" << endl;
     ElementPtr cmd, routing, data;

Modified: branches/jelte-configuration/src/lib/config/cpp/ccsession.h
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/ccsession.h (original)
+++ branches/jelte-configuration/src/lib/config/cpp/ccsession.h Thu Feb 18 14:11:43 2010
@@ -23,20 +23,20 @@
 #include <cc/session.h>
 #include <cc/data.h>
 
-class CommandSession {
+class ModuleCCSession {
 public:
     /**
      * Initialize a config/command session
      * @param module_name: The name of this module. This is not a
      *                     reference because we expect static strings
      *                     to be passed here.
-     * @param spec_file_name: The name of the file containing the data
-     *                        definition.
+     * @param spec_file_name: The name of the file containing the
+     *                        module specification.
      */
-    CommandSession(std::string spec_file_name,
-                   isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config) = NULL,
-                   isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command) = NULL
-                  ) throw (isc::cc::SessionError);
+    ModuleCCSession(std::string spec_file_name,
+                    isc::data::ElementPtr(*config_handler)(isc::data::ElementPtr new_config) = NULL,
+                    isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command) = NULL
+                    ) throw (isc::cc::SessionError);
     int getSocket();
 
     /**
@@ -71,11 +71,11 @@
     void set_command_handler(isc::data::ElementPtr(*command_handler)(isc::data::ElementPtr command)) { command_handler_ = command_handler; };
     
 private:
-    void read_data_definition(const std::string& filename);
+    void read_module_specification(const std::string& filename);
     
     std::string module_name_;
     isc::cc::Session session_;
-    isc::data::ModuleSpec data_definition_;
+    isc::data::ModuleSpec module_specification_;
     isc::data::ElementPtr config_;
 
     isc::data::ElementPtr(*config_handler_)(isc::data::ElementPtr new_config);

Modified: branches/jelte-configuration/src/lib/config/cpp/data_def.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/data_def.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/data_def.cc Thu Feb 18 14:11:43 2010
@@ -25,6 +25,10 @@
 // todo: add more context to thrown ModuleSpecErrors?
 
 using namespace isc::data;
+
+//
+// static functions
+//
 
 // todo: is there a direct way to get a std::string from an enum label?
 static std::string
@@ -98,7 +102,7 @@
                     !spec->get("item_optional")->boolValue()
                    );
 
-    // if list, check the list definition
+    // if list, check the list specification
     if (getType_value(spec->get("item_type")->stringValue()) == Element::list) {
         check_leaf_item(spec, "list_item_spec", Element::map, true);
         check_config_item(spec->get("list_item_spec"));
@@ -150,10 +154,10 @@
     }
 }
 
-// checks whether the given element is a valid data definition
+// checks whether the given element is a valid module specification
 // throws a ModuleSpecError if the specification is bad
 static void
-check_definition(const ElementPtr& def)
+check_module_specification(const ElementPtr& def)
 {
     if (!def->contains("module_spec")) {
         throw ModuleSpecError("Data specification does not contain module_spec element");
@@ -161,6 +165,10 @@
         check_data_specification(def->get("module_spec"));
     }
 }
+
+//
+// Public functions
+//
 
 ModuleSpec::ModuleSpec(const std::string& file_name,
                                const bool check)
@@ -174,20 +182,59 @@
         throw ModuleSpecError(errs.str());
     }
 
-    definition = Element::createFromString(file, file_name);
+    module_specification = Element::createFromString(file, file_name);
     if (check) {
-        check_definition(definition);
-    }
-}
+        check_module_specification(module_specification);
+    }
+}
+
 
 ModuleSpec::ModuleSpec(std::istream& in, const bool check)
                                throw(ParseError, ModuleSpecError) {
-    definition = Element::createFromString(in);
+    module_specification = Element::createFromString(in);
     // make sure the whole structure is complete and valid
     if (check) {
-        check_definition(definition);
-    }
-}
+        check_module_specification(module_specification);
+    }
+}
+
+const ElementPtr
+ModuleSpec::getCommandsSpec()
+{
+    if (module_specification->contains("commands")) {
+        return module_specification->get("commands");
+    } else {
+        return ElementPtr();
+    }
+}
+
+const ElementPtr
+ModuleSpec::getConfigSpec()
+{
+    if (module_specification->contains("config_data")) {
+        return module_specification->get("config_data");
+    } else {
+        return ElementPtr();
+    }
+}
+
+const std::string
+ModuleSpec::getModuleName()
+{
+    return module_specification->get("module_name")->stringValue();
+}
+
+bool
+ModuleSpec::validate(const ElementPtr data)
+{
+    ElementPtr spec = module_specification->find("module_spec/config_data");
+    return validate_spec_list(spec, data);
+}
+
+
+//
+// private functions
+//
 
 //
 // helper functions for validation
@@ -285,12 +332,3 @@
     return true;
 }
 
-// TODO
-// this function does *not* check if the specification is in correct
-// form, we should do that in the constructor
-bool
-ModuleSpec::validate(const ElementPtr data) {
-    ElementPtr spec = definition->find("module_spec/config_data");
-    return validate_spec_list(spec, data);
-}
-

Modified: branches/jelte-configuration/src/lib/config/cpp/data_def.h
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/data_def.h (original)
+++ branches/jelte-configuration/src/lib/config/cpp/data_def.h Thu Feb 18 14:11:43 2010
@@ -30,7 +30,7 @@
     /// what() there
     class ModuleSpecError : public std::exception {
     public:
-        ModuleSpecError(std::string m = "Data definition is invalid") : msg(m) {}
+        ModuleSpecError(std::string m = "Module specification is invalid") : msg(m) {}
         ~ModuleSpecError() throw() {}
         const char* what() const throw() { return msg.c_str(); }
     private:
@@ -53,38 +53,52 @@
         /// Create a \c ModuleSpec instance with the given data as
         /// the specification
         /// \param e The Element containing the data specification
-        explicit ModuleSpec(ElementPtr e) : definition(e) {};
+        explicit ModuleSpec(ElementPtr e) : module_specification(e) {};
 
         /// Creates a \c ModuleSpec instance from the contents
         /// of the file given by file_name.
-        /// If check is true, and the definition is not of the correct
-        /// form, a ModuleSpecError is thrown. If the file could
-        /// not be parse, a ParseError is thrown.
+        /// If check is true, and the module specification is not of
+        /// the correct form, a ModuleSpecError is thrown. If the file
+        /// could not be parse, a ParseError is thrown.
         /// \param file_name The file to be opened and parsed
-        /// \param check If true, the data definition in the file is
-        /// checked to be of the correct form
+        /// \param check If true, the module specification in the file
+        /// is checked to be of the correct form
         ModuleSpec(const std::string& file_name, const bool check = true)
                        throw(ParseError, ModuleSpecError);
 
-        // todo: make check default false, or leave out option completely and always check?
         /// Creates a \c ModuleSpec instance from the given input
         /// stream that contains the contents of a .spec file.
-        /// If check is true, and the definition is not of
+        /// If check is true, and the module specification is not of
         /// the correct form, a ModuleSpecError is thrown. If the
         /// file could not be parsed, a ParseError is thrown.
         /// \param in The std::istream containing the .spec file data
-        /// \param check If true, the data definition is checked to be
-        /// of the correct form
+        /// \param check If true, the module specification is checked
+        /// to be of the correct form
         explicit ModuleSpec(std::istream& in, const bool check = true)
                                 throw(ParseError, ModuleSpecError);
 
-        /// Returns the base \c element of the data definition contained
-        /// by this instance
-        /// \return ElementPtr Shared pointer to the data definition
-        const ElementPtr getDefinition() { return definition; };
+        /// Returns the commands part of the specification as an
+        /// ElementPtr, returns an empty ElementPtr if there is none
+        /// \return ElementPtr Shared pointer to the commands
+        ///                    part of the specification
+        const ElementPtr getCommandsSpec();
+
+        /// Returns the configuration part of the specification as an
+        /// ElementPtr
+        /// \return ElementPtr Shared pointer to the configuration
+        ///                    part of the specification
+        const ElementPtr getConfigSpec();
+
+        /// Returns the full module specification as an ElementPtr
+        /// \return ElementPtr Shared pointer to the specification
+        const ElementPtr getFullSpec() { return module_specification; };
+
+        /// Returns the module name as specified by the specification
+        const std::string getModuleName();
+        
         // returns true if the given element conforms to this data
-        // definition scheme
-        /// Validates the given data for this specification.
+        // configuration specification
+        /// Validates the given configuration data for this specification.
         /// \param data The base \c Element of the data to check
         /// \return true if the data conforms to the specification,
         /// false otherwise.
@@ -95,7 +109,7 @@
         bool validate_spec(const ElementPtr spec, const ElementPtr data);
         bool validate_spec_list(const ElementPtr spec, const ElementPtr data);
 
-        ElementPtr definition;
+        ElementPtr module_specification;
     };
 
 } }

Modified: branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc
==============================================================================
--- branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc (original)
+++ branches/jelte-configuration/src/lib/config/cpp/data_def_unittests.cc Thu Feb 18 14:11:43 2010
@@ -47,11 +47,11 @@
     // Tests whether we can open specfiles and if we get the
     // right parse errors
     ModuleSpec dd = ModuleSpec(specfile("spec1.spec"));
-    EXPECT_EQ(dd.getDefinition()->get("module_spec")
+    EXPECT_EQ(dd.getFullSpec()->get("module_spec")
                                 ->get("module_name")
                                 ->stringValue(), "Spec1");
     dd = ModuleSpec(specfile("spec2.spec"));
-    EXPECT_EQ(dd.getDefinition()->get("module_spec")
+    EXPECT_EQ(dd.getFullSpec()->get("module_spec")
                                 ->get("config_data")->size(), 6);
     data_def_error("doesnotexist",
                    "Error opening ",
@@ -61,7 +61,7 @@
     std::ifstream file;
     file.open(specfile("spec1.spec").c_str());
     dd = ModuleSpec(file);
-    EXPECT_EQ(dd.getDefinition()->get("module_spec")
+    EXPECT_EQ(dd.getFullSpec()->get("module_spec")
                                 ->get("module_name")
                                 ->stringValue(), "Spec1");
 }




More information about the bind10-changes mailing list