Ensure that there are always more hosts addresses than any other option
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Fri, 30 Sep 2011 00:49:36 +0000 (21:49 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Fri, 30 Sep 2011 00:49:48 +0000 (21:49 -0300)
- in other works, it is not allowed to have [host] without "name" option
- here is the assertions, but the treatment must be provided in a higher layer

src/config/option/hostpingintervaloption.cpp
src/config/option/hostpingprotocoloption.cpp
src/config/option/hostportoption.cpp

index a5bf64e..b65ed83 100644 (file)
@@ -61,18 +61,23 @@ bool HostPingIntervalOption::parse(
         Configuration *configuration
 )
 {
-    size_t hosts_interval_count = 0;
     size_t hosts_count = 0;
+    size_t hosts_intervals_count = 0;
     bool parsed_success = false;
 
     // [host] interval
-    if ( vm.count( get_command_string() ) > 0 )
+    if ( 1 <= vm.count( get_command_string() ) )
     {
         HostList hosts_list = configuration->get_hosts();
         HostList::iterator hosts_list_iterator = hosts_list.begin();
+        hosts_count = hosts_list.size();
+
+        vector<int> hosts_intervals_list = vm[ get_command_string() ].as< vector<int> >();
+        hosts_intervals_count = hosts_intervals_list.size();
 
-        vector<int> hosts_intervals = vm[ get_command_string() ].as< vector<int> >();
-        BOOST_FOREACH( int host_interval_in_sec, hosts_intervals )
+        BOOST_ASSERT( hosts_count >= hosts_intervals_count );
+
+        BOOST_FOREACH( int host_interval_in_sec, hosts_intervals_list )
         {
             BOOST_ASSERT( 0 < host_interval_in_sec );
 
@@ -84,18 +89,16 @@ bool HostPingIntervalOption::parse(
                     << host_interval_in_sec << endl;
         }
 
-        hosts_interval_count = hosts_intervals.size();
-        hosts_count = hosts_list.size();
         parsed_success = true;
     }
 
-    set_hosts_count( hosts_interval_count );
+    set_hosts_count( hosts_intervals_count );
 
     // TODO receive the host_down_limit by parameter, use a std::map to find this configuration inside the Options container
     // TODO BOOST_ASSERT( hosts_names_count >= static_cast<size_t>( host_down_limit ) );
 //    BOOST_ASSERT( hosts_names_count == host_port_count );
 //    BOOST_ASSERT( hosts_names_count == host_ping_protocol_count );
-    BOOST_ASSERT( hosts_count == hosts_interval_count );
+    BOOST_ASSERT( hosts_count == hosts_intervals_count );
 
     return parsed_success;
 }
index 8b6af41..553b14a 100644 (file)
@@ -61,18 +61,23 @@ bool HostPingProtocolOption::parse(
         Configuration *configuration
 )
 {
-    size_t host_ping_protocol_count = 0;
     size_t hosts_count = 0;
+    size_t hosts_protocols_count = 0;
     bool parsed_success = false;
 
     // [host] ping-protocol
-    if ( vm.count( get_command_string() ) > 0 )
+    if ( 1 <= vm.count( get_command_string() ) )
     {
         HostList hosts_list = configuration->get_hosts();
         HostList::iterator hosts_list_iterator = hosts_list.begin();
+        hosts_count = hosts_list.size();
+
+        vector<string> hosts_protocols_list = vm[ get_command_string() ].as< vector<string> >();
+        hosts_protocols_count = hosts_protocols_list.size();
 
-        vector<string> hosts_protocols = vm[ get_command_string() ].as< vector<string> >();
-        BOOST_FOREACH( string protocol_string, hosts_protocols )
+        BOOST_ASSERT( hosts_count >= hosts_protocols_count );
+
+        BOOST_FOREACH( string protocol_string, hosts_protocols_list )
         {
             BOOST_ASSERT( !protocol_string.empty() );
 
@@ -85,17 +90,15 @@ bool HostPingProtocolOption::parse(
                     << protocol_string << endl;
         }
 
-        host_ping_protocol_count = hosts_protocols.size();
-        hosts_count = hosts_list.size();
         parsed_success = true;
     }
 
-    set_hosts_count( host_ping_protocol_count );
+    set_hosts_count( hosts_protocols_count );
 
     // TODO receive the host_down_limit by parameter, use a std::map to find this configuration inside the Options container
     // TODO BOOST_ASSERT( hosts_names_count >= static_cast<size_t>( host_down_limit ) );
 //    BOOST_ASSERT( hosts_names_count == host_port_count );
-    BOOST_ASSERT( hosts_count == host_ping_protocol_count );
+    BOOST_ASSERT( hosts_count == hosts_protocols_count );
 //    BOOST_ASSERT( hosts_names_count == hosts_interval_count );
 
     return parsed_success;
index 2fec26a..5d68ebd 100644 (file)
@@ -62,18 +62,23 @@ bool HostPortOption::parse(
         Configuration *configuration
 )
 {
-    size_t host_port_count = 0;
     size_t hosts_count = 0;
+    size_t hosts_ports_count = 0;
     bool parsed_success = false;
 
     // [host] port
-    if ( vm.count( get_command_string() ) > 0 )
+    if ( 1 <= vm.count( get_command_string() ) )
     {
         HostList hosts_list = configuration->get_hosts();
         HostList::iterator hosts_list_iterator = hosts_list.begin();
+        hosts_count = hosts_list.size();
+
+        vector<int> hosts_ports_list = vm[ get_command_string() ].as< vector<int> >();
+        hosts_ports_count = hosts_ports_list.size();
 
-        vector<int> hosts_ports = vm[ get_command_string() ].as< vector<int> >();
-        BOOST_FOREACH( int host_port, hosts_ports )
+        BOOST_ASSERT( hosts_count >= hosts_ports_count );
+
+        BOOST_FOREACH( int host_port, hosts_ports_list )
         {
             BOOST_ASSERT( ( 0 <= host_port ) && ( host_port <= numeric_limits<uint16_t>::max() ) );
 
@@ -84,16 +89,14 @@ bool HostPortOption::parse(
             GlobalLogger.info() <<  get_command_string() << "=" << host_port << endl;
         }
 
-        host_port_count = hosts_ports.size();
-        hosts_count = hosts_list.size();
         parsed_success = true;
     }
 
-    set_hosts_count( host_port_count );
+    set_hosts_count( hosts_ports_count );
 
     // TODO receive the host_down_limit by parameter, use a std::map to find this configuration inside the Options container
     // TODO BOOST_ASSERT( hosts_names_count >= static_cast<size_t>( host_down_limit ) );
-    BOOST_ASSERT( hosts_count == host_port_count );
+    BOOST_ASSERT( hosts_count == hosts_ports_count );
 //    BOOST_ASSERT( hosts_names_count == host_ping_protocol_count );
 //    BOOST_ASSERT( hosts_names_count == hosts_interval_count );